Skip to main content
Module

x/canvas/mod.ts>Font

Canvas API for Deno, ported from canvaskit-wasm (Skia).
Latest
interface Font
implements EmbindObject<Font>
import { type Font } from "https://deno.land/x/canvas@v1.4.1/mod.ts";

See SkFont.h for more on this class.

Methods

getMetrics(): FontMetrics

Returns the FontMetrics for this font.

getGlyphBounds(
paint?: Paint | null,
output?: Float32Array,
): Float32Array

Retrieves the bounds for each glyph in glyphs. If paint is not null, its stroking, PathEffect, and MaskFilter fields are respected. These are returned as flattened rectangles. For each glyph, there will be 4 floats for left, top, right, bottom (relative to 0, 0) for that glyph.

getGlyphIDs(
str: string,
numCodePoints?: number,
output?: GlyphIDArray,
): GlyphIDArray

Retrieves the glyph ids for each code point in the provided string. This call is passed to the typeface of this font. Note that glyph IDs are typeface-dependent; different faces may have different ids for the same code point.

getGlyphWidths(
paint?: Paint | null,
output?: Float32Array,
): Float32Array

Retrieves the advanceX measurements for each glyph. If paint is not null, its stroking, PathEffect, and MaskFilter fields are respected. One width per glyph is returned in the returned array.

getGlyphIntercepts(
positions: Float32Array | number[],
top: number,
bottom: number,
): Float32Array

Computes any intersections of a thick "line" and a run of positionsed glyphs. The thick line is represented as a top and bottom coordinate (positive for below the baseline, negative for above). If there are no intersections (e.g. if this is intended as an underline, and there are no "collisions") then the returned array will be empty. If there are intersections, the array will contain pairs of X coordinates [start, end] for each segment that intersected with a glyph.

getScaleX(): number

Returns text scale on x-axis. Default value is 1.

getSize(): number

Returns text size in points.

getSkewX(): number

Returns text skew on x-axis. Default value is zero.

isEmbolden(): boolean

Returns embolden effect for this font. Default value is false.

getTypeface(): Typeface | null

Returns the Typeface set for this font.

setEdging(edging: FontEdging): void

Requests, but does not require, that edge pixels draw opaque or with partial transparency.

setEmbeddedBitmaps(embeddedBitmaps: boolean): void

Requests, but does not require, to use bitmaps in fonts instead of outlines.

setHinting(hinting: FontHinting): void

Sets level of glyph outline adjustment.

setLinearMetrics(linearMetrics: boolean): void

Requests, but does not require, linearly scalable font and glyph metrics.

For outline fonts 'true' means font and glyph metrics should ignore hinting and rounding. Note that some bitmap formats may not be able to scale linearly and will ignore this flag.

setScaleX(sx: number): void

Sets the text scale on the x-axis.

setSize(points: number): void

Sets the text size in points on this font.

setSkewX(sx: number): void

Sets the text-skew on the x axis for this font.

setEmbolden(embolden: boolean): void

Set embolden effect for this font.

setSubpixel(subpixel: boolean): void

Requests, but does not require, that glyphs respect sub-pixel positioning.

setTypeface(face: Typeface | null): void

Sets the typeface to use with this font. null means to clear the typeface and use the default one.