Skip to content

Commit 79d8dc0

Browse files
andyclymertypemytype
authored andcommittedOct 9, 2019
Moving commits, adding the ability to set stroke color and cutoff sizes for drawing attributes in the glyphLineView (#33)
1 parent c4e89dc commit 79d8dc0

File tree

2 files changed

+51
-16
lines changed

2 files changed

+51
-16
lines changed
 

‎Lib/defconAppKit/controls/glyphLineView.py

+43-10
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,22 @@ def init(self):
4444
self._upm = 1000
4545
self._descender = -250
4646
self._bufferLeft = self._bufferRight = self._bufferBottom = self._bufferTop = 15
47+
48+
self._cutoffDisplayPointSizes = dict(
49+
showFontVerticalMetrics=150,
50+
showGlyphStartPoints=175,
51+
showGlyphOnCurvePoints=175,
52+
showGlyphOffCurvePoints=175,
53+
showGlyphPointCoordinates=250,
54+
showGlyphAnchors=50
55+
)
4756

4857
self._fitToFrame = None
4958

5059
self._backgroundColor = NSColor.whiteColor()
5160
self._glyphColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 0, 1)
61+
self._strokeColor = None
62+
self._pointColor = None
5263
self._alternateHighlightColor = defaultAlternateHighlightColor
5364
self._notdefBackgroundColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(1, 0, 0, .25)
5465
return self
@@ -93,6 +104,14 @@ def setGlyphColor_(self, color):
93104
self._glyphColor = color
94105
self.setNeedsDisplay_(True)
95106

107+
def setStrokeColor_(self, color):
108+
self._strokeColor = color
109+
self.setNeedsDisplay_(True)
110+
111+
def setPointColor_(self, color):
112+
self._pointColor = color
113+
self.setNeedsDisplay_(True)
114+
96115
def setBackgroundColor_(self, color):
97116
self._backgroundColor = color
98117
self.setNeedsDisplay_(True)
@@ -133,7 +152,14 @@ def getDrawingAttribute_layerName_(self, attr, layerName):
133152
return self._fallbackDrawingAttributes.get(attr)
134153
d = self._layerDrawingAttributes.get(layerName, {})
135154
return d.get(attr)
136-
155+
156+
def setCutoffDisplayPointSizeAttribute_value_(self, attr, value):
157+
self._cutoffDisplayPointSizes[attr] = value
158+
self.setNeedsDisplay_(True)
159+
160+
def getCutoffDisplayPointSizeAttribute_(self, attr):
161+
return self._cutoffDisplayPointSizes.get(attr, None)
162+
137163
# ----------------
138164
# Frame Management
139165
# ----------------
@@ -319,7 +345,7 @@ def drawFamilyBlues(self, glyph, layerName, rect):
319345

320346
@python_method
321347
def drawVerticalMetrics(self, glyph, layerName, rect):
322-
drawText = self.getDrawingAttribute_layerName_("showFontVerticalMetricsTitles", layerName) and self._impliedPointSize > 150
348+
drawText = self.getDrawingAttribute_layerName_("showFontVerticalMetricsTitles", layerName) and self._impliedPointSize > self._cutoffDisplayPointSizes["showFontVerticalMetrics"]
323349
drawing.drawFontVerticalMetrics(glyph, self._inverseScale, rect, drawText=drawText, backgroundColor=self._backgroundColor, flipped=True)
324350

325351
@python_method
@@ -333,22 +359,29 @@ def drawFillAndStroke(self, glyph, layerName, rect):
333359
fillColor = None
334360
if not self._showLayers:
335361
fillColor = self._glyphColor
336-
drawing.drawGlyphFillAndStroke(glyph, self._inverseScale, rect, drawFill=showFill, drawStroke=showStroke, contourFillColor=fillColor, componentFillColor=fillColor, backgroundColor=self._backgroundColor)
362+
strokeColor = self._strokeColor
363+
drawing.drawGlyphFillAndStroke(glyph, self._inverseScale, rect, drawFill=showFill, drawStroke=showStroke, contourFillColor=fillColor, contourStrokeColor=strokeColor, componentFillColor=fillColor, backgroundColor=self._backgroundColor)
337364

