def _drawNeighborsGlyphs(self, glyph, stroke=True, scale=1): if glyph is None: return font = glyph.getParent() baseName = self.getBaseGlyph(glyph.name) left, right = RamsayStData.get(baseName, ("n", "n")) if left in font: leftGlyph = font[left] save() # translate back the width of the glyph translate(-leftGlyph.width, 0) # performance tricks, the naked attr will return the defcon object # and get the cached bezier path to draw path = leftGlyph.naked().getRepresentation("defconAppKit.NSBezierPath") # fill the path path.fill() if stroke: path.setLineWidth_(scale) strokePixelPath(path) restore() # do the same for the other glyph if right in font: rightGlyph = font[right] save() # translate forward the width of the current glyph translate(glyph.width, 0) path = rightGlyph.naked().getRepresentation("defconAppKit.NSBezierPath") path.fill() if stroke: path.setLineWidth_(scale) strokePixelPath(path) restore()
def drawPoints(self, glyph, scale): save() _onCurveSize = self._onCurvePointsSize * scale _offCurveSize = self._offCurvePointsSize * scale _strokeWidth = self._strokeWidth * scale self._pointsColor.set() path = NSBezierPath.bezierPath() offCurveHandlesPath = NSBezierPath.bezierPath() pointsData = glyph.getRepresentation("doodle.OutlineInformation") for point1, point2 in pointsData["bezierHandles"]: offCurveHandlesPath.moveToPoint_(point1) offCurveHandlesPath.lineToPoint_(point2) for point in pointsData.get("offCurvePoints"): (x, y) = point["point"] path.appendBezierPathWithOvalInRect_(NSMakeRect(x - _offCurveSize, y - _offCurveSize, _offCurveSize * 2, _offCurveSize * 2)) for point in pointsData.get("onCurvePoints"): (x, y) = point["point"] path.appendBezierPathWithRect_(NSMakeRect(x - _onCurveSize, y - _onCurveSize, _onCurveSize * 2, _onCurveSize * 2)) path.fill() offCurveHandlesPath.setLineWidth_(_strokeWidth) strokePixelPath(offCurveHandlesPath) restore()
def draw(self, scale): ## draw stuff in the current glyph view if self.isDragging() and self.minPoint and self.maxPoint: ## draw only during drag and when recorded some rect ## make the rect x, y, w, h = self.getRect() rect = NSMakeRect(x, y, w, h) ## set the color NSColor.redColor().set() if self.shape == "rect": ## create a rect path path = NSBezierPath.bezierPathWithRect_(rect) elif self.shape == "oval": ## create a oval path path = NSBezierPath.bezierPathWithOvalInRect_(rect) if self.origin == "center": ## draw a cross hair at the center point crossHairLength = 3 * scale ## get the center of the rectangle centerX = x + w * .5 centerY = y + h * .5 path.moveToPoint_((centerX, centerY - crossHairLength)) path.lineToPoint_((centerX, centerY + crossHairLength)) path.moveToPoint_((centerX - crossHairLength, centerY)) path.lineToPoint_((centerX + crossHairLength, centerY)) ## set the line width path.setLineWidth_(scale) ## draw without anti-alias strokePixelPath(path)
def _drawLeftNeighborsGlyphs(self, glyph, stroke=True, scale=1): if glyph is None: return font = glyph.font left = self.view.unicodeLeftEditText.get() left = self.stringToGlyphs(left, font) save() for index, leftGlyph in enumerate(reversed(list(left))): if leftGlyph in font: leftGlyph = font[leftGlyph] # translate back the width of the glyph translate(-leftGlyph.width, 0) # performance tricks, the naked attr will return the defcon object # and get the cached bezier path to draw path = leftGlyph.naked().getRepresentation( "defconAppKit.NSBezierPath") # fill the path path.fill() if stroke: path.setLineWidth_(scale) strokePixelPath(path) restore()
def _drawNeighborsGlyphs(self, glyph, stroke=True, scale=1): if glyph is None: return font = glyph.font baseName = self.getBaseGlyph(glyph.name) left, right = RamsayStData.get(baseName, ("n", "n")) if left in font: leftGlyph = font[left] save() # translate back the width of the glyph translate(-leftGlyph.width, 0) # performance tricks, the naked attr will return the defcon object # and get the cached bezier path to draw path = leftGlyph.naked().getRepresentation("defconAppKit.NSBezierPath") # fill the path path.fill() if stroke: path.setLineWidth_(scale) strokePixelPath(path) restore() # do the same for the other glyph if right in font: rightGlyph = font[right] save() # translate forward the width of the current glyph translate(glyph.width, 0) path = rightGlyph.naked().getRepresentation("defconAppKit.NSBezierPath") path.fill() if stroke: path.setLineWidth_(scale) strokePixelPath(path) restore()
def _drawRightNeighborsGlyphs(self, glyph, stroke=True, scale=1): if glyph is None: return font = glyph.font # left = self.view.unicodeLeftEditText.get() right = self.view.unicodeRightEditText.get() # right = self.rightInput right = self.stringToGlyphs(right, font) save() for index, rightGlyph in enumerate(list(right)): if rightGlyph in font: rightGlyph = font[rightGlyph] # translate back the width of the glyph if index == 0: translate(glyph.width, 0) else: translate(font[list(right)[index - 1]].width, 0) # performance tricks, the naked attr will return the defcon object # and get the cached bezier path to draw path = rightGlyph.naked().getRepresentation( "defconAppKit.NSBezierPath") # fill the path path.fill() if stroke: path.setLineWidth_(scale) strokePixelPath(path) restore()
def drawGlyph(self, info={}, stroke=True, fill=True): glyph = self.getSource() translate(self.offset[0], self.offset[1]) scale(self.scale[0], self.scale[1]) drawGlyphPath = TX.naked(glyph).getRepresentation("defconAppKit.NSBezierPath") if fill: drawGlyphPath.fill() if stroke: strokePixelPath(drawGlyphPath) translate(-self.offset[0], -self.offset[1]) scale(1/float(self.scale[0]), 1/float(self.scale[1]))
def drawGlyph(self, info={}, stroke=True, fill=True): glyph = self.getSource() translate(self.offset[0], self.offset[1]) scale(self.scale[0], self.scale[1]) drawGlyphPath = TX.naked(glyph).getRepresentation( "defconAppKit.NSBezierPath") if fill: drawGlyphPath.fill() if stroke: strokePixelPath(drawGlyphPath) translate(-self.offset[0], -self.offset[1]) scale(1 / float(self.scale[0]), 1 / float(self.scale[1]))
def draw(self, scale): ## draw stuff in the current glyph view if self.isDragging() and self.minPoint and self.maxPoint: ## draw only during drag and when recorded some rect ## make the rect x, y, w, h = self.getRect() rect = NSMakeRect(x, y, w, h) ## set the color NSColor.redColor().set() if self.shape == "rect": ## create a rect path path = NSBezierPath.bezierPathWithRect_(rect) elif self.shape == "oval": ## create a oval path path = NSBezierPath.bezierPathWithOvalInRect_(rect) ## set the line width path.setLineWidth_(scale) ## draw without anit-alias strokePixelPath(path)
def draw(self, info): if not self._drawing: return glyph = info.get("glyph") drawingScale = info.get('scale') if glyph is None: return current = glyph.getParent() fonts = self.getActiveFonts() for font in fonts: nakedFont = font.naked() contextLeft, contextCurrent, contextRight = self.getContexts() contextLeft = splitText(contextLeft or '', nakedFont.unicodeData or '') contextLeft = [font[gname] for gname in contextLeft if gname in font.keys()] contextRight = splitText(contextRight or '', nakedFont.unicodeData or '') contextRight = [font[gname] for gname in contextRight if gname in font.keys()] contextCurrent = splitText(contextCurrent or '', nakedFont.unicodeData or '') 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] contextCurrent = [sourceGlyph] else: sourceGlyph = None contextCurrent = [] save() self._fillColor.setFill() self._strokeColor.setStroke() scale(current.info.unitsPerEm/float(font.info.unitsPerEm)) # Draw left context previousGlyph = sourceGlyph contextLeft.reverse() totalWidth = 0 for i, cbGlyph in enumerate(contextLeft): kernValue = self.getKernValue(nakedFont, cbGlyph, previousGlyph) # right to left translate(-cbGlyph.width-kernValue, 0) totalWidth += cbGlyph.width + kernValue glyphBezierPath = cbGlyph.naked().getRepresentation("defconAppKit.NSBezierPath") if self._fill: glyphBezierPath.fill() if self._stroke: glyphBezierPath.setLineWidth_(self._strokeWidth*drawingScale) strokePixelPath(glyphBezierPath) previousGlyph = cbGlyph translate(totalWidth, 0) # Draw current context or current glyph if contextCurrent: previousGlyph = None alignment = self.getAlignment() if alignment == 'left': offset = 0 elif alignment == 'center': offset = (glyph.width - contextCurrent[0].width)/2 elif alignment == 'right': offset = glyph.width - contextCurrent[0].width totalWidth = offset translate(totalWidth, 0) for i, cbGlyph in enumerate(contextCurrent): #if cbGlyph == glyph: # continue # Don't show if is current glyph kernValue = self.getKernValue(nakedFont, previousGlyph, cbGlyph) translate(kernValue, 0) glyphBezierPath = cbGlyph.naked().getRepresentation("defconAppKit.NSBezierPath") if self._fill: glyphBezierPath.fill() if self._stroke: glyphBezierPath.setLineWidth_(self._strokeWidth*drawingScale) strokePixelPath(glyphBezierPath) if self._points: self.drawPoints(cbGlyph, info['scale']) translate(cbGlyph.width, 0) totalWidth += cbGlyph.width + kernValue previousGlyph = cbGlyph translate(-totalWidth, 0) # Draw right context translate(glyph.width) totalWidth = glyph.width for i, cbGlyph in enumerate(contextRight): kernValue = self.getKernValue(nakedFont, previousGlyph, cbGlyph) translate(kernValue, 0) glyphBezierPath = cbGlyph.naked().getRepresentation("defconAppKit.NSBezierPath") if self._fill: glyphBezierPath.fill() if self._stroke: glyphBezierPath.setLineWidth_(self._strokeWidth*drawingScale) strokePixelPath(glyphBezierPath) translate(cbGlyph.width, 0) totalWidth += cbGlyph.width + kernValue previousGlyph = cbGlyph restore()
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))