SOLVED Strings into Names



  • Hi, I'm working on extension that will perform some operations on strings.

    My question is:
    Is there any way to translate python string object into list of nice names, that later I could use for calling glyphs with those names (with CurrentFont()['name'])?

    Thanks in advance for your help :)



  • hi Rafał,

    if I understand it correctly, you wish to convert a unicode string into PostScript names?

    if so, try this out:

    from fontTools.agl import UV2AGL
    
    myText = "héllø"
    myText = myText.decode("utf-8")
    
    f = CurrentFont()
    
    for char in myText:
        uni = ord(char)
        glyphName = UV2AGL.get(uni)
        if glyphName and glyphName in f:
            print f[glyphName]
    

    based on this example

    let us know if it works!



  • @gferreira
    Thanks!
    Works perfectly!



  • hi Rafał,

    if I understand it correctly, you wish to convert a unicode string into PostScript names?

    if so, try this out:

    from fontTools.agl import UV2AGL
    
    myText = "héllø"
    myText = myText.decode("utf-8")
    
    f = CurrentFont()
    
    for char in myText:
        uni = ord(char)
        glyphName = UV2AGL.get(uni)
        if glyphName and glyphName in f:
            print f[glyphName]
    

    based on this example

    let us know if it works!