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

Method draw

Lib/pagebot/elements/variablefonts/fittowidth.py:106–192  ·  view source on GitHub ↗
(self, view, p)

Source from the content-addressed store, hash-verified

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