|
| 1 | +from mojo.roboFont import * |
| 2 | + |
| 3 | +list_of_fonts = AllFonts() |
| 4 | + |
| 5 | +font_PTsans = list_of_fonts.getFontsByFamilyNameStyleName( 'PT Sans', 'Regular' ) |
| 6 | +font_MYfont = list_of_fonts.getFontsByFamilyNameStyleName( 'MY FONT NAME', 'Regular' ) |
| 7 | + |
| 8 | +def getUnicodeByNameGlyph(font, glyphname): |
| 9 | + return font[glyphname].unicode |
| 10 | + |
| 11 | +def getNameGlyphByUnicode(font, ucode): |
| 12 | + dic = font.getCharacterMapping() |
| 13 | + return dic[ucode][0] |
| 14 | + |
| 15 | +for glyphPT in font_PTsans: |
| 16 | + if len( glyphPT.components ) != 0: |
| 17 | + name_Of_New_Glyph = glyphPT.name |
| 18 | + font_MYfont.newGlyph( name_Of_New_Glyph ) |
| 19 | + font_MYfont[name_Of_New_Glyph].width = 500 |
| 20 | + for index, component in enumerate(glyphPT.components): |
| 21 | + PT_baseGlyph = component.baseGlyph |
| 22 | + PT_unicode_component = getUnicodeByNameGlyph( font_PTsans , PT_baseGlyph ) |
| 23 | + if PT_unicode_component != None: |
| 24 | + MY_component_name = getNameGlyphByUnicode(font_MYfont, PT_unicode_component ) |
| 25 | + xmin, ymin, xmax, ymin = glyphPT.box |
| 26 | + offsetX = (xmax - xmin)/2 |
| 27 | + font_MYfont[name_Of_New_Glyph].appendComponent( MY_component_name ) |
| 28 | + if index == 0: |
| 29 | + font_MYfont[name_Of_New_Glyph].leftMargin = font_MYfont[MY_component_name].leftMargin |
| 30 | + font_MYfont[name_Of_New_Glyph].rightMargin = font_MYfont[MY_component_name].rightMargin |
| 31 | + else: |
| 32 | + Xmove = (font_MYfont[name_Of_New_Glyph].width /2) - offsetX + font_MYfont[name_Of_New_Glyph].leftMargin |
| 33 | + |
| 34 | + font_MYfont[name_Of_New_Glyph].components[index].move((Xmove,0)) |
| 35 | + font_MYfont[name_Of_New_Glyph].mark = (0, 0.3, 0, 0.25) |
| 36 | + |
| 37 | + |
| 38 | + |
0 commit comments