Skip to content

@pdfa-lab/fontkit / Glyph

Abstract Class: Glyph ​

Defined in: src/glyph/glyph.ts:102

Glyph objects represent a glyph in the font. They have various properties for accessing metrics and the actual vector path the glyph represents, and methods for rendering the glyph to a graphics context.

You do not create glyph objects directly. They are created by various methods on the font object. There are several subclasses of the base Glyph class internally that may be returned depending on the font format, but they all inherit from this class.

Extended by ​

Constructors ​

Constructor ​

new Glyph(id, codePoints, font): Glyph

Defined in: src/glyph/glyph.ts:125

An array of unicode code points that are represented by this glyph. There can be multiple code points in the case of ligatures and other glyphs that represent multiple visual characters.

Parameters ​

ParameterTypeDescription
idnumberthe glyph id in the font.
codePointsreadonly number[]the array of Unicode code points.
fontTrueTypeSubsetFont | OpenTypeFontthe font containing the glyph

Returns ​

Glyph

Properties ​

PropertyModifierTypeDefined in
_metrics?protectedGlyphLayoutMetricssrc/glyph/glyph.ts:109
codePointsreadonlyreadonly number[]src/glyph/glyph.ts:104
fontreadonlyTrueTypeSubsetFont | OpenTypeFontsrc/glyph/glyph.ts:105
idreadonlynumbersrc/glyph/glyph.ts:103
isLigaturereadonlybooleansrc/glyph/glyph.ts:107
isMarkreadonlybooleansrc/glyph/glyph.ts:106

Accessors ​

advanceHeight ​

Get Signature ​

get advanceHeight(): number

Defined in: src/glyph/glyph.ts:294

The glyph's advance height.

Returns ​

number


advanceWidth ​

Get Signature ​

get advanceWidth(): number

Defined in: src/glyph/glyph.ts:283

The glyph's advance width.

Returns ​

number


bbox ​

Get Signature ​

get bbox(): Readonly<BoundingBox>

Defined in: src/glyph/glyph.ts:250

The glyph’s bounding box, i.e. the rectangle that encloses the glyph outline as tightly as possible.

Returns ​

Readonly<BoundingBox>


cbox ​

Get Signature ​

get cbox(): Readonly<BoundingBox>

Defined in: src/glyph/glyph.ts:238

The glyph’s control box. This is often the same as the bounding box, but is faster to compute. Because of the way bezier curves are defined, some of the control points can be outside of the bounding box. Where bbox takes this into account, cbox does not. Thus, cbox is less accurate, but faster to compute. See here for a more detailed description.

Returns ​

Readonly<BoundingBox>


name ​

Get Signature ​

get name(): string | null

Defined in: src/glyph/glyph.ts:352

The glyph's name.

Returns ​

string | null


path ​

Get Signature ​

get path(): Readonly<Path>

Defined in: src/glyph/glyph.ts:262

A vector Path object representing the glyph outline.

Returns ​

Readonly<Path>

Methods ​

getBBox() ​

protected getBBox(): Readonly<BoundingBox>

Defined in: src/glyph/glyph.ts:150

Returns ​

Readonly<BoundingBox>


getCBox() ​

protected getCBox(_?): Readonly<BoundingBox>

Defined in: src/glyph/glyph.ts:146

Parameters ​

ParameterType
_?boolean

Returns ​

Readonly<BoundingBox>


getName() ​

protected getName(): string | null

Defined in: src/glyph/glyph.ts:302

Returns ​

string | null


getScaledPath() ​

getScaledPath(size): Path

Defined in: src/glyph/glyph.ts:275

Returns a path scaled to the given font size.

Parameters ​

ParameterType
sizenumber

Returns ​

Path


render() ​

render(ctx, size): void

Defined in: src/glyph/glyph.ts:377

Renders the glyph to the given graphics context, at the specified font size.

The rendering context ctx should actually be an instance of pdfkit. However, for regular glyphs, you can also pass an HTML5 CanvasRenderingContext2D or one of the implementations for Node.js, like canvas, although you have to cast this, when using TypeScript.

Unfortunately, this will crash, for colour glyphs, see https://github.com/gflohr/pdfa-lab/issues/105.

Parameters ​

ParameterTypeDescription
ctxFontkitCanvasthe FontkitCanvas
sizenumberthe font size in points

Returns ​

void