GithubHelp home page GithubHelp logo

exponenta / freetype-wasm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ciantic/freetype-wasm

0.0 0.0 0.0 459 KB

FreeType compiled in WASM with emscripten

Home Page: https://exponenta.github.io/freetype-wasm/example/

License: MIT License

Shell 6.96% JavaScript 26.62% C++ 62.82% HTML 3.61%

freetype-wasm's Introduction

FreeType library built with WASM

Exposed API of the library can be seen from TypeScript definitions. Goal for the moment is not to expose all parts of the FreeType API, but enough to render text with kerning in Deno and browsers.

This WASM wrapper is MIT licensed, but Freetype is dual licensed, see licensing options from FreeType repository. For WOFF2 support the library is built with Google's Brotli which is MIT licensed.

Usage with browsers and Deno directly

You need to do this inside a module to initiate the wrapper:

import FreeTypeInit from "https://cdn.jsdelivr.net/npm/freetype-wasm@0/dist/freetype.js";
const FreeType = await FreeTypeInit();
// ...

See example.js for how to render text to canvas.

Usage with Node web apps like React

Library works with Node projects which target the web like React. Since FreeType JS wrapper fetches the WASM file asynchronously it might not work automatically as the various bundlers have different ways to configure the depenencies.

Currently it's possible to use the library in Node web projects like this:

npm install freetype-wasm

Then import and initialize the WASM module from CDN, e.g. JSDelivr:

import FreeTypeInit from "freetype-wasm/dist/freetype.js";
const FreeType = await FreeTypeInit({
    locateFile: (path) =>
        "https://cdn.jsdelivr.net/npm/freetype-wasm@0/dist/freetype.wasm",
});

Depending on your bundler you might get URL to the bundled WASM file also. I haven't tried with Create React App template, but it could be similar as next example with Vite.

Usage with Vite bundler like in Solid

npm install freetype-wasm

Then fetch the URL for your bundler using special import with ?url suffix:

import FreeTypeInit from "freetype-wasm/dist/freetype.js";
import wasmUrl from "freetype-wasm/dist/freetype.wasm?url";
const Freetype = await FreeTypeInit({
    locateFile: (path) => wasmUrl,
});

Run tests with deno

./test.sh

TODO

  • Variable font interface not implemented yet
  • Compile Freetype with Harfbuzz for ligatures and better kerning (?)
  • LoadGlyphsFromCharmap is slow with big font sizes, probably not much to do other than threading.

freetype-wasm's People

Contributors

ciantic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.