reamkit 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +95 -0
- package/dist/esm/bidi/algorithm.d.ts +9 -0
- package/dist/esm/bidi/algorithm.js +458 -0
- package/dist/esm/bidi/char-types.d.ts +2 -0
- package/dist/esm/bidi/char-types.js +439 -0
- package/dist/esm/bidi/index.d.ts +14 -0
- package/dist/esm/bidi/index.js +25 -0
- package/dist/esm/converter/docx-to-pdf.d.ts +15 -0
- package/dist/esm/converter/docx-to-pdf.js +227 -0
- package/dist/esm/converter/index.d.ts +4 -0
- package/dist/esm/converter/index.js +2 -0
- package/dist/esm/converter/xlsx-to-pdf.d.ts +13 -0
- package/dist/esm/converter/xlsx-to-pdf.js +515 -0
- package/dist/esm/crypto/asn1.d.ts +23 -0
- package/dist/esm/crypto/asn1.js +123 -0
- package/dist/esm/crypto/cms.d.ts +9 -0
- package/dist/esm/crypto/cms.js +34 -0
- package/dist/esm/crypto/index.d.ts +2 -0
- package/dist/esm/crypto/index.js +1 -0
- package/dist/esm/document-model/index.d.ts +1 -0
- package/dist/esm/document-model/index.js +0 -0
- package/dist/esm/document-model/types.d.ts +403 -0
- package/dist/esm/font/arabic-joining.d.ts +4 -0
- package/dist/esm/font/arabic-joining.js +97 -0
- package/dist/esm/font/binary-reader.d.ts +13 -0
- package/dist/esm/font/binary-reader.js +44 -0
- package/dist/esm/font/font-registry.d.ts +19 -0
- package/dist/esm/font/font-registry.js +39 -0
- package/dist/esm/font/index.d.ts +7 -0
- package/dist/esm/font/opentype-layout.d.ts +21 -0
- package/dist/esm/font/opentype-layout.js +329 -0
- package/dist/esm/font/ttf-parser.d.ts +29 -0
- package/dist/esm/font/ttf-parser.js +290 -0
- package/dist/esm/font/ttf-subset.d.ts +3 -0
- package/dist/esm/font/ttf-subset.js +201 -0
- package/dist/esm/fonts/index.d.ts +2 -0
- package/dist/esm/fonts/remote-fonts.d.ts +13 -0
- package/dist/esm/fonts/remote-fonts.js +94 -0
- package/dist/esm/hyphenation/index.d.ts +10 -0
- package/dist/esm/hyphenation/index.js +38 -0
- package/dist/esm/hyphenation/liang.d.ts +10 -0
- package/dist/esm/hyphenation/liang.js +79 -0
- package/dist/esm/hyphenation/patterns-en-us.d.ts +2 -0
- package/dist/esm/hyphenation/patterns-en-us.js +5 -0
- package/dist/esm/hyphenation/patterns-ru.d.ts +2 -0
- package/dist/esm/hyphenation/patterns-ru.js +5 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/line-breaker/index.d.ts +2 -0
- package/dist/esm/line-breaker/knuth-plass.d.ts +30 -0
- package/dist/esm/line-breaker/knuth-plass.js +172 -0
- package/dist/esm/numbering/index.d.ts +1 -0
- package/dist/esm/numbering/state.d.ts +6 -0
- package/dist/esm/numbering/state.js +83 -0
- package/dist/esm/ooxml/drawingml/chart-parser.d.ts +3 -0
- package/dist/esm/ooxml/drawingml/chart-parser.js +218 -0
- package/dist/esm/ooxml/drawingml/colors.d.ts +17 -0
- package/dist/esm/ooxml/drawingml/colors.js +125 -0
- package/dist/esm/ooxml/drawingml/theme-parser.d.ts +1 -0
- package/dist/esm/ooxml/drawingml/theme-parser.js +55 -0
- package/dist/esm/ooxml/index.d.ts +1 -0
- package/dist/esm/ooxml/math/omml-parser.d.ts +4 -0
- package/dist/esm/ooxml/math/omml-parser.js +217 -0
- package/dist/esm/ooxml/spreadsheet/cell-reference.d.ts +6 -0
- package/dist/esm/ooxml/spreadsheet/cell-reference.js +26 -0
- package/dist/esm/ooxml/spreadsheet/defined-name-ref.d.ts +11 -0
- package/dist/esm/ooxml/spreadsheet/defined-name-ref.js +64 -0
- package/dist/esm/ooxml/spreadsheet/index.d.ts +12 -0
- package/dist/esm/ooxml/spreadsheet/index.js +7 -0
- package/dist/esm/ooxml/spreadsheet/number-format.d.ts +1 -0
- package/dist/esm/ooxml/spreadsheet/number-format.js +438 -0
- package/dist/esm/ooxml/spreadsheet/shared-strings-parser.d.ts +1 -0
- package/dist/esm/ooxml/spreadsheet/shared-strings-parser.js +47 -0
- package/dist/esm/ooxml/spreadsheet/styles-parser.d.ts +52 -0
- package/dist/esm/ooxml/spreadsheet/styles-parser.js +225 -0
- package/dist/esm/ooxml/spreadsheet/workbook-parser.d.ts +16 -0
- package/dist/esm/ooxml/spreadsheet/workbook-parser.js +90 -0
- package/dist/esm/ooxml/spreadsheet/worksheet-parser.d.ts +60 -0
- package/dist/esm/ooxml/spreadsheet/worksheet-parser.js +311 -0
- package/dist/esm/ooxml/wordproc/document-parser.d.ts +9 -0
- package/dist/esm/ooxml/wordproc/document-parser.js +274 -0
- package/dist/esm/ooxml/wordproc/drawing-parser.d.ts +33 -0
- package/dist/esm/ooxml/wordproc/drawing-parser.js +374 -0
- package/dist/esm/ooxml/wordproc/font-table.d.ts +15 -0
- package/dist/esm/ooxml/wordproc/font-table.js +82 -0
- package/dist/esm/ooxml/wordproc/index.d.ts +10 -0
- package/dist/esm/ooxml/wordproc/index.js +9 -0
- package/dist/esm/ooxml/wordproc/numbering-parser.d.ts +3 -0
- package/dist/esm/ooxml/wordproc/numbering-parser.js +89 -0
- package/dist/esm/ooxml/wordproc/paragraph-properties.d.ts +2 -0
- package/dist/esm/ooxml/wordproc/paragraph-properties.js +85 -0
- package/dist/esm/ooxml/wordproc/po-helpers.d.ts +14 -0
- package/dist/esm/ooxml/wordproc/po-helpers.js +76 -0
- package/dist/esm/ooxml/wordproc/po-to-flat.d.ts +2 -0
- package/dist/esm/ooxml/wordproc/po-to-flat.js +28 -0
- package/dist/esm/ooxml/wordproc/run-properties.d.ts +2 -0
- package/dist/esm/ooxml/wordproc/run-properties.js +82 -0
- package/dist/esm/ooxml/wordproc/settings-parser.d.ts +5 -0
- package/dist/esm/ooxml/wordproc/settings-parser.js +26 -0
- package/dist/esm/ooxml/wordproc/styles-parser.d.ts +3 -0
- package/dist/esm/ooxml/wordproc/styles-parser.js +67 -0
- package/dist/esm/ooxml/wordproc/table-parser.d.ts +3 -0
- package/dist/esm/ooxml/wordproc/table-parser.js +162 -0
- package/dist/esm/ooxml/wordproc/text-extractor.d.ts +1 -0
- package/dist/esm/ooxml/wordproc/text-extractor.js +1 -0
- package/dist/esm/ooxml/wordproc/xml-helpers.d.ts +9 -0
- package/dist/esm/ooxml/wordproc/xml-helpers.js +36 -0
- package/dist/esm/opc/core-properties.d.ts +11 -0
- package/dist/esm/opc/core-properties.js +51 -0
- package/dist/esm/opc/index.d.ts +5 -0
- package/dist/esm/opc/index.js +3 -0
- package/dist/esm/opc/package.d.ts +26 -0
- package/dist/esm/opc/package.js +113 -0
- package/dist/esm/opc/relationship-types.d.ts +3 -0
- package/dist/esm/opc/relationship-types.js +4 -0
- package/dist/esm/opc/relationships.d.ts +7 -0
- package/dist/esm/opc/relationships.js +28 -0
- package/dist/esm/pdf/arc-to-bezier.d.ts +5 -0
- package/dist/esm/pdf/arc-to-bezier.js +58 -0
- package/dist/esm/pdf/builtin-fonts.d.ts +2 -0
- package/dist/esm/pdf/chart-geometry.d.ts +64 -0
- package/dist/esm/pdf/chart-geometry.js +674 -0
- package/dist/esm/pdf/cid-font.d.ts +15 -0
- package/dist/esm/pdf/cid-font.js +174 -0
- package/dist/esm/pdf/embedded-file.d.ts +11 -0
- package/dist/esm/pdf/embedded-file.js +23 -0
- package/dist/esm/pdf/icc-profile.d.ts +1 -0
- package/dist/esm/pdf/icc-profile.js +166 -0
- package/dist/esm/pdf/image-xobject.d.ts +13 -0
- package/dist/esm/pdf/image-xobject.js +335 -0
- package/dist/esm/pdf/index.d.ts +11 -0
- package/dist/esm/pdf/index.js +5 -0
- package/dist/esm/pdf/math-layout.d.ts +45 -0
- package/dist/esm/pdf/math-layout.js +1138 -0
- package/dist/esm/pdf/objects.d.ts +32 -0
- package/dist/esm/pdf/objects.js +54 -0
- package/dist/esm/pdf/preset-geometry.d.ts +6 -0
- package/dist/esm/pdf/preset-geometry.js +199 -0
- package/dist/esm/pdf/serialize.d.ts +3 -0
- package/dist/esm/pdf/serialize.js +54 -0
- package/dist/esm/pdf/signature.d.ts +25 -0
- package/dist/esm/pdf/signature.js +126 -0
- package/dist/esm/pdf/struct-tree.d.ts +31 -0
- package/dist/esm/pdf/struct-tree.js +109 -0
- package/dist/esm/pdf/styled-page-renderer.d.ts +43 -0
- package/dist/esm/pdf/styled-page-renderer.js +2317 -0
- package/dist/esm/pdf/text-encoding.d.ts +2 -0
- package/dist/esm/pdf/text-page-renderer.d.ts +16 -0
- package/dist/esm/pdf/text-page-renderer.js +4 -0
- package/dist/esm/pdf/vector-graphics.d.ts +46 -0
- package/dist/esm/pdf/vector-graphics.js +103 -0
- package/dist/esm/pdf/writer.d.ts +10 -0
- package/dist/esm/pdf/writer.js +81 -0
- package/dist/esm/pdf/xmp.d.ts +13 -0
- package/dist/esm/pdf/xmp.js +38 -0
- package/dist/esm/style-cascade/index.d.ts +3 -0
- package/dist/esm/style-cascade/resolver.d.ts +4 -0
- package/dist/esm/style-cascade/resolver.js +96 -0
- package/dist/esm/style-cascade/types.d.ts +29 -0
- package/dist/esm/style-cascade/types.js +26 -0
- package/package.json +90 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { shapeText } from "../font/opentype-layout.js";
|
|
2
|
+
import { glyphClosure, subsetTtf } from "../font/ttf-subset.js";
|
|
3
|
+
import { dict, name, ref, stream } from "./objects.js";
|
|
4
|
+
//#region src/pdf/cid-font.ts
|
|
5
|
+
var encoder = new TextEncoder();
|
|
6
|
+
function embedTtfFont(doc, parsed, options = {}) {
|
|
7
|
+
const scale = 1e3 / parsed.unitsPerEm;
|
|
8
|
+
const toPdfUnits = (v) => Math.round(v * scale);
|
|
9
|
+
const usedGidsArr = options.usedGids ? [...options.usedGids] : void 0;
|
|
10
|
+
const fontFileBytes = usedGidsArr ? subsetTtf(parsed, usedGidsArr) : parsed.raw;
|
|
11
|
+
const fontFileRef = doc.add(stream({ Length1: fontFileBytes.byteLength }, fontFileBytes));
|
|
12
|
+
const cidSetRef = usedGidsArr !== void 0 && options.cidSet ? doc.add(stream({}, buildCidSet(glyphClosure(parsed, usedGidsArr)))) : void 0;
|
|
13
|
+
const baseFontName = usedGidsArr ? `${subsetTag(parsed.postScriptName, usedGidsArr)}+${parsed.postScriptName}` : parsed.postScriptName;
|
|
14
|
+
const descriptorRef = doc.add(dict({
|
|
15
|
+
Type: name("FontDescriptor"),
|
|
16
|
+
FontName: name(baseFontName),
|
|
17
|
+
Flags: parsed.flags,
|
|
18
|
+
FontBBox: [
|
|
19
|
+
toPdfUnits(parsed.fontBBox[0]),
|
|
20
|
+
toPdfUnits(parsed.fontBBox[1]),
|
|
21
|
+
toPdfUnits(parsed.fontBBox[2]),
|
|
22
|
+
toPdfUnits(parsed.fontBBox[3])
|
|
23
|
+
],
|
|
24
|
+
ItalicAngle: parsed.italicAngle,
|
|
25
|
+
Ascent: toPdfUnits(parsed.ascender),
|
|
26
|
+
Descent: toPdfUnits(parsed.descender),
|
|
27
|
+
CapHeight: toPdfUnits(parsed.capHeight),
|
|
28
|
+
XHeight: toPdfUnits(parsed.xHeight),
|
|
29
|
+
StemV: parsed.stemV,
|
|
30
|
+
FontFile2: ref(fontFileRef.id),
|
|
31
|
+
...cidSetRef ? { CIDSet: ref(cidSetRef.id) } : {}
|
|
32
|
+
}));
|
|
33
|
+
const widths = new Array(parsed.numGlyphs);
|
|
34
|
+
for (let i = 0; i < parsed.numGlyphs; i++) widths[i] = toPdfUnits(parsed.advanceWidths[i] ?? 0);
|
|
35
|
+
const cidFontRef = doc.add(dict({
|
|
36
|
+
Type: name("Font"),
|
|
37
|
+
Subtype: name("CIDFontType2"),
|
|
38
|
+
BaseFont: name(baseFontName),
|
|
39
|
+
CIDSystemInfo: dict({
|
|
40
|
+
Registry: "Adobe",
|
|
41
|
+
Ordering: "Identity",
|
|
42
|
+
Supplement: 0
|
|
43
|
+
}),
|
|
44
|
+
FontDescriptor: ref(descriptorRef.id),
|
|
45
|
+
DW: 1e3,
|
|
46
|
+
W: [0, widths],
|
|
47
|
+
CIDToGIDMap: name("Identity")
|
|
48
|
+
}));
|
|
49
|
+
const toUnicodeRef = doc.add(stream({}, buildToUnicodeCMap(parsed)));
|
|
50
|
+
const type0Ref = doc.add(dict({
|
|
51
|
+
Type: name("Font"),
|
|
52
|
+
Subtype: name("Type0"),
|
|
53
|
+
BaseFont: name(baseFontName),
|
|
54
|
+
Encoding: name("Identity-H"),
|
|
55
|
+
DescendantFonts: [ref(cidFontRef.id)],
|
|
56
|
+
ToUnicode: ref(toUnicodeRef.id)
|
|
57
|
+
}));
|
|
58
|
+
const pdfWidthForGid = (gid) => {
|
|
59
|
+
if (gid < 0 || gid >= parsed.numGlyphs) return 1e3;
|
|
60
|
+
return widths[gid];
|
|
61
|
+
};
|
|
62
|
+
const textWidthPt = (text, fontSize) => {
|
|
63
|
+
const shaped = shapeText(text, parsed.glyphForCodepoint, parsed.advanceWidths, parsed.ligatures, parsed.kerning, parsed.joiningForms);
|
|
64
|
+
let totalEm = 0;
|
|
65
|
+
for (const a of shaped.advances) totalEm += a;
|
|
66
|
+
return totalEm * fontSize / parsed.unitsPerEm;
|
|
67
|
+
};
|
|
68
|
+
const encodeTextAsCidHexFn = (text) => {
|
|
69
|
+
const shaped = shapeText(text, parsed.glyphForCodepoint, parsed.advanceWidths, parsed.ligatures, parsed.kerning, parsed.joiningForms);
|
|
70
|
+
let out = "";
|
|
71
|
+
for (const gid of shaped.gids) out += gid.toString(16).padStart(4, "0").toUpperCase();
|
|
72
|
+
return out;
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
fontRef: type0Ref,
|
|
76
|
+
parsed,
|
|
77
|
+
pdfWidthForGid,
|
|
78
|
+
textWidthPt,
|
|
79
|
+
encodeTextAsCidHex: encodeTextAsCidHexFn
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function buildCidSet(cids) {
|
|
83
|
+
let maxCid = 0;
|
|
84
|
+
for (const c of cids) if (c > maxCid) maxCid = c;
|
|
85
|
+
const bytes = new Uint8Array((maxCid >> 3) + 1);
|
|
86
|
+
for (const c of cids) bytes[c >> 3] |= 128 >> (c & 7);
|
|
87
|
+
return bytes;
|
|
88
|
+
}
|
|
89
|
+
function subsetTag(postScriptName, gids) {
|
|
90
|
+
let h = 2166136261;
|
|
91
|
+
const mix = (n) => {
|
|
92
|
+
h = (h ^ n & 255) >>> 0;
|
|
93
|
+
h = Math.imul(h, 16777619) >>> 0;
|
|
94
|
+
};
|
|
95
|
+
for (let i = 0; i < postScriptName.length; i++) mix(postScriptName.charCodeAt(i));
|
|
96
|
+
for (const g of [...gids].sort((a, b) => a - b)) {
|
|
97
|
+
mix(g);
|
|
98
|
+
mix(g >> 8);
|
|
99
|
+
}
|
|
100
|
+
let tag = "";
|
|
101
|
+
for (let i = 0; i < 6; i++) {
|
|
102
|
+
tag += String.fromCharCode(65 + h % 26);
|
|
103
|
+
h = Math.floor(h / 26) + 1;
|
|
104
|
+
}
|
|
105
|
+
return tag;
|
|
106
|
+
}
|
|
107
|
+
function buildToUnicodeCMap(parsed) {
|
|
108
|
+
const gidToCps = /* @__PURE__ */ new Map();
|
|
109
|
+
const order = [];
|
|
110
|
+
for (let cp = 9; cp <= 65535; cp++) {
|
|
111
|
+
if (cp >= 55296 && cp <= 57343) continue;
|
|
112
|
+
const gid = parsed.glyphForCodepoint(cp);
|
|
113
|
+
if (gid === 0 || gidToCps.has(gid)) continue;
|
|
114
|
+
gidToCps.set(gid, [cp]);
|
|
115
|
+
order.push(gid);
|
|
116
|
+
}
|
|
117
|
+
let changed = true;
|
|
118
|
+
while (changed) {
|
|
119
|
+
changed = false;
|
|
120
|
+
for (const [key, ligGid] of parsed.ligatures) {
|
|
121
|
+
if (gidToCps.has(ligGid)) continue;
|
|
122
|
+
const cps = [];
|
|
123
|
+
let ok = true;
|
|
124
|
+
for (const comp of key.split(",")) {
|
|
125
|
+
const c = gidToCps.get(Number(comp));
|
|
126
|
+
if (!c) {
|
|
127
|
+
ok = false;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
cps.push(...c);
|
|
131
|
+
}
|
|
132
|
+
if (ok && cps.length > 0) {
|
|
133
|
+
gidToCps.set(ligGid, cps);
|
|
134
|
+
order.push(ligGid);
|
|
135
|
+
changed = true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const pairs = order.map((g) => [g, gidToCps.get(g)]).sort((a, b) => a[0] - b[0]);
|
|
140
|
+
const utf16beHex = (cps) => {
|
|
141
|
+
let hex = "";
|
|
142
|
+
for (const cp of cps) if (cp <= 65535) hex += cp.toString(16).padStart(4, "0").toUpperCase();
|
|
143
|
+
else {
|
|
144
|
+
const adj = cp - 65536;
|
|
145
|
+
hex += (55296 + (adj >> 10)).toString(16).padStart(4, "0").toUpperCase();
|
|
146
|
+
hex += (56320 + (adj & 1023)).toString(16).padStart(4, "0").toUpperCase();
|
|
147
|
+
}
|
|
148
|
+
return hex;
|
|
149
|
+
};
|
|
150
|
+
const lines = [];
|
|
151
|
+
lines.push("/CIDInit /ProcSet findresource begin");
|
|
152
|
+
lines.push("12 dict begin");
|
|
153
|
+
lines.push("begincmap");
|
|
154
|
+
lines.push("/CIDSystemInfo <</Registry (Adobe) /Ordering (UCS) /Supplement 0>> def");
|
|
155
|
+
lines.push("/CMapName /Adobe-Identity-UCS def");
|
|
156
|
+
lines.push("/CMapType 2 def");
|
|
157
|
+
lines.push("1 begincodespacerange");
|
|
158
|
+
lines.push("<0000> <FFFF>");
|
|
159
|
+
lines.push("endcodespacerange");
|
|
160
|
+
const CHUNK = 100;
|
|
161
|
+
for (let i = 0; i < pairs.length; i += CHUNK) {
|
|
162
|
+
const chunk = pairs.slice(i, i + CHUNK);
|
|
163
|
+
lines.push(`${chunk.length} beginbfchar`);
|
|
164
|
+
for (const [gid, cps] of chunk) lines.push(`<${gid.toString(16).padStart(4, "0").toUpperCase()}> <${utf16beHex(cps)}>`);
|
|
165
|
+
lines.push("endbfchar");
|
|
166
|
+
}
|
|
167
|
+
lines.push("endcmap");
|
|
168
|
+
lines.push("CMapName currentdict /CMap defineresource pop");
|
|
169
|
+
lines.push("end");
|
|
170
|
+
lines.push("end");
|
|
171
|
+
return encoder.encode(lines.join("\n"));
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
export { embedTtfFont };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PdfRef } from './objects.js';
|
|
2
|
+
import { PdfDocument } from './writer.js';
|
|
3
|
+
export type AFRelationship = 'Source' | 'Data' | 'Alternative' | 'Supplement' | 'Unspecified';
|
|
4
|
+
export interface AttachedFile {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly bytes: Uint8Array;
|
|
7
|
+
readonly mimeType: string;
|
|
8
|
+
readonly relationship?: AFRelationship;
|
|
9
|
+
readonly description?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function embedAssociatedFile(doc: PdfDocument, file: AttachedFile): PdfRef;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { dict, name, ref, stream, unicodeString } from "./objects.js";
|
|
2
|
+
//#region src/pdf/embedded-file.ts
|
|
3
|
+
function embedAssociatedFile(doc, file) {
|
|
4
|
+
const efRef = doc.add(stream({
|
|
5
|
+
Type: name("EmbeddedFile"),
|
|
6
|
+
Subtype: name(file.mimeType),
|
|
7
|
+
Params: dict({ Size: file.bytes.byteLength })
|
|
8
|
+
}, file.bytes));
|
|
9
|
+
const filespec = {
|
|
10
|
+
Type: name("Filespec"),
|
|
11
|
+
F: file.name,
|
|
12
|
+
UF: unicodeString(file.name),
|
|
13
|
+
EF: dict({
|
|
14
|
+
F: ref(efRef.id),
|
|
15
|
+
UF: ref(efRef.id)
|
|
16
|
+
}),
|
|
17
|
+
AFRelationship: name(file.relationship ?? "Unspecified")
|
|
18
|
+
};
|
|
19
|
+
if (file.description) filespec["Desc"] = unicodeString(file.description);
|
|
20
|
+
return doc.add(dict(filespec));
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { embedAssociatedFile };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildSrgbIccProfile(): Uint8Array;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
//#region src/pdf/icc-profile.ts
|
|
2
|
+
function s15Fixed16(value) {
|
|
3
|
+
return Math.round(value * 65536);
|
|
4
|
+
}
|
|
5
|
+
function writeU32BE(view, offset, value) {
|
|
6
|
+
view.setUint32(offset, value >>> 0, false);
|
|
7
|
+
}
|
|
8
|
+
function tag(s) {
|
|
9
|
+
return (s.charCodeAt(0) << 24 | s.charCodeAt(1) << 16 | s.charCodeAt(2) << 8 | s.charCodeAt(3)) >>> 0;
|
|
10
|
+
}
|
|
11
|
+
var D50 = {
|
|
12
|
+
x: .9642,
|
|
13
|
+
y: 1,
|
|
14
|
+
z: .8249
|
|
15
|
+
};
|
|
16
|
+
var RED = {
|
|
17
|
+
x: .43607,
|
|
18
|
+
y: .22249,
|
|
19
|
+
z: .0139
|
|
20
|
+
};
|
|
21
|
+
var GREEN = {
|
|
22
|
+
x: .38515,
|
|
23
|
+
y: .71687,
|
|
24
|
+
z: .09708
|
|
25
|
+
};
|
|
26
|
+
var BLUE = {
|
|
27
|
+
x: .14307,
|
|
28
|
+
y: .06061,
|
|
29
|
+
z: .7141
|
|
30
|
+
};
|
|
31
|
+
var DESC = "sRGB-compatible";
|
|
32
|
+
var COPYRIGHT = "Public Domain";
|
|
33
|
+
function buildTextDescription(text) {
|
|
34
|
+
const ascii = text + "\0";
|
|
35
|
+
const asciiBytes = new TextEncoder().encode(ascii);
|
|
36
|
+
const size = 12 + asciiBytes.length + 4 + 4 + 2 + 1 + 67;
|
|
37
|
+
const buf = new Uint8Array(align4(size));
|
|
38
|
+
const view = new DataView(buf.buffer);
|
|
39
|
+
writeU32BE(view, 0, tag("desc"));
|
|
40
|
+
writeU32BE(view, 4, 0);
|
|
41
|
+
writeU32BE(view, 8, asciiBytes.length);
|
|
42
|
+
buf.set(asciiBytes, 12);
|
|
43
|
+
return buf;
|
|
44
|
+
}
|
|
45
|
+
function buildText(text) {
|
|
46
|
+
const bytes = new TextEncoder().encode(text + "\0");
|
|
47
|
+
const size = 8 + bytes.length;
|
|
48
|
+
const buf = new Uint8Array(align4(size));
|
|
49
|
+
const view = new DataView(buf.buffer);
|
|
50
|
+
writeU32BE(view, 0, tag("text"));
|
|
51
|
+
writeU32BE(view, 4, 0);
|
|
52
|
+
buf.set(bytes, 8);
|
|
53
|
+
return buf;
|
|
54
|
+
}
|
|
55
|
+
function buildXYZ(x, y, z) {
|
|
56
|
+
const buf = new Uint8Array(20);
|
|
57
|
+
const view = new DataView(buf.buffer);
|
|
58
|
+
writeU32BE(view, 0, tag("XYZ "));
|
|
59
|
+
writeU32BE(view, 4, 0);
|
|
60
|
+
view.setInt32(8, s15Fixed16(x), false);
|
|
61
|
+
view.setInt32(12, s15Fixed16(y), false);
|
|
62
|
+
view.setInt32(16, s15Fixed16(z), false);
|
|
63
|
+
return buf;
|
|
64
|
+
}
|
|
65
|
+
function buildCurveGamma(gamma) {
|
|
66
|
+
const buf = new Uint8Array(align4(14));
|
|
67
|
+
const view = new DataView(buf.buffer);
|
|
68
|
+
writeU32BE(view, 0, tag("curv"));
|
|
69
|
+
writeU32BE(view, 4, 0);
|
|
70
|
+
writeU32BE(view, 8, 1);
|
|
71
|
+
view.setUint16(12, Math.round(gamma * 256), false);
|
|
72
|
+
return buf;
|
|
73
|
+
}
|
|
74
|
+
function align4(n) {
|
|
75
|
+
return n + 3 & -4;
|
|
76
|
+
}
|
|
77
|
+
function buildSrgbIccProfile() {
|
|
78
|
+
const desc = buildTextDescription(DESC);
|
|
79
|
+
const wtpt = buildXYZ(D50.x, D50.y, D50.z);
|
|
80
|
+
const rXYZ = buildXYZ(RED.x, RED.y, RED.z);
|
|
81
|
+
const gXYZ = buildXYZ(GREEN.x, GREEN.y, GREEN.z);
|
|
82
|
+
const bXYZ = buildXYZ(BLUE.x, BLUE.y, BLUE.z);
|
|
83
|
+
const trc = buildCurveGamma(2.2);
|
|
84
|
+
const cprt = buildText(COPYRIGHT);
|
|
85
|
+
const entries = [
|
|
86
|
+
{
|
|
87
|
+
sig: "desc",
|
|
88
|
+
data: desc
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
sig: "wtpt",
|
|
92
|
+
data: wtpt
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
sig: "rXYZ",
|
|
96
|
+
data: rXYZ
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
sig: "gXYZ",
|
|
100
|
+
data: gXYZ
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
sig: "bXYZ",
|
|
104
|
+
data: bXYZ
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
sig: "rTRC",
|
|
108
|
+
data: trc
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
sig: "gTRC",
|
|
112
|
+
data: trc
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
sig: "bTRC",
|
|
116
|
+
data: trc
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
sig: "cprt",
|
|
120
|
+
data: cprt
|
|
121
|
+
}
|
|
122
|
+
];
|
|
123
|
+
const headerSize = 128;
|
|
124
|
+
const tagCount = entries.length;
|
|
125
|
+
let dataOffset = align4(headerSize + (4 + tagCount * 12));
|
|
126
|
+
const blockOffsets = /* @__PURE__ */ new Map();
|
|
127
|
+
const orderedBlocks = [];
|
|
128
|
+
for (const e of entries) if (!blockOffsets.has(e.data)) {
|
|
129
|
+
blockOffsets.set(e.data, dataOffset);
|
|
130
|
+
orderedBlocks.push({
|
|
131
|
+
data: e.data,
|
|
132
|
+
offset: dataOffset
|
|
133
|
+
});
|
|
134
|
+
dataOffset += align4(e.data.length);
|
|
135
|
+
}
|
|
136
|
+
const totalSize = dataOffset;
|
|
137
|
+
const out = new Uint8Array(totalSize);
|
|
138
|
+
const view = new DataView(out.buffer);
|
|
139
|
+
writeU32BE(view, 0, totalSize);
|
|
140
|
+
writeU32BE(view, 4, 0);
|
|
141
|
+
writeU32BE(view, 8, 35651584);
|
|
142
|
+
writeU32BE(view, 12, tag("mntr"));
|
|
143
|
+
writeU32BE(view, 16, tag("RGB "));
|
|
144
|
+
writeU32BE(view, 20, tag("XYZ "));
|
|
145
|
+
view.setUint16(24, 2e3, false);
|
|
146
|
+
view.setUint16(26, 1, false);
|
|
147
|
+
view.setUint16(28, 1, false);
|
|
148
|
+
writeU32BE(view, 36, tag("acsp"));
|
|
149
|
+
writeU32BE(view, 64, 0);
|
|
150
|
+
view.setInt32(68, s15Fixed16(D50.x), false);
|
|
151
|
+
view.setInt32(72, s15Fixed16(D50.y), false);
|
|
152
|
+
view.setInt32(76, s15Fixed16(D50.z), false);
|
|
153
|
+
writeU32BE(view, headerSize, tagCount);
|
|
154
|
+
let p = headerSize + 4;
|
|
155
|
+
for (const e of entries) {
|
|
156
|
+
const off = blockOffsets.get(e.data);
|
|
157
|
+
writeU32BE(view, p, tag(e.sig));
|
|
158
|
+
writeU32BE(view, p + 4, off);
|
|
159
|
+
writeU32BE(view, p + 8, e.data.length);
|
|
160
|
+
p += 12;
|
|
161
|
+
}
|
|
162
|
+
for (const b of orderedBlocks) out.set(b.data, b.offset);
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
export { buildSrgbIccProfile };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PdfRef } from './objects.js';
|
|
2
|
+
import { PdfDocument } from './writer.js';
|
|
3
|
+
export type ImageFormat = 'jpeg' | 'png' | 'jpeg2000';
|
|
4
|
+
export interface EmbeddedImage {
|
|
5
|
+
readonly ref: PdfRef;
|
|
6
|
+
readonly widthPx: number;
|
|
7
|
+
readonly heightPx: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function detectImageFormat(bytes: Uint8Array): ImageFormat | null;
|
|
10
|
+
export interface EmbedImageOptions {
|
|
11
|
+
readonly flattenAlpha?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function embedImage(doc: PdfDocument, bytes: Uint8Array, options?: EmbedImageOptions): EmbeddedImage;
|