inserting glyph with specific unicode value

RoboFont Forums Help / General inserting glyph with specific unicode value

This topic contains 3 replies, has 2 voices, and was last updated by  frederik 6 years, 4 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #5895

    luke
    Member

    i would like to append a certain glyph with a specific unicode value –
    g.autoUnicodes()
    unfortunately did not work, because of the glyph name I guess.
    i also tried
    g.unicode = 0302
    without success.

    i am using this line to append a glyph.

    font.insertGlyph(g, glyphName)

    thanks in advance.

    #5896

    frederik
    Keymaster

    2 possible options:

    first check: when inserting a glyph and the glyph name is already in the font, all unicodes are removed, duplicates are not allowed

    secondly: when setting a unicode it must be the integer value of the hex value

    unicodeValueHex = "0302"
    print int(unicodeValueHex, 16)
    

    g.autoUnicodes() only works when the glyph name is in the from fontTools.agl import AGL2UV dict,
    FYI in the next version its is possible to set your own agl (adobe glyph list) in the prefs

    #5897

    luke
    Member

    thank you – works fine!

    just for better understanding

     int(unicodeValueHex, 16) 

    16 is some kind of general conversion factor? sorry – bad at maths today.

    if I print

    from fontTools.agl import AGL2UV

    I get the glyphNames and the hex value of the unicodes, right?

    can you help with a line of code for converting the hex value back the actual unicode value?

    #5898

    frederik
    Keymaster

    A unicode value is a hexadecimal number (using 0123456789ABCDEF) that makes it base 16. In a glyph object a unicode value is stored as a decimal (base 10) so you have to convert it, an option is to use int("FFFF", 16).

    The values in the AGL2UV dictionary are already decimal numbers as you need to put into glyph.unicode

    if you want to convert a decimal number back to the hex value: "%X" % 255

    good luck

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.