def process(self, stringOrGlyphList, script="latn", langSys=None, rightToLeft=False, case="unchanged", logger=None): if isinstance(stringOrGlyphList, basestring): stringOrGlyphList = self.stringToGlyphNames(stringOrGlyphList) if case != "unchanged": l = langSys if l is not None: l = l.strip() stringOrGlyphList = convertCase(case, stringOrGlyphList, self.cmap, self.reversedCMAP, l, self.fallbackGlyph) glyphRecords = self.glyphListToGlyphRecords(stringOrGlyphList) if rightToLeft: glyphRecords.reverse() if logger: logger.logStart() glyphNames = [r.glyphName for r in glyphRecords] logger.logMainSettings(glyphNames, script, langSys) if self.gsub is not None: if logger: logger.logTableStart(self.gsub) glyphRecords = self.gsub.process(glyphRecords, script=script, langSys=langSys, logger=logger) if logger: logger.logResults(glyphRecords) logger.logTableEnd() if self.gpos is not None: if logger: logger.logTableStart(self.gpos) glyphRecords = self.gpos.process(glyphRecords, script=script, langSys=langSys, logger=logger) if logger: logger.logResults(glyphRecords) logger.logTableEnd() if logger: logger.logEnd() return glyphRecords
def updateGlyphLineView(self): # get the settings settings = self.glyphLineControls.get() # set the display mode mode = settings["mode"] if mode == "preview": self.w.previewTabs.set(0) else: self.w.previewTabs.set(1) # set the direction self.glyphLineView.setRightToLeft(settings["rightToLeft"]) # get the typed glyphs glyphs = self.glyphLineInput.get() # set into the view case = settings["case"] if self.featureFont is None: # convert case if case != "unchanged": # the case converter expects a slightly # more strict set of mappings than the # ones provided in font.unicodeData. # so, make them. cmap = {} reversedCMAP = {} for uniValue, glyphName in self.font.unicodeData.items(): cmap[uniValue] = glyphName[0] reversedCMAP[glyphName[0]] = [uniValue] # transform to glyph names glyphNames = [glyph.name for glyph in glyphs] # convert glyphNames = convertCase(case, glyphNames, cmap, reversedCMAP, None, ".notdef") # back to glyphs glyphs = [self.font[glyphName] for glyphName in glyphNames if glyphName in self.font] # set the glyphs self.glyphLineView.set(glyphs) records = [dict(Name=glyph.name, XP=0, YP=0, XA=0, YA=0, Alternates="") for glyph in glyphs] self.glyphRecordsList.set(records) else: # get the settings script = settings["script"] language = settings["language"] rightToLeft = settings["rightToLeft"] case = settings["case"] for tag, state in settings["gsub"].items(): self.featureFont.gsub.setFeatureState(tag, state) for tag, state in settings["gpos"].items(): self.featureFont.gpos.setFeatureState(tag, state) # convert to glyph names glyphNames = [glyph.name for glyph in glyphs] # process glyphRecords = self.featureFont.process(glyphNames, script=script, langSys=language, rightToLeft=rightToLeft, case=case) # set the UFO's glyphs into the records finalRecords = [] for glyphRecord in glyphRecords: if glyphRecord.glyphName not in self.font: continue glyphRecord.glyph = self.font[glyphRecord.glyphName] finalRecords.append(glyphRecord) # set the records self.glyphLineView.set(finalRecords) records = [dict(Name=record.glyph.name, XP=record.xPlacement, YP=record.yPlacement, XA=record.xAdvance, YA=record.yAdvance, Alternates=", ".join(record.alternates)) for record in finalRecords] self.glyphRecordsList.set(records)