Skip to content

Instantly share code, notes, and snippets.

@smhanov
smhanov / OpenType.ts
Last active December 17, 2023 04:58
Here is my implementation of a TrueType font reader in Typescript. You can read a font directly from an ArrayBuffer, and then call drawText() to draw it. See my article http://stevehanov.ca/blog/index.php?id=143. The second file, OpenType.ts is the same thing but it handles more TrueType files. It is also more coplex
// To see this run, you first stub out these imports. Then put the file in a Uint8Array.
// let slice = new Slice(array);
// let font = new OTFFont(slice);
// Then you can call methods like font.drawText(canvasContext, )
//
//
import { ICanvasContext } from "./ICanvasContext"
import { log as Log } from "./log"
const log = Log.create("OPENTYPE");
<div class="controls">
<a href="#add-color">+ Add New Color</a>
<a href="#random-hue">Random Hue</a>
<input type="range" name="hue-adjustment" value="0" min="0" max="359" />
</div>
<div class="colors-wrapper">
<div class="colors">
<div class="color-wrapper">
<div class="color" style="background-color: #000; "><span class="hue-value"></span></div>
<input type="text" />