Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions WINDOWKIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dependent names its URL:
| Patch | Upstream |
| --- | --- |
| `getVariation()` for fonts in WOFF and WOFF2 containers (#1) | [foliojs/fontkit#389](https://github.com/foliojs/fontkit/pull/389) |
| Decoded structs hold their hidden fields in private fields of a class, not `Object.defineProperties`: a face's first shaping takes a third less time (#4, `src/restructure.js`) | Not offered. The change belongs in [restructure](https://github.com/foliojs/restructure)'s `Struct#_setup` ([sidorares/ntk#437](https://github.com/sidorares/ntk/issues/437)) |
| Builds for Chrome 91 rather than 70, so those private fields stay native instead of being compiled to WeakMaps (#4) | Fork only |

When upstream releases a version with everything in this table, the fork
has done its job: point the dependent back at `fontkit` on npm.
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@
"source": "src/node.js",
"context": "browser",
"engines": {
"browsers": "chrome >= 70"
"browsers": "chrome >= 91"
}
},
"node-module": {
"source": "src/node.js",
"isLibrary": true,
"includeNodeModules": false,
"engines": {
"browsers": "chrome >= 70"
"browsers": "chrome >= 91"
}
},
"module": {
"source": "src/index.js",
"engines": {
"browsers": "chrome >= 70"
"browsers": "chrome >= 91"
}
},
"browser": {
"source": "src/index.js",
"engines": {
"browsers": "chrome >= 70"
"browsers": "chrome >= 91"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/DFont.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from './restructure';
import TTFFont from './TTFFont';

let DFontName = new r.String(r.uint8);
Expand Down
2 changes: 1 addition & 1 deletion src/TrueTypeCollection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from './restructure';
import TTFFont from './TTFFont';
import Directory from './tables/directory';
import tables from './tables';
Expand Down
2 changes: 1 addition & 1 deletion src/WOFF2Font.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from './restructure';
import brotli from 'brotli/decompress.js';
import TTFFont from './TTFFont';
import TTFGlyph, { Point } from './glyph/TTFGlyph';
Expand Down
2 changes: 1 addition & 1 deletion src/cff/CFFTop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';
import { resolveLength } from 'restructure';
import CFFDict from './CFFDict';
import CFFIndex from './CFFIndex';
Expand Down
2 changes: 1 addition & 1 deletion src/glyph/SBIXGlyph.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import TTFGlyph from './TTFGlyph';
import * as r from 'restructure';
import * as r from '../restructure';

let SBIXImage = new r.Struct({
originX: r.uint16,
Expand Down
2 changes: 1 addition & 1 deletion src/glyph/TTFGlyph.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Glyph from './Glyph';
import Path from './Path';
import BBox from './BBox';
import * as r from 'restructure';
import * as r from '../restructure';

// The header for both simple and composite glyphs
let GlyfHeader = new r.Struct({
Expand Down
2 changes: 1 addition & 1 deletion src/glyph/TTFGlyphEncoder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

// Flags for simple glyphs
const ON_CURVE = 1 << 0;
Expand Down
91 changes: 91 additions & 0 deletions src/restructure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// restructure, with the structs fontkit decodes made without
// Object.defineProperties.
//
// restructure gives every struct it decodes four hidden fields (parent,
// _startOffset, _currentOffset, _length) with one Object.defineProperties
// call, which is a runtime call, and fontkit decodes thousands of structs in
// a face's first shaping and a glyph's first outline. The structs made here
// keep the four in private fields of a class and read them through accessors
// on its prototype, which takes a fifth to two fifths off a face's first
// shaping, more for a face with more lookups (sidorares/ntk#437).
//
// They are only fast where the private fields are native: package.json's
// targets are Chrome 91 rather than 70 for that, since below it the build
// compiles them to WeakMaps.
//
// Everything that reads them reads the same: they stay out of Object.keys,
// for...in, JSON.stringify and Object.assign, `struct.parent` reads, and a
// write to it throws in strict code. What differs is that they are no longer
// own properties (hasOwnProperty, getOwnPropertyNames), and that a decoded
// struct's prototype is DecodedStruct's rather than Object.prototype.
//
// This is a module of its own rather than a change to restructure's
// prototype because restructure is shared by everything in the process that
// uses it: only the structs fontkit declares are made this way. Files that
// declare structs import restructure from here, which test/restructure.js
// checks.
import * as r from 'restructure';

// By name, not `export * from 'restructure'`: the parcel this builds with
// drops a star re-export of an external package from a module it wraps, and
// it wraps this one. test/restructure.js checks the list is all of them.
export {
Array, Bitfield, Boolean, Buffer, DecodeStream, EncodeStream, Enum, Fixed,
LazyArray, Number, Optional, Pointer, PropertyDescriptor, Reserved, String,
VoidPointer, double, doublebe, doublele, fixed16, fixed16be, fixed16le,
fixed32, fixed32be, fixed32le, float, floatbe, floatle, int16, int16be,
int16le, int24, int24be, int24le, int32, int32be, int32le, int8,
resolveLength, uint16, uint16be, uint16le, uint24, uint24be, uint24le,
uint32, uint32be, uint32le, uint8
} from 'restructure';

export class DecodedStruct {
#parent;
#startOffset;
#currentOffset;
#length;

constructor(parent, startOffset, length) {
this.#parent = parent;
this.#startOffset = startOffset;
this.#currentOffset = 0;
this.#length = length;
}

// An object made with Object.create(DecodedStruct.prototype) has none of
// the fields, which is what a deep copy by the clone package is (subsets
// copy maxp, head and hhea that way). It reads them as undefined, as a
// copy of one of restructure's own structs does.

get parent() {
return #parent in this ? this.#parent : undefined;
}

get _startOffset() {
return #startOffset in this ? this.#startOffset : undefined;
}

get _currentOffset() {
return #currentOffset in this ? this.#currentOffset : undefined;
}

set _currentOffset(value) {
this.#currentOffset = value;
}

get _length() {
return #length in this ? this.#length : undefined;
}
}

export class Struct extends r.Struct {
_setup(stream, parent, length) {
return new DecodedStruct(parent, stream.pos, length);
}
}

export class VersionedStruct extends r.VersionedStruct {
_setup(stream, parent, length) {
return new DecodedStruct(parent, stream.pos, length);
}
}
2 changes: 1 addition & 1 deletion src/tables/BASE.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';
import {ScriptList, FeatureList, LookupList, Coverage, ClassDef, Device} from './opentype';
import {ItemVariationStore} from './variations';

Expand Down
2 changes: 1 addition & 1 deletion src/tables/COLR.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let LayerRecord = new r.Struct({
gid: r.uint16, // Glyph ID of layer glyph (must be in z-order from bottom to top).
Expand Down
2 changes: 1 addition & 1 deletion src/tables/CPAL.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let ColorRecord = new r.Struct({
blue: r.uint8,
Expand Down
2 changes: 1 addition & 1 deletion src/tables/DSIG.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let Signature = new r.Struct({
format: r.uint32,
Expand Down
2 changes: 1 addition & 1 deletion src/tables/EBDT.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

export let BigMetrics = new r.Struct({
height: r.uint8,
Expand Down
2 changes: 1 addition & 1 deletion src/tables/EBLC.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';
import {BigMetrics} from './EBDT';

let SBitLineMetrics = new r.Struct({
Expand Down
2 changes: 1 addition & 1 deletion src/tables/GDEF.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';
import {ScriptList, FeatureList, LookupList, Coverage, ClassDef, Device} from './opentype';
import {ItemVariationStore} from './variations';

Expand Down
2 changes: 1 addition & 1 deletion src/tables/GPOS.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';
import {ScriptList, FeatureList, LookupList, Coverage, ClassDef, Device, Context, ChainingContext} from './opentype';
import {FeatureVariations} from './variations';

Expand Down
2 changes: 1 addition & 1 deletion src/tables/GSUB.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';
import {ScriptList, FeatureList, LookupList, Coverage, ClassDef, Device, Context, ChainingContext} from './opentype';
import {FeatureVariations} from './variations';

Expand Down
2 changes: 1 addition & 1 deletion src/tables/HVAR.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';
import { resolveLength } from 'restructure';
import { ItemVariationStore } from './variations';

Expand Down
2 changes: 1 addition & 1 deletion src/tables/JSTF.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';
import { ScriptList, FeatureList, LookupList, Coverage, ClassDef, Device } from './opentype';
import { GPOSLookup } from './GPOS';

Expand Down
2 changes: 1 addition & 1 deletion src/tables/LTSH.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

// Linear Threshold table
// Records the ppem for each glyph at which the scaling becomes linear again,
Expand Down
2 changes: 1 addition & 1 deletion src/tables/OS2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

var OS2 = new r.VersionedStruct(r.uint16, {
header: {
Expand Down
2 changes: 1 addition & 1 deletion src/tables/PCLT.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

// PCL 5 Table
// NOTE: The PCLT table is strongly discouraged for OpenType fonts with TrueType outlines
Expand Down
2 changes: 1 addition & 1 deletion src/tables/VDMX.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

// VDMX tables contain ascender/descender overrides for certain (usually small)
// sizes. This is needed in order to match font metrics on Windows.
Expand Down
2 changes: 1 addition & 1 deletion src/tables/VORG.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let VerticalOrigin = new r.Struct({
glyphIndex: r.uint16,
Expand Down
2 changes: 1 addition & 1 deletion src/tables/WOFF2Directory.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

const Base128 = {
decode(stream) {
Expand Down
2 changes: 1 addition & 1 deletion src/tables/WOFFDirectory.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';
import tables from './';

let WOFFDirectoryEntry = new r.Struct({
Expand Down
2 changes: 1 addition & 1 deletion src/tables/aat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

class UnboundedArrayAccessor {
constructor(type, stream, parent) {
Expand Down
2 changes: 1 addition & 1 deletion src/tables/avar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let shortFrac = new r.Fixed(16, 'BE', 14);

Expand Down
2 changes: 1 addition & 1 deletion src/tables/bsln.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';
import { LookupTable } from './aat';

let BslnSubtable = new r.VersionedStruct('format', {
Expand Down
2 changes: 1 addition & 1 deletion src/tables/cmap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let SubHeader = new r.Struct({
firstCode: r.uint16,
Expand Down
2 changes: 1 addition & 1 deletion src/tables/cvt.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

// An array of predefined values accessible by instructions
export default new r.Struct({
Expand Down
2 changes: 1 addition & 1 deletion src/tables/directory.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';
import Tables from './';

let TableEntry = new r.Struct({
Expand Down
2 changes: 1 addition & 1 deletion src/tables/feat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let Setting = new r.Struct({
setting: r.uint16,
Expand Down
2 changes: 1 addition & 1 deletion src/tables/fpgm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

// A list of instructions that are executed once when a font is first used.
// These instructions are known as the font program. The main use of this table
Expand Down
2 changes: 1 addition & 1 deletion src/tables/fvar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let Axis = new r.Struct({
axisTag: new r.String(4),
Expand Down
2 changes: 1 addition & 1 deletion src/tables/gasp.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let GaspRange = new r.Struct({
rangeMaxPPEM: r.uint16, // Upper limit of range, in ppem
Expand Down
2 changes: 1 addition & 1 deletion src/tables/gvar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let shortFrac = new r.Fixed(16, 'BE', 14);
class Offset {
Expand Down
2 changes: 1 addition & 1 deletion src/tables/hdmx.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let DeviceRecord = new r.Struct({
pixelSize: r.uint8,
Expand Down
2 changes: 1 addition & 1 deletion src/tables/head.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

// font header
export default new r.Struct({
Expand Down
2 changes: 1 addition & 1 deletion src/tables/hhea.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

// horizontal header
export default new r.Struct({
Expand Down
2 changes: 1 addition & 1 deletion src/tables/hmtx.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let HmtxEntry = new r.Struct({
advance: r.uint16,
Expand Down
2 changes: 1 addition & 1 deletion src/tables/just.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';
import { LookupTable, StateTable1 } from './aat';

let ClassTable = new r.Struct({
Expand Down
2 changes: 1 addition & 1 deletion src/tables/kern.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let KernPair = new r.Struct({
left: r.uint16,
Expand Down
2 changes: 1 addition & 1 deletion src/tables/loca.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as r from 'restructure';
import * as r from '../restructure';

let loca = new r.VersionedStruct('head.indexToLocFormat', {
0: {
Expand Down
Loading