MCPcopy Create free account
hub / github.com/PageBot/PageBot / draw

Method draw

Lib/pagebot/elements/variablefonts/variablecube2.py:64–119  ·  view source on GitHub ↗
(self, view, origin)

Source from the content-addressed store, hash-verified

62 self.location = copy(location)
63
64 def draw(self, view, origin):
65 c = self.doc.context
66
67 p = pointOffset(self.origin, origin)
68 p = self._applyScale(view, p)
69 px, py, _ = self._applyAlignment(p) # Ignore z-axis for now.
70
71 fillColor = self.style.get('fill')
72 if fillColor is not None:
73 c.fill(fillColor)
74
75 c.stroke((0.8, 0.8, 0.8), 0.5)
76 c.rect(px, py, self.w, self.h)
77 if len(self.dimensions) == 1:
78 raise ValueError('Not supporting 1 axis now')
79 if len(self.dimensions) > 2:
80 raise ValueError('Not supporting >2 axis now')
81
82 axisNames = sorted(self.dimensions.keys())
83 axisX = axisNames[0]
84 sizeX = self.dimensions[axisX]
85 axisY = axisNames[1]
86 sizeY = self.dimensions[axisY]
87 stepX = self.w / (sizeX+1)
88 stepY = self.h / (sizeY+1)
89 """Add more parametric layout behavior here."""
90 RANGE = 1000
91 for indexX in range(sizeX+1):
92 for indexY in range(sizeY+1):
93 ox = 30
94 oy = 25
95 ppx = ox + px + indexX * stepX
96 ppy = oy + py + indexY * stepY
97 self.location[axisX] = indexX * RANGE / sizeX
98 self.location[axisY] = indexY * RANGE / sizeY
99 glyphPathScale = self.fontSize/self.font.info.unitsPerEm
100
101 c.drawGlyphPath(c, self.vfFont.ttFont, self.glyphNames[0],
102 ppx, ppy, self.location, s=glyphPathScale,
103 fillColor=(0, 0, 0))
104
105 bs = c.newString('%s %d\n%s %d' % (axisX,
106 indexX * RANGE / sizeX,
107 axisY,
108 indexY * RANGE / sizeY),
109 fontSize=6,
110 fill=blackColor)
111 w, h = bs.textSize()
112
113 c.text(bs, ppx - stepX/4, ppy - 16)
114 # Bit of hack, we need the width of the glyph here.
115
116 bs = c.newString('Other axes: %s' % self.location,
117 fontSize=6, fill=blackColor)
118 w, h = bs.textSize()
119 c.text(bs, px, py - 16)
120
121

Callers

nothing calls this directly

Calls 12

pointOffsetFunction · 0.90
_applyScaleMethod · 0.80
_applyAlignmentMethod · 0.80
newStringMethod · 0.80
getMethod · 0.45
fillMethod · 0.45
strokeMethod · 0.45
rectMethod · 0.45
keysMethod · 0.45
drawGlyphPathMethod · 0.45
textSizeMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected