triangulated-font-geometry
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

triangulated-font-geometry

This utility consumes SVG paths of glyphs and triangulate them for the creation of 3D meshes.

Usage

The following code is used after you have created a font instance using harfbuzz-modern-wrapper:

import TriangulatedFontGeometry from "triangulated-font-geometry";

const textShaper = new TriangulatedFontGeometry(font, options);
const layout = textShaper.shape(text);
for (const component of layout.components) {
  // access `component.position` and `component.geometry` for rendering
}

Here component.geometry.geometry is the result of triangulating the glyph using polygon-winding-solver; component.geometry.hspan provides the horizontal span that this character occupies, and will be undefined when the character is a whitespace. All coordinates will be given using the internal metrics defined by the font file. To convert them for display, scale all numbers by a ratio of fontSize / layout.bounds.height).

Initialisation options

  • options.flatteningEM: the font size to use when converting curves in a glyph to polylines. The larger this value is, the more points will be sampled on the glyph. Defaults to 100.

  • options.triangulator: supply a custom triangulator to use with the polygon-winding-solver package.

TODO

2D constructive solid geometry is a planned feature of the triangulator we use. Expect in the near future an option to merge the overlapping components.

Readme

Keywords

none

Package Sidebar

Install

npm i triangulated-font-geometry

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

9.48 kB

Total Files

7

Last publish

Collaborators

  • beanandbean