Giter VIP home page Giter VIP logo

font-js's Introduction

font

📱 Try a glyph viewer right now in your browser!

Utilities and a CLI for extracting glyphs and metadata from font files.

Currently allows loading TrueType or OpenType fonts or font collections, and extracting metadata and glyph geometry.

The command-line interface allows for extracting black-and-white, grayscale, and signed distance field PNG renderings, and JSON metadata.

Run the command-line interface without arguments to check all the available options.

Run via npx: npx @hlorenzi/font

Install with: npm install @hlorenzi/font

Command-line Examples

# Extracts all glyphs from "arial.ttf" into PNG and JSON files.
npx @hlorenzi/font arial.ttf -o "output/unicode_[unicode]"

# Set glyph range.
npx @hlorenzi/font arial.ttf -o "output/unicode_[unicode]" --glyphs="u+30..u+39"

# Set output mode.
npx @hlorenzi/font arial.ttf -o "output/unicode_[unicode]" --img-mode="png-sdf"

Package Example

import { FontCollection, GlyphRenderer } from "@hlorenzi/font"
import fs from "fs"

// Load font file.
const fontBuffer = fs.readFileSync("arial.ttf")

// Load font collection and get first font.
const fontCollection = FontCollection.fromBytes(fontBuffer)
const font = fontCollection.fonts[0]

// Find glyph for Unicode character "a" and get its geometry,
// simplifying each bézier curve into 100 line segments.
const glyphIndex = font.getGlyphIndexForUnicode("a".charCodeAt(0))
const glyphGeometry = font.getGlyphGeometry(glyphIndex, 100)

// Render into a black-and-white buffer with scale factor 1 EM = 30 pixels,
// then crop empty borders and print to the console.
const glyphImage = GlyphRenderer.render(glyphGeometry, 30).cropped()
console.log(glyphImage.printToString())

font-js's People

Contributors

hlorenzi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

font-js's Issues

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.