Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1a2a572
Use hard coded offSize in CFF encoder
devongovett Jan 28, 2019
2d1b0eb
1.7.8
devongovett Jan 28, 2019
e8ad1df
Added `defaultLanguage` to font objects (#194)
scottrippey Mar 7, 2019
b2a7529
Fix issue with undefined private dict in CFF
devongovett Mar 11, 2019
7b4f75d
Allow deleting a glyph via a multiple substitution in GSUB
devongovett Mar 11, 2019
4ca73fe
Merge branch 'master' of github.com:devongovett/fontkit
devongovett Mar 11, 2019
abbe9c2
Set a global default language (#195)
scottrippey Mar 11, 2019
436bd5e
Fix saving loca index format/version when subsetting (#191)
blikblum Mar 11, 2019
408f67c
Add missing font
devongovett Mar 11, 2019
d6a46e3
Formatting
devongovett Mar 11, 2019
374f1c4
1.8.0
devongovett Mar 11, 2019
1a53baa
Adding repository entry to packages json so that it appears on npm (#…
luanpotter Mar 11, 2019
9d41540
Augment AATMorxProcessor to allow for features to be disabled (instea…
issacgerges Oct 6, 2019
f2aa3d6
Use Promise instead of process.nextTick (#209)
blikblum Nov 17, 2019
cebf94e
Fix getting the fd index for OTF/CFF CID fonts (#207)
blikblum Nov 17, 2019
0e04e01
Update brf to ^2.0.0 so that it does not pull static-eval versions lo…
musculman Nov 17, 2019
15ef9d9
Fixes getting path from woff files with CFF (#200)
blikblum Nov 17, 2019
881d1b6
Bump lodash from 4.17.4 to 4.17.15 (#210)
dependabot[bot] Nov 17, 2019
f3f55a0
Fix for FDArray parsing in CFF (#224)
liborm85 Apr 25, 2020
fe37449
Fix for new Function call (#223)
liborm85 Apr 25, 2020
417af0c
1.8.1
devongovett Apr 25, 2020
006d0da
Merge with upstream repo
joewestcott Mar 30, 2022
a94a26a
chore: update `package.json`
aminaz Mar 25, 2025
d4fd01a
chore: update `README.md`
aminaz Mar 25, 2025
2bc56ce
feat: add GH publish action
aminaz Mar 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish Package to npmjs
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build
run: yarn make

- name: Release latest
run: yarn releaseLatest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
171 changes: 91 additions & 80 deletions README.md

Large diffs are not rendered by default.

21 changes: 9 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pdf-lib/fontkit",
"version": "1.1.0",
"name": "@cryptact/fontkit",
"version": "1.2.0",
"description": "An advanced font engine for Node and the browser",
"main": "dist/fontkit.umd.js",
"unpkg": "dist/fontkit.umd.min.js",
Expand Down Expand Up @@ -34,14 +34,14 @@
"babel-plugin-istanbul": "^4.1.3",
"base64-arraybuffer": "^0.1.5",
"buffer": "^5.6.0",
"clone": "^1.0.1",
"clone": "^1.0.4",
"codepoints": "^1.2.0",
"concat-stream": "^1.4.6",
"concat-stream": "^1.6.2",
"deep-equal": "^1.0.0",
"dfa": "^1.0.0",
"dfa": "^1.2.0",
"esdoc": "^0.4.8",
"esdoc-es7-plugin": "0.0.3",
"iconv-lite": "^0.4.13",
"iconv-lite": "^0.4.24",
"mocha": "^2.0.1",
"nyc": "^10.3.2",
"rollup": "^2.10.2",
Expand All @@ -56,7 +56,7 @@
},
"repository": {
"type": "git",
"url": "git://github.com/Hopding/fontkit.git"
"url": "git://github.com/Cryptact/fontkit.git"
},
"keywords": [
"opentype",
Expand All @@ -68,12 +68,9 @@
"layout"
],
"author": "Andrew Dillon <andrew.dillon.j@gmail.com>",
"contributors": [
"Devon Govett <devongovett@gmail.com> (http://badassjs.com/)"
],
"bugs": {
"url": "https://github.com/Hopding/fontkit/issues"
"url": "https://github.com/Cryptact/fontkit/issues"
},
"license": "MIT",
"homepage": "https://github.com/Hopding/fontkit"
"homepage": "https://github.com/Cryptact/fontkit"
}
41 changes: 24 additions & 17 deletions src/TTFFont.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class TTFFont {
}

constructor(stream, variationCoords = null) {
this.defaultLanguage = null;
this.stream = stream;
this.variationCoords = variationCoords;

Expand All @@ -44,6 +45,10 @@ export default class TTFFont {
}
}

setDefaultLanguage(lang = null) {
this.defaultLanguage = lang;
}

_getTable(table) {
if (!(table.tag in this._tables)) {
try {
Expand Down Expand Up @@ -83,34 +88,36 @@ export default class TTFFont {
return result;
}

/**
* The unique PostScript name for this font
* @type {string}
*/
get postscriptName() {
let name = this.name.records.postscriptName;
if (name) {
let lang = Object.keys(name)[0];
return name[lang];
}

return null;
}

/**
* Gets a string from the font's `name` table
* `lang` is a BCP-47 language code.
* @return {string}
*/
getName(key, lang = 'en') {
let record = this.name.records[key];
getName(key, lang = this.defaultLanguage || fontkit.defaultLanguage) {
let record = this.name && this.name.records[key];
if (record) {
return record[lang];
// Attempt to retrieve the entry, depending on which translation is available:
return (
record[lang]
|| record[this.defaultLanguage]
|| record[fontkit.defaultLanguage]
|| record['en']
|| record[Object.keys(record)[0]] // Seriously, ANY language would be fine
|| null
);
}

return null;
}

/**
* The unique PostScript name for this font, e.g. "Helvetica-Bold"
* @type {string}
*/
get postscriptName() {
return this.getName('postscriptName');
}

/**
* The font's full name, e.g. "Helvetica Bold"
* @type {string}
Expand Down
13 changes: 9 additions & 4 deletions src/aat/AATMorxProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,22 @@ export default class AATMorxProcessor {
}

// Processes an array of glyphs and applies the specified features
// Features should be in the form of {featureType:{featureSetting:true}}
// Features should be in the form of {featureType:{featureSetting:boolean}}
process(glyphs, features = {}) {
for (let chain of this.morx.chains) {
let flags = chain.defaultFlags;

// enable/disable the requested features
for (let feature of chain.features) {
let f;
if ((f = features[feature.featureType]) && f[feature.featureSetting]) {
flags &= feature.disableFlags;
flags |= feature.enableFlags;
if (f = features[feature.featureType]) {
if (f[feature.featureSetting]) {
flags &= feature.disableFlags;
flags |= feature.enableFlags;
} else if (f[feature.featureSetting] === false) {
flags |= ~feature.disableFlags;
flags &= ~feature.enableFlags;
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ const fontkit = {
},
};

fontkit.defaultLanguage = 'en';
fontkit.setDefaultLanguage = function(lang = 'en') {
fontkit.defaultLanguage = lang;
};

export default fontkit;

2 changes: 1 addition & 1 deletion src/cff/CFFFont.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class CFFFont {

if (gid < ranges[mid].first) {
high = mid - 1;
} else if (mid < high && gid > ranges[mid + 1].first) {
} else if (mid < high && gid >= ranges[mid + 1].first) {
low = mid + 1;
} else {
return ranges[mid].fd;
Expand Down
4 changes: 3 additions & 1 deletion src/cff/CFFTop.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ class CFFPrivateOp {
let FontDict = new CFFDict([
// key name type(s) default
[18, 'Private', new CFFPrivateOp, null],
[[12, 38], 'FontName', 'sid', null]
[[12, 38], 'FontName', 'sid', null],
[[12, 7], 'FontMatrix', 'array', [0.001, 0, 0, 0.001, 0, 0]],
[[12, 5], 'PaintType', 'number', 0],
]);

let CFFTopDict = new CFFDict([
Expand Down
6 changes: 2 additions & 4 deletions src/glyph/CFFGlyph.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ export default class CFFGlyph extends Glyph {
}

_getPath() {
let { stream } = this._font;
let { pos } = stream;

let cff = this._font.CFF2 || this._font['CFF '];
let { stream } = cff;
let str = cff.topDict.CharStrings[this.id];
let end = str.offset + str.length;
stream.pos = str.offset;
Expand All @@ -49,7 +47,7 @@ export default class CFFGlyph extends Glyph {
let gsubrs = cff.globalSubrIndex || [];
let gsubrsBias = this.bias(gsubrs);

let privateDict = cff.privateDictForGlyph(this.id);
let privateDict = cff.privateDictForGlyph(this.id) || {};
let subrs = privateDict.Subrs || [];
let subrsBias = this.bias(subrs);

Expand Down
6 changes: 5 additions & 1 deletion src/glyph/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export default class Path {
* @return {string}
*/
toFunction() {
return (ctx) => this.commands.forEach((c) => ctx[c.command].apply(ctx, c.args));
return ctx => {
this.commands.forEach(c => {
return ctx[c.command].apply(ctx, c.args)
})
};
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/opentype/GSUBProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export default class GSUBProcessor extends OTProcessor {
let index = this.coverageIndex(table.coverage);
if (index !== -1) {
let sequence = table.sequences.get(index);

if (sequence.length === 0) {
// If the sequence length is zero, delete the glyph.
// The OpenType spec disallows this, but seems like Harfbuzz and Uniscribe allow it.
this.glyphs.splice(this.glyphIterator.index, 1);
return true;
}

this.glyphIterator.cur.id = sequence[0];
this.glyphIterator.cur.ligatureComponent = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/subset/CFFSubset.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default class CFFSubset extends Subset {
let top = {
version: 1,
hdrSize: this.cff.hdrSize,
offSize: this.cff.length,
offSize: 4,
header: this.cff.header,
nameIndex: [this.cff.postscriptName],
topDictIndex: [topDict],
Expand Down
4 changes: 3 additions & 1 deletion src/subset/Subset.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import r from '@pdf-lib/restructure';

const resolved = Promise.resolve();

export default class Subset {
constructor(font) {
this.font = font;
Expand All @@ -26,7 +28,7 @@ export default class Subset {
encodeStream() {
let s = new r.EncodeStream();

process.nextTick(() => {
resolved.then(() => {
this.encode(s);
return s.end();
});
Expand Down
4 changes: 2 additions & 2 deletions src/subset/TTFSubset.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export default class TTFSubset extends Subset {
this.glyf = [];
this.offset = 0;
this.loca = {
offsets: []
offsets: [],
version: this.font.loca.version
};

this.hmtx = {
Expand All @@ -77,7 +78,6 @@ export default class TTFSubset extends Subset {
maxp.numGlyphs = this.glyf.length;

this.loca.offsets.push(this.offset);
Tables.loca.preEncode.call(this.loca);

let head = cloneDeep(this.font.head);
head.indexToLocFormat = this.loca.version;
Expand Down
5 changes: 0 additions & 5 deletions src/tables/loca.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ loca.process = function() {
};

loca.preEncode = function() {
if (this.version != null) return;

// assume this.offsets is a sorted array
this.version = this.offsets[this.offsets.length - 1] > 0xffff ? 1 : 0;

if (this.version === 0) {
for (let i = 0; i < this.offsets.length; i++) {
this.offsets[i] >>>= 1;
Expand Down
Binary file added test/data/FiraSans/FiraSans-Regular.ttf
Binary file not shown.
Loading