(
ctx: CanvasRenderingContext2D,
text: string | string[],
x: number,
y: number,
font: CanvasFontSpec,
opts: RenderTextOpts = {}
)
| 447 | * Render text onto the canvas |
| 448 | */ |
| 449 | export function renderText( |
| 450 | ctx: CanvasRenderingContext2D, |
| 451 | text: string | string[], |
| 452 | x: number, |
| 453 | y: number, |
| 454 | font: CanvasFontSpec, |
| 455 | opts: RenderTextOpts = {} |
| 456 | ) { |
| 457 | const lines = isArray(text) ? text : [text]; |
| 458 | const stroke = opts.strokeWidth > 0 && opts.strokeColor !== ''; |
| 459 | let i: number, line: string; |
| 460 | |
| 461 | ctx.save(); |
| 462 | ctx.font = font.string; |
| 463 | setRenderOpts(ctx, opts); |
| 464 | |
| 465 | for (i = 0; i < lines.length; ++i) { |
| 466 | line = lines[i]; |
| 467 | |
| 468 | if (opts.backdrop) { |
| 469 | drawBackdrop(ctx, opts.backdrop); |
| 470 | } |
| 471 | |
| 472 | if (stroke) { |
| 473 | if (opts.strokeColor) { |
| 474 | ctx.strokeStyle = opts.strokeColor; |
| 475 | } |
| 476 | |
| 477 | if (!isNullOrUndef(opts.strokeWidth)) { |
| 478 | ctx.lineWidth = opts.strokeWidth; |
| 479 | } |
| 480 | |
| 481 | ctx.strokeText(line, x, y, opts.maxWidth); |
| 482 | } |
| 483 | |
| 484 | ctx.fillText(line, x, y, opts.maxWidth); |
| 485 | decorateText(ctx, x, y, line, opts); |
| 486 | |
| 487 | y += Number(font.lineHeight); |
| 488 | } |
| 489 | |
| 490 | ctx.restore(); |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * Add a path of a rectangle with rounded corners to the current sub-path |
no test coverage detected