pdf-codec 1.8.0 → 1.10.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.
Files changed (36) hide show
  1. package/README.md +10 -6
  2. package/dist/codec.d.cts +12 -0
  3. package/dist/codec.d.ts +12 -0
  4. package/dist/content-write.cjs +177 -5
  5. package/dist/content-write.d.cts +1 -1
  6. package/dist/content-write.d.ts +1 -1
  7. package/dist/content-write.js +178 -6
  8. package/dist/{embedded-font-CLedn-mT.d.cts → embedded-font-BU6Jgcof.d.cts} +7 -1
  9. package/dist/{embedded-font-CbqkKgBl.d.ts → embedded-font-fREdbxnr.d.ts} +7 -1
  10. package/dist/embedded-font-write.d.cts +1 -1
  11. package/dist/embedded-font-write.d.ts +1 -1
  12. package/dist/embedded-font.cjs +22 -5
  13. package/dist/embedded-font.d.cts +2 -2
  14. package/dist/embedded-font.d.ts +2 -2
  15. package/dist/embedded-font.js +22 -5
  16. package/dist/{font-registry-yby02snZ.d.cts → font-registry-B5qL0Vi0.d.cts} +1 -1
  17. package/dist/{font-registry-Cn7P9lAh.d.ts → font-registry-mgdbNP8_.d.ts} +1 -1
  18. package/dist/font-registry.d.cts +1 -1
  19. package/dist/font-registry.d.ts +1 -1
  20. package/dist/gpos-table.cjs +189 -0
  21. package/dist/gpos-table.d.cts +6 -0
  22. package/dist/gpos-table.d.ts +6 -0
  23. package/dist/gpos-table.js +188 -0
  24. package/dist/index.d.cts +2 -2
  25. package/dist/index.d.ts +2 -2
  26. package/dist/math-table.cjs +7 -21
  27. package/dist/math-table.js +7 -21
  28. package/dist/measure.d.cts +1 -1
  29. package/dist/measure.d.ts +1 -1
  30. package/dist/ot-layout-common.cjs +95 -0
  31. package/dist/ot-layout-common.d.cts +10 -0
  32. package/dist/ot-layout-common.d.ts +10 -0
  33. package/dist/ot-layout-common.js +93 -0
  34. package/dist/write.d.cts +2 -2
  35. package/dist/write.d.ts +2 -2
  36. package/package.json +2 -2
