Skip to content

Commit

Permalink
feat(troika-three-text): fix kerning by updating from Typr.js to Typr.ts
Browse files Browse the repository at this point in the history
Fixes #70. Our old Typr.js had broken kerning, and has since moved to a
Harfbuzz approach which removed base support for some features like
ligatures. Thankfully fredli74's Typr.ts fork maintains those and has
fixed the kerning bug. This commit updates the Typr build to use that
fork, and adds kerning calculation to FontParser_Typr.js.
  • Loading branch information
lojjic committed Dec 4, 2020
1 parent ff1b9ae commit 43144cf
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 3,309 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"build": "lerna exec --ignore=troika-examples -- rollup -c \\$LERNA_ROOT_PATH/rollup.config.js",
"build-opentype": "lerna exec --scope=troika-three-text -- npm run build-opentype",
"build-typr": "lerna exec --scope=troika-three-text -- npm run build-typr",
"build-woff2otf": "lerna exec --scope=troika-three-text -- npm run build-woff2otf",
"build-yoga": "npm run bootstrap && lerna exec --scope=troika-flex-layout -- npm run build-yoga",
"test": "jest",
"build-examples": "lerna exec --scope=troika-examples -- npm run build",
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-examples/text/TextExample.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class TextExample extends React.Component {

<div className="example_desc">
<p>This demonstrates Troika's high quality text rendering, which uses Signed Distance Field ("SDF") texture atlases for crisp glyph vector edges at any scale. It can be used via <a href="https://github.com/protectwise/troika/blob/master/packages/troika-3d-text/src/facade/Text3DFacade.js">Text3DFacade</a> or outside the Troika framework as a standalone Three.js <a href="https://github.com/protectwise/troika/blob/master/packages/troika-3d-text/src/three/TextMesh.js">TextMesh</a>.</p>
<p>Behind the scenes it uses <a href="https://github.com/photopea/Typr.js">Typr.js</a> to parse fonts, giving it support for font features such as kerning and ligatures. It generates SDF textures for each glyph on the fly as needed, assembles a single geometry for all the glyphs, seamlessly upgrades any Material's shaders to support the SDFs with high quality antialiasing, and renders the whole thing in a single draw call. Font parsing and SDF generation is done in a web worker so frames won't be dropped during processing.</p>
<p>Behind the scenes it uses <a href="https://github.com/fredli74/Typr.ts">Typr</a> to parse fonts, giving it support for font features such as kerning and ligatures. It generates SDF textures for each glyph on the fly as needed, assembles a single geometry for all the glyphs, seamlessly upgrades any Material's shaders to support the SDFs with high quality antialiasing, and renders the whole thing in a single draw call. Font parsing and SDF generation is done in a web worker so frames won't be dropped during processing.</p>
</div>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-three-text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This package provides high quality text rendering in [Three.js](https://threejs.org) scenes, using signed distance fields (SDF) and antialiasing using standard derivatives.

Rather than relying on pre-generated SDF textures, this parses font files (.ttf, .otf, .woff) directly using [Typr.js](https://github.com/photopea/Typr.js), and generates the SDF atlas for glyphs on-the-fly as they are used. It also handles proper kerning and ligature glyph substitution. All font parsing, SDF generation, and glyph layout is performed in a web worker to prevent frame drops.
Rather than relying on pre-generated SDF textures, this parses font files (.ttf, .otf, .woff) directly using [Typr](https://github.com/fredli74/Typr.ts), and generates the SDF atlas for glyphs on-the-fly as they are used. It also handles proper kerning and ligature glyph substitution. All font parsing, SDF generation, and glyph layout is performed in a web worker to prevent frame drops.

Once the SDFs are generated, it assembles a geometry that positions all the glyphs, and _patches_ any Three.js Material with the proper shader code for rendering the SDFs. This means you can still benefit from all the features of Three.js's built-in materials like lighting, physically-based rendering, shadows, and fog.

Expand Down
86 changes: 0 additions & 86 deletions packages/troika-three-text/build-typr.js

This file was deleted.

Loading

0 comments on commit 43144cf

Please sign in to comment.