@automovie/ingest 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -29
- package/lib/AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE.d.ts +4 -1
- package/lib/AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE.js +4 -1
- package/lib/AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE.js.map +1 -1
- package/lib/AUTO_MOVIE_EXTERNAL_MODEL_INGEST_PROFILES.d.ts +4 -1
- package/lib/AUTO_MOVIE_EXTERNAL_MODEL_INGEST_PROFILES.js +4 -1
- package/lib/AUTO_MOVIE_EXTERNAL_MODEL_INGEST_PROFILES.js.map +1 -1
- package/lib/adoptAutoMovieExternalMotion.d.ts +21 -11
- package/lib/adoptAutoMovieExternalMotion.js +26 -12
- package/lib/adoptAutoMovieExternalMotion.js.map +1 -1
- package/lib/audio/admitProductionTtsReceipt.d.ts +25 -0
- package/lib/audio/admitProductionTtsReceipt.js +166 -0
- package/lib/audio/admitProductionTtsReceipt.js.map +1 -0
- package/lib/audio/decodeProductionAudioAsset.d.ts +42 -14
- package/lib/audio/decodeProductionAudioAsset.js +53 -30
- package/lib/audio/decodeProductionAudioAsset.js.map +1 -1
- package/lib/audio/index.d.ts +1 -0
- package/lib/audio/index.js +1 -0
- package/lib/audio/index.js.map +1 -1
- package/lib/audio/resampleProductionAudio.d.ts +22 -0
- package/lib/audio/resampleProductionAudio.js +103 -0
- package/lib/audio/resampleProductionAudio.js.map +1 -0
- package/lib/decodeAutoMoviePpmImage.d.ts +10 -18
- package/lib/decodeAutoMoviePpmImage.js +10 -18
- package/lib/decodeAutoMoviePpmImage.js.map +1 -1
- package/lib/font/TrueTypeByteReader.d.ts +34 -0
- package/lib/font/TrueTypeByteReader.js +67 -0
- package/lib/font/TrueTypeByteReader.js.map +1 -0
- package/lib/font/decodeAutoMovieTrueTypeFont.d.ts +31 -0
- package/lib/font/decodeAutoMovieTrueTypeFont.js +168 -0
- package/lib/font/decodeAutoMovieTrueTypeFont.js.map +1 -0
- package/lib/font/index.d.ts +1 -0
- package/lib/font/index.js +18 -0
- package/lib/font/index.js.map +1 -0
- package/lib/font/readTrueTypeCharacterMap.d.ts +23 -0
- package/lib/font/readTrueTypeCharacterMap.js +98 -0
- package/lib/font/readTrueTypeCharacterMap.js.map +1 -0
- package/lib/font/readTrueTypeGlyphOutline.d.ts +45 -0
- package/lib/font/readTrueTypeGlyphOutline.js +275 -0
- package/lib/font/readTrueTypeGlyphOutline.js.map +1 -0
- package/lib/font/readTrueTypeKerning.d.ts +19 -0
- package/lib/font/readTrueTypeKerning.js +63 -0
- package/lib/font/readTrueTypeKerning.js.map +1 -0
- package/lib/font/readTrueTypeNames.d.ts +20 -0
- package/lib/font/readTrueTypeNames.js +75 -0
- package/lib/font/readTrueTypeNames.js.map +1 -0
- package/lib/humanoidSkeleton.d.ts +28 -15
- package/lib/humanoidSkeleton.js +28 -15
- package/lib/humanoidSkeleton.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/ingestDocument.d.ts +25 -12
- package/lib/ingestDocument.js +25 -12
- package/lib/ingestDocument.js.map +1 -1
- package/lib/inspectAutoMovieExternalModelBytes.d.ts +24 -12
- package/lib/inspectAutoMovieExternalModelBytes.js +24 -12
- package/lib/inspectAutoMovieExternalModelBytes.js.map +1 -1
- package/lib/internal/IAccessorSource.d.ts +11 -8
- package/lib/internal/IExternalModelAccessorReader.d.ts +1 -8
- package/lib/internal/IHumanoidSlot.d.ts +9 -10
- package/lib/internal/IParsedContainer.d.ts +10 -8
- package/lib/internal/SHAPE_COMPONENTS.d.ts +4 -1
- package/lib/internal/SHAPE_COMPONENTS.js +4 -1
- package/lib/internal/SHAPE_COMPONENTS.js.map +1 -1
- package/lib/internal/accessorElementByteLength.d.ts +1 -11
- package/lib/internal/accessorElementByteLength.js +1 -11
- package/lib/internal/accessorElementByteLength.js.map +1 -1
- package/lib/internal/accessorReader.d.ts +5 -9
- package/lib/internal/accessorReader.js +5 -9
- package/lib/internal/accessorReader.js.map +1 -1
- package/lib/internal/accessorValues.d.ts +10 -10
- package/lib/internal/accessorValues.js +10 -10
- package/lib/internal/collectExternalResources.d.ts +1 -11
- package/lib/internal/collectExternalResources.js +1 -11
- package/lib/internal/collectExternalResources.js.map +1 -1
- package/lib/internal/compareCodeUnits.d.ts +1 -11
- package/lib/internal/compareCodeUnits.js +1 -11
- package/lib/internal/compareCodeUnits.js.map +1 -1
- package/lib/internal/composeLocalTransform.d.ts +13 -10
- package/lib/internal/composeLocalTransform.js +13 -10
- package/lib/internal/composeLocalTransform.js.map +1 -1
- package/lib/internal/decodeDataUri.d.ts +4 -9
- package/lib/internal/decodeDataUri.js +4 -9
- package/lib/internal/decodeDataUri.js.map +1 -1
- package/lib/internal/decodeGlb.d.ts +1 -11
- package/lib/internal/decodeGlb.js +1 -11
- package/lib/internal/decodeGlb.js.map +1 -1
- package/lib/internal/decodeJson.d.ts +1 -11
- package/lib/internal/decodeJson.js +10 -12
- package/lib/internal/decodeJson.js.map +1 -1
- package/lib/internal/fileExtension.d.ts +2 -9
- package/lib/internal/fileExtension.js +2 -9
- package/lib/internal/fileExtension.js.map +1 -1
- package/lib/internal/finiteTuple.d.ts +4 -9
- package/lib/internal/finiteTuple.js +4 -9
- package/lib/internal/finiteTuple.js.map +1 -1
- package/lib/internal/gltfHumanoidBones.d.ts +5 -9
- package/lib/internal/gltfHumanoidBones.js +5 -9
- package/lib/internal/gltfHumanoidBones.js.map +1 -1
- package/lib/internal/humanoidBoneOfName.d.ts +7 -9
- package/lib/internal/humanoidBoneOfName.js +7 -9
- package/lib/internal/humanoidBoneOfName.js.map +1 -1
- package/lib/internal/inspectExternalModelHierarchy.d.ts +1 -11
- package/lib/internal/inspectExternalModelHierarchy.js +1 -11
- package/lib/internal/inspectExternalModelHierarchy.js.map +1 -1
- package/lib/internal/inspectExternalMotion.d.ts +8 -9
- package/lib/internal/inspectExternalMotion.js +8 -9
- package/lib/internal/inspectExternalMotion.js.map +1 -1
- package/lib/internal/inspectExternalMotionNodes.d.ts +6 -9
- package/lib/internal/inspectExternalMotionNodes.js +6 -9
- package/lib/internal/inspectExternalMotionNodes.js.map +1 -1
- package/lib/internal/integerIndex.d.ts +1 -11
- package/lib/internal/integerIndex.js +1 -11
- package/lib/internal/integerIndex.js.map +1 -1
- package/lib/internal/integerIndices.d.ts +1 -11
- package/lib/internal/integerIndices.js +1 -11
- package/lib/internal/integerIndices.js.map +1 -1
- package/lib/internal/nonNegativeInteger.d.ts +1 -11
- package/lib/internal/nonNegativeInteger.js +1 -11
- package/lib/internal/nonNegativeInteger.js.map +1 -1
- package/lib/internal/object.d.ts +1 -11
- package/lib/internal/object.js +1 -11
- package/lib/internal/object.js.map +1 -1
- package/lib/internal/optionalArray.d.ts +1 -11
- package/lib/internal/optionalArray.js +1 -11
- package/lib/internal/optionalArray.js.map +1 -1
- package/lib/internal/optionalObject.d.ts +1 -11
- package/lib/internal/optionalObject.js +1 -11
- package/lib/internal/optionalObject.js.map +1 -1
- package/lib/internal/optionalStringArray.d.ts +1 -11
- package/lib/internal/optionalStringArray.js +1 -11
- package/lib/internal/optionalStringArray.js.map +1 -1
- package/lib/internal/positiveInteger.d.ts +1 -11
- package/lib/internal/positiveInteger.js +1 -11
- package/lib/internal/positiveInteger.js.map +1 -1
- package/lib/internal/readMotionAccessor.d.ts +5 -9
- package/lib/internal/readMotionAccessor.js +5 -9
- package/lib/internal/readMotionAccessor.js.map +1 -1
- package/lib/internal/requiredArray.d.ts +1 -11
- package/lib/internal/requiredArray.js +1 -11
- package/lib/internal/requiredArray.js.map +1 -1
- package/lib/internal/uniqueStrings.d.ts +1 -11
- package/lib/internal/uniqueStrings.js +1 -11
- package/lib/internal/uniqueStrings.js.map +1 -1
- package/lib/internal/validNodeIndex.d.ts +1 -11
- package/lib/internal/validNodeIndex.js +1 -11
- package/lib/internal/validNodeIndex.js.map +1 -1
- package/lib/internal/validateAccessorRange.d.ts +6 -9
- package/lib/internal/validateAccessorRange.js +6 -9
- package/lib/internal/validateAccessorRange.js.map +1 -1
- package/lib/internal/validateHumanoidSkinning.d.ts +8 -10
- package/lib/internal/validateHumanoidSkinning.js +8 -10
- package/lib/internal/validateHumanoidSkinning.js.map +1 -1
- package/lib/internal/validatePayloadClosure.d.ts +8 -9
- package/lib/internal/validatePayloadClosure.js +8 -9
- package/lib/internal/validatePayloadClosure.js.map +1 -1
- package/lib/internal/validateSparseAccessor.d.ts +6 -9
- package/lib/internal/validateSparseAccessor.js +6 -9
- package/lib/internal/validateSparseAccessor.js.map +1 -1
- package/lib/internal/vrmHumanoidBones.d.ts +7 -9
- package/lib/internal/vrmHumanoidBones.js +12 -10
- package/lib/internal/vrmHumanoidBones.js.map +1 -1
- package/lib/isAutoMovieExternalModelIngestProfile.d.ts +4 -10
- package/lib/isAutoMovieExternalModelIngestProfile.js +4 -10
- package/lib/isAutoMovieExternalModelIngestProfile.js.map +1 -1
- package/package.json +7 -7
- package/src/AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE.ts +4 -1
- package/src/AUTO_MOVIE_EXTERNAL_MODEL_INGEST_PROFILES.ts +4 -1
- package/src/adoptAutoMovieExternalMotion.ts +26 -12
- package/src/audio/admitProductionTtsReceipt.ts +262 -0
- package/src/audio/decodeProductionAudioAsset.ts +54 -39
- package/src/audio/index.ts +1 -0
- package/src/audio/resampleProductionAudio.ts +114 -0
- package/src/decodeAutoMoviePpmImage.ts +10 -18
- package/src/font/TrueTypeByteReader.ts +80 -0
- package/src/font/decodeAutoMovieTrueTypeFont.ts +217 -0
- package/src/font/index.ts +1 -0
- package/src/font/readTrueTypeCharacterMap.ts +115 -0
- package/src/font/readTrueTypeGlyphOutline.ts +375 -0
- package/src/font/readTrueTypeKerning.ts +73 -0
- package/src/font/readTrueTypeNames.ts +74 -0
- package/src/humanoidSkeleton.ts +28 -15
- package/src/index.ts +1 -0
- package/src/ingestDocument.ts +25 -12
- package/src/inspectAutoMovieExternalModelBytes.ts +24 -12
- package/src/internal/IAccessorSource.ts +11 -8
- package/src/internal/IExternalModelAccessorReader.ts +1 -8
- package/src/internal/IHumanoidSlot.ts +9 -10
- package/src/internal/IParsedContainer.ts +10 -8
- package/src/internal/SHAPE_COMPONENTS.ts +4 -1
- package/src/internal/accessorElementByteLength.ts +1 -11
- package/src/internal/accessorReader.ts +5 -9
- package/src/internal/accessorValues.ts +10 -10
- package/src/internal/collectExternalResources.ts +1 -11
- package/src/internal/compareCodeUnits.ts +1 -11
- package/src/internal/composeLocalTransform.ts +13 -10
- package/src/internal/decodeDataUri.ts +4 -9
- package/src/internal/decodeGlb.ts +1 -11
- package/src/internal/decodeJson.ts +10 -12
- package/src/internal/fileExtension.ts +2 -9
- package/src/internal/finiteTuple.ts +4 -9
- package/src/internal/gltfHumanoidBones.ts +5 -9
- package/src/internal/humanoidBoneOfName.ts +7 -9
- package/src/internal/inspectExternalModelHierarchy.ts +1 -11
- package/src/internal/inspectExternalMotion.ts +8 -9
- package/src/internal/inspectExternalMotionNodes.ts +6 -9
- package/src/internal/integerIndex.ts +1 -11
- package/src/internal/integerIndices.ts +1 -11
- package/src/internal/nonNegativeInteger.ts +1 -11
- package/src/internal/object.ts +1 -11
- package/src/internal/optionalArray.ts +1 -11
- package/src/internal/optionalObject.ts +1 -11
- package/src/internal/optionalStringArray.ts +1 -11
- package/src/internal/positiveInteger.ts +1 -11
- package/src/internal/readMotionAccessor.ts +5 -9
- package/src/internal/requiredArray.ts +1 -11
- package/src/internal/uniqueStrings.ts +1 -11
- package/src/internal/validNodeIndex.ts +1 -11
- package/src/internal/validateAccessorRange.ts +6 -9
- package/src/internal/validateHumanoidSkinning.ts +8 -10
- package/src/internal/validatePayloadClosure.ts +8 -9
- package/src/internal/validateSparseAccessor.ts +6 -9
- package/src/internal/vrmHumanoidBones.ts +12 -10
- package/src/isAutoMovieExternalModelIngestProfile.ts +4 -10
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeAutoMovieTrueTypeFont = decodeAutoMovieTrueTypeFont;
|
|
4
|
+
const TrueTypeByteReader_1 = require("./TrueTypeByteReader");
|
|
5
|
+
const readTrueTypeCharacterMap_1 = require("./readTrueTypeCharacterMap");
|
|
6
|
+
const readTrueTypeGlyphOutline_1 = require("./readTrueTypeGlyphOutline");
|
|
7
|
+
const readTrueTypeKerning_1 = require("./readTrueTypeKerning");
|
|
8
|
+
const readTrueTypeNames_1 = require("./readTrueTypeNames");
|
|
9
|
+
/** Tables every admitted font must carry. */
|
|
10
|
+
const REQUIRED = [
|
|
11
|
+
"head",
|
|
12
|
+
"hhea",
|
|
13
|
+
"maxp",
|
|
14
|
+
"cmap",
|
|
15
|
+
"hmtx",
|
|
16
|
+
"loca",
|
|
17
|
+
"glyf",
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Decode one TrueType-outline font's bytes into outlines, metrics, kerning and
|
|
21
|
+
* descriptive names, following the Open Font Format (ISO/IEC 14496-22).
|
|
22
|
+
*
|
|
23
|
+
* It admits a single font whose `sfnt` version is `0x00010000` or the tag
|
|
24
|
+
* `true`, and refuses, each with its own diagnostic, CFF outlines (`OTTO`), a
|
|
25
|
+
* font collection (`ttcf`), WOFF (`wOFF`) and WOFF2 (`wOF2`), any other
|
|
26
|
+
* version, a missing required table (`head`, `hhea`, `maxp`, `cmap`, `hmtx`,
|
|
27
|
+
* `loca`, `glyf`), a table record or field outside the bytes, a `head` magic
|
|
28
|
+
* number other than `0x5F0F3CF5`, a units-per-em outside 16 to 16384, and a
|
|
29
|
+
* `loca` offset that decreases or lies past the end of `glyf`.
|
|
30
|
+
*
|
|
31
|
+
* It reads `head` (units per em, `loca` format), `hhea` (ascender, descender,
|
|
32
|
+
* line gap, horizontal metric count), `maxp` (glyph count), `cmap` (formats 4
|
|
33
|
+
* and 12 for Unicode), `hmtx`, `loca` and `glyf`, composite glyphs included;
|
|
34
|
+
* `kern` format 0 pairs when present; the `OS/2` `fsType` and `name` IDs 1, 13
|
|
35
|
+
* and 14 when present. Only glyphs a code point maps to are decoded, each once.
|
|
36
|
+
* Table checksums are not verified: a damaged byte that still decodes yields
|
|
37
|
+
* the outline it encodes, and the asset ledger's digest is what fixes the
|
|
38
|
+
* bytes. Hinting instructions are skipped.
|
|
39
|
+
*
|
|
40
|
+
* The function is pure: the same bytes always give a deep-equal record, and the
|
|
41
|
+
* result shares no storage with the input.
|
|
42
|
+
*
|
|
43
|
+
* @param bytes The font file's bytes; only read.
|
|
44
|
+
* @returns The decoded record in font units.
|
|
45
|
+
* @throws {Error} Any refusal above, naming the format, table, glyph or offset
|
|
46
|
+
* at fault.
|
|
47
|
+
*/
|
|
48
|
+
function decodeAutoMovieTrueTypeFont(bytes) {
|
|
49
|
+
const reader = new TrueTypeByteReader_1.TrueTypeByteReader(bytes);
|
|
50
|
+
const version = reader.u32(0, "sfnt header");
|
|
51
|
+
const tag = reader.tag(0, "sfnt header");
|
|
52
|
+
if (tag === "OTTO")
|
|
53
|
+
throw new Error("The font has CFF outlines (sfnt version OTTO); only TrueType outlines are supported");
|
|
54
|
+
if (tag === "ttcf")
|
|
55
|
+
throw new Error("The bytes are a font collection (ttcf); supply one TrueType font");
|
|
56
|
+
if (tag === "wOFF")
|
|
57
|
+
throw new Error("The bytes are a WOFF font; supply the uncompressed TrueType font");
|
|
58
|
+
if (tag === "wOF2")
|
|
59
|
+
throw new Error("The bytes are a WOFF2 font; supply the uncompressed TrueType font");
|
|
60
|
+
if (version !== 0x00010000 && tag !== "true")
|
|
61
|
+
throw new Error(`The bytes are not a TrueType font: sfnt version 0x${version.toString(16).padStart(8, "0")}`);
|
|
62
|
+
// The table directory; every record must lie inside the bytes.
|
|
63
|
+
const count = reader.u16(4, "sfnt header");
|
|
64
|
+
const tables = new Map();
|
|
65
|
+
for (let index = 0; index < count; ++index) {
|
|
66
|
+
const record = 12 + index * 16;
|
|
67
|
+
const name = reader.tag(record, "table record");
|
|
68
|
+
const offset = reader.u32(record + 8, "table record");
|
|
69
|
+
const length = reader.u32(record + 12, "table record");
|
|
70
|
+
reader.require(offset, length, `table "${name}"`);
|
|
71
|
+
tables.set(name, { offset, length });
|
|
72
|
+
}
|
|
73
|
+
for (const name of REQUIRED)
|
|
74
|
+
if (!tables.has(name))
|
|
75
|
+
throw new Error(`The TrueType font is missing required table "${name}"`);
|
|
76
|
+
const table = (name, minimum) => {
|
|
77
|
+
const found = tables.get(name);
|
|
78
|
+
if (found.length < minimum)
|
|
79
|
+
throw new Error(`TrueType table "${name}" is ${found.length} bytes, shorter than its ${minimum}-byte header`);
|
|
80
|
+
return found.offset;
|
|
81
|
+
};
|
|
82
|
+
const head = table("head", 54);
|
|
83
|
+
if (reader.u32(head + 12, "head") !== 0x5f0f3cf5)
|
|
84
|
+
throw new Error("TrueType head table magic number is not 0x5F0F3CF5");
|
|
85
|
+
const unitsPerEm = reader.u16(head + 18, "head");
|
|
86
|
+
if (unitsPerEm < 16 || unitsPerEm > 16384)
|
|
87
|
+
throw new Error(`TrueType units per em ${unitsPerEm} is outside the 16 to 16384 range the format allows`);
|
|
88
|
+
const longOffsets = reader.i16(head + 50, "head") === 1;
|
|
89
|
+
const hhea = table("hhea", 36);
|
|
90
|
+
const ascender = reader.i16(hhea + 4, "hhea");
|
|
91
|
+
const descender = reader.i16(hhea + 6, "hhea");
|
|
92
|
+
const lineGap = reader.i16(hhea + 8, "hhea");
|
|
93
|
+
const metrics = reader.u16(hhea + 34, "hhea");
|
|
94
|
+
const glyphCount = reader.u16(table("maxp", 6) + 4, "maxp");
|
|
95
|
+
if (metrics === 0 || metrics > glyphCount)
|
|
96
|
+
throw new Error(`TrueType hhea declares ${metrics} horizontal metrics for ${glyphCount} glyphs`);
|
|
97
|
+
// Glyphs past the last full metric repeat its advance.
|
|
98
|
+
const hmtx = table("hmtx", 0);
|
|
99
|
+
reader.require(hmtx, metrics * 4 + (glyphCount - metrics) * 2, "hmtx table");
|
|
100
|
+
const advance = (glyph) => reader.u16(hmtx + Math.min(glyph, metrics - 1) * 4, "hmtx");
|
|
101
|
+
// loca: one offset per glyph and one past the last, increasing within glyf.
|
|
102
|
+
const glyf = tables.get("glyf");
|
|
103
|
+
const locaAt = table("loca", (glyphCount + 1) * (longOffsets ? 4 : 2));
|
|
104
|
+
const loca = [];
|
|
105
|
+
for (let glyph = 0; glyph <= glyphCount; ++glyph) {
|
|
106
|
+
const value = longOffsets
|
|
107
|
+
? reader.u32(locaAt + glyph * 4, "loca")
|
|
108
|
+
: reader.u16(locaAt + glyph * 2, "loca") * 2;
|
|
109
|
+
if (value > glyf.length)
|
|
110
|
+
throw new Error(`TrueType loca offset ${value} for glyph ${glyph} lies past the end of the ${glyf.length}-byte glyf table`);
|
|
111
|
+
if (glyph > 0 && value < loca[glyph - 1])
|
|
112
|
+
throw new Error(`TrueType loca offset ${value} for glyph ${glyph} decreases from ${loca[glyph - 1]}`);
|
|
113
|
+
loca.push(value);
|
|
114
|
+
}
|
|
115
|
+
const characters = (0, readTrueTypeCharacterMap_1.readTrueTypeCharacterMap)(reader, table("cmap", 4), glyphCount);
|
|
116
|
+
const cache = new Map();
|
|
117
|
+
const glyphs = [];
|
|
118
|
+
const codePoints = new Map();
|
|
119
|
+
for (const [codePoint, glyph] of characters) {
|
|
120
|
+
const contours = (0, readTrueTypeGlyphOutline_1.readTrueTypeGlyphOutline)({
|
|
121
|
+
reader,
|
|
122
|
+
glyf: glyf.offset,
|
|
123
|
+
loca,
|
|
124
|
+
glyph,
|
|
125
|
+
cache,
|
|
126
|
+
});
|
|
127
|
+
glyphs.push({
|
|
128
|
+
codePoint,
|
|
129
|
+
advance: advance(glyph),
|
|
130
|
+
contours: contours.map((contour) => contour.map((segment) => ({
|
|
131
|
+
start: [...segment.start],
|
|
132
|
+
control: [...segment.control],
|
|
133
|
+
end: [...segment.end],
|
|
134
|
+
}))),
|
|
135
|
+
});
|
|
136
|
+
const shared = codePoints.get(glyph);
|
|
137
|
+
if (shared === undefined)
|
|
138
|
+
codePoints.set(glyph, [codePoint]);
|
|
139
|
+
else
|
|
140
|
+
shared.push(codePoint);
|
|
141
|
+
}
|
|
142
|
+
// Kerning by glyph pair, expanded to every code point pair that maps to it.
|
|
143
|
+
const kerning = [];
|
|
144
|
+
if (tables.has("kern"))
|
|
145
|
+
for (const [key, value] of (0, readTrueTypeKerning_1.readTrueTypeKerning)(reader, table("kern", 4))) {
|
|
146
|
+
if (value === 0)
|
|
147
|
+
continue;
|
|
148
|
+
for (const left of codePoints.get(Math.floor(key / 65536)) ?? [])
|
|
149
|
+
for (const right of codePoints.get(key % 65536) ?? [])
|
|
150
|
+
kerning.push({ left, right, value });
|
|
151
|
+
}
|
|
152
|
+
kerning.sort((a, b) => a.left - b.left || a.right - b.right);
|
|
153
|
+
return {
|
|
154
|
+
unitsPerEm,
|
|
155
|
+
ascender,
|
|
156
|
+
descender,
|
|
157
|
+
lineGap,
|
|
158
|
+
glyphs,
|
|
159
|
+
kerning,
|
|
160
|
+
fsType: tables.has("OS/2")
|
|
161
|
+
? reader.u16(table("OS/2", 10) + 8, "OS/2")
|
|
162
|
+
: null,
|
|
163
|
+
names: tables.has("name")
|
|
164
|
+
? (0, readTrueTypeNames_1.readTrueTypeNames)(reader, table("name", 6))
|
|
165
|
+
: { family: null, licenseDescription: null, licenseUrl: null },
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=decodeAutoMovieTrueTypeFont.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeAutoMovieTrueTypeFont.js","sourceRoot":"","sources":["../../src/font/decodeAutoMovieTrueTypeFont.ts"],"names":[],"mappings":";;;AAOA,6DAA0D;AAC1D,yEAAsE;AACtE,yEAAsE;AACtE,+DAA4D;AAC5D,2DAAwD;AAExD,6CAA6C;AAC7C,MAAM,QAA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IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,IAAI,EAAE;gBAC9D,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,EAAE;oBACnD,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3C,CAAC;IACH,OAAO,CAAC,IAAI,CACV,CAAC,CAAwB,EAAE,CAAwB,EAAU,EAAE,CAC7D,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CACvC,CAAC;IAEF,OAAO;QACL,UAAU;QACV,QAAQ;QACR,SAAS;QACT,OAAO;QACP,MAAM;QACN,OAAO;QACP,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;YACxB,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;YAC3C,CAAC,CAAC,IAAI;QACR,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;YACvB,CAAC,CAAC,IAAA,qCAAiB,EAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YAC7C,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;KACjE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./decodeAutoMovieTrueTypeFont";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./decodeAutoMovieTrueTypeFont"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/font/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA8C"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { TrueTypeByteReader } from "./TrueTypeByteReader";
|
|
2
|
+
/**
|
|
3
|
+
* Read a font's Unicode character map: which glyph each code point selects,
|
|
4
|
+
* from the `cmap` table (ISO/IEC 14496-22, section 5.2.1).
|
|
5
|
+
*
|
|
6
|
+
* The Unicode encoding records are platform 0 with any encoding, and platform 3
|
|
7
|
+
* with encoding 1 (BMP) or 10 (full repertoire). A format 12 subtable among
|
|
8
|
+
* them is read in preference to a format 4 one, because it covers code points
|
|
9
|
+
* past U+FFFF; other formats are skipped. Format 4 follows the segment arrays
|
|
10
|
+
* exactly, including the `idRangeOffset` indirection and modulo-65536
|
|
11
|
+
* `idDelta`. Code point U+FFFF and glyph 0 (`.notdef`) map nothing, so a code
|
|
12
|
+
* point the font cannot draw is absent instead of silently drawing `.notdef`.
|
|
13
|
+
*
|
|
14
|
+
* @param reader Bounds-checked reader over the font bytes.
|
|
15
|
+
* @param offset Byte offset of the `cmap` table.
|
|
16
|
+
* @param glyphCount `maxp` glyph count; a mapping to a glyph at or past it
|
|
17
|
+
* refuses.
|
|
18
|
+
* @returns Code point to glyph index, in increasing code point order.
|
|
19
|
+
* @throws {Error} No Unicode subtable of format 4 or 12 exists, a field lies
|
|
20
|
+
* outside the bytes, or a mapping names a glyph past the glyph count or a
|
|
21
|
+
* code point past U+10FFFF.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readTrueTypeCharacterMap(reader: TrueTypeByteReader, offset: number, glyphCount: number): Map<number, number>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readTrueTypeCharacterMap = readTrueTypeCharacterMap;
|
|
4
|
+
/**
|
|
5
|
+
* Read a font's Unicode character map: which glyph each code point selects,
|
|
6
|
+
* from the `cmap` table (ISO/IEC 14496-22, section 5.2.1).
|
|
7
|
+
*
|
|
8
|
+
* The Unicode encoding records are platform 0 with any encoding, and platform 3
|
|
9
|
+
* with encoding 1 (BMP) or 10 (full repertoire). A format 12 subtable among
|
|
10
|
+
* them is read in preference to a format 4 one, because it covers code points
|
|
11
|
+
* past U+FFFF; other formats are skipped. Format 4 follows the segment arrays
|
|
12
|
+
* exactly, including the `idRangeOffset` indirection and modulo-65536
|
|
13
|
+
* `idDelta`. Code point U+FFFF and glyph 0 (`.notdef`) map nothing, so a code
|
|
14
|
+
* point the font cannot draw is absent instead of silently drawing `.notdef`.
|
|
15
|
+
*
|
|
16
|
+
* @param reader Bounds-checked reader over the font bytes.
|
|
17
|
+
* @param offset Byte offset of the `cmap` table.
|
|
18
|
+
* @param glyphCount `maxp` glyph count; a mapping to a glyph at or past it
|
|
19
|
+
* refuses.
|
|
20
|
+
* @returns Code point to glyph index, in increasing code point order.
|
|
21
|
+
* @throws {Error} No Unicode subtable of format 4 or 12 exists, a field lies
|
|
22
|
+
* outside the bytes, or a mapping names a glyph past the glyph count or a
|
|
23
|
+
* code point past U+10FFFF.
|
|
24
|
+
*/
|
|
25
|
+
function readTrueTypeCharacterMap(reader, offset, glyphCount) {
|
|
26
|
+
const count = reader.u16(offset + 2, "cmap header");
|
|
27
|
+
let format4 = null;
|
|
28
|
+
let format12 = null;
|
|
29
|
+
for (let index = 0; index < count; ++index) {
|
|
30
|
+
const record = offset + 4 + index * 8;
|
|
31
|
+
const platform = reader.u16(record, "cmap encoding record");
|
|
32
|
+
const encoding = reader.u16(record + 2, "cmap encoding record");
|
|
33
|
+
const unicode = platform === 0 || (platform === 3 && (encoding === 1 || encoding === 10));
|
|
34
|
+
if (!unicode)
|
|
35
|
+
continue;
|
|
36
|
+
const subtable = offset + reader.u32(record + 4, "cmap encoding record");
|
|
37
|
+
const format = reader.u16(subtable, "cmap subtable");
|
|
38
|
+
if (format === 12 && format12 === null)
|
|
39
|
+
format12 = subtable;
|
|
40
|
+
else if (format === 4 && format4 === null)
|
|
41
|
+
format4 = subtable;
|
|
42
|
+
}
|
|
43
|
+
const map = new Map();
|
|
44
|
+
const assign = (codePoint, glyph) => {
|
|
45
|
+
if (glyph === 0 || codePoint === 0xffff)
|
|
46
|
+
return;
|
|
47
|
+
if (glyph >= glyphCount)
|
|
48
|
+
throw new Error(`TrueType cmap maps U+${codePoint.toString(16).toUpperCase().padStart(4, "0")} to glyph ${glyph}, past the font's ${glyphCount} glyphs`);
|
|
49
|
+
if (codePoint > 0x10ffff)
|
|
50
|
+
throw new Error(`TrueType cmap maps code point ${codePoint}, past U+10FFFF`);
|
|
51
|
+
map.set(codePoint, glyph);
|
|
52
|
+
};
|
|
53
|
+
if (format12 !== null) {
|
|
54
|
+
const groups = reader.u32(format12 + 12, "cmap format 12 header");
|
|
55
|
+
reader.require(format12 + 16, groups * 12, "cmap format 12 groups");
|
|
56
|
+
for (let group = 0; group < groups; ++group) {
|
|
57
|
+
const at = format12 + 16 + group * 12;
|
|
58
|
+
const first = reader.u32(at, "cmap format 12 group");
|
|
59
|
+
const last = reader.u32(at + 4, "cmap format 12 group");
|
|
60
|
+
const glyph = reader.u32(at + 8, "cmap format 12 group");
|
|
61
|
+
if (last < first || last > 0x10ffff)
|
|
62
|
+
throw new Error(`TrueType cmap format 12 group ${group} spans ${first} to ${last}, not an increasing range within U+10FFFF`);
|
|
63
|
+
for (let codePoint = first; codePoint <= last; ++codePoint)
|
|
64
|
+
assign(codePoint, glyph + codePoint - first);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (format4 !== null) {
|
|
68
|
+
const segments = reader.u16(format4 + 6, "cmap format 4 header") / 2;
|
|
69
|
+
const ends = format4 + 14;
|
|
70
|
+
const starts = ends + segments * 2 + 2;
|
|
71
|
+
const deltas = starts + segments * 2;
|
|
72
|
+
const ranges = deltas + segments * 2;
|
|
73
|
+
reader.require(ends, segments * 8 + 2, "cmap format 4 segment arrays");
|
|
74
|
+
for (let segment = 0; segment < segments; ++segment) {
|
|
75
|
+
const end = reader.u16(ends + segment * 2, "cmap format 4");
|
|
76
|
+
const start = reader.u16(starts + segment * 2, "cmap format 4");
|
|
77
|
+
const delta = reader.i16(deltas + segment * 2, "cmap format 4");
|
|
78
|
+
const rangeAt = ranges + segment * 2;
|
|
79
|
+
const range = reader.u16(rangeAt, "cmap format 4");
|
|
80
|
+
for (let codePoint = start; codePoint <= end; ++codePoint) {
|
|
81
|
+
// idRangeOffset counts bytes from its own slot into glyphIdArray.
|
|
82
|
+
let glyph;
|
|
83
|
+
if (range === 0)
|
|
84
|
+
glyph = (codePoint + delta) & 0xffff;
|
|
85
|
+
else {
|
|
86
|
+
glyph = reader.u16(rangeAt + range + 2 * (codePoint - start), "cmap format 4 glyph array");
|
|
87
|
+
if (glyph !== 0)
|
|
88
|
+
glyph = (glyph + delta) & 0xffff;
|
|
89
|
+
}
|
|
90
|
+
assign(codePoint, glyph);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else
|
|
95
|
+
throw new Error("TrueType cmap has no Unicode subtable of format 4 or 12 (platform 0, or platform 3 encoding 1 or 10)");
|
|
96
|
+
return new Map([...map.entries()].sort((a, b) => a[0] - b[0]));
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=readTrueTypeCharacterMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readTrueTypeCharacterMap.js","sourceRoot":"","sources":["../../src/font/readTrueTypeCharacterMap.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,kCACE,MAA0B,EAC1B,MAAc,EACd,UAAkB;IAElB,MAAM,KAAK,GAAW,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,aAAa,CAAC,CAAC;IAC5D,IAAI,OAAO,GAAkB,IAAI,CAAC;IAClC,IAAI,QAAQ,GAAkB,IAAI,CAAC;IACnC,KAAK,IAAI,KAAK,GAAW,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC;QACnD,MAAM,MAAM,GAAW,MAAM,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;QAC9C,MAAM,QAAQ,GAAW,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;QACpE,MAAM,QAAQ,GAAW,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,sBAAsB,CAAC,CAAC;QACxE,MAAM,OAAO,GACX,QAAQ,KAAK,CAAC,IAAI,CAAC,QAAQ,KAAK,CAAC,IAAI,CAAC,QAAQ,KAAK,CAAC,IAAI,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC;QAC5E,IAAI,CAAC,OAAO;YAAE,SAAS;QACvB,MAAM,QAAQ,GACZ,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,sBAAsB,CAAC,CAAC;QAC1D,MAAM,MAAM,GAAW,MAAM,CAAC,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|
+
import type { IAutoMovieFontSegment } from "@automovie/interface";
|
|
2
|
+
import type { TrueTypeByteReader } from "./TrueTypeByteReader";
|
|
3
|
+
/**
|
|
4
|
+
* Read one glyph's outline from `glyf` as closed chains of quadratic segments
|
|
5
|
+
* in font units, resolving a composite glyph into its transformed components.
|
|
6
|
+
*
|
|
7
|
+
* A simple glyph's points are decoded from their run-length flags and delta
|
|
8
|
+
* coordinates. Each contour is then walked in order: two consecutive off-curve
|
|
9
|
+
* points imply an on-curve point at their midpoint, and a straight piece is
|
|
10
|
+
* written as a quadratic with its control at the midpoint of its ends (ISO/IEC
|
|
11
|
+
* 14496-22, section 5.3.4). A contour that starts off-curve starts at its last
|
|
12
|
+
* point when that is on-curve, else at the midpoint of its last and first
|
|
13
|
+
* points. Zero-length pieces are dropped, and a contour left with no piece,
|
|
14
|
+
* such as a lone anchor point, is dropped.
|
|
15
|
+
*
|
|
16
|
+
* A composite glyph places each component by its x/y offset and its 2 × 2
|
|
17
|
+
* transform, `x' = a·x + c·y + dx`, `y' = b·x + d·y + dy` with `a = xscale`, `b
|
|
18
|
+
* = scale01`, `c = scale10`, `d = yscale`; the offset is transformed only when
|
|
19
|
+
* `SCALED_COMPONENT_OFFSET` is set without `UNSCALED_COMPONENT_OFFSET`, the
|
|
20
|
+
* Open Font Format default. Components placed by matching point numbers are
|
|
21
|
+
* refused. Nesting deeper than 16 levels and a component that contains itself
|
|
22
|
+
* are refused.
|
|
23
|
+
*
|
|
24
|
+
* Results are cached per glyph index in `cache`, so a component shared by
|
|
25
|
+
* several glyphs is decoded once; callers must not mutate the returned arrays.
|
|
26
|
+
*
|
|
27
|
+
* @throws {Error} A field lies outside the glyph's `loca` span, a simple
|
|
28
|
+
* glyph's end points do not increase, a component uses point matching, nests
|
|
29
|
+
* too deep or contains itself.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readTrueTypeGlyphOutline(props: {
|
|
32
|
+
/** Bounds-checked reader over the font bytes. */
|
|
33
|
+
reader: TrueTypeByteReader;
|
|
34
|
+
/** Byte offset of the `glyf` table. */
|
|
35
|
+
glyf: number;
|
|
36
|
+
/**
|
|
37
|
+
* `loca` offsets relative to `glyf`, one more than the glyph count, already
|
|
38
|
+
* checked to increase within `glyf`.
|
|
39
|
+
*/
|
|
40
|
+
loca: readonly number[];
|
|
41
|
+
/** Glyph index to read. */
|
|
42
|
+
glyph: number;
|
|
43
|
+
/** Outlines already read, by glyph index. */
|
|
44
|
+
cache: Map<number, IAutoMovieFontSegment[][]>;
|
|
45
|
+
}): IAutoMovieFontSegment[][];
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readTrueTypeGlyphOutline = readTrueTypeGlyphOutline;
|
|
4
|
+
/**
|
|
5
|
+
* Deepest component nesting a composite glyph may use; real fonts nest one or
|
|
6
|
+
* two levels.
|
|
7
|
+
*/
|
|
8
|
+
const MAX_COMPONENT_DEPTH = 16;
|
|
9
|
+
/**
|
|
10
|
+
* Composite glyph flag (ISO/IEC 14496-22, section 5.3.4, the `glyf` composite
|
|
11
|
+
* glyph description): the component's two arguments are 16-bit, else 8-bit.
|
|
12
|
+
*/
|
|
13
|
+
const ARG_1_AND_2_ARE_WORDS = 0x0001;
|
|
14
|
+
/** Composite flag: the arguments are signed x/y offsets, else point numbers. */
|
|
15
|
+
const ARGS_ARE_XY_VALUES = 0x0002;
|
|
16
|
+
/** Composite flag: one scale applies to both axes of the component. */
|
|
17
|
+
const WE_HAVE_A_SCALE = 0x0008;
|
|
18
|
+
/** Composite flag: another component follows this one. */
|
|
19
|
+
const MORE_COMPONENTS = 0x0020;
|
|
20
|
+
/** Composite flag: the component has separate x and y scales. */
|
|
21
|
+
const WE_HAVE_AN_X_AND_Y_SCALE = 0x0040;
|
|
22
|
+
/** Composite flag: a 2 × 2 matrix transforms the component. */
|
|
23
|
+
const WE_HAVE_A_TWO_BY_TWO = 0x0080;
|
|
24
|
+
/** Composite flag: the component's offset is scaled by its transform. */
|
|
25
|
+
const SCALED_COMPONENT_OFFSET = 0x0800;
|
|
26
|
+
/** Composite flag: the component's offset is not scaled by its transform. */
|
|
27
|
+
const UNSCALED_COMPONENT_OFFSET = 0x1000;
|
|
28
|
+
/**
|
|
29
|
+
* Read one glyph's outline from `glyf` as closed chains of quadratic segments
|
|
30
|
+
* in font units, resolving a composite glyph into its transformed components.
|
|
31
|
+
*
|
|
32
|
+
* A simple glyph's points are decoded from their run-length flags and delta
|
|
33
|
+
* coordinates. Each contour is then walked in order: two consecutive off-curve
|
|
34
|
+
* points imply an on-curve point at their midpoint, and a straight piece is
|
|
35
|
+
* written as a quadratic with its control at the midpoint of its ends (ISO/IEC
|
|
36
|
+
* 14496-22, section 5.3.4). A contour that starts off-curve starts at its last
|
|
37
|
+
* point when that is on-curve, else at the midpoint of its last and first
|
|
38
|
+
* points. Zero-length pieces are dropped, and a contour left with no piece,
|
|
39
|
+
* such as a lone anchor point, is dropped.
|
|
40
|
+
*
|
|
41
|
+
* A composite glyph places each component by its x/y offset and its 2 × 2
|
|
42
|
+
* transform, `x' = a·x + c·y + dx`, `y' = b·x + d·y + dy` with `a = xscale`, `b
|
|
43
|
+
* = scale01`, `c = scale10`, `d = yscale`; the offset is transformed only when
|
|
44
|
+
* `SCALED_COMPONENT_OFFSET` is set without `UNSCALED_COMPONENT_OFFSET`, the
|
|
45
|
+
* Open Font Format default. Components placed by matching point numbers are
|
|
46
|
+
* refused. Nesting deeper than 16 levels and a component that contains itself
|
|
47
|
+
* are refused.
|
|
48
|
+
*
|
|
49
|
+
* Results are cached per glyph index in `cache`, so a component shared by
|
|
50
|
+
* several glyphs is decoded once; callers must not mutate the returned arrays.
|
|
51
|
+
*
|
|
52
|
+
* @throws {Error} A field lies outside the glyph's `loca` span, a simple
|
|
53
|
+
* glyph's end points do not increase, a component uses point matching, nests
|
|
54
|
+
* too deep or contains itself.
|
|
55
|
+
*/
|
|
56
|
+
function readTrueTypeGlyphOutline(props) {
|
|
57
|
+
return read(props, props.glyph, []);
|
|
58
|
+
}
|
|
59
|
+
/** Read one glyph with the component stack above it. */
|
|
60
|
+
function read(props, glyph, stack) {
|
|
61
|
+
const cached = props.cache.get(glyph);
|
|
62
|
+
if (cached !== undefined)
|
|
63
|
+
return cached;
|
|
64
|
+
if (stack.includes(glyph))
|
|
65
|
+
throw new Error(`TrueType composite glyph ${stack[0]} contains itself through glyph ${glyph}`);
|
|
66
|
+
if (stack.length > MAX_COMPONENT_DEPTH)
|
|
67
|
+
throw new Error(`TrueType composite glyph ${stack[0]} nests components deeper than ${MAX_COMPONENT_DEPTH} levels`);
|
|
68
|
+
if (glyph < 0 || glyph + 1 >= props.loca.length)
|
|
69
|
+
throw new Error(`TrueType glyph ${glyph} is past the font's ${props.loca.length - 1} glyphs`);
|
|
70
|
+
const start = props.glyf + props.loca[glyph];
|
|
71
|
+
const end = props.glyf + props.loca[glyph + 1];
|
|
72
|
+
let contours;
|
|
73
|
+
if (end === start)
|
|
74
|
+
contours = [];
|
|
75
|
+
else {
|
|
76
|
+
const span = { reader: props.reader, end, glyph };
|
|
77
|
+
const count = at(span, start, 2, "i16");
|
|
78
|
+
contours =
|
|
79
|
+
count >= 0
|
|
80
|
+
? simple(span, start + 10, count)
|
|
81
|
+
: composite(props, span, start + 10, [...stack, glyph]);
|
|
82
|
+
}
|
|
83
|
+
props.cache.set(glyph, contours);
|
|
84
|
+
return contours;
|
|
85
|
+
}
|
|
86
|
+
/** Read one field that must lie inside the glyph's span. */
|
|
87
|
+
function at(span, offset, size, type) {
|
|
88
|
+
if (offset + size > span.end)
|
|
89
|
+
throw new Error(`TrueType glyph ${span.glyph} reads byte ${offset + size - 1}, past its loca span ending at byte ${span.end}`);
|
|
90
|
+
const what = `glyph ${span.glyph}`;
|
|
91
|
+
switch (type) {
|
|
92
|
+
case "u8":
|
|
93
|
+
return span.reader.u8(offset, what);
|
|
94
|
+
case "i8":
|
|
95
|
+
return span.reader.i8(offset, what);
|
|
96
|
+
case "u16":
|
|
97
|
+
return span.reader.u16(offset, what);
|
|
98
|
+
case "i16":
|
|
99
|
+
return span.reader.i16(offset, what);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** Decode a simple glyph's contours. */
|
|
103
|
+
function simple(span, offset, count) {
|
|
104
|
+
if (count === 0)
|
|
105
|
+
return [];
|
|
106
|
+
const ends = [];
|
|
107
|
+
for (let contour = 0; contour < count; ++contour) {
|
|
108
|
+
const last = at(span, offset + contour * 2, 2, "u16");
|
|
109
|
+
if (contour > 0 && last <= ends[contour - 1])
|
|
110
|
+
throw new Error(`TrueType glyph ${span.glyph} contour end points must increase`);
|
|
111
|
+
ends.push(last);
|
|
112
|
+
}
|
|
113
|
+
const points = ends[count - 1] + 1;
|
|
114
|
+
const instructions = at(span, offset + count * 2, 2, "u16");
|
|
115
|
+
let cursor = offset + count * 2 + 2 + instructions;
|
|
116
|
+
// Flags, with bit 3 repeating a flag the following byte's count of times.
|
|
117
|
+
const flags = [];
|
|
118
|
+
while (flags.length < points) {
|
|
119
|
+
const flag = at(span, cursor++, 1, "u8");
|
|
120
|
+
flags.push(flag);
|
|
121
|
+
if ((flag & 0x08) !== 0) {
|
|
122
|
+
const repeat = at(span, cursor++, 1, "u8");
|
|
123
|
+
for (let r = 0; r < repeat && flags.length < points; ++r)
|
|
124
|
+
flags.push(flag);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Coordinates are deltas: a short delta is one unsigned byte signed by the
|
|
128
|
+
// "same" bit, a long one an i16, and "same" without "short" repeats the last.
|
|
129
|
+
const axis = (short, same) => {
|
|
130
|
+
const values = [];
|
|
131
|
+
let value = 0;
|
|
132
|
+
for (const flag of flags) {
|
|
133
|
+
if ((flag & short) !== 0) {
|
|
134
|
+
const delta = at(span, cursor++, 1, "u8");
|
|
135
|
+
value += (flag & same) !== 0 ? delta : -delta;
|
|
136
|
+
}
|
|
137
|
+
else if ((flag & same) === 0) {
|
|
138
|
+
value += at(span, cursor, 2, "i16");
|
|
139
|
+
cursor += 2;
|
|
140
|
+
}
|
|
141
|
+
values.push(value);
|
|
142
|
+
}
|
|
143
|
+
return values;
|
|
144
|
+
};
|
|
145
|
+
const xs = axis(0x02, 0x10);
|
|
146
|
+
const ys = axis(0x04, 0x20);
|
|
147
|
+
const contours = [];
|
|
148
|
+
let first = 0;
|
|
149
|
+
for (const last of ends) {
|
|
150
|
+
const ring = [];
|
|
151
|
+
for (let index = first; index <= last; ++index)
|
|
152
|
+
ring.push({
|
|
153
|
+
point: [xs[index], ys[index]],
|
|
154
|
+
on: (flags[index] & 1) !== 0,
|
|
155
|
+
});
|
|
156
|
+
first = last + 1;
|
|
157
|
+
const segments = quadratics(ring);
|
|
158
|
+
if (segments.length > 0)
|
|
159
|
+
contours.push(segments);
|
|
160
|
+
}
|
|
161
|
+
return contours;
|
|
162
|
+
}
|
|
163
|
+
/** Turn one contour's on- and off-curve points into closed quadratic segments. */
|
|
164
|
+
function quadratics(ring) {
|
|
165
|
+
const n = ring.length;
|
|
166
|
+
const first = ring[0];
|
|
167
|
+
const last = ring[n - 1];
|
|
168
|
+
let start;
|
|
169
|
+
let sequence;
|
|
170
|
+
if (first.on) {
|
|
171
|
+
start = first.point;
|
|
172
|
+
sequence = ring.slice(1);
|
|
173
|
+
}
|
|
174
|
+
else if (last.on) {
|
|
175
|
+
start = last.point;
|
|
176
|
+
sequence = ring.slice(0, n - 1);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
start = midpoint(last.point, first.point);
|
|
180
|
+
sequence = ring;
|
|
181
|
+
}
|
|
182
|
+
const segments = [];
|
|
183
|
+
const push = (from, control, to) => {
|
|
184
|
+
if (from[0] === to[0] &&
|
|
185
|
+
from[1] === to[1] &&
|
|
186
|
+
control[0] === to[0] &&
|
|
187
|
+
control[1] === to[1])
|
|
188
|
+
return;
|
|
189
|
+
segments.push({ start: [...from], control: [...control], end: [...to] });
|
|
190
|
+
};
|
|
191
|
+
let current = start;
|
|
192
|
+
let pending = null;
|
|
193
|
+
for (const entry of [...sequence, { point: start, on: true }]) {
|
|
194
|
+
if (entry.on) {
|
|
195
|
+
push(current, pending ?? midpoint(current, entry.point), entry.point);
|
|
196
|
+
current = entry.point;
|
|
197
|
+
pending = null;
|
|
198
|
+
}
|
|
199
|
+
else if (pending === null)
|
|
200
|
+
pending = entry.point;
|
|
201
|
+
else {
|
|
202
|
+
const implied = midpoint(pending, entry.point);
|
|
203
|
+
push(current, pending, implied);
|
|
204
|
+
current = implied;
|
|
205
|
+
pending = entry.point;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return segments;
|
|
209
|
+
}
|
|
210
|
+
/** The point halfway between two points. */
|
|
211
|
+
function midpoint(a, b) {
|
|
212
|
+
return [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];
|
|
213
|
+
}
|
|
214
|
+
/** Resolve a composite glyph's components into transformed contours. */
|
|
215
|
+
function composite(props, span, offset, stack) {
|
|
216
|
+
const contours = [];
|
|
217
|
+
let cursor = offset;
|
|
218
|
+
let flags;
|
|
219
|
+
do {
|
|
220
|
+
flags = at(span, cursor, 2, "u16");
|
|
221
|
+
const component = at(span, cursor + 2, 2, "u16");
|
|
222
|
+
cursor += 4;
|
|
223
|
+
if ((flags & ARGS_ARE_XY_VALUES) === 0)
|
|
224
|
+
throw new Error(`TrueType composite glyph ${span.glyph} places component ${component} by matching point numbers, which is not supported; use x/y offsets`);
|
|
225
|
+
let dx;
|
|
226
|
+
let dy;
|
|
227
|
+
if ((flags & ARG_1_AND_2_ARE_WORDS) !== 0) {
|
|
228
|
+
dx = at(span, cursor, 2, "i16");
|
|
229
|
+
dy = at(span, cursor + 2, 2, "i16");
|
|
230
|
+
cursor += 4;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
dx = at(span, cursor, 1, "i8");
|
|
234
|
+
dy = at(span, cursor + 1, 1, "i8");
|
|
235
|
+
cursor += 2;
|
|
236
|
+
}
|
|
237
|
+
let a = 1;
|
|
238
|
+
let b = 0;
|
|
239
|
+
let c = 0;
|
|
240
|
+
let d = 1;
|
|
241
|
+
const fixed = (index) => at(span, cursor + index * 2, 2, "i16") / 16384;
|
|
242
|
+
if ((flags & WE_HAVE_A_SCALE) !== 0) {
|
|
243
|
+
a = fixed(0);
|
|
244
|
+
d = a;
|
|
245
|
+
cursor += 2;
|
|
246
|
+
}
|
|
247
|
+
else if ((flags & WE_HAVE_AN_X_AND_Y_SCALE) !== 0) {
|
|
248
|
+
a = fixed(0);
|
|
249
|
+
d = fixed(1);
|
|
250
|
+
cursor += 4;
|
|
251
|
+
}
|
|
252
|
+
else if ((flags & WE_HAVE_A_TWO_BY_TWO) !== 0) {
|
|
253
|
+
a = fixed(0);
|
|
254
|
+
b = fixed(1);
|
|
255
|
+
c = fixed(2);
|
|
256
|
+
d = fixed(3);
|
|
257
|
+
cursor += 8;
|
|
258
|
+
}
|
|
259
|
+
if ((flags & SCALED_COMPONENT_OFFSET) !== 0 &&
|
|
260
|
+
(flags & UNSCALED_COMPONENT_OFFSET) === 0)
|
|
261
|
+
[dx, dy] = [a * dx + c * dy, b * dx + d * dy];
|
|
262
|
+
const map = (point) => [
|
|
263
|
+
a * point[0] + c * point[1] + dx,
|
|
264
|
+
b * point[0] + d * point[1] + dy,
|
|
265
|
+
];
|
|
266
|
+
for (const contour of read(props, component, stack))
|
|
267
|
+
contours.push(contour.map((segment) => ({
|
|
268
|
+
start: map(segment.start),
|
|
269
|
+
control: map(segment.control),
|
|
270
|
+
end: map(segment.end),
|
|
271
|
+
})));
|
|
272
|
+
} while ((flags & MORE_COMPONENTS) !== 0);
|
|
273
|
+
return contours;
|
|
274
|
+
}
|
|
275
|
+
//# sourceMappingURL=readTrueTypeGlyphOutline.js.map
|