Module

x/canvas/mod.ts

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

See SkFont.h for more on this class.

Methods

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

Retrieves the bounds for each glyph in glyphs. If paint is not null, its stroking, SkPathEffect, and SkMaskFilter 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?: TypedArray,
): GlyphIDArray

Retrieves the glyph ids for each code point in the provided string. Note that glyph IDs are font-dependent; different fonts may have different ids for the same code point.

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

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

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.

getTypeface(): SkTypeface | null

Returns the SkTypeface set for this font.

getWidths(str: string): number[]

Retrieves the advanceX measurements for each code point in str. [deprecated] Use getGlyphIDs and getGlyphWidths instead.

measureText(str: string): number

Retrieves the total advance with the given string. If attempting to shape text to fit into a given width, using getGlyphIDs and getGlyphWidths is probably easier / more efficient.

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.

setSubpixel(subpixel: boolean): void

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

setTypeface(face: SkTypeface | null): void

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