Skip to content

Lists of available functions

Zean Isnomo edited this page Jul 21, 2026 · 4 revisions

This page will contain the interfaces, functions, or other useful programatic utilities that you can use within Derakuma.

Types and interfaces

PenCommand

PenCommand contains all of the glyphs' pen data. Usually, PenCommand is an objected array, defined as PenCommand[].

Commands

Note: PD and PU are always in pairs!

  • PD: Pen down. Puts the pen down and starts drawing
  • PU: Pen up. Stops drawing temporarily until the next PD
  • MP: Move pen. Moves the pen to the next location. This must be done after a PD command has been invoked.

Object contents

  • command: 'PD' | 'PU' | 'MP': Defines all of the commands.
  • x: number: Defines the absolute x coordinate of the specified vector, from 0 to 9 to the right.
  • y: number: Defines the absolute y coordinate of the specified vector, from 0 to 9 upwards.

FontLoadMethod

Defines the loading method of .bene font files.

  • FontLoadMethod.FETCH: Requests Derakuma to load .bene via a web request. If this is used, Derakuma must be wrapped under an async function.
  • FontLoadMethod.FILE Node/Bun only! Loads the .bene font synchronously via your system's filesystem. This will not work on the web version.

FontMetadata

Contains the entire font metadata.

  • formatVersion?: string: Specifies the Fontobene format version.
  • id?: string: Specifies the font's unique ID. Do not apply spaces here, only alphabets or numbers are allowed. Any encoding formats are allowed, provided they are supplied in the constructor. However for web, this must be explicitly UTF-8
  • name?: string: The font name.
  • description?: string: Describes the font.
  • version?: string (Not to be confused with the format version) Specifies the font's current version/revision
  • authors: string[]: Lists the authors responsible for the font.
  • licenses: string[]: Specifies the license of the font.
  • letterSpacing: number: Specifies the spacing required between letters/characters. The letter spacing should range from 0-16.
  • lineSpacing: number: Specifies the line spacing required, vertically. Vertical line spacing must range between 0-24.
  • monospaceWidth?: number: If specified, specifies the fixed with of all characters.

Glyph

Contains information about the requested glyph.

  • codepoint: string: Specifies the Unicode codepoint (e.g. codepoint is 0061, then unicode is certainly U+0061)
  • char?: string: Specifies the character requested
  • polylines: Array<Array<{ x: number; y: number }>>: Contains the polyline data. Every instance of Array<{ x: number; y: number }> is a stroke (e.g. length of the parent Array is 2, so there are two strokes)
  • whitespace: number: Specifies the whitespace needed, trailing and is part of the advancement calculation.
  • minX: number: Specifies the absolute minimum of a character's glyph (nearest edge in the left). Typically, the bare minimum should be 0.
  • maxX: number: Specifies the maximum of the character. This must be equal or lower than 9 (<= 9).

DerakumaParser

The main class for handling all of Derakuma's main Fontobene features.

new DerakumaParser(source, loadMethod?, encoding?)

The main constructor for Derakuma. This is a must before doing any font operations, which means code such as new DerakumaParser('./source.bene').documentedFunction() is highly illegal.

  • source: string: Defines the URL of the font file. It can either be a URL or a local file system resource.
  • loadMethod?: FontLoadMethod: Defines the load method needed to load the specific font. Refer to FontLoadMethod for this. Defaults to FontLoadMethod.FETCH.
  • encoding?: BufferEncoding | string Node/Bun only! Specifies the encoding to open and parse the file, if your .bene file is saved not in UTF-8. Defaults to utf-8.

async DerakumaParser.ready()

Runs an asynchronous method to specify that waiting for the font to be loaded. Only required when loadMethod in the constructor is left blank or is FontLoadMethod.FETCH. Returns a Promise<void> object.

DerakumaParser.metadata: FontMetada

Displays the full metadata of the parsed Fontobene file. Refer to FontMetadata.

DerakumaParser.getGlyph(character)

Gets pen commands, only for one character. Returns PenCommand[], or an Error if not initialized. If a glyph does not exist, it will return the glyph for U+FFFD, if available, or Derakuma's built-in placeholder.

  • character: string | number: Specifies the requested character. It can be a single character, or a Unicode that has been turned into a decimal.

DerakumaParser.getGlyphData(character)

Same as getGlyph(character), however this returns a full Glyph object of the specified character, or an Error if not initialized. If a glyph does not exist, it will return the glyph for U+FFFD, if available, or Derakuma's built-in placeholder.

  • character: string | number: Specifies the requested character. It can be a single character, or a Unicode that has been turned into a decimal.

DerakumaParser.hasGlyph(character)

Returns a boolean to check whether a glyph exists for a specified character or Unicode decimal, or an Error if not initialized.

  • character: string | number: Specifies the requested character. It can be a single character, or a Unicode that has been turned into a decimal.

DerakumaParser.getAdvance(character)

Returns a number to calculate horizontal advancements from previous glyph to the next glyph, or an Error if not initialized. If monospaceWidth is defined, this will return the monospaceWidth value instead.

  • character: string | number: Specifies the requested character. It can be a single character, or a Unicode that has been turned into a decimal.

DerakumaParser.getSentenceCommand(text)

Gets all pen commands of each characters in a sentence.

  • text: string: The text to display (can be separated by spaces) Returns Array<{ char: string; x: number; commands: PenCommand[] }>, or an Error if not initialized.

Explanation of the return Array

  • char: The character itself.
  • x: The x position relative from the last glyph's minimum X position, added up by the last glyph's maximum X position.

DerakumaParser.listGlyphs()

Returns a string[] to list all available glyphs for the specified font, or an Error if not initialized.