def getGlyphsFromString(self): self.glyphName2Glyph = {} string = "" for e in self.mainInputString: string += self.leftInputString string += e string += self.rightInputString txt = splitText(string, self.ui.font.naked().unicodeData) self.text = txt for glyphName in txt: if glyphName in self.glyphName2Glyph: continue if glyphName in self.ui.font.keys(): glyph = self.ui.font[glyphName].copy() glyph = self.decomposeGlyph(glyph) self.glyphName2Glyph[glyphName] = glyph
def drawBackground(self, info): u"""Draw the background of defined glyphs and fonbts. Scale is available as mouse.scale.""" view = self.getView() if not view.viewEnabled.get(): return fill = getExtensionDefault(self.DEFAULTKEY_FILL, True) stroke = getExtensionDefault(self.DEFAULTKEY_STROKE, True) fillcolor = getExtensionDefaultColor(self.DEFAULTKEY_FILLCOLOR, self.FALLBACK_FILLCOLOR) glyph = info.get('glyph') if glyph is not None: current = glyph.font else: current = self.tool.getCurrentFont() if glyph is None or current is None: return align = self.getAlignment() # Get the fonts from the list and see if they are selected. sourceItems = self.getSourceFonts() showFonts = [] for item in sourceItems: if not item['status']: continue path = item['path'] font = self.getHiddenFont(path) showFonts.append(font) if view.viewCurrent.get() and current not in showFonts: showFonts.append(current) for font in showFonts: self.fillColor.setFill() self.strokeColor.setStroke() contextBefore, contextCurrent, contextAfter = self.getContexts() if font is not None: contextBefore = splitText(contextBefore, TX.naked(font).unicodeData, TX.naked(font).groups) contextBefore = [ font[gname] for gname in contextBefore if gname in font.keys() ] contextAfter = splitText(contextAfter, TX.naked(font).unicodeData, TX.naked(font).groups) contextAfter = [ font[gname] for gname in contextAfter if gname in font.keys() ] contextCurrent = splitText(contextCurrent, TX.naked(font).unicodeData, TX.naked(font).groups) if len(contextCurrent) > 0: contextCurrent = [ font[gname] for gname in [contextCurrent[0]] if gname in font.keys() ] if len(contextCurrent) > 0: sourceGlyph = contextCurrent[0] else: sourceGlyph = None elif glyph.name in font.keys(): sourceGlyph = font[glyph.name] else: sourceGlyph = None """ #There is an experimental feature that will change the case of the context characters based on the case of the current glyph. But I'm disabling that for now. if view.contextUandlc.get(): caseTransform = None if self.isUpper(glyph): caseTransform = FontTX.unicodes.getUpperFromLower elif self.isLower(glyph): caseTransform = FontTX.unicodes.getLowerFromUpper if caseTransform: for i, g in enumerate(contextBefore): newG = caseTransform(g) if newG is not None: contextBefore[i] = newG newG = caseTransform(sourceGlyph) if newG is not None: sourceGlyph = newG if caseTransform: for i, g in enumerate(contextAfter): newG = caseTransform(g) if newG is not None: contextAfter[i] = newG """ scale(current.info.unitsPerEm / float(font.info.unitsPerEm)) widthOffset = 0 if sourceGlyph is not None: if align == 'center': destCenter = float( glyph.width / 2) / current.info.unitsPerEm sourceCenter = float( sourceGlyph.width / 2) / font.info.unitsPerEm widthOffset = (destCenter - sourceCenter) * font.info.unitsPerEm elif align == 'right': widthOffset = ( (glyph.width / glyph.font.info.unitsPerEm) - (sourceGlyph.width / sourceGlyph.font.info.unitsPerEm) ) * font.info.unitsPerEm translate(widthOffset, 0) previousGlyph = sourceGlyph contextBefore.reverse() totalWidth = 0 for i, cbGlyph in enumerate(contextBefore): kernValue = 0 if previousGlyph is not None and previousGlyph.font == cbGlyph.font: # Uncomment to activate kerning. Requires FontTX. #kernValue += FontTX.kerning.getValue((previousGlyph.name, cbGlyph.name), font.kerning, font.groups) kernValue += 0 translate(-cbGlyph.width - kernValue, 0) totalWidth += cbGlyph.width + kernValue drawGlyphPath = TX.naked(cbGlyph).getRepresentation( "defconAppKit.NSBezierPath") if view.fill.get(): drawGlyphPath.fill() if view.stroke.get(): strokePixelPath(drawGlyphPath) previousGlyph = cbGlyph translate(totalWidth, 0) totalWidth = 0 contextCurrentAndAfter = [sourceGlyph] + contextAfter for i, cbGlyph in enumerate(contextCurrentAndAfter): if cbGlyph is None: cbGlyph = sourceGlyph nextGlyph = None if i + 1 < len(contextCurrentAndAfter): nextGlyph = contextCurrentAndAfter[i + 1] if (i == 0 and cbGlyph == glyph) or sourceGlyph is None: pass else: drawGlyphPath = TX.naked(cbGlyph).getRepresentation( "defconAppKit.NSBezierPath") if view.fill.get(): drawGlyphPath.fill() if view.stroke.get(): strokePixelPath(drawGlyphPath) kernValue = 0 if cbGlyph is not None and nextGlyph is not None and nextGlyph.font == cbGlyph.font: #kernValue = FontTX.kerning.getValue((cbGlyph.name, nextGlyph.name), font.kerning, font.groups) # Uncomment to activate kerning. Requires FontTX. kernValue = 0 width = 0 if cbGlyph is not None: width = cbGlyph.width translate(width + kernValue, 0) totalWidth += width + kernValue previousGlyph = cbGlyph translate(-totalWidth, 0) translate(-widthOffset, 0) scale(font.info.unitsPerEm / float(current.info.unitsPerEm))
def drawBackground(self, info): u"""Draw the background of defined glyphs and fonbts. Scale is available as mouse.scale.""" view = self.getView() if not view.viewEnabled.get(): return fill = getExtensionDefault(self.DEFAULTKEY_FILL, True) stroke = getExtensionDefault(self.DEFAULTKEY_STROKE, True) fillcolor = getExtensionDefaultColor(self.DEFAULTKEY_FILLCOLOR, self.FALLBACK_FILLCOLOR) glyph = info.get('glyph') if glyph is not None: current = glyph.getParent() else: current = self.tool.getCurrentFont() if glyph is None or current is None: return align = self.getAlignment() # Get the fonts from the list and see if they are selected. sourceItems = self.getSourceFonts() showFonts = [] for item in sourceItems: if not item['status']: continue path = item['path'] font = self.getHiddenFont(path) showFonts.append(font) if view.viewCurrent.get() and current not in showFonts: showFonts.append(current) for font in showFonts: self.fillColor.setFill() self.strokeColor.setStroke() contextBefore, contextCurrent, contextAfter = self.getContexts() if font is not None: contextBefore = splitText(contextBefore, TX.naked(font).unicodeData, TX.naked(font).groups) contextBefore = [font[gname] for gname in contextBefore if gname in font.keys()] contextAfter = splitText(contextAfter, TX.naked(font).unicodeData, TX.naked(font).groups) contextAfter = [font[gname] for gname in contextAfter if gname in font.keys()] contextCurrent = splitText(contextCurrent, TX.naked(font).unicodeData, TX.naked(font).groups) if len(contextCurrent) > 0: contextCurrent = [font[gname] for gname in [contextCurrent[0]] if gname in font.keys()] if len(contextCurrent) > 0: sourceGlyph = contextCurrent[0] else: sourceGlyph = None elif glyph.name in font.keys(): sourceGlyph = font[glyph.name] else: sourceGlyph = None """ #There is an experimental feature that will change the case of the context characters based on the case of the current glyph. But I'm disabling that for now. if view.contextUandlc.get(): caseTransform = None if self.isUpper(glyph): caseTransform = FontTX.unicodes.getUpperFromLower elif self.isLower(glyph): caseTransform = FontTX.unicodes.getLowerFromUpper if caseTransform: for i, g in enumerate(contextBefore): newG = caseTransform(g) if newG is not None: contextBefore[i] = newG newG = caseTransform(sourceGlyph) if newG is not None: sourceGlyph = newG if caseTransform: for i, g in enumerate(contextAfter): newG = caseTransform(g) if newG is not None: contextAfter[i] = newG """ scale(current.info.unitsPerEm/float(font.info.unitsPerEm)) widthOffset = 0 if sourceGlyph is not None: if align == 'center': destCenter = float(glyph.width/2) / current.info.unitsPerEm sourceCenter = float(sourceGlyph.width/2) / font.info.unitsPerEm widthOffset = (destCenter-sourceCenter) * font.info.unitsPerEm elif align == 'right': widthOffset = ( ( glyph.width / glyph.getParent().info.unitsPerEm ) - (sourceGlyph.width / sourceGlyph.getParent().info.unitsPerEm ) ) * font.info.unitsPerEm translate(widthOffset, 0) previousGlyph = sourceGlyph contextBefore.reverse() totalWidth = 0 for i, cbGlyph in enumerate(contextBefore): kernValue = 0 if previousGlyph is not None and previousGlyph.getParent() == cbGlyph.getParent(): # Uncomment to activate kerning. Requires FontTX. #kernValue += FontTX.kerning.getValue((previousGlyph.name, cbGlyph.name), font.kerning, font.groups) kernValue += 0 translate(-cbGlyph.width-kernValue, 0) totalWidth += cbGlyph.width + kernValue drawGlyphPath = TX.naked(cbGlyph).getRepresentation("defconAppKit.NSBezierPath") if view.fill.get(): drawGlyphPath.fill() if view.stroke.get(): strokePixelPath(drawGlyphPath) previousGlyph = cbGlyph translate(totalWidth, 0) totalWidth = 0 contextCurrentAndAfter = [sourceGlyph]+contextAfter for i, cbGlyph in enumerate(contextCurrentAndAfter): if cbGlyph is None: cbGlyph = sourceGlyph nextGlyph = None if i + 1 < len(contextCurrentAndAfter): nextGlyph = contextCurrentAndAfter[i+1] if (i == 0 and cbGlyph == glyph) or sourceGlyph is None: pass else: drawGlyphPath = TX.naked(cbGlyph).getRepresentation("defconAppKit.NSBezierPath") if view.fill.get(): drawGlyphPath.fill() if view.stroke.get(): strokePixelPath(drawGlyphPath) kernValue = 0 if cbGlyph is not None and nextGlyph is not None and nextGlyph.getParent() == cbGlyph.getParent(): #kernValue = FontTX.kerning.getValue((cbGlyph.name, nextGlyph.name), font.kerning, font.groups) # Uncomment to activate kerning. Requires FontTX. kernValue = 0 width = 0 if cbGlyph is not None: width = cbGlyph.width translate(width+kernValue, 0) totalWidth += width + kernValue previousGlyph = cbGlyph translate(-totalWidth, 0) translate(-widthOffset, 0) scale(font.info.unitsPerEm/float(current.info.unitsPerEm))