Skip to content
pixi-silk
GitHub repository
Interface

GlyphContext

import type { GlyphContext } from 'pixi-silk/text';

The slice of a 2D canvas context the atlas needs. Pass your own to SdfAtlasOptions.context to bake glyphs somewhere else (a worker canvas, or a fake one in tests).

Properties#

PropertyModifierTypeDescriptionDefined in
canvasreadonly{ height: number; width: number; }The canvas behind the context. The atlas grows it when a glyph does not fit.text/atlas.ts:52
canvas.heightpublicnumberHeight in pixels.text/atlas.ts:56
canvas.widthpublicnumberWidth in pixels.text/atlas.ts:54
fillStylepublicunknownFill colour of the glyph raster.text/atlas.ts:46
fontpublicstringCSS font shorthand used by measureText and fillText.text/atlas.ts:44
textAlignpublicstringHorizontal anchor of fillText. The atlas sets left.text/atlas.ts:50
textBaselinepublicstringVertical anchor of fillText. The atlas sets alphabetic.text/atlas.ts:48

Methods#

clearRect()#

clearRect(
   x: number, 
   y: number, 
   w: number, 
   h: number
): void;

Clears a rectangle to transparent.

Parameters#

ParameterType
xnumber
ynumber
wnumber
hnumber

Returns#

void


fillText()#

fillText(
   text: string, 
   x: number, 
   y: number
): void;

Draws a string with its pen at (x, y).

Parameters#

ParameterType
textstring
xnumber
ynumber

Returns#

void


getImageData()#

getImageData(
   x: number, 
   y: number, 
   w: number, 
   h: number
): {
  data: ArrayLike<number>;
};

Reads pixels back as RGBA bytes.

Parameters#

ParameterType
xnumber
ynumber
wnumber
hnumber

Returns#

NameTypeDescriptionDefined in
dataArrayLike<number>RGBA bytes, row by row.text/atlas.ts:81

measureText()#

measureText(text: string): Pick<TextMetrics, 
  | "width"
  | "actualBoundingBoxLeft"
  | "actualBoundingBoxRight"
  | "actualBoundingBoxAscent"
| "actualBoundingBoxDescent">;

Measures a string in the current font.

Parameters#

ParameterType
textstring

Returns#

Pick<TextMetrics, | "width" | "actualBoundingBoxLeft" | "actualBoundingBoxRight" | "actualBoundingBoxAscent" | "actualBoundingBoxDescent">