pdf-codec 1.3.0 → 1.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 +38 -0
- package/dist/afm-widths-BoeTOK2r.cjs +826 -0
- package/dist/afm-widths-Dxucrg7D.js +779 -0
- package/dist/afm-widths-DyDq56Ph.d.cts +19 -0
- package/dist/afm-widths-DyDq56Ph.d.ts +19 -0
- package/dist/afm-widths.cjs +4 -0
- package/dist/afm-widths.d.cts +2 -0
- package/dist/afm-widths.d.ts +2 -0
- package/dist/afm-widths.js +2 -0
- package/dist/assets/stix-two-math-font.cjs +5 -0
- package/dist/assets/stix-two-math-font.d.cts +4 -0
- package/dist/assets/stix-two-math-font.d.ts +4 -0
- package/dist/assets/stix-two-math-font.js +4 -0
- package/dist/bytes/crc32.cjs +21 -0
- package/dist/bytes/crc32.d.cts +4 -0
- package/dist/bytes/crc32.d.ts +4 -0
- package/dist/bytes/crc32.js +20 -0
- package/dist/bytes/flate.cjs +53 -0
- package/dist/bytes/flate.d.cts +12 -0
- package/dist/bytes/flate.d.ts +12 -0
- package/dist/bytes/flate.js +49 -0
- package/dist/bytes/reader.cjs +60 -0
- package/dist/bytes/reader.d.cts +20 -0
- package/dist/bytes/reader.d.ts +20 -0
- package/dist/bytes/reader.js +58 -0
- package/dist/bytes/writer.cjs +37 -0
- package/dist/bytes/writer.d.cts +13 -0
- package/dist/bytes/writer.d.ts +13 -0
- package/dist/bytes/writer.js +35 -0
- package/dist/cmap.cjs +110 -0
- package/dist/cmap.d.cts +8 -0
- package/dist/cmap.d.ts +8 -0
- package/dist/cmap.js +109 -0
- package/dist/codec.cjs +34 -0
- package/dist/codec.d.cts +167 -0
- package/dist/codec.d.ts +167 -0
- package/dist/codec.js +32 -0
- package/dist/content-read.cjs +126 -0
- package/dist/content-read.d.cts +21 -0
- package/dist/content-read.d.ts +21 -0
- package/dist/content-read.js +125 -0
- package/dist/content-write.cjs +138 -0
- package/dist/content-write.d.cts +24 -0
- package/dist/content-write.d.ts +24 -0
- package/dist/content-write.js +137 -0
- package/dist/diagnostics.cjs +21 -0
- package/dist/diagnostics.d.cts +19 -0
- package/dist/diagnostics.d.ts +19 -0
- package/dist/diagnostics.js +18 -0
- package/dist/document.cjs +162 -0
- package/dist/document.d.cts +12 -0
- package/dist/document.d.ts +12 -0
- package/dist/document.js +161 -0
- package/dist/encoding.cjs +5 -0
- package/dist/encoding.d.cts +6 -0
- package/dist/encoding.d.ts +6 -0
- package/dist/encoding.js +2 -0
- package/dist/filters.cjs +223 -0
- package/dist/filters.d.cts +14 -0
- package/dist/filters.d.ts +14 -0
- package/dist/filters.js +218 -0
- package/dist/font-read.cjs +199 -0
- package/dist/font-read.d.cts +23 -0
- package/dist/font-read.d.ts +23 -0
- package/dist/font-read.js +198 -0
- package/dist/font-style.cjs +35 -0
- package/dist/font-style.d.cts +14 -0
- package/dist/font-style.d.ts +14 -0
- package/dist/font-style.js +34 -0
- package/dist/fonts.cjs +124 -0
- package/dist/fonts.d.cts +15 -0
- package/dist/fonts.d.ts +15 -0
- package/dist/fonts.js +122 -0
- package/dist/formula.cjs +0 -0
- package/dist/formula.d.cts +10 -0
- package/dist/formula.d.ts +10 -0
- package/dist/formula.js +0 -0
- package/dist/image/jpeg-info.cjs +71 -0
- package/dist/image/jpeg-info.d.cts +12 -0
- package/dist/image/jpeg-info.d.ts +12 -0
- package/dist/image/jpeg-info.js +70 -0
- package/dist/image/png-decode.cjs +181 -0
- package/dist/image/png-decode.d.cts +14 -0
- package/dist/image/png-decode.d.ts +14 -0
- package/dist/image/png-decode.js +180 -0
- package/dist/image/png-encode.cjs +64 -0
- package/dist/image/png-encode.d.cts +8 -0
- package/dist/image/png-encode.d.ts +8 -0
- package/dist/image/png-encode.js +63 -0
- package/dist/image/png-filter.cjs +95 -0
- package/dist/image/png-filter.d.cts +6 -0
- package/dist/image/png-filter.d.ts +6 -0
- package/dist/image/png-filter.js +93 -0
- package/dist/images-read.cjs +250 -0
- package/dist/images-read.d.cts +13 -0
- package/dist/images-read.d.ts +13 -0
- package/dist/images-read.js +249 -0
- package/dist/index.cjs +45 -5912
- package/dist/index.d.cts +21 -483
- package/dist/index.d.ts +21 -483
- package/dist/index.js +18 -5885
- package/dist/interpret.cjs +587 -0
- package/dist/interpret.d.cts +84 -0
- package/dist/interpret.d.ts +84 -0
- package/dist/interpret.js +586 -0
- package/dist/lexer.cjs +180 -0
- package/dist/lexer.d.cts +29 -0
- package/dist/lexer.d.ts +29 -0
- package/dist/lexer.js +179 -0
- package/dist/math-cmap.cjs +81 -0
- package/dist/math-cmap.d.cts +6 -0
- package/dist/math-cmap.d.ts +6 -0
- package/dist/math-cmap.js +80 -0
- package/dist/math-content-write.cjs +83 -0
- package/dist/math-content-write.d.cts +11 -0
- package/dist/math-content-write.d.ts +11 -0
- package/dist/math-content-write.js +81 -0
- package/dist/math-font-write.cjs +100 -0
- package/dist/math-font-write.d.cts +19 -0
- package/dist/math-font-write.d.ts +19 -0
- package/dist/math-font-write.js +99 -0
- package/dist/math-font.cjs +103 -0
- package/dist/math-font.d.cts +25 -0
- package/dist/math-font.d.ts +25 -0
- package/dist/math-font.js +102 -0
- package/dist/math-hmtx.cjs +17 -0
- package/dist/math-hmtx.d.cts +8 -0
- package/dist/math-hmtx.d.ts +8 -0
- package/dist/math-hmtx.js +16 -0
- package/dist/math-table.cjs +117 -0
- package/dist/math-table.d.cts +45 -0
- package/dist/math-table.d.ts +45 -0
- package/dist/math-table.js +116 -0
- package/dist/math-types-Ba8qAf1p.d.cts +82 -0
- package/dist/math-types-Ba8qAf1p.d.ts +82 -0
- package/dist/math-types.cjs +0 -0
- package/dist/math-types.d.cts +2 -0
- package/dist/math-types.d.ts +2 -0
- package/dist/math-types.js +0 -0
- package/dist/matrix-B3c2_a2f.d.cts +18 -0
- package/dist/matrix-B3c2_a2f.d.ts +18 -0
- package/dist/matrix.cjs +93 -0
- package/dist/matrix.d.cts +2 -0
- package/dist/matrix.d.ts +2 -0
- package/dist/matrix.js +83 -0
- package/dist/measure.cjs +54 -0
- package/dist/measure.d.cts +20 -0
- package/dist/measure.d.ts +20 -0
- package/dist/measure.js +53 -0
- package/dist/objects.cjs +100 -0
- package/dist/objects.d.cts +58 -0
- package/dist/objects.d.ts +58 -0
- package/dist/objects.js +84 -0
- package/dist/parse.cjs +230 -0
- package/dist/parse.d.cts +13 -0
- package/dist/parse.d.ts +13 -0
- package/dist/parse.js +228 -0
- package/dist/predictors.cjs +64 -0
- package/dist/predictors.d.cts +13 -0
- package/dist/predictors.d.ts +13 -0
- package/dist/predictors.js +62 -0
- package/dist/read.cjs +418 -0
- package/dist/read.d.cts +21 -0
- package/dist/read.d.ts +21 -0
- package/dist/read.js +413 -0
- package/dist/serialize.cjs +69 -0
- package/dist/serialize.d.cts +8 -0
- package/dist/serialize.d.ts +8 -0
- package/dist/serialize.js +66 -0
- package/dist/sfnt.cjs +52 -0
- package/dist/sfnt.d.cts +17 -0
- package/dist/sfnt.d.ts +17 -0
- package/dist/sfnt.js +46 -0
- package/dist/text-layout.cjs +224 -0
- package/dist/text-layout.d.cts +37 -0
- package/dist/text-layout.d.ts +37 -0
- package/dist/text-layout.js +222 -0
- package/dist/util/abort.cjs +7 -0
- package/dist/util/abort.d.cts +4 -0
- package/dist/util/abort.d.ts +4 -0
- package/dist/util/abort.js +6 -0
- package/dist/util/base64.cjs +48 -0
- package/dist/util/base64.d.cts +5 -0
- package/dist/util/base64.d.ts +5 -0
- package/dist/util/base64.js +46 -0
- package/dist/winansi.cjs +5 -0
- package/dist/winansi.d.cts +20 -0
- package/dist/winansi.d.ts +20 -0
- package/dist/winansi.js +2 -0
- package/dist/write.cjs +421 -0
- package/dist/write.d.cts +16 -0
- package/dist/write.d.ts +16 -0
- package/dist/write.js +419 -0
- package/dist/xref.cjs +325 -0
- package/dist/xref.d.cts +21 -0
- package/dist/xref.d.ts +21 -0
- package/dist/xref.js +324 -0
- package/package.json +9 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sfnt = require("./sfnt.cjs");
|
|
3
|
+
//#region src/math-table.ts
|
|
4
|
+
const MATH_VALUE_RECORD_INDEX = {
|
|
5
|
+
axisHeight: 1,
|
|
6
|
+
subscriptShiftDown: 4,
|
|
7
|
+
subscriptBaselineDropMin: 6,
|
|
8
|
+
superscriptShiftUp: 7,
|
|
9
|
+
superscriptShiftUpCramped: 8,
|
|
10
|
+
superscriptBaselineDropMax: 10,
|
|
11
|
+
subSuperscriptGapMin: 11,
|
|
12
|
+
spaceAfterScript: 13,
|
|
13
|
+
upperLimitGapMin: 14,
|
|
14
|
+
upperLimitBaselineRiseMin: 15,
|
|
15
|
+
lowerLimitGapMin: 16,
|
|
16
|
+
lowerLimitBaselineDropMin: 17,
|
|
17
|
+
stackTopShiftUp: 18,
|
|
18
|
+
stackBottomShiftDown: 20,
|
|
19
|
+
stackGapMin: 22,
|
|
20
|
+
fractionNumeratorShiftUp: 28,
|
|
21
|
+
fractionNumeratorDisplayStyleShiftUp: 29,
|
|
22
|
+
fractionDenominatorShiftDown: 30,
|
|
23
|
+
fractionDenominatorDisplayStyleShiftDown: 31,
|
|
24
|
+
fractionNumeratorGapMin: 32,
|
|
25
|
+
fractionRuleThickness: 34,
|
|
26
|
+
fractionDenominatorGapMin: 35,
|
|
27
|
+
radicalVerticalGap: 45,
|
|
28
|
+
radicalRuleThickness: 47,
|
|
29
|
+
radicalExtraAscender: 48,
|
|
30
|
+
radicalKernBeforeDegree: 49,
|
|
31
|
+
radicalKernAfterDegree: 50
|
|
32
|
+
};
|
|
33
|
+
const MATH_VALUE_RECORDS_START = 8;
|
|
34
|
+
const MATH_VALUE_RECORD_SIZE = 4;
|
|
35
|
+
const RADICAL_DEGREE_BOTTOM_RAISE_PERCENT_OFFSET = 212;
|
|
36
|
+
function mathValueRecord(bytes, constantsOffset, index) {
|
|
37
|
+
return require_sfnt.i16(bytes, constantsOffset + MATH_VALUE_RECORDS_START + index * MATH_VALUE_RECORD_SIZE);
|
|
38
|
+
}
|
|
39
|
+
function parseMathConstants(bytes, mathTableOffset) {
|
|
40
|
+
const constantsOffset = mathTableOffset + require_sfnt.u16(bytes, mathTableOffset + 4);
|
|
41
|
+
const field = (index) => mathValueRecord(bytes, constantsOffset, index);
|
|
42
|
+
return {
|
|
43
|
+
scriptPercentScaleDown: require_sfnt.i16(bytes, constantsOffset + 0) / 100,
|
|
44
|
+
scriptScriptPercentScaleDown: require_sfnt.i16(bytes, constantsOffset + 2) / 100,
|
|
45
|
+
axisHeight: field(MATH_VALUE_RECORD_INDEX.axisHeight),
|
|
46
|
+
subscriptShiftDown: field(MATH_VALUE_RECORD_INDEX.subscriptShiftDown),
|
|
47
|
+
subscriptBaselineDropMin: field(MATH_VALUE_RECORD_INDEX.subscriptBaselineDropMin),
|
|
48
|
+
superscriptShiftUp: field(MATH_VALUE_RECORD_INDEX.superscriptShiftUp),
|
|
49
|
+
superscriptShiftUpCramped: field(MATH_VALUE_RECORD_INDEX.superscriptShiftUpCramped),
|
|
50
|
+
superscriptBaselineDropMax: field(MATH_VALUE_RECORD_INDEX.superscriptBaselineDropMax),
|
|
51
|
+
subSuperscriptGapMin: field(MATH_VALUE_RECORD_INDEX.subSuperscriptGapMin),
|
|
52
|
+
spaceAfterScript: field(MATH_VALUE_RECORD_INDEX.spaceAfterScript),
|
|
53
|
+
upperLimitGapMin: field(MATH_VALUE_RECORD_INDEX.upperLimitGapMin),
|
|
54
|
+
upperLimitBaselineRiseMin: field(MATH_VALUE_RECORD_INDEX.upperLimitBaselineRiseMin),
|
|
55
|
+
lowerLimitGapMin: field(MATH_VALUE_RECORD_INDEX.lowerLimitGapMin),
|
|
56
|
+
lowerLimitBaselineDropMin: field(MATH_VALUE_RECORD_INDEX.lowerLimitBaselineDropMin),
|
|
57
|
+
stackTopShiftUp: field(MATH_VALUE_RECORD_INDEX.stackTopShiftUp),
|
|
58
|
+
stackBottomShiftDown: field(MATH_VALUE_RECORD_INDEX.stackBottomShiftDown),
|
|
59
|
+
stackGapMin: field(MATH_VALUE_RECORD_INDEX.stackGapMin),
|
|
60
|
+
fractionNumeratorShiftUp: field(MATH_VALUE_RECORD_INDEX.fractionNumeratorShiftUp),
|
|
61
|
+
fractionNumeratorDisplayStyleShiftUp: field(MATH_VALUE_RECORD_INDEX.fractionNumeratorDisplayStyleShiftUp),
|
|
62
|
+
fractionDenominatorShiftDown: field(MATH_VALUE_RECORD_INDEX.fractionDenominatorShiftDown),
|
|
63
|
+
fractionDenominatorDisplayStyleShiftDown: field(MATH_VALUE_RECORD_INDEX.fractionDenominatorDisplayStyleShiftDown),
|
|
64
|
+
fractionNumeratorGapMin: field(MATH_VALUE_RECORD_INDEX.fractionNumeratorGapMin),
|
|
65
|
+
fractionRuleThickness: field(MATH_VALUE_RECORD_INDEX.fractionRuleThickness),
|
|
66
|
+
fractionDenominatorGapMin: field(MATH_VALUE_RECORD_INDEX.fractionDenominatorGapMin),
|
|
67
|
+
radicalVerticalGap: field(MATH_VALUE_RECORD_INDEX.radicalVerticalGap),
|
|
68
|
+
radicalRuleThickness: field(MATH_VALUE_RECORD_INDEX.radicalRuleThickness),
|
|
69
|
+
radicalExtraAscender: field(MATH_VALUE_RECORD_INDEX.radicalExtraAscender),
|
|
70
|
+
radicalKernBeforeDegree: field(MATH_VALUE_RECORD_INDEX.radicalKernBeforeDegree),
|
|
71
|
+
radicalKernAfterDegree: field(MATH_VALUE_RECORD_INDEX.radicalKernAfterDegree),
|
|
72
|
+
radicalDegreeBottomRaisePercent: require_sfnt.i16(bytes, constantsOffset + RADICAL_DEGREE_BOTTOM_RAISE_PERCENT_OFFSET)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function parseCoverageIndex(bytes, coverageOffset) {
|
|
76
|
+
const format = require_sfnt.u16(bytes, coverageOffset);
|
|
77
|
+
const index = /* @__PURE__ */ new Map();
|
|
78
|
+
if (format === 1) {
|
|
79
|
+
const glyphCount = require_sfnt.u16(bytes, coverageOffset + 2);
|
|
80
|
+
for (let i = 0; i < glyphCount; i++) index.set(require_sfnt.u16(bytes, coverageOffset + 4 + i * 2), i);
|
|
81
|
+
} else if (format === 2) {
|
|
82
|
+
const rangeCount = require_sfnt.u16(bytes, coverageOffset + 2);
|
|
83
|
+
for (let i = 0; i < rangeCount; i++) {
|
|
84
|
+
const recordOffset = coverageOffset + 4 + i * 6;
|
|
85
|
+
const startGlyphId = require_sfnt.u16(bytes, recordOffset);
|
|
86
|
+
const endGlyphId = require_sfnt.u16(bytes, recordOffset + 2);
|
|
87
|
+
const startCoverageIndex = require_sfnt.u16(bytes, recordOffset + 4);
|
|
88
|
+
for (let glyphId = startGlyphId; glyphId <= endGlyphId; glyphId++) index.set(glyphId, startCoverageIndex + (glyphId - startGlyphId));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return index;
|
|
92
|
+
}
|
|
93
|
+
function parseGlyphValueTable(bytes, tableOffset) {
|
|
94
|
+
const coverage = parseCoverageIndex(bytes, tableOffset + require_sfnt.u16(bytes, tableOffset));
|
|
95
|
+
const values = /* @__PURE__ */ new Map();
|
|
96
|
+
for (const [glyphId, coverageIndex] of coverage) values.set(glyphId, require_sfnt.i16(bytes, tableOffset + 4 + coverageIndex * 4));
|
|
97
|
+
return values;
|
|
98
|
+
}
|
|
99
|
+
function parseMathGlyphInfo(bytes, mathTableOffset) {
|
|
100
|
+
const glyphInfoOffset = mathTableOffset + require_sfnt.u16(bytes, mathTableOffset + 6);
|
|
101
|
+
const italicsInfoOffset = require_sfnt.u16(bytes, glyphInfoOffset + 0);
|
|
102
|
+
const topAccentOffset = require_sfnt.u16(bytes, glyphInfoOffset + 2);
|
|
103
|
+
return {
|
|
104
|
+
italicsCorrection: italicsInfoOffset === 0 ? /* @__PURE__ */ new Map() : parseGlyphValueTable(bytes, glyphInfoOffset + italicsInfoOffset),
|
|
105
|
+
topAccentAttachment: topAccentOffset === 0 ? /* @__PURE__ */ new Map() : parseGlyphValueTable(bytes, glyphInfoOffset + topAccentOffset)
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function parseMathTable(font) {
|
|
109
|
+
const mathBytes = require_sfnt.sfntTableBytes(font, "MATH");
|
|
110
|
+
if (mathBytes === void 0) throw new Error("math font has no MATH table");
|
|
111
|
+
return {
|
|
112
|
+
constants: parseMathConstants(mathBytes, 0),
|
|
113
|
+
glyphInfo: parseMathGlyphInfo(mathBytes, 0)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
exports.parseMathTable = parseMathTable;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SfntFont } from "./sfnt.cjs";
|
|
2
|
+
//#region src/math-table.d.ts
|
|
3
|
+
interface MathConstants {
|
|
4
|
+
readonly scriptPercentScaleDown: number;
|
|
5
|
+
readonly scriptScriptPercentScaleDown: number;
|
|
6
|
+
readonly axisHeight: number;
|
|
7
|
+
readonly subscriptShiftDown: number;
|
|
8
|
+
readonly subscriptBaselineDropMin: number;
|
|
9
|
+
readonly superscriptShiftUp: number;
|
|
10
|
+
readonly superscriptShiftUpCramped: number;
|
|
11
|
+
readonly superscriptBaselineDropMax: number;
|
|
12
|
+
readonly subSuperscriptGapMin: number;
|
|
13
|
+
readonly spaceAfterScript: number;
|
|
14
|
+
readonly upperLimitGapMin: number;
|
|
15
|
+
readonly upperLimitBaselineRiseMin: number;
|
|
16
|
+
readonly lowerLimitGapMin: number;
|
|
17
|
+
readonly lowerLimitBaselineDropMin: number;
|
|
18
|
+
readonly stackTopShiftUp: number;
|
|
19
|
+
readonly stackBottomShiftDown: number;
|
|
20
|
+
readonly stackGapMin: number;
|
|
21
|
+
readonly fractionNumeratorShiftUp: number;
|
|
22
|
+
readonly fractionNumeratorDisplayStyleShiftUp: number;
|
|
23
|
+
readonly fractionDenominatorShiftDown: number;
|
|
24
|
+
readonly fractionDenominatorDisplayStyleShiftDown: number;
|
|
25
|
+
readonly fractionNumeratorGapMin: number;
|
|
26
|
+
readonly fractionRuleThickness: number;
|
|
27
|
+
readonly fractionDenominatorGapMin: number;
|
|
28
|
+
readonly radicalVerticalGap: number;
|
|
29
|
+
readonly radicalRuleThickness: number;
|
|
30
|
+
readonly radicalExtraAscender: number;
|
|
31
|
+
readonly radicalKernBeforeDegree: number;
|
|
32
|
+
readonly radicalKernAfterDegree: number;
|
|
33
|
+
readonly radicalDegreeBottomRaisePercent: number;
|
|
34
|
+
}
|
|
35
|
+
interface MathGlyphInfo {
|
|
36
|
+
readonly italicsCorrection: ReadonlyMap<number, number>;
|
|
37
|
+
readonly topAccentAttachment: ReadonlyMap<number, number>;
|
|
38
|
+
}
|
|
39
|
+
interface MathTable {
|
|
40
|
+
readonly constants: MathConstants;
|
|
41
|
+
readonly glyphInfo: MathGlyphInfo;
|
|
42
|
+
}
|
|
43
|
+
declare function parseMathTable(font: SfntFont): MathTable;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { MathConstants, MathGlyphInfo, MathTable, parseMathTable };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SfntFont } from "./sfnt.js";
|
|
2
|
+
//#region src/math-table.d.ts
|
|
3
|
+
interface MathConstants {
|
|
4
|
+
readonly scriptPercentScaleDown: number;
|
|
5
|
+
readonly scriptScriptPercentScaleDown: number;
|
|
6
|
+
readonly axisHeight: number;
|
|
7
|
+
readonly subscriptShiftDown: number;
|
|
8
|
+
readonly subscriptBaselineDropMin: number;
|
|
9
|
+
readonly superscriptShiftUp: number;
|
|
10
|
+
readonly superscriptShiftUpCramped: number;
|
|
11
|
+
readonly superscriptBaselineDropMax: number;
|
|
12
|
+
readonly subSuperscriptGapMin: number;
|
|
13
|
+
readonly spaceAfterScript: number;
|
|
14
|
+
readonly upperLimitGapMin: number;
|
|
15
|
+
readonly upperLimitBaselineRiseMin: number;
|
|
16
|
+
readonly lowerLimitGapMin: number;
|
|
17
|
+
readonly lowerLimitBaselineDropMin: number;
|
|
18
|
+
readonly stackTopShiftUp: number;
|
|
19
|
+
readonly stackBottomShiftDown: number;
|
|
20
|
+
readonly stackGapMin: number;
|
|
21
|
+
readonly fractionNumeratorShiftUp: number;
|
|
22
|
+
readonly fractionNumeratorDisplayStyleShiftUp: number;
|
|
23
|
+
readonly fractionDenominatorShiftDown: number;
|
|
24
|
+
readonly fractionDenominatorDisplayStyleShiftDown: number;
|
|
25
|
+
readonly fractionNumeratorGapMin: number;
|
|
26
|
+
readonly fractionRuleThickness: number;
|
|
27
|
+
readonly fractionDenominatorGapMin: number;
|
|
28
|
+
readonly radicalVerticalGap: number;
|
|
29
|
+
readonly radicalRuleThickness: number;
|
|
30
|
+
readonly radicalExtraAscender: number;
|
|
31
|
+
readonly radicalKernBeforeDegree: number;
|
|
32
|
+
readonly radicalKernAfterDegree: number;
|
|
33
|
+
readonly radicalDegreeBottomRaisePercent: number;
|
|
34
|
+
}
|
|
35
|
+
interface MathGlyphInfo {
|
|
36
|
+
readonly italicsCorrection: ReadonlyMap<number, number>;
|
|
37
|
+
readonly topAccentAttachment: ReadonlyMap<number, number>;
|
|
38
|
+
}
|
|
39
|
+
interface MathTable {
|
|
40
|
+
readonly constants: MathConstants;
|
|
41
|
+
readonly glyphInfo: MathGlyphInfo;
|
|
42
|
+
}
|
|
43
|
+
declare function parseMathTable(font: SfntFont): MathTable;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { MathConstants, MathGlyphInfo, MathTable, parseMathTable };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { i16, sfntTableBytes, u16 } from "./sfnt.js";
|
|
2
|
+
//#region src/math-table.ts
|
|
3
|
+
const MATH_VALUE_RECORD_INDEX = {
|
|
4
|
+
axisHeight: 1,
|
|
5
|
+
subscriptShiftDown: 4,
|
|
6
|
+
subscriptBaselineDropMin: 6,
|
|
7
|
+
superscriptShiftUp: 7,
|
|
8
|
+
superscriptShiftUpCramped: 8,
|
|
9
|
+
superscriptBaselineDropMax: 10,
|
|
10
|
+
subSuperscriptGapMin: 11,
|
|
11
|
+
spaceAfterScript: 13,
|
|
12
|
+
upperLimitGapMin: 14,
|
|
13
|
+
upperLimitBaselineRiseMin: 15,
|
|
14
|
+
lowerLimitGapMin: 16,
|
|
15
|
+
lowerLimitBaselineDropMin: 17,
|
|
16
|
+
stackTopShiftUp: 18,
|
|
17
|
+
stackBottomShiftDown: 20,
|
|
18
|
+
stackGapMin: 22,
|
|
19
|
+
fractionNumeratorShiftUp: 28,
|
|
20
|
+
fractionNumeratorDisplayStyleShiftUp: 29,
|
|
21
|
+
fractionDenominatorShiftDown: 30,
|
|
22
|
+
fractionDenominatorDisplayStyleShiftDown: 31,
|
|
23
|
+
fractionNumeratorGapMin: 32,
|
|
24
|
+
fractionRuleThickness: 34,
|
|
25
|
+
fractionDenominatorGapMin: 35,
|
|
26
|
+
radicalVerticalGap: 45,
|
|
27
|
+
radicalRuleThickness: 47,
|
|
28
|
+
radicalExtraAscender: 48,
|
|
29
|
+
radicalKernBeforeDegree: 49,
|
|
30
|
+
radicalKernAfterDegree: 50
|
|
31
|
+
};
|
|
32
|
+
const MATH_VALUE_RECORDS_START = 8;
|
|
33
|
+
const MATH_VALUE_RECORD_SIZE = 4;
|
|
34
|
+
const RADICAL_DEGREE_BOTTOM_RAISE_PERCENT_OFFSET = 212;
|
|
35
|
+
function mathValueRecord(bytes, constantsOffset, index) {
|
|
36
|
+
return i16(bytes, constantsOffset + MATH_VALUE_RECORDS_START + index * MATH_VALUE_RECORD_SIZE);
|
|
37
|
+
}
|
|
38
|
+
function parseMathConstants(bytes, mathTableOffset) {
|
|
39
|
+
const constantsOffset = mathTableOffset + u16(bytes, mathTableOffset + 4);
|
|
40
|
+
const field = (index) => mathValueRecord(bytes, constantsOffset, index);
|
|
41
|
+
return {
|
|
42
|
+
scriptPercentScaleDown: i16(bytes, constantsOffset + 0) / 100,
|
|
43
|
+
scriptScriptPercentScaleDown: i16(bytes, constantsOffset + 2) / 100,
|
|
44
|
+
axisHeight: field(MATH_VALUE_RECORD_INDEX.axisHeight),
|
|
45
|
+
subscriptShiftDown: field(MATH_VALUE_RECORD_INDEX.subscriptShiftDown),
|
|
46
|
+
subscriptBaselineDropMin: field(MATH_VALUE_RECORD_INDEX.subscriptBaselineDropMin),
|
|
47
|
+
superscriptShiftUp: field(MATH_VALUE_RECORD_INDEX.superscriptShiftUp),
|
|
48
|
+
superscriptShiftUpCramped: field(MATH_VALUE_RECORD_INDEX.superscriptShiftUpCramped),
|
|
49
|
+
superscriptBaselineDropMax: field(MATH_VALUE_RECORD_INDEX.superscriptBaselineDropMax),
|
|
50
|
+
subSuperscriptGapMin: field(MATH_VALUE_RECORD_INDEX.subSuperscriptGapMin),
|
|
51
|
+
spaceAfterScript: field(MATH_VALUE_RECORD_INDEX.spaceAfterScript),
|
|
52
|
+
upperLimitGapMin: field(MATH_VALUE_RECORD_INDEX.upperLimitGapMin),
|
|
53
|
+
upperLimitBaselineRiseMin: field(MATH_VALUE_RECORD_INDEX.upperLimitBaselineRiseMin),
|
|
54
|
+
lowerLimitGapMin: field(MATH_VALUE_RECORD_INDEX.lowerLimitGapMin),
|
|
55
|
+
lowerLimitBaselineDropMin: field(MATH_VALUE_RECORD_INDEX.lowerLimitBaselineDropMin),
|
|
56
|
+
stackTopShiftUp: field(MATH_VALUE_RECORD_INDEX.stackTopShiftUp),
|
|
57
|
+
stackBottomShiftDown: field(MATH_VALUE_RECORD_INDEX.stackBottomShiftDown),
|
|
58
|
+
stackGapMin: field(MATH_VALUE_RECORD_INDEX.stackGapMin),
|
|
59
|
+
fractionNumeratorShiftUp: field(MATH_VALUE_RECORD_INDEX.fractionNumeratorShiftUp),
|
|
60
|
+
fractionNumeratorDisplayStyleShiftUp: field(MATH_VALUE_RECORD_INDEX.fractionNumeratorDisplayStyleShiftUp),
|
|
61
|
+
fractionDenominatorShiftDown: field(MATH_VALUE_RECORD_INDEX.fractionDenominatorShiftDown),
|
|
62
|
+
fractionDenominatorDisplayStyleShiftDown: field(MATH_VALUE_RECORD_INDEX.fractionDenominatorDisplayStyleShiftDown),
|
|
63
|
+
fractionNumeratorGapMin: field(MATH_VALUE_RECORD_INDEX.fractionNumeratorGapMin),
|
|
64
|
+
fractionRuleThickness: field(MATH_VALUE_RECORD_INDEX.fractionRuleThickness),
|
|
65
|
+
fractionDenominatorGapMin: field(MATH_VALUE_RECORD_INDEX.fractionDenominatorGapMin),
|
|
66
|
+
radicalVerticalGap: field(MATH_VALUE_RECORD_INDEX.radicalVerticalGap),
|
|
67
|
+
radicalRuleThickness: field(MATH_VALUE_RECORD_INDEX.radicalRuleThickness),
|
|
68
|
+
radicalExtraAscender: field(MATH_VALUE_RECORD_INDEX.radicalExtraAscender),
|
|
69
|
+
radicalKernBeforeDegree: field(MATH_VALUE_RECORD_INDEX.radicalKernBeforeDegree),
|
|
70
|
+
radicalKernAfterDegree: field(MATH_VALUE_RECORD_INDEX.radicalKernAfterDegree),
|
|
71
|
+
radicalDegreeBottomRaisePercent: i16(bytes, constantsOffset + RADICAL_DEGREE_BOTTOM_RAISE_PERCENT_OFFSET)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function parseCoverageIndex(bytes, coverageOffset) {
|
|
75
|
+
const format = u16(bytes, coverageOffset);
|
|
76
|
+
const index = /* @__PURE__ */ new Map();
|
|
77
|
+
if (format === 1) {
|
|
78
|
+
const glyphCount = u16(bytes, coverageOffset + 2);
|
|
79
|
+
for (let i = 0; i < glyphCount; i++) index.set(u16(bytes, coverageOffset + 4 + i * 2), i);
|
|
80
|
+
} else if (format === 2) {
|
|
81
|
+
const rangeCount = u16(bytes, coverageOffset + 2);
|
|
82
|
+
for (let i = 0; i < rangeCount; i++) {
|
|
83
|
+
const recordOffset = coverageOffset + 4 + i * 6;
|
|
84
|
+
const startGlyphId = u16(bytes, recordOffset);
|
|
85
|
+
const endGlyphId = u16(bytes, recordOffset + 2);
|
|
86
|
+
const startCoverageIndex = u16(bytes, recordOffset + 4);
|
|
87
|
+
for (let glyphId = startGlyphId; glyphId <= endGlyphId; glyphId++) index.set(glyphId, startCoverageIndex + (glyphId - startGlyphId));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return index;
|
|
91
|
+
}
|
|
92
|
+
function parseGlyphValueTable(bytes, tableOffset) {
|
|
93
|
+
const coverage = parseCoverageIndex(bytes, tableOffset + u16(bytes, tableOffset));
|
|
94
|
+
const values = /* @__PURE__ */ new Map();
|
|
95
|
+
for (const [glyphId, coverageIndex] of coverage) values.set(glyphId, i16(bytes, tableOffset + 4 + coverageIndex * 4));
|
|
96
|
+
return values;
|
|
97
|
+
}
|
|
98
|
+
function parseMathGlyphInfo(bytes, mathTableOffset) {
|
|
99
|
+
const glyphInfoOffset = mathTableOffset + u16(bytes, mathTableOffset + 6);
|
|
100
|
+
const italicsInfoOffset = u16(bytes, glyphInfoOffset + 0);
|
|
101
|
+
const topAccentOffset = u16(bytes, glyphInfoOffset + 2);
|
|
102
|
+
return {
|
|
103
|
+
italicsCorrection: italicsInfoOffset === 0 ? /* @__PURE__ */ new Map() : parseGlyphValueTable(bytes, glyphInfoOffset + italicsInfoOffset),
|
|
104
|
+
topAccentAttachment: topAccentOffset === 0 ? /* @__PURE__ */ new Map() : parseGlyphValueTable(bytes, glyphInfoOffset + topAccentOffset)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function parseMathTable(font) {
|
|
108
|
+
const mathBytes = sfntTableBytes(font, "MATH");
|
|
109
|
+
if (mathBytes === void 0) throw new Error("math font has no MATH table");
|
|
110
|
+
return {
|
|
111
|
+
constants: parseMathConstants(mathBytes, 0),
|
|
112
|
+
glyphInfo: parseMathGlyphInfo(mathBytes, 0)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
export { parseMathTable };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//#region src/math-types.d.ts
|
|
2
|
+
interface MathColor {
|
|
3
|
+
readonly r: number;
|
|
4
|
+
readonly g: number;
|
|
5
|
+
readonly b: number;
|
|
6
|
+
}
|
|
7
|
+
interface MathGlyphRun {
|
|
8
|
+
readonly kind: 'glyphs';
|
|
9
|
+
readonly xPt: number;
|
|
10
|
+
readonly yPt: number;
|
|
11
|
+
readonly text: string;
|
|
12
|
+
readonly sizePt: number;
|
|
13
|
+
readonly color: MathColor;
|
|
14
|
+
}
|
|
15
|
+
interface MathRule {
|
|
16
|
+
readonly kind: 'rule';
|
|
17
|
+
readonly xPt: number;
|
|
18
|
+
readonly yPt: number;
|
|
19
|
+
readonly widthPt: number;
|
|
20
|
+
readonly heightPt: number;
|
|
21
|
+
readonly color: MathColor;
|
|
22
|
+
}
|
|
23
|
+
interface MathStroke {
|
|
24
|
+
readonly kind: 'stroke';
|
|
25
|
+
readonly points: readonly {
|
|
26
|
+
readonly xPt: number;
|
|
27
|
+
readonly yPt: number;
|
|
28
|
+
}[];
|
|
29
|
+
readonly widthPt: number;
|
|
30
|
+
readonly color: MathColor;
|
|
31
|
+
}
|
|
32
|
+
type MathLayoutItem = MathGlyphRun | MathRule | MathStroke;
|
|
33
|
+
interface MathBox {
|
|
34
|
+
readonly widthPt: number;
|
|
35
|
+
readonly heightPt: number;
|
|
36
|
+
readonly ascentPt: number;
|
|
37
|
+
readonly descentPt: number;
|
|
38
|
+
readonly items: readonly MathLayoutItem[];
|
|
39
|
+
}
|
|
40
|
+
interface MathGlyphMetrics {
|
|
41
|
+
readonly advanceWidthPt: number;
|
|
42
|
+
readonly italicCorrectionPt: number;
|
|
43
|
+
readonly topAccentXPt?: number;
|
|
44
|
+
}
|
|
45
|
+
interface MathFontMetrics {
|
|
46
|
+
readonly ascentPerEm: number;
|
|
47
|
+
readonly descentPerEm: number;
|
|
48
|
+
readonly axisHeightPt: number;
|
|
49
|
+
readonly fractionRuleThicknessPt: number;
|
|
50
|
+
readonly fractionNumeratorShiftUpPt: number;
|
|
51
|
+
readonly fractionNumeratorDisplayShiftUpPt: number;
|
|
52
|
+
readonly fractionDenominatorShiftDownPt: number;
|
|
53
|
+
readonly fractionDenominatorDisplayShiftDownPt: number;
|
|
54
|
+
readonly fractionNumeratorGapMinPt: number;
|
|
55
|
+
readonly fractionDenominatorGapMinPt: number;
|
|
56
|
+
readonly radicalRuleThicknessPt: number;
|
|
57
|
+
readonly radicalExtraAscenderPt: number;
|
|
58
|
+
readonly radicalVerticalGapPt: number;
|
|
59
|
+
readonly radicalKernBeforeDegreePt: number;
|
|
60
|
+
readonly radicalKernAfterDegreePt: number;
|
|
61
|
+
readonly radicalDegreeBottomRaisePercent: number;
|
|
62
|
+
readonly subscriptShiftDownPt: number;
|
|
63
|
+
readonly superscriptShiftUpPt: number;
|
|
64
|
+
readonly superscriptShiftUpCrampedPt: number;
|
|
65
|
+
readonly subSuperscriptGapMinPt: number;
|
|
66
|
+
readonly superscriptBaselineDropMaxPt: number;
|
|
67
|
+
readonly subscriptBaselineDropMinPt: number;
|
|
68
|
+
readonly spaceAfterScriptPt: number;
|
|
69
|
+
readonly upperLimitGapMinPt: number;
|
|
70
|
+
readonly upperLimitBaselineRiseMinPt: number;
|
|
71
|
+
readonly lowerLimitGapMinPt: number;
|
|
72
|
+
readonly lowerLimitBaselineDropMinPt: number;
|
|
73
|
+
readonly stackTopShiftUpPt: number;
|
|
74
|
+
readonly stackBottomShiftDownPt: number;
|
|
75
|
+
readonly stackGapMinPt: number;
|
|
76
|
+
readonly scriptPercentScaleDown: number;
|
|
77
|
+
readonly scriptScriptPercentScaleDown: number;
|
|
78
|
+
readonly defaultRuleThicknessPt: number;
|
|
79
|
+
glyph(codePoint: number, sizePt: number): MathGlyphMetrics | undefined;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { MathGlyphRun as a, MathStroke as c, MathGlyphMetrics as i, MathColor as n, MathLayoutItem as o, MathFontMetrics as r, MathRule as s, MathBox as t };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//#region src/math-types.d.ts
|
|
2
|
+
interface MathColor {
|
|
3
|
+
readonly r: number;
|
|
4
|
+
readonly g: number;
|
|
5
|
+
readonly b: number;
|
|
6
|
+
}
|
|
7
|
+
interface MathGlyphRun {
|
|
8
|
+
readonly kind: 'glyphs';
|
|
9
|
+
readonly xPt: number;
|
|
10
|
+
readonly yPt: number;
|
|
11
|
+
readonly text: string;
|
|
12
|
+
readonly sizePt: number;
|
|
13
|
+
readonly color: MathColor;
|
|
14
|
+
}
|
|
15
|
+
interface MathRule {
|
|
16
|
+
readonly kind: 'rule';
|
|
17
|
+
readonly xPt: number;
|
|
18
|
+
readonly yPt: number;
|
|
19
|
+
readonly widthPt: number;
|
|
20
|
+
readonly heightPt: number;
|
|
21
|
+
readonly color: MathColor;
|
|
22
|
+
}
|
|
23
|
+
interface MathStroke {
|
|
24
|
+
readonly kind: 'stroke';
|
|
25
|
+
readonly points: readonly {
|
|
26
|
+
readonly xPt: number;
|
|
27
|
+
readonly yPt: number;
|
|
28
|
+
}[];
|
|
29
|
+
readonly widthPt: number;
|
|
30
|
+
readonly color: MathColor;
|
|
31
|
+
}
|
|
32
|
+
type MathLayoutItem = MathGlyphRun | MathRule | MathStroke;
|
|
33
|
+
interface MathBox {
|
|
34
|
+
readonly widthPt: number;
|
|
35
|
+
readonly heightPt: number;
|
|
36
|
+
readonly ascentPt: number;
|
|
37
|
+
readonly descentPt: number;
|
|
38
|
+
readonly items: readonly MathLayoutItem[];
|
|
39
|
+
}
|
|
40
|
+
interface MathGlyphMetrics {
|
|
41
|
+
readonly advanceWidthPt: number;
|
|
42
|
+
readonly italicCorrectionPt: number;
|
|
43
|
+
readonly topAccentXPt?: number;
|
|
44
|
+
}
|
|
45
|
+
interface MathFontMetrics {
|
|
46
|
+
readonly ascentPerEm: number;
|
|
47
|
+
readonly descentPerEm: number;
|
|
48
|
+
readonly axisHeightPt: number;
|
|
49
|
+
readonly fractionRuleThicknessPt: number;
|
|
50
|
+
readonly fractionNumeratorShiftUpPt: number;
|
|
51
|
+
readonly fractionNumeratorDisplayShiftUpPt: number;
|
|
52
|
+
readonly fractionDenominatorShiftDownPt: number;
|
|
53
|
+
readonly fractionDenominatorDisplayShiftDownPt: number;
|
|
54
|
+
readonly fractionNumeratorGapMinPt: number;
|
|
55
|
+
readonly fractionDenominatorGapMinPt: number;
|
|
56
|
+
readonly radicalRuleThicknessPt: number;
|
|
57
|
+
readonly radicalExtraAscenderPt: number;
|
|
58
|
+
readonly radicalVerticalGapPt: number;
|
|
59
|
+
readonly radicalKernBeforeDegreePt: number;
|
|
60
|
+
readonly radicalKernAfterDegreePt: number;
|
|
61
|
+
readonly radicalDegreeBottomRaisePercent: number;
|
|
62
|
+
readonly subscriptShiftDownPt: number;
|
|
63
|
+
readonly superscriptShiftUpPt: number;
|
|
64
|
+
readonly superscriptShiftUpCrampedPt: number;
|
|
65
|
+
readonly subSuperscriptGapMinPt: number;
|
|
66
|
+
readonly superscriptBaselineDropMaxPt: number;
|
|
67
|
+
readonly subscriptBaselineDropMinPt: number;
|
|
68
|
+
readonly spaceAfterScriptPt: number;
|
|
69
|
+
readonly upperLimitGapMinPt: number;
|
|
70
|
+
readonly upperLimitBaselineRiseMinPt: number;
|
|
71
|
+
readonly lowerLimitGapMinPt: number;
|
|
72
|
+
readonly lowerLimitBaselineDropMinPt: number;
|
|
73
|
+
readonly stackTopShiftUpPt: number;
|
|
74
|
+
readonly stackBottomShiftDownPt: number;
|
|
75
|
+
readonly stackGapMinPt: number;
|
|
76
|
+
readonly scriptPercentScaleDown: number;
|
|
77
|
+
readonly scriptScriptPercentScaleDown: number;
|
|
78
|
+
readonly defaultRuleThicknessPt: number;
|
|
79
|
+
glyph(codePoint: number, sizePt: number): MathGlyphMetrics | undefined;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { MathGlyphRun as a, MathStroke as c, MathGlyphMetrics as i, MathColor as n, MathLayoutItem as o, MathFontMetrics as r, MathRule as s, MathBox as t };
|
|
File without changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as MathGlyphRun, c as MathStroke, i as MathGlyphMetrics, n as MathColor, o as MathLayoutItem, r as MathFontMetrics, s as MathRule, t as MathBox } from "./math-types-Ba8qAf1p.cjs";
|
|
2
|
+
export { MathBox, MathColor, MathFontMetrics, MathGlyphMetrics, MathGlyphRun, MathLayoutItem, MathRule, MathStroke };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as MathGlyphRun, c as MathStroke, i as MathGlyphMetrics, n as MathColor, o as MathLayoutItem, r as MathFontMetrics, s as MathRule, t as MathBox } from "./math-types-Ba8qAf1p.js";
|
|
2
|
+
export { MathBox, MathColor, MathFontMetrics, MathGlyphMetrics, MathGlyphRun, MathLayoutItem, MathRule, MathStroke };
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/matrix.d.ts
|
|
2
|
+
type Matrix = readonly [number, number, number, number, number, number];
|
|
3
|
+
declare const IDENTITY_MATRIX: Matrix;
|
|
4
|
+
declare function multiplyMatrices(m: Matrix, n: Matrix): Matrix;
|
|
5
|
+
interface Point {
|
|
6
|
+
readonly x: number;
|
|
7
|
+
readonly y: number;
|
|
8
|
+
}
|
|
9
|
+
declare function applyMatrix(m: Matrix, point: Point): Point;
|
|
10
|
+
declare function translationMatrix(x: number, y: number): Matrix;
|
|
11
|
+
declare function scaleMatrix(sx: number, sy: number): Matrix;
|
|
12
|
+
declare function rotationMatrix(degrees: number): Matrix;
|
|
13
|
+
declare function matrixScaleX(m: Matrix): number;
|
|
14
|
+
declare function matrixScaleY(m: Matrix): number;
|
|
15
|
+
declare function matrixRotationDegrees(m: Matrix): number;
|
|
16
|
+
declare function rotatePointAboutCenter(point: Point, center: Point, degrees: number): Point;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { matrixRotationDegrees as a, multiplyMatrices as c, scaleMatrix as d, translationMatrix as f, applyMatrix as i, rotatePointAboutCenter as l, Matrix as n, matrixScaleX as o, Point as r, matrixScaleY as s, IDENTITY_MATRIX as t, rotationMatrix as u };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/matrix.d.ts
|
|
2
|
+
type Matrix = readonly [number, number, number, number, number, number];
|
|
3
|
+
declare const IDENTITY_MATRIX: Matrix;
|
|
4
|
+
declare function multiplyMatrices(m: Matrix, n: Matrix): Matrix;
|
|
5
|
+
interface Point {
|
|
6
|
+
readonly x: number;
|
|
7
|
+
readonly y: number;
|
|
8
|
+
}
|
|
9
|
+
declare function applyMatrix(m: Matrix, point: Point): Point;
|
|
10
|
+
declare function translationMatrix(x: number, y: number): Matrix;
|
|
11
|
+
declare function scaleMatrix(sx: number, sy: number): Matrix;
|
|
12
|
+
declare function rotationMatrix(degrees: number): Matrix;
|
|
13
|
+
declare function matrixScaleX(m: Matrix): number;
|
|
14
|
+
declare function matrixScaleY(m: Matrix): number;
|
|
15
|
+
declare function matrixRotationDegrees(m: Matrix): number;
|
|
16
|
+
declare function rotatePointAboutCenter(point: Point, center: Point, degrees: number): Point;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { matrixRotationDegrees as a, multiplyMatrices as c, scaleMatrix as d, translationMatrix as f, applyMatrix as i, rotatePointAboutCenter as l, Matrix as n, matrixScaleX as o, Point as r, matrixScaleY as s, IDENTITY_MATRIX as t, rotationMatrix as u };
|
package/dist/matrix.cjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/matrix.ts
|
|
3
|
+
const IDENTITY_MATRIX = [
|
|
4
|
+
1,
|
|
5
|
+
0,
|
|
6
|
+
0,
|
|
7
|
+
1,
|
|
8
|
+
0,
|
|
9
|
+
0
|
|
10
|
+
];
|
|
11
|
+
function multiplyMatrices(m, n) {
|
|
12
|
+
const [a1, b1, c1, d1, e1, f1] = m;
|
|
13
|
+
const [a2, b2, c2, d2, e2, f2] = n;
|
|
14
|
+
return [
|
|
15
|
+
a1 * a2 + b1 * c2,
|
|
16
|
+
a1 * b2 + b1 * d2,
|
|
17
|
+
c1 * a2 + d1 * c2,
|
|
18
|
+
c1 * b2 + d1 * d2,
|
|
19
|
+
e1 * a2 + f1 * c2 + e2,
|
|
20
|
+
e1 * b2 + f1 * d2 + f2
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
function applyMatrix(m, point) {
|
|
24
|
+
const [a, b, c, d, e, f] = m;
|
|
25
|
+
return {
|
|
26
|
+
x: point.x * a + point.y * c + e,
|
|
27
|
+
y: point.x * b + point.y * d + f
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function translationMatrix(x, y) {
|
|
31
|
+
return [
|
|
32
|
+
1,
|
|
33
|
+
0,
|
|
34
|
+
0,
|
|
35
|
+
1,
|
|
36
|
+
x,
|
|
37
|
+
y
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
function scaleMatrix(sx, sy) {
|
|
41
|
+
return [
|
|
42
|
+
sx,
|
|
43
|
+
0,
|
|
44
|
+
0,
|
|
45
|
+
sy,
|
|
46
|
+
0,
|
|
47
|
+
0
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
function rotationMatrix(degrees) {
|
|
51
|
+
const radians = degrees * Math.PI / 180;
|
|
52
|
+
const cos = Math.cos(radians);
|
|
53
|
+
const sin = Math.sin(radians);
|
|
54
|
+
return [
|
|
55
|
+
cos,
|
|
56
|
+
sin,
|
|
57
|
+
-sin,
|
|
58
|
+
cos,
|
|
59
|
+
0,
|
|
60
|
+
0
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
function matrixScaleX(m) {
|
|
64
|
+
return Math.hypot(m[0], m[1]);
|
|
65
|
+
}
|
|
66
|
+
function matrixScaleY(m) {
|
|
67
|
+
return Math.hypot(m[2], m[3]);
|
|
68
|
+
}
|
|
69
|
+
function matrixRotationDegrees(m) {
|
|
70
|
+
return Math.atan2(m[1], m[0]) * 180 / Math.PI;
|
|
71
|
+
}
|
|
72
|
+
function rotatePointAboutCenter(point, center, degrees) {
|
|
73
|
+
const relative = {
|
|
74
|
+
x: point.x - center.x,
|
|
75
|
+
y: point.y - center.y
|
|
76
|
+
};
|
|
77
|
+
const rotated = applyMatrix(rotationMatrix(degrees), relative);
|
|
78
|
+
return {
|
|
79
|
+
x: rotated.x + center.x,
|
|
80
|
+
y: rotated.y + center.y
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
|
|
85
|
+
exports.applyMatrix = applyMatrix;
|
|
86
|
+
exports.matrixRotationDegrees = matrixRotationDegrees;
|
|
87
|
+
exports.matrixScaleX = matrixScaleX;
|
|
88
|
+
exports.matrixScaleY = matrixScaleY;
|
|
89
|
+
exports.multiplyMatrices = multiplyMatrices;
|
|
90
|
+
exports.rotatePointAboutCenter = rotatePointAboutCenter;
|
|
91
|
+
exports.rotationMatrix = rotationMatrix;
|
|
92
|
+
exports.scaleMatrix = scaleMatrix;
|
|
93
|
+
exports.translationMatrix = translationMatrix;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as matrixRotationDegrees, c as multiplyMatrices, d as scaleMatrix, f as translationMatrix, i as applyMatrix, l as rotatePointAboutCenter, n as Matrix, o as matrixScaleX, r as Point, s as matrixScaleY, t as IDENTITY_MATRIX, u as rotationMatrix } from "./matrix-B3c2_a2f.cjs";
|
|
2
|
+
export { IDENTITY_MATRIX, Matrix, Point, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|
package/dist/matrix.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as matrixRotationDegrees, c as multiplyMatrices, d as scaleMatrix, f as translationMatrix, i as applyMatrix, l as rotatePointAboutCenter, n as Matrix, o as matrixScaleX, r as Point, s as matrixScaleY, t as IDENTITY_MATRIX, u as rotationMatrix } from "./matrix-B3c2_a2f.js";
|
|
2
|
+
export { IDENTITY_MATRIX, Matrix, Point, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|