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

Method draw

Lib/pagebot/elements/variablefonts/typeramps.py:115–201  ·  view source on GitHub ↗
(self, view, p)

Source from the content-addressed store, hash-verified

113 view.drawElementInfo(self, origin) # Depends on flag 'view.showElementInfo'
114
115 def draw(self, view, p):
116 if not self.show:
117 return
118 w = self.w # Width of the icon
119 h = self.h # Height of the icon
120 e = w*self.earSize # Ear size fraction of the width
121
122 x,y = p[0], p[1]
123 c = self.context
124
125 c.newPath()
126 c.moveTo((0, 0))
127 if self.earLeft:
128 c.lineTo((0, h-e))
129 c.lineTo((e, h))
130 c.lineTo((w, h))
131
132 else:
133 c.lineTo((0, h))
134 c.lineTo((w-e, h))
135 c.lineTo((w, h-e))
136 c.lineTo((w, 0))
137 c.lineTo((0, 0))
138 c.closePath()
139 c.save()
140 c.fill(self.css("fill"))
141 c.stroke(self.css("stroke"), self.css("strokeWidth"))
142 c.translate(x, y)
143 c.drawPath()
144
145 c.newPath()
146 if self.earLeft:
147 #draw ear
148 c.moveTo((e, h))
149 c.lineTo((e, h-e))
150 c.lineTo((0, h-e))
151 c.lineTo((e, h))
152
153 else:
154 #draw ear
155 c.moveTo((w-e, h))
156 c.lineTo((w-e, h-e))
157 c.lineTo((w, h-e))
158 c.lineTo((w-e, h))
159 c.closePath()
160 c.fill(self.earFill)
161 c.lineJoin("bevel")
162 c.drawPath()
163
164 labelSize = e
165 bs = c.newString(self.c,
166 style=dict(font=self.f.path,
167 textFill=self.cFill,
168 textStroke=self.cStroke,
169 textStrokeWidth=self.cStrokeWidth,
170 fontSize=h*2/3))
171 tw, th = bs.textSize
172 c.text(bs, (w/2-tw/2, h/2-th/3.2))

Callers 1

buildMethod · 0.95

Calls 15

uptFunction · 0.90
newStringMethod · 0.80
newPathMethod · 0.45
moveToMethod · 0.45
lineToMethod · 0.45
closePathMethod · 0.45
saveMethod · 0.45
fillMethod · 0.45
cssMethod · 0.45
strokeMethod · 0.45
translateMethod · 0.45
drawPathMethod · 0.45

Tested by

no test coverage detected