MCPcopy
hub / github.com/canvg/canvg / renderChildren

Method renderChildren

src/Document/TextPathElement.ts:174–238  ·  view source on GitHub ↗
(ctx: RenderingContext2D)

Source from the content-addressed store, hash-verified

172 }
173
174 override renderChildren(ctx: RenderingContext2D) {
175 this.setTextData(ctx)
176 ctx.save()
177
178 const textDecoration = this.parent.getStyle('text-decoration').getString()
179 const fontSize = this.getFontSize()
180 const { glyphInfo } = this
181 const fill = ctx.fillStyle
182
183 if (textDecoration === 'underline') {
184 ctx.beginPath()
185 }
186
187 glyphInfo.forEach((glyph, i) => {
188 const {
189 p0,
190 p1,
191 rotation,
192 text: partialText
193 } = glyph
194
195 ctx.save()
196 ctx.translate(p0.x, p0.y)
197 ctx.rotate(rotation)
198
199 if (ctx.fillStyle) {
200 ctx.fillText(partialText, 0, 0)
201 }
202
203 if (ctx.strokeStyle) {
204 ctx.strokeText(partialText, 0, 0)
205 }
206
207 ctx.restore()
208
209 if (textDecoration === 'underline') {
210 if (i === 0) {
211 ctx.moveTo(p0.x, p0.y + fontSize / 8)
212 }
213
214 ctx.lineTo(p1.x, p1.y + fontSize / 5)
215 }
216
217 // // To assist with debugging visually, uncomment following
218 //
219 // ctx.beginPath();
220 // if (i % 2)
221 // ctx.strokeStyle = 'red';
222 // else
223 // ctx.strokeStyle = 'green';
224 // ctx.moveTo(p0.x, p0.y);
225 // ctx.lineTo(p1.x, p1.y);
226 // ctx.stroke();
227 // ctx.closePath();
228 })
229
230 if (textDecoration === 'underline') {
231 ctx.lineWidth = fontSize / 20

Callers

nothing calls this directly

Calls 3

setTextDataMethod · 0.95
getStringMethod · 0.80
getFontSizeMethod · 0.80

Tested by

no test coverage detected