{"id":13576059,"url":"https://github.com/harfbuzz/harfbuzzjs","last_synced_at":"2026-02-24T15:04:28.422Z","repository":{"id":34741824,"uuid":"182279264","full_name":"harfbuzz/harfbuzzjs","owner":"harfbuzz","description":"Providing HarfBuzz shaping library for client/server side JavaScript projects","archived":false,"fork":false,"pushed_at":"2024-03-24T15:41:46.000Z","size":3555,"stargazers_count":175,"open_issues_count":9,"forks_count":31,"subscribers_count":17,"default_branch":"main","last_synced_at":"2024-04-22T14:23:45.356Z","etag":null,"topics":["harfbuzz","javascript","nodejs","opentype","wasm"],"latest_commit_sha":null,"homepage":"https://harfbuzz.github.io/harfbuzzjs/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/harfbuzz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-04-19T14:42:50.000Z","updated_at":"2024-04-21T01:21:06.000Z","dependencies_parsed_at":"2023-10-12T06:03:58.327Z","dependency_job_id":"7a8c9531-e4cc-4fb0-8a70-851ec325a8d6","html_url":"https://github.com/harfbuzz/harfbuzzjs","commit_stats":{"total_commits":203,"total_committers":15,"mean_commits":"13.533333333333333","dds":"0.46798029556650245","last_synced_commit":"acbdcb2e5a6ce5dd0c8c7ec63fb4ad61594cce79"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harfbuzz%2Fharfbuzzjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harfbuzz%2Fharfbuzzjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harfbuzz%2Fharfbuzzjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harfbuzz%2Fharfbuzzjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harfbuzz","download_url":"https://codeload.github.com/harfbuzz/harfbuzzjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166168,"owners_count":20894654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["harfbuzz","javascript","nodejs","opentype","wasm"],"created_at":"2024-08-01T15:01:06.668Z","updated_at":"2026-02-24T15:04:28.400Z","avatar_url":"https://github.com/harfbuzz.png","language":"JavaScript","readme":"# harfbuzzjs\n\n\u003cdiv align=\"center\"\u003e\n\u003cp\u003e\u003cimg src=\"logo.png\" alt=\"harfbuzzjs Logo\" width=\"256\" align=\"center\"/\u003e\u003c/p\u003e\n\n[![Build](https://github.com/harfbuzz/harfbuzzjs/actions/workflows/build.yml/badge.svg)](https://github.com/harfbuzz/harfbuzzjs/actions/workflows/build.yml)\n[![NPM Version](https://img.shields.io/npm/v/harfbuzzjs)](https://www.npmjs.com/package/harfbuzzjs)\n\n\u003c/div\u003e\n\nProviding [HarfBuzz](https://github.com/harfbuzz/harfbuzz) shaping\nlibrary for client/server side JavaScript projects.\n\nSee the demo [here](https://harfbuzz.github.io/harfbuzzjs/).\n\n## Building\n1. Install emscripten\n2. `make`\n\n## Testing\n1. `make test`\n\n## Download\nDownload from the [releases tab](https://github.com/harfbuzz/harfbuzzjs/releases).\n\n## Usage\n\n### TL;DR\n\n```javascript\nrequire(\"harfbuzzjs\").then(function (hb) {\n  fetch('myfont.ttf').then(function (data) {\n    return data.arrayBuffer();\n  }).then(function (fontdata) {\n    var blob = hb.createBlob(fontdata); // Load the font data into something Harfbuzz can use\n    var face = hb.createFace(blob, 0);  // Select the first font in the file (there's normally only one!)\n    var font = hb.createFont(face);     // Create a Harfbuzz font object from the face\n    var buffer = hb.createBuffer();     // Make a buffer to hold some text\n    buffer.addText('abc');              // Fill it with some stuff\n    buffer.guessSegmentProperties();    // Set script, language and direction\n    hb.shape(font, buffer);             // Shape the text, determining glyph IDs and positions\n    var output = buffer.json();\n\n    // Enumerate the glyphs\n    var xCursor = 0;\n    var yCursor = 0;\n    for (var glyph of output) {\n        var glyphId = glyph.g;\n        var xAdvance = glyph.ax;\n        var xDisplacement = glyph.dx;\n        var yDisplacement = glyph.dy;\n\n        var svgPath = font.glyphToPath(glyphId);\n        // You need to supply this bit\n        drawAGlyph(svgPath, xCursor + xDisplacement, yDisplacement);\n\n        xCursor += xAdvance;\n        yCursor += yAdvance;\n    }\n\n    // Release memory\n    buffer.destroy();\n    font.destroy();\n    face.destroy();\n    blob.destroy();\n  })\n})\n```\n\nMore examples:\n\n### Browser\n\n1. `npx pad.js`\n2. Open `http://127.0.0.1/examples/hbjs.example.html` or `http://127.0.0.1/examples/nohbjs.html`\n\n### Node.js\n\n1. `(cd examples \u0026\u0026 node hbjs.example.node.js)`\n\nWe provide a 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.)\n\n## [npm](https://www.npmjs.com/package/harfbuzzjs)\nCan be added with `npm i harfbuzzjs` or `yarn add harfbuzzjs`, see the examples for\nhow to use it.\n\n## Need more of the library?\n\nharfbuzzjs 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:\n\n1. First, undefine the macro in question, by adding e.g. `#undef HB_NO_OT_GLYPH_NAMES` to `config-override.h`.\n2. Next, export any function that you need by adding a line to `hbjs.symbols`; in this case `_hb_ot_get_glyph_name`.\n3. 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.\n\nIf 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.\n\n## Using the library in a bigger emscripten project?\nSee [harfbuzz port inside emscripten](https://github.com/emscripten-core/emscripten/blob/master/tools/ports/harfbuzz.py)\nand [emscripten-ports/HarfBuzz](https://github.com/emscripten-ports/HarfBuzz), basically all you need is to use\n`-s USE_HARFBUZZ=1` in your build.\n\n## binaryen\n\nOptionally you can install `binaryen` and use `wasm-opt` like:\n\n```\nwasm-opt -Oz hb.wasm -o hb.wasm\n```\n\n`binaryen` also provides `wasm-dis` which can be used for,\n\n```\nwasm-dis hb.wasm | grep export\nwasm-dis hb.wasm | grep import\n```\n\nwith that you can check if the built wasm file only exports things you need and\ndoesn't need to import anything, as usual with wasm files built here.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharfbuzz%2Fharfbuzzjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharfbuzz%2Fharfbuzzjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharfbuzz%2Fharfbuzzjs/lists"}