All Projects → harfbuzz → harfbuzzjs

harfbuzz / harfbuzzjs

Licence: other
Providing HarfBuzz shaping library for client/server side JavaScript projects

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
C++
36643 projects - #6 most used programming language
shell
77523 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to harfbuzzjs

Tehreer-Android
Standalone text engine for Android aimed to be free from platform limitations
Stars: ✭ 61 (-44.04%)
Mutual labels:  opentype, harfbuzz
Tehreer-Cocoa
Standalone text engine for iOS
Stars: ✭ 31 (-71.56%)
Mutual labels:  opentype, harfbuzz
Bettertypepanel
A sketch plugin to help manage common OpenType properties
Stars: ✭ 80 (-26.61%)
Mutual labels:  opentype
punk-otf
Punk Nova - an OpenType implementation of Donald Knuth's Punk font
Stars: ✭ 37 (-66.06%)
Mutual labels:  opentype
Harfbuzz
HarfBuzz text shaping engine
Stars: ✭ 2,206 (+1923.85%)
Mutual labels:  opentype
Source Han Code Jp
Source Han Code JP | 源ノ角ゴシック Code
Stars: ✭ 1,362 (+1149.54%)
Mutual labels:  opentype
Ptex Ng
Asiatic pTeX
Stars: ✭ 239 (+119.27%)
Mutual labels:  opentype
Fonthx
Font File Generation in Haxe
Stars: ✭ 64 (-41.28%)
Mutual labels:  opentype
typesetting
High quality text shaping in pure Go.
Stars: ✭ 28 (-74.31%)
Mutual labels:  harfbuzz
Source Han Super Otc
Source Han & Noto CJK Mega/Ultra OTCs
Stars: ✭ 153 (+40.37%)
Mutual labels:  opentype
Fonts
✒️ Font loading and drawing library.
Stars: ✭ 135 (+23.85%)
Mutual labels:  opentype
Adobe Variable Font Prototype
Variable font example in OpenType-CFF2 & TrueType formats
Stars: ✭ 116 (+6.42%)
Mutual labels:  opentype
Typography
C# Font Reader (TrueType / OpenType / OpenFont / CFF / woff / woff2) , Glyphs Layout and Rendering
Stars: ✭ 246 (+125.69%)
Mutual labels:  opentype
Source Han Sans
Source Han Sans | 思源黑体 | 思源黑體 | 思源黑體 香港 | 源ノ角ゴシック | 본고딕
Stars: ✭ 10,181 (+9240.37%)
Mutual labels:  opentype
perplexed
OTF monospace typeface, a derivative of IBM Plex Mono with Powerline glyphs added
Stars: ✭ 23 (-78.9%)
Mutual labels:  opentype
Free Font
大概是2020年最全的免费可商用字体,这里收录的商免字体都能找到明确的授权出处,可以放心使用,持续更新中...
Stars: ✭ 1,140 (+945.87%)
Mutual labels:  opentype
Fonttools Opentype Feature Freezer
OTFeatureFreezer GUI app and pyftfeatfreeze commandline tool in Python to permanently "apply" OpenType features to fonts, by remapping their Unicode assignments
Stars: ✭ 130 (+19.27%)
Mutual labels:  opentype
Ttf Parser
A high-level, safe, zero-allocation TrueType font parser.
Stars: ✭ 221 (+102.75%)
Mutual labels:  opentype
harfpy
Python wrapper for HarfBuzz
Stars: ✭ 29 (-73.39%)
Mutual labels:  harfbuzz
fdiff
An OpenType table diff tool for fonts. Based on the fontTools TTX format.
Stars: ✭ 33 (-69.72%)
Mutual labels:  opentype

harfbuzzjs

Providing HarfBuzz shaping library for client/server side JavaScript projects.

See the demo here.

Building

  1. Install emscripten
  2. ./build.sh

Download

Download the pack from releases tab of the project, or just download the demo page (the demo source is in gh-pages branch).

Usage and testing

TDLR

hb = require("hbjs.js")
WebAssembly.instantiateStreaming(fetch("hb.wasm")).then(function (result) {
  fetch('myfont.ttf').then(function (data) {
    return data.arrayBuffer();
  }).then(function (fontdata) {
    var blob = hb.createBlob(fontdata); // Load the font data into something Harfbuzz can use
    var face = hb.createFace(blob, 0);  // Select the first font in the file (there's normally only one!)
    var font = hb.createFont(face);     // Create a Harfbuzz font object from the face
    var buffer = hb.createBuffer();     // Make a buffer to hold some text
    buffer.addText('abc');              // Fill it with some stuff
    buffer.guessSegmentProperties();    // Set script, language and direction
    hb.shape(font, buffer);             // Shape the text, determining glyph IDs and positions
    var output = shape.json();

    // Enumerate the glyphs
    var xCursor = 0;
    var yCursor = 0;
    for (glyph of output) {
        var glyphId = glyph.g;
        var xAdvance = glyph.ax;
        var xDisplacement = glyph.dx;
        var yDisplacement = glyph.dy;

        var svgPath = font.glyphToPath(glyphId);
        // You need to supply this bit
        drawAGlyph(svgPath, xCursor + xDisplacement, yDisplacement);

        xCursor += xAdvance;
    }

    // Release memory
    buffer.destroy();
    font.destroy();
    face.destroy();
    blob.destroy();
})

More examples:

Browser

  1. npx pad.js
  2. Open http://127.0.0.1/examples/hbjs.example.html or http://127.0.0.1/examples/nohbjs.html

Node.js

  1. (cd examples && node hbjs.example.node.js)

We provide a tiny wrapper (hbjs.js) around the main functionality of harfbuzz, but it's also easy to use other parts. (See example/nohbjs.js as an example. However, you may need a custom build to expose additional functionality.)

npm

Can be added with npm i harfbuzzjs or yarn add harfbuzzjs, see the examples for how to use it.

Need more of the library?

harfbuzzjs uses a stripped-down version of Harfbuzz generated by compiling Harfbuzz with -DHB_TINY. This may mean that some functions you need are not available. Look at src/hb-config.hh in the Harfbuzz source directory to see what has been removed. For example, HB_TINY defines HB_LEAN which (amongst other things) defines HB_NO_OT_GLYPH_NAMES. If, for example, you really need to get at the glyph names:

  1. First, undefine the macro in question, by adding e.g. #undef HB_NO_OT_GLYPH_NAMES to config-override.h.
  2. Next, export any function that you need by adding a line to hbjs.symbols; in this case _hb_ot_get_glyph_name.
  3. Now the function will be exported through the WASM object, but you need to add Javascript to bridge to it - in this case, handling the memory allocation of the char * parameter name and marshalling it to a JavaScript string with heapu8.subarray. The best way to do this is to look at hbjs.js for functions which use similar signatures.

If you have extended harfbuzzjs in ways that you think others will also benefit from, please raise a pull request. If there are parts of Harfbuzz that you need but the instructions above don't work, describe what you are trying to do in an issue.

Using the library in a bigger emscripten project?

See harfbuzz port inside emscripten and emscripten-ports/HarfBuzz, basically all you need is to use -s USE_HARFBUZZ=1 in your build.

binaryen

Optionally you can install binaryen and use wasm-opt like:

wasm-opt -Oz hb.wasm -o hb.wasm

binaryen also provides wasm-dis which can be used for,

wasm-dis hb.wasm | grep export
wasm-dis hb.wasm | grep import

with that you can check if the built wasm file only exports things you need and doesn't need to import anything, as usual with wasm files built here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].