@@ -0,0 +1,93 @@
1
+ import { hasBytes, u16 } from "./sfnt.js";
2
+ //#region src/ot-layout-common.ts
3
+ function findRange(ranges, glyphId) {
4
+ let low = 0;
5
+ let high = ranges.length - 1;
6
+ while (low <= high) {
7
+ const mid = low + high >> 1;
8
+ const range = ranges[mid];
9
+ if (glyphId < range.startGlyphId) high = mid - 1;
10
+ else if (glyphId > range.endGlyphId) low = mid + 1;
11
+ else return range;
12
+ }
13
+ }
14
+ function pushGlyph(ranges, glyphId, value, valueStep) {
15
+ const previous = ranges[ranges.length - 1];
16
+ if (previous !== void 0 && glyphId === previous.endGlyphId + 1 && value === previous.value + (previous.endGlyphId - previous.startGlyphId + 1) * valueStep) {
17
+ ranges[ranges.length - 1] = {
18
+ startGlyphId: previous.startGlyphId,
19
+ endGlyphId: glyphId,
20
+ value: previous.value
21
+ };
22
+ return;
23
+ }
24
+ ranges.push({
25
+ startGlyphId: glyphId,
26
+ endGlyphId: glyphId,
27
+ value
28
+ });
29
+ }
30
+ const RANGE_RECORD_SIZE = 6;
31
+ function parseRangeRecords(bytes, recordsOffset, recordCount) {
32
+ if (!hasBytes(bytes, recordsOffset, recordCount * RANGE_RECORD_SIZE)) return;
33
+ const ranges = [];
34
+ for (let i = 0; i < recordCount; i++) {
35
+ const recordOffset = recordsOffset + i * RANGE_RECORD_SIZE;
36
+ const startGlyphId = u16(bytes, recordOffset);
37
+ const endGlyphId = u16(bytes, recordOffset + 2);
38
+ if (endGlyphId < startGlyphId) continue;
39
+ ranges.push({
40
+ startGlyphId,
41
+ endGlyphId,
42
+ value: u16(bytes, recordOffset + 4)
43
+ });
44
+ }
45
+ ranges.sort((a, b) => a.startGlyphId - b.startGlyphId);
46
+ return ranges;
47
+ }
48
+ const COVERAGE_HEADER_SIZE = 4;
49
+ function parseCoverage(bytes, coverageOffset) {
50
+ if (!hasBytes(bytes, coverageOffset, COVERAGE_HEADER_SIZE)) return;
51
+ const format = u16(bytes, coverageOffset);
52
+ const count = u16(bytes, coverageOffset + 2);
53
+ let ranges;
54
+ if (format === 1) {
55
+ const glyphArrayOffset = coverageOffset + COVERAGE_HEADER_SIZE;
56
+ if (!hasBytes(bytes, glyphArrayOffset, count * 2)) return;
57
+ ranges = [];
58
+ for (let i = 0; i < count; i++) pushGlyph(ranges, u16(bytes, glyphArrayOffset + i * 2), i, 1);
59
+ ranges.sort((a, b) => a.startGlyphId - b.startGlyphId);
60
+ } else if (format === 2) ranges = parseRangeRecords(bytes, coverageOffset + COVERAGE_HEADER_SIZE, count);
61
+ if (ranges === void 0) return;
62
+ const resolved = ranges;
63
+ return {
64
+ coverageIndex(glyphId) {
65
+ const range = findRange(resolved, glyphId);
66
+ return range === void 0 ? void 0 : range.value + (glyphId - range.startGlyphId);
67
+ },
68
+ *entries() {
69
+ for (const range of resolved) for (let glyphId = range.startGlyphId; glyphId <= range.endGlyphId; glyphId++) yield [glyphId, range.value + (glyphId - range.startGlyphId)];
70
+ }
71
+ };
72
+ }
73
+ const CLASS_DEF_FORMAT_1_HEADER_SIZE = 6;
74
+ const CLASS_DEF_FORMAT_2_HEADER_SIZE = 4;
75
+ function parseClassDef(bytes, classDefOffset) {
76
+ if (!hasBytes(bytes, classDefOffset, CLASS_DEF_FORMAT_2_HEADER_SIZE)) return;
77
+ const format = u16(bytes, classDefOffset);
78
+ let ranges;
79
+ if (format === 1) {
80
+ if (!hasBytes(bytes, classDefOffset, CLASS_DEF_FORMAT_1_HEADER_SIZE)) return;
81
+ const startGlyphId = u16(bytes, classDefOffset + 2);
82
+ const glyphCount = u16(bytes, classDefOffset + 4);
83
+ const classArrayOffset = classDefOffset + CLASS_DEF_FORMAT_1_HEADER_SIZE;
84
+ if (!hasBytes(bytes, classArrayOffset, glyphCount * 2)) return;
85
+ ranges = [];
86
+ for (let i = 0; i < glyphCount; i++) pushGlyph(ranges, startGlyphId + i, u16(bytes, classArrayOffset + i * 2), 0);
87
+ } else if (format === 2) ranges = parseRangeRecords(bytes, classDefOffset + CLASS_DEF_FORMAT_2_HEADER_SIZE, u16(bytes, classDefOffset + 2));
88
+ if (ranges === void 0) return;
89
+ const resolved = ranges;
90
+ return (glyphId) => findRange(resolved, glyphId)?.value ?? 0;
91
+ }
92
+ //#endregion
93
+ export { parseClassDef, parseCoverage };
package/dist/write.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { r as EmbeddedFaceSubstitution } from "./embedded-font-CLedn-mT.cjs";
2
- import { t as FontRegistry } from "./font-registry-yby02snZ.cjs";
1
+ import { r as EmbeddedFaceSubstitution } from "./embedded-font-BU6Jgcof.cjs";
2
+ import { t as FontRegistry } from "./font-registry-B5qL0Vi0.cjs";
3
3
  import { WinAnsiSubstitution } from "./winansi.cjs";
4
4
  import { PositionedFormula } from "./formula.cjs";
5
5
  import { LayoutDocument } from "document-schema.js";
package/dist/write.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { r as EmbeddedFaceSubstitution } from "./embedded-font-CbqkKgBl.js";
2
- import { t as FontRegistry } from "./font-registry-Cn7P9lAh.js";
1
+ import { r as EmbeddedFaceSubstitution } from "./embedded-font-fREdbxnr.js";
2
+ import { t as FontRegistry } from "./font-registry-mgdbNP8_.js";
3
3
  import { WinAnsiSubstitution } from "./winansi.js";
4
4
  import { PositionedFormula } from "./formula.js";
5
5
  import { LayoutDocument } from "document-schema.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-codec",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "description": "Hand-written, dependency-minimal PDF codec: parses arbitrary real-world PDFs and generates new ones, built on document-schema.js's LayoutDocument pivot and Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -70,7 +70,7 @@
70
70
  "license": "MIT",
71
71
  "packageManager": "pnpm@11.6.0",
72
72
  "dependencies": {
73
- "document-schema.js": "^2.0.0",
73
+ "document-schema.js": "^2.1.0",
74
74
  "fflate": "^0.8.3",
75
75
  "zod": "^4.4.3"
76
76
  },