338365
@python_method
339366
def drawPoints(self, glyph, layerName, rect):
340-
drawStartPoint = self.getDrawingAttribute_layerName_("showGlyphStartPoints", layerName) and self._impliedPointSize > 175
341-
drawOnCurves = self.getDrawingAttribute_layerName_("showGlyphOnCurvePoints", layerName) and self._impliedPointSize > 175
342-
drawOffCurves = self.getDrawingAttribute_layerName_("showGlyphOffCurvePoints", layerName) and self._impliedPointSize > 175
343-
drawCoordinates = self.getDrawingAttribute_layerName_("showGlyphPointCoordinates", layerName) and self._impliedPointSize > 250
367+
drawStartPoint = self.getDrawingAttribute_layerName_("showGlyphStartPoints", layerName) and self._impliedPointSize > self._cutoffDisplayPointSizes["showGlyphStartPoints"]
368+
drawOnCurves = self.getDrawingAttribute_layerName_("showGlyphOnCurvePoints", layerName) and self._impliedPointSize > self._cutoffDisplayPointSizes["showGlyphOnCurvePoints"]
369+
drawOffCurves = self.getDrawingAttribute_layerName_("showGlyphOffCurvePoints", layerName) and self._impliedPointSize > self._cutoffDisplayPointSizes["showGlyphOffCurvePoints"]
370+
drawCoordinates = self.getDrawingAttribute_layerName_("showGlyphPointCoordinates", layerName) and self._impliedPointSize > self._cutoffDisplayPointSizes["showGlyphPointCoordinates"]
371+
pointColor = None
372+
if not self._showLayers:
373+
pointColor = self._pointColor
344374
drawing.drawGlyphPoints(glyph, self._inverseScale, rect,
345375
drawStartPoint=drawStartPoint, drawOnCurves=drawOnCurves, drawOffCurves=drawOffCurves, drawCoordinates=drawCoordinates,
346-
backgroundColor=self._backgroundColor, flipped=True)
376+
color=pointColor, backgroundColor=self._backgroundColor, flipped=True)
347377

348378
@python_method
349379
def drawAnchors(self, glyph, layerName, rect):
350-
drawText = self._impliedPointSize > 50
351-
drawing.drawGlyphAnchors(glyph, self._inverseScale, rect, drawText=drawText, backgroundColor=self._backgroundColor, flipped=True)
380+
drawText = self._impliedPointSize > self._cutoffDisplayPointSizes["showGlyphAnchors"]
381+
color = None
382+
if not self._showLayers:
383+
color = self._glyphColor
384+
drawing.drawGlyphAnchors(glyph, self._inverseScale, rect, drawText=drawText, color=color, backgroundColor=self._backgroundColor, flipped=True)
352385

353386
@python_method
354387
def drawGlyphForeground(self, glyph, rect, alternate=False):

‎Lib/defconAppKit/tools/drawing.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,16 @@ def drawGlyphFillAndStroke(glyph, scale, rect,
365365
# points
366366

367367
def drawGlyphPoints(glyph, scale, rect, drawStartPoint=True, drawOnCurves=True, drawOffCurves=True, drawCoordinates=True, color=None, backgroundColor=None, flipped=False):
368+
# get the layer color
368369
layer = glyph.layer
369-
if layer is not None:
370-
if layer.color is not None:
371-
color = colorToNSColor(layer.color)
372-
if color is None:
370+
layerColor = None
371+
if layer is not None and layer.color is not None:
372+
layerColor = colorToNSColor(layer.color)
373+
# work out the colors
374+
if color is None and layerColor is not None:
375+
color = layerColor
376+
elif color is None and layerColor is None:
373377
color = getDefaultColor("glyphPoints")
374-
if backgroundColor is None:
375-
backgroundColor = getDefaultColor("background")
376378
# get the outline data
377379
outlineData = glyph.getRepresentation("defconAppKit.OutlineInformation")
378380
points = []

0 commit comments

Comments
 (0)
Please sign in to comment.