MCPcopy
hub / github.com/canvg/canvg / measureText

Method measureText

src/Document/TextPathElement.ts:308–324  ·  view source on GitHub ↗
(
    ctx: RenderingContext2D,
    text?: string
  )

Source from the content-addressed store, hash-verified

306 }
307
308 protected override measureText(
309 ctx: RenderingContext2D,
310 text?: string
311 ) {
312 const { measuresCache } = this
313 const targetText = text || this.getText()
314
315 if (measuresCache.has(targetText)) {
316 return measuresCache.get(targetText)
317 }
318
319 const measure = this.measureTargetText(ctx, targetText)
320
321 measuresCache.set(targetText, measure)
322
323 return measure
324 }
325
326 // This method supposes what all custom fonts already loaded.
327 // If some font will be loaded after this method call, <textPath> will not be rendered correctly.

Callers 2

findSegmentToFitCharMethod · 0.95
setTextDataMethod · 0.95

Calls 2

getTextMethod · 0.95
measureTargetTextMethod · 0.80

Tested by

no test coverage detected