back to home

opentypejs / opentype.js

Read and write OpenType fonts using JavaScript.

4,884 stars
528 forks
182 issues
JavaScript

AI Architecture Analysis

This repository is indexed by RepoMind. By analyzing opentypejs/opentype.js in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.

Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.

Source files are only loaded when you start an analysis to optimize performance.

Embed this Badge

Showcase RepoMind's analysis directly in your repository's README.

[![Analyzed by RepoMind](https://img.shields.io/badge/Analyzed%20by-RepoMind-4F46E5?style=for-the-badge)](https://repomind.in/repo/opentypejs/opentype.js)
Preview:Analyzed by RepoMind

Repository Overview (README excerpt)

Crawler view

opentype.js It gives you access to the **letterforms** of text from the browser or Node.js. See https://opentype.js.org/ for a live demo. Features • Create a bézier path out of a piece of text. • Support for composite glyphs (accented letters). • Support for WOFF, OTF, TTF (both with TrueType and PostScript outlines) • Support for kerning (Using GPOS or the kern table). • Support for ligatures. • Support for TrueType font hinting. • Support arabic text rendering (See issue #364 & PR #359 #361) • Support for emojis and other SVG or COLR/CPAL color glyphs • A low memory mode is available as an option (see #329) • Runs in the browser and Node.js. Installation via CDN Select one of the following sources in the next example: • https://opentype.js.org/dist/opentype.js • https://cdn.jsdelivr.net/npm/opentype.js • https://unpkg.com/opentype.js via npm package manager Using TypeScript? See this example Contribute If you plan on improving or debugging opentype.js, you can: • Fork the opentype.js repo • clone your fork • move into the project • install needed dependencies with • make your changes • **option A:** for a simple build, use • **option B:** for a development server, use and navigate to the folder • check if all still works fine with • commit and open a Pull Request with your changes. Thank you! Usage Loading a WOFF/OTF/TTF font This is done in two steps: first, we load the font file into an ... ... then we it into a instance Loading a WOFF2 font WOFF2 Brotli compression perform 29% better than it WOFF predecessor. But this compression is also more complex, and would result in a much heavier (>10×!) opentype.js library (≈120KB => ≈1400KB). To solve this: Decompress the font beforehand (for example with fontello/wawoff2). Craft a font It is also possible to craft a Font from scratch by defining each glyph bézier paths. Saving a Font Once you have a object (from crafting or from ) you can save it back out as file. The Font object A Font represents a loaded OpenType font file. It contains a set of glyphs and methods to draw text on a drawing context, or to get a path representing the text. • : an indexed list of Glyph objects. • : X/Y coordinates in fonts are stored as integers. This value determines the size of the grid. Common values are and . • : Distance from baseline of highest ascender. In font units, not pixels. • : Distance from baseline of lowest descender. In font units, not pixels. Create a Path that represents the given text. • : Horizontal position of the beginning of the text. (default: ) • : Vertical position of the *baseline* of the text. (default: ) • : Size of the text in pixels (default: ). • : _{GlyphRenderOptions}_ passed to each glyph, see below Options is an optional _{GlyphRenderOptions}_ object containing: • : script used to determine which features to apply (default: or ) • : language system used to determine which features to apply (default: ) • : if true takes kerning information into account (default: ) • : an object with OpenType feature tags as keys, and a boolean value to enable each feature. Currently only ligature features and are supported (default: ). • : if true uses TrueType font hinting if available (default: ). • : the format colors are converted to for rendering (default: ). Can be / for / output, / for 6/8 digit hex colors, or / for / output. outputs an object with r, g, b, a keys (r/g/b from 0-255, a from 0-1). outputs an integer as used in the CPAL table. • : font color, the color used to render each glyph (default: ) _**Note:** there is also with the same arguments, which returns a list of Paths._ Create a Path that represents the given text. • : A 2D drawing context, like Canvas. • : Horizontal position of the beginning of the text. (default: ) • : Vertical position of the *baseline* of the text. (default: ) • : Size of the text in pixels (default: ). • : _{GlyphRenderOptions}_ passed to each glyph, see Options is an optional object containing: • : if , takes kerning information into account (default: ) • : an object with OpenType feature tags as keys, and a boolean value to enable each feature. Currently only ligature features and are supported (default: ). • : if true uses TrueType font hinting if available (default: ). Draw the points of all glyphs in the text. On-curve points will be drawn in blue, off-curve points will be drawn in red. The arguments are the same as . Draw lines indicating important font measurements for all glyphs in the text. Black lines indicate the origin of the coordinate system (point 0,0). Blue lines indicate the glyph bounding box. Green line indicates the advance width of the glyph. Convert the string to a list of glyph objects. Note that there is no strict 1-to-1 correspondence between the string and glyph list due to possible substitutions such as ligatures. The list of returned glyphs can be larger or smaller than the length of the given string. Convert the character to a Glyph object. Returns if the glyph could not be found. Note that this function assumes that there is a one-to-one mapping between the given character and a glyph; for complex scripts, this might not be the case. Retrieve the value of the kerning pair between the left glyph (or its index) and the right glyph (or its index). If no kerning pair is found, return . The kerning value gets added to the advance width when calculating the spacing between glyphs. Returns the advance width of a text. This is something different than ; for example a suffixed whitespace increases the advancewidth but not the bounding box or an overhanging letter like a calligraphic 'f' might have a quite larger bounding box than its advance width. This corresponds to • : Size of the text in pixels (default: ). • : _{GlyphRenderOptions}_, see The object ( ) This allows to manage the palettes and colors in the CPAL table, without having to modify the table manually. Add a new palette. • : (optional) colors to add to the palette, differe…