Skip to content

Commit d4fd01a

Browse files
committed
chore: update README.md
1 parent a94a26a commit d4fd01a

1 file changed

Lines changed: 88 additions & 77 deletions

File tree

README.md

Lines changed: 88 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,122 @@
11
# Purpose of this Fork
2+
23
This project is a fork of https://github.com/foliojs/fontkit created for use in https://github.com/Hopding/pdf-lib.
34

45
Listed below are changes that have been made in this fork:
56

6-
* Store binary data as compressed base64 JSON so the `fs` module isn't needed to read it back:
7-
* [968e35c](https://github.com/Hopding/fontkit/commit/968e35c158589294e9543818f56d0b229b95a475)
8-
* [99a35c7](/Hopding/fontkit/commit/99a35c7b0f0f6549d7727bcbc1ddabb7f9ca19bf)
9-
* [2f1445d](/Hopding/fontkit/commit/2f1445d9a3f8426bc259690819eea8306a98545a)
10-
* [f674bf2-R24](https://github.com/Hopding/fontkit/commit/f674bf2e3c8a8e0a34083e19f0abe65df20520e3#diff-b61f8676a8a37c519e9c3c86c4676208R24), [f674bf2-R13](https://github.com/Hopding/fontkit/commit/f674bf2e3c8a8e0a34083e19f0abe65df20520e3#diff-a73febb5d14ad8d9d7ab6ac378a698aaR13)
11-
* Rewrote `Makefile` to `Makefile.js` using `shelljs`:
12-
* [a246e7f](https://github.com/Hopding/fontkit/commit/a246e7fda8c0bb5df4be355a993e0ba59f07300e)
13-
* Update to Babel 7:
14-
* [70049f8](https://github.com/Hopding/fontkit/commit/70049f8f038145cc0caca83c75e0b76f49d11f52)
15-
* [8d5b29b](https://github.com/Hopding/fontkit/commit/8d5b29bd00b752a6ab9348e6be1997e201055d31)
16-
* Build UMD modules:
17-
* [cce995c](https://github.com/Hopding/fontkit/commit/cce995c3378c35b247ed2965e15eb92ffad9ea09)
18-
* [08cacef](https://github.com/Hopding/fontkit/commit/08cacefa3e745f83a2c95051e38985b02aa2f16d)
19-
* Build ES modules:
20-
* [dbe8e9d](https://github.com/Hopding/fontkit/commit/dbe8e9da4e8f2e23f507ba5a767a8109e81fb7ab)
21-
* [9363d1f](https://github.com/Hopding/fontkit/commit/9363d1f8e97985d8a94ee6dac1fac39631ee3c77)
22-
* Bundle Node dependencies (`stream`, `util`, `Buffer`) into UMD and ES modules so consumers of this lib don't have to deal with them:
23-
* [9363d1f](https://github.com/Hopding/fontkit/commit/9363d1f8e97985d8a94ee6dac1fac39631ee3c77)
24-
* Accept `Uint8Array` objects for font data instead of `Buffer` objects, so consumers can stick to plain JS regardless of their environment:
25-
* [9363d1f-R12](https://github.com/Hopding/fontkit/commit/9363d1f8e97985d8a94ee6dac1fac39631ee3c77#diff-d7e697eff3913f1acaacac8002c3b05eR12)
26-
* Add TypeScript declaration file:
27-
* [387ebc4](https://github.com/Hopding/fontkit/commit/387ebc418cc04be51d82d39e05f4db01b1bf063f)
28-
* [3bafdbc](https://github.com/Hopding/fontkit/commit/3bafdbc3656ebba5251f8d4dc77dcc4b6c11afa6)
29-
* [b0241e7](https://github.com/Hopding/fontkit/commit/b0241e7c30cdb83bda6867aa8c9229c1ab1cb8e3)
30-
* Remove calls to `new Function()` to allow usage on CSP sites:
31-
* [e3dcc8a](https://github.com/Hopding/fontkit/commit/e3dcc8aad014081b8106c47d89049ba9e6f3dd48)
32-
* Released to NPM as `@pdf-lib/fontkit`
33-
* [873b05d](https://github.com/Hopding/fontkit/commit/873b05d23aecb9f0142fc3ebda593fd2a7d81c17)
7+
- Store binary data as compressed base64 JSON so the `fs` module isn't needed to read it back:
8+
- [968e35c](https://github.com/Hopding/fontkit/commit/968e35c158589294e9543818f56d0b229b95a475)
9+
- [99a35c7](/Hopding/fontkit/commit/99a35c7b0f0f6549d7727bcbc1ddabb7f9ca19bf)
10+
- [2f1445d](/Hopding/fontkit/commit/2f1445d9a3f8426bc259690819eea8306a98545a)
11+
- [f674bf2-R24](https://github.com/Hopding/fontkit/commit/f674bf2e3c8a8e0a34083e19f0abe65df20520e3#diff-b61f8676a8a37c519e9c3c86c4676208R24), [f674bf2-R13](https://github.com/Hopding/fontkit/commit/f674bf2e3c8a8e0a34083e19f0abe65df20520e3#diff-a73febb5d14ad8d9d7ab6ac378a698aaR13)
12+
- Rewrote `Makefile` to `Makefile.js` using `shelljs`:
13+
- [a246e7f](https://github.com/Hopding/fontkit/commit/a246e7fda8c0bb5df4be355a993e0ba59f07300e)
14+
- Update to Babel 7:
15+
- [70049f8](https://github.com/Hopding/fontkit/commit/70049f8f038145cc0caca83c75e0b76f49d11f52)
16+
- [8d5b29b](https://github.com/Hopding/fontkit/commit/8d5b29bd00b752a6ab9348e6be1997e201055d31)
17+
- Build UMD modules:
18+
- [cce995c](https://github.com/Hopding/fontkit/commit/cce995c3378c35b247ed2965e15eb92ffad9ea09)
19+
- [08cacef](https://github.com/Hopding/fontkit/commit/08cacefa3e745f83a2c95051e38985b02aa2f16d)
20+
- Build ES modules:
21+
- [dbe8e9d](https://github.com/Hopding/fontkit/commit/dbe8e9da4e8f2e23f507ba5a767a8109e81fb7ab)
22+
- [9363d1f](https://github.com/Hopding/fontkit/commit/9363d1f8e97985d8a94ee6dac1fac39631ee3c77)
23+
- Bundle Node dependencies (`stream`, `util`, `Buffer`) into UMD and ES modules so consumers of this lib don't have to deal with them:
24+
- [9363d1f](https://github.com/Hopding/fontkit/commit/9363d1f8e97985d8a94ee6dac1fac39631ee3c77)
25+
- Accept `Uint8Array` objects for font data instead of `Buffer` objects, so consumers can stick to plain JS regardless of their environment:
26+
- [9363d1f-R12](https://github.com/Hopding/fontkit/commit/9363d1f8e97985d8a94ee6dac1fac39631ee3c77#diff-d7e697eff3913f1acaacac8002c3b05eR12)
27+
- Add TypeScript declaration file:
28+
- [387ebc4](https://github.com/Hopding/fontkit/commit/387ebc418cc04be51d82d39e05f4db01b1bf063f)
29+
- [3bafdbc](https://github.com/Hopding/fontkit/commit/3bafdbc3656ebba5251f8d4dc77dcc4b6c11afa6)
30+
- [b0241e7](https://github.com/Hopding/fontkit/commit/b0241e7c30cdb83bda6867aa8c9229c1ab1cb8e3)
31+
- Remove calls to `new Function()` to allow usage on CSP sites:
32+
- [e3dcc8a](https://github.com/Hopding/fontkit/commit/e3dcc8aad014081b8106c47d89049ba9e6f3dd48)
33+
- Released to NPM as `@pdf-lib/fontkit`
34+
- [873b05d](https://github.com/Hopding/fontkit/commit/873b05d23aecb9f0142fc3ebda593fd2a7d81c17)
3435

3536
Also see
36-
* https://github.com/Hopding/unicode-properties
37-
* https://github.com/Hopding/brotli.js
38-
* https://github.com/Hopding/restructure
39-
* https://github.com/Hopding/png-ts
37+
38+
- https://github.com/Hopding/unicode-properties
39+
- https://github.com/Hopding/brotli.js
40+
- https://github.com/Hopding/restructure
41+
- https://github.com/Hopding/png-ts
42+
43+
## Acknowledgements
44+
45+
This fork is maintained by pafin Inc. because the original repository is no longer maintained and to enable Asian font subsetting. Special thanks to [@joewestcott](https://github.com/joewestcott) for his PR that provided the foundation for this feature.
4046

4147
# fontkit
4248

4349
Fontkit is an advanced font engine for Node and the browser, used by [PDFKit](https://github.com/devongovett/pdfkit) and [`pdf-lib`](https://github.com/Hopding/pdf-lib). It supports many font formats, advanced glyph substitution and layout features, glyph path extraction, color emoji glyphs, font subsetting, and more.
4450

4551
## Features
4652

47-
* Suports TrueType (.ttf), OpenType (.otf), WOFF, WOFF2, TrueType Collection (.ttc), and Datafork TrueType (.dfont) font files
48-
* Supports mapping characters to glyphs, including support for ligatures and other advanced substitutions (see below)
49-
* Supports reading glyph metrics and laying out glyphs, including support for kerning and other advanced layout features (see below)
50-
* Advanced OpenType features including glyph substitution (GSUB) and positioning (GPOS)
51-
* Apple Advanced Typography (AAT) glyph substitution features (morx table)
52-
* Support for getting glyph vector paths and converting them to SVG paths, or rendering them to a graphics context
53-
* Supports TrueType (glyf) and PostScript (CFF) outlines
54-
* Support for color glyphs (e.g. emoji), including Apple’s SBIX table, and Microsoft’s COLR table
55-
* Support for AAT variation glyphs, allowing for nearly infinite design control over weight, width, and other axes.
56-
* Font subsetting support - create a new font including only the specified glyphs
53+
- Suports TrueType (.ttf), OpenType (.otf), WOFF, WOFF2, TrueType Collection (.ttc), and Datafork TrueType (.dfont) font files
54+
- Supports mapping characters to glyphs, including support for ligatures and other advanced substitutions (see below)
55+
- Supports reading glyph metrics and laying out glyphs, including support for kerning and other advanced layout features (see below)
56+
- Advanced OpenType features including glyph substitution (GSUB) and positioning (GPOS)
57+
- Apple Advanced Typography (AAT) glyph substitution features (morx table)
58+
- Support for getting glyph vector paths and converting them to SVG paths, or rendering them to a graphics context
59+
- Supports TrueType (glyf) and PostScript (CFF) outlines
60+
- Support for color glyphs (e.g. emoji), including Apple’s SBIX table, and Microsoft’s COLR table
61+
- Support for AAT variation glyphs, allowing for nearly infinite design control over weight, width, and other axes.
62+
- Font subsetting support - create a new font including only the specified glyphs
5763

5864
## Example
5965

6066
```js
61-
import fontkit from '@pdf-lib/fontkit';
62-
import fs from 'fs';
67+
import fontkit from "@pdf-lib/fontkit";
68+
import fs from "fs";
6369

6470
// open a font synchronously
65-
const fontData = fs.readFileSync('font.ttf');
71+
const fontData = fs.readFileSync("font.ttf");
6672
const font = fontkit.create(fontData);
6773

6874
// layout a string, using default shaping features.
6975
// returns a GlyphRun, describing glyphs and positions.
70-
const run = font.layout('hello world!');
76+
const run = font.layout("hello world!");
7177

7278
// get an SVG path for a glyph
7379
const svg = run.glyphs[0].path.toSVG();
7480

7581
// create a font subset
7682
const subset = font.createSubset();
77-
run.glyphs.forEach(function(glyph) {
83+
run.glyphs.forEach(function (glyph) {
7884
subset.includeGlyph(glyph);
7985
});
8086

81-
subset.encodeStream()
82-
.pipe(fs.createWriteStream('subset.ttf'));
87+
subset.encodeStream().pipe(fs.createWriteStream("subset.ttf"));
8388
```
8489

8590
## Installation
91+
8692
### NPM Module
93+
8794
To install the latest stable version:
95+
8896
```bash
8997
# With npm
9098
npm install --save @pdf-lib/fontkit
9199

92100
# With yarn
93101
yarn add @pdf-lib/fontkit
94102
```
103+
95104
This assumes you're using [npm](https://www.npmjs.com/) or [yarn](https://yarnpkg.com/lang/en/) as your package manager.
96105

97106
### UMD Module
107+
98108
You can also download `@pdf-lib/fontkit` as a UMD module from [unpkg](https://unpkg.com/#/). The UMD builds have been compiled to ES5, so they should work [in any modern browser](https://caniuse.com/#feat=es5). UMD builds are useful if you aren't using a package manager or module bundler. For example, you can use them directly in the `<script>` tag of an HTML page.
99109

100110
The following builds are available:
101111

102-
* https://unpkg.com/@pdf-lib/fontkit/dist/fontkit.umd.js
103-
* https://unpkg.com/@pdf-lib/fontkit/dist/fontkit.umd.min.js
112+
- https://unpkg.com/@pdf-lib/fontkit/dist/fontkit.umd.js
113+
- https://unpkg.com/@pdf-lib/fontkit/dist/fontkit.umd.min.js
104114

105115
When using a UMD build, you will have access to a global `window.fontkit` variable. This variable contains the object exported by `@pdf-lib/fontkit`. For example:
106116

107117
```javascript
108118
// NPM module
109-
import fontkit from '@pdf-lib/fontkit';
119+
import fontkit from "@pdf-lib/fontkit";
110120

111121
// UMD module
112122
var fontkit = window.fontkit;
@@ -126,33 +136,33 @@ There are several different types of font objects that are returned by fontkit d
126136

127137
The following properties are strings (or null if the font does not contain strings for them) describing the font, as specified by the font creator.
128138

129-
* `postscriptName`
130-
* `fullName`
131-
* `familyName`
132-
* `subfamilyName`
133-
* `copyright`
134-
* `version`
139+
- `postscriptName`
140+
- `fullName`
141+
- `familyName`
142+
- `subfamilyName`
143+
- `copyright`
144+
- `version`
135145

136146
### Metrics
137147

138148
The following properties describe the general metrics of the font. See [here](http://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html) for a good overview of how all of these properties relate to one another.
139149

140-
* `unitsPerEm` - the size of the font’s internal coordinate grid
141-
* `ascent` - the font’s [ascender](http://en.wikipedia.org/wiki/Ascender_(typography))
142-
* `descent` - the font’s [descender](http://en.wikipedia.org/wiki/Descender)
143-
* `lineGap` - the amount of space that should be included between lines
144-
* `underlinePosition` - the offset from the normal underline position that should be used
145-
* `underlineThickness` - the weight of the underline that should be used
146-
* `italicAngle` - if this is an italic font, the angle the cursor should be drawn at to match the font design
147-
* `capHeight` - the height of capital letters above the baseline. See [here](http://en.wikipedia.org/wiki/Cap_height) for more details.
148-
* `xHeight`- the height of lower case letters. See [here](http://en.wikipedia.org/wiki/X-height) for more details.
149-
* `bbox` - the font’s bounding box, i.e. the box that encloses all glyphs in the font
150+
- `unitsPerEm` - the size of the font’s internal coordinate grid
151+
- `ascent` - the font’s [ascender](<http://en.wikipedia.org/wiki/Ascender_(typography)>)
152+
- `descent` - the font’s [descender](http://en.wikipedia.org/wiki/Descender)
153+
- `lineGap` - the amount of space that should be included between lines
154+
- `underlinePosition` - the offset from the normal underline position that should be used
155+
- `underlineThickness` - the weight of the underline that should be used
156+
- `italicAngle` - if this is an italic font, the angle the cursor should be drawn at to match the font design
157+
- `capHeight` - the height of capital letters above the baseline. See [here](http://en.wikipedia.org/wiki/Cap_height) for more details.
158+
- `xHeight`- the height of lower case letters. See [here](http://en.wikipedia.org/wiki/X-height) for more details.
159+
- `bbox` - the font’s bounding box, i.e. the box that encloses all glyphs in the font
150160

151161
### Other properties
152162

153-
* `numGlyphs` - the number of glyphs in the font
154-
* `characterSet` - an array of all of the unicode code points supported by the font
155-
* `availableFeatures` - an array of all [OpenType feature tags](https://www.microsoft.com/typography/otspec/featuretags.htm) (or mapped AAT tags) supported by the font (see below for a description of this)
163+
- `numGlyphs` - the number of glyphs in the font
164+
- `characterSet` - an array of all of the unicode code points supported by the font
165+
- `availableFeatures` - an array of all [OpenType feature tags](https://www.microsoft.com/typography/otspec/featuretags.htm) (or mapped AAT tags) supported by the font (see below for a description of this)
156166

157167
### Character to glyph mapping
158168

@@ -242,12 +252,12 @@ You do not create glyph objects directly. They are created by various methods on
242252

243253
### Properties
244254

245-
* `id` - the glyph id in the font
246-
* `codePoints` - an array of unicode code points that are represented by this glyph. There can be multiple code points in the case of ligatures and other glyphs that represent multiple visual characters.
247-
* `path` - a vector Path object representing the glyph
248-
* `bbox` - the glyph’s bounding box, i.e. the rectangle that encloses the glyph outline as tightly as possible.
249-
* `cbox` - the glyph’s control box. This is often the same as the bounding box, but is faster to compute. Because of the way bezier curves are defined, some of the control points can be outside of the bounding box. Where `bbox` takes this into account, `cbox` does not. Thus, `cbox` is less accurate, but faster to compute. See [here](http://www.freetype.org/freetype2/docs/glyphs/glyphs-6.html#section-2) for a more detailed description.
250-
* `advanceWidth` - the glyph’s advance width.
255+
- `id` - the glyph id in the font
256+
- `codePoints` - an array of unicode code points that are represented by this glyph. There can be multiple code points in the case of ligatures and other glyphs that represent multiple visual characters.
257+
- `path` - a vector Path object representing the glyph
258+
- `bbox` - the glyph’s bounding box, i.e. the rectangle that encloses the glyph outline as tightly as possible.
259+
- `cbox` - the glyph’s control box. This is often the same as the bounding box, but is faster to compute. Because of the way bezier curves are defined, some of the control points can be outside of the bounding box. Where `bbox` takes this into account, `cbox` does not. Thus, `cbox` is less accurate, but faster to compute. See [here](http://www.freetype.org/freetype2/docs/glyphs/glyphs-6.html#section-2) for a more detailed description.
260+
- `advanceWidth` - the glyph’s advance width.
251261

252262
### `glyph.render(ctx, size)`
253263

@@ -322,4 +332,5 @@ Includes the given glyph object or glyph ID in the subset.
322332
Returns a [stream](https://nodejs.org/api/stream.html) containing the encoded font file that can be piped to a destination, such as a file.
323333

324334
## License
335+
325336
[MIT](https://choosealicense.com/licenses/mit/)

0 commit comments

Comments
 (0)