def create_glyph(codepoint, width, contours): glyph = Glyph() glyph.name = get_glyph_name(codepoint) glyph.unicode = ord(codepoint) glyph.width = width for contour in contours: glyph.appendContour(contour) return glyph
def getGlyphFromDict(glyph_dict): g = Glyph() # Set attributes g.height = glyph_dict.get('height', 0) g.lib = glyph_dict.get('lib', {}) g.name = glyph_dict.get('name', '') g.note = glyph_dict.get('note', None) g.unicode = glyph_dict.get('unicode', None) g.unicodes = glyph_dict.get('unicodes', []) g.width = glyph_dict.get('width', 0) # Draw the outlines with a pen pen = g.getPointPen() for contour in glyph_dict.get('contours', []): pen.beginPath() for point in contour: pen.addPoint( ( point.get('x'), point.get('y') ), segmentType = point.get('type', None), name = point.get('name', None), smooth = point.get('smooth', None), ) pen.endPath() # Add components for component in glyph_dict.get('components', []): c = Component() c.baseGlyph = component.get('ref', '') c.transformation = component.get('transformation', (1, 0, 0, 1, 0, 0)) g.appendComponent(c) # Add anchors for anchor in glyph_dict.get('anchors', []): a = Anchor(anchorDict = anchor) g.appendAnchor(a) # Return the completed glyph object return g
def createGlyphs(self): self.UFO.newGlyph('.notdef') missing = '' for glf in self.GDB.Master2Search: glfUnicode = int(self.GDB.Master2Unicode[glf], 16) print('') layer = 0 stopAt = 'arAlef.fina.la' glfSrc = self.GDB.Master2Search[glf].split(',') if glf == stopAt: m = 1 log = (glf + ' ' * 50)[0:20] if glf in self.GDB.MAPPING: try: mgName = [self.GDB.MAPPING[glf]] glyph = Glyph() glyph.copyDataFromGlyph(self.srcUFO[mgName[0]]) glyph.name = glf if layer == 0: glyph.unicode = glfUnicode glyph.unicodes = [glfUnicode] else: glyph.unicode = None glyph.anchors = [] glyph.decomposeAllComponents() if layer > 0: currentLayer = self.getLayer(layer) currentLayer.insertGlyph(glyph) else: self.UFO.insertGlyph(glyph) layer += 1 # print(g + ' found :)' + ' L ' + str(layer)) gLog = log + (mgName[0] + ' ' * 50)[0:20] print(gLog + '[' + str(layer) + '] *') except: pass for g in glfSrc: mgName = None gCode = None gLog = log + (g + ' ' * 50)[0:20] try: try: gCode = self.GDB.Prod2Decimal[g] mgName = self.srcUFO.unicodeData[gCode] except: try: mgName = [g] except: pass glyph = Glyph() glyph.copyDataFromGlyph(self.srcUFO[mgName[0]]) glyph.name = glf if layer == 0: glyph.unicode = glfUnicode glyph.unicodes = [glfUnicode] else: glyph.unicode = None glyph.anchors = [] glyph.decomposeAllComponents() if layer > 0: currentLayer = self.getLayer(layer) currentLayer.insertGlyph(glyph) else: self.UFO.insertGlyph(glyph) layer += 1 print(gLog + '[' + str(layer) + ']') except: print(gLog + '[ ]') glyph = None if layer == 0: self.UFO.newGlyph(glf) missing += log + "\n" if len(missing) > 1: print('\n') print('=' * 60) print('Missing glyphes ' + str(len(missing.splitlines()))) print('=' * 60) print(missing) print('=' * 60)