Font#

Font objects can be created from TrueType, OpenType, Type1 or CFF fonts. In PDF there are also special Type3 fonts.

CONSTRUCTOR METHODS

Font(ref: string)#

Create a new font from a built-in font name.

The built-in standard PDF fonts are:

  • Times-Roman.

  • Times-Italic.

  • Times-Bold.

  • Times-BoldItalic.

  • Helvetica.

  • Helvetica-Oblique.

  • Helvetica-Bold.

  • Helvetica-BoldOblique.

  • Courier.

  • Courier-Oblique.

  • Courier-Bold.

  • Courier-BoldOblique.

  • Symbol.

  • ZapfDingbats.

The built-in CJK fonts are referenced by language code: zh-Hant, zh-Hans, ja, ko.

Parameters:

refstring. Font name or file name.

Returns:

Font.

EXAMPLE

var font = new mupdfjs.Font("Times-Roman");
Font(name: string, data: AnyBuffer)#

Create a new font with a designated name and the data buffer for the supplied font.

Parameters:
  • namestring. Font name.

  • dataAnyBuffer. Buffer of font data.

Returns:

Font.

EXAMPLE

let fontBuffer = fs.readFileSync("FreigSans.ttf");
let font = new mupdfjs.Font("Freight Sans", fontBuffer);

INSTANCE METHODS

getName()#

Get the font name.

Returns:

string.

EXAMPLE

var name = font.getName();
encodeCharacter(unicode: number)#

Get the glyph index for a unicode character. Glyph 0 is returned if the font does not have a glyph for the character.

Parameters:

unicodenumber. The unicode character.

Returns:

number. Glyph index.

EXAMPLE

var index = font.encodeCharacter(0x42);
advanceGlyph(glyph: number, wmode: number = 0)#

Return advance width for a glyph in either horizontal or vertical writing mode.

Parameters:
  • glyphnumber. The glyph as unicode character.

  • wmodenumber. 0 for horizontal writing, and 1 for vertical writing.

Returns:

number. Width for the glyph.

EXAMPLE

var width = font.advanceGlyph(0x42);
isBold()#

Returns true if font is bold.

Returns:

boolean.

EXAMPLE

var isBold = font.isBold();
isItalic()#

Returns true if font is italic.

Returns:

boolean.

EXAMPLE

var isItalic = font.isItalic();
isMono()#

Returns true if font is monospaced.

Returns:

boolean.

EXAMPLE

var isMono = font.isMono();
isSerif()#

Returns true if font is serif.

Returns:

boolean.

EXAMPLE

var isSerif = font.isSerif();

Code samples

Code samples are in TypeScript and assume that the following requirements are defined in your TypeScript file header as follows:

import * as fs from "fs"
import * as mupdfjs from "mupdf/mupdfjs"