@doccloak/core 0.12.1 → 0.13.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 (79) hide show
  1. package/CHANGELOG.md +333 -0
  2. package/NOTICE +5 -0
  3. package/README.md +131 -9
  4. package/dist/dom/errors.d.ts +1 -1
  5. package/dist/dom/ocr.d.ts +33 -7
  6. package/dist/dom/ocr.js +98 -4
  7. package/dist/dom/office.d.ts +20 -6
  8. package/dist/dom/office.js +44 -11
  9. package/dist/engine.js +4 -5
  10. package/dist/env.d.ts +3 -3
  11. package/dist/pdf/cmap.d.ts +83 -0
  12. package/dist/pdf/cmap.js +659 -0
  13. package/dist/pdf/encodings.d.ts +49 -0
  14. package/dist/pdf/encodings.js +181 -0
  15. package/dist/pdf/extract.d.ts +106 -0
  16. package/dist/pdf/extract.js +1064 -0
  17. package/dist/pdf/fallback-fonts.d.ts +146 -0
  18. package/dist/pdf/fallback-fonts.js +312 -0
  19. package/dist/pdf/fit.d.ts +35 -0
  20. package/dist/pdf/fit.js +60 -0
  21. package/dist/pdf/fonts.d.ts +82 -0
  22. package/dist/pdf/fonts.js +465 -0
  23. package/dist/pdf/glyphlist.d.ts +37 -0
  24. package/dist/pdf/glyphlist.js +485 -0
  25. package/dist/pdf/index.d.ts +21 -0
  26. package/dist/pdf/index.js +7 -0
  27. package/dist/pdf/lexer.d.ts +61 -0
  28. package/dist/pdf/lexer.js +554 -0
  29. package/dist/pdf/objects.d.ts +57 -0
  30. package/dist/pdf/objects.js +217 -0
  31. package/dist/pdf/oracle.d.ts +149 -0
  32. package/dist/pdf/oracle.js +384 -0
  33. package/dist/pdf/raster.d.ts +45 -0
  34. package/dist/pdf/raster.js +89 -0
  35. package/dist/pdf/read.d.ts +36 -0
  36. package/dist/pdf/read.js +65 -0
  37. package/dist/pdf/serializer.d.ts +21 -0
  38. package/dist/pdf/serializer.js +106 -0
  39. package/dist/pdf/standard-metrics.d.ts +27 -0
  40. package/dist/pdf/standard-metrics.js +72 -0
  41. package/dist/pdf/surgery.d.ts +131 -0
  42. package/dist/pdf/surgery.js +847 -0
  43. package/dist/pdf/textstate.d.ts +77 -0
  44. package/dist/pdf/textstate.js +280 -0
  45. package/dist/pdf/types.d.ts +191 -0
  46. package/dist/pdf/types.js +11 -0
  47. package/dist/pdf/verify.d.ts +33 -0
  48. package/dist/pdf/verify.js +446 -0
  49. package/dist/pdf/write.d.ts +52 -0
  50. package/dist/pdf/write.js +644 -0
  51. package/dist/pipeline.d.ts +15 -0
  52. package/dist/pipeline.js +123 -8
  53. package/dist/providers/bardsai.d.ts +1 -1
  54. package/dist/providers/bardsai.js +5 -1
  55. package/dist/providers/gliner-base.d.ts +1 -1
  56. package/dist/providers/gliner-base.js +5 -1
  57. package/dist/providers/gliner.d.ts +1 -1
  58. package/dist/providers/gliner.js +5 -1
  59. package/dist/regex/rules.data.js +13 -8
  60. package/dist/types.d.ts +17 -2
  61. package/dist/types.js +17 -0
  62. package/dist/worker-protocol.d.ts +11 -0
  63. package/dist/worker-protocol.js +41 -8
  64. package/fonts/liberation/LICENSE +102 -0
  65. package/fonts/liberation/LiberationMono-Bold.ttf +0 -0
  66. package/fonts/liberation/LiberationMono-BoldItalic.ttf +0 -0
  67. package/fonts/liberation/LiberationMono-Italic.ttf +0 -0
  68. package/fonts/liberation/LiberationMono-Regular.ttf +0 -0
  69. package/fonts/liberation/LiberationSans-Bold.ttf +0 -0
  70. package/fonts/liberation/LiberationSans-BoldItalic.ttf +0 -0
  71. package/fonts/liberation/LiberationSans-Italic.ttf +0 -0
  72. package/fonts/liberation/LiberationSans-Regular.ttf +0 -0
  73. package/fonts/liberation/LiberationSerif-Bold.ttf +0 -0
  74. package/fonts/liberation/LiberationSerif-BoldItalic.ttf +0 -0
  75. package/fonts/liberation/LiberationSerif-Italic.ttf +0 -0
  76. package/fonts/liberation/LiberationSerif-Regular.ttf +0 -0
  77. package/package.json +11 -2
  78. package/rules/pl.json +7 -3
  79. package/rules/universal.json +6 -5
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @doccloak/core/pdf - simple-font encodings (T207).
3
+ *
4
+ * Code -> glyph-name tables for the predefined simple-font encodings of
5
+ * ISO 32000-1:2008 Annex D: D.2 (StandardEncoding, WinAnsiEncoding,
6
+ * MacRomanEncoding, PDFDocEncoding), D.4 (MacExpertEncoding), D.5 (Symbol)
7
+ * and D.6 (ZapfDingbats). The tables are owned by this module; nothing here
8
+ * depends on the shape of a third-party library.
9
+ *
10
+ * Each table is stored as a run string: an `@XX` token sets the current code
11
+ * (hex), every other token is the glyph name of the current code and advances
12
+ * it by one. Codes never mentioned are undefined (no glyph).
13
+ *
14
+ * Annex D notes applied:
15
+ * - WinAnsi: unused codes above 040 (octal) map to `bullet` (0x7F, 0x80..0x9F
16
+ * gaps), 0xA0 is `space` (non-breaking space), 0xAD is `hyphen` (soft hyphen).
17
+ * - MacRoman: 0xCA is `space`, 0xDB is `currency` (Mac OS Roman shows Euro
18
+ * there). The 15 Mac OS Roman characters the spec table leaves undefined
19
+ * (notequal, infinity, lessequal, greaterequal, partialdiff, summation,
20
+ * product, pi, integral, Omega, radical, approxequal, Delta, lozenge, apple)
21
+ * are filled in as every major viewer does; they occupy codes that Annex D
22
+ * leaves unassigned, so no spec-defined code is changed.
23
+ * - Standard: 0x27 is `quoteright` and 0x60 `quoteleft`; `quotesingle` lives at
24
+ * 0xA9 and `grave` at 0xC1.
25
+ * - PDFDoc: 0x18..0x1F carry the accents, 0x80..0x9E the typographic block,
26
+ * 0xA0 is `Euro`, 0xAD is undefined (D.3), everything else follows Latin-1.
27
+ * - Symbol: 0xA0 is `Euro`; 0xF0 (apple) and 0xFF are undefined.
28
+ */
29
+ /** 256 entries: the glyph name of the code, or undefined when the code has no glyph. */
30
+ export type EncodingTable = ReadonlyArray<string | undefined>;
31
+ /** Annex D.2, STD column (Adobe standard Latin encoding, the Type 1 built-in default). */
32
+ export declare const STANDARD_ENCODING: EncodingTable;
33
+ /** Annex D.2, WIN column (Windows code page 1252 as used by PDF). */
34
+ export declare const WIN_ANSI_ENCODING: EncodingTable;
35
+ /** Annex D.2, MAC column (Mac OS Roman as used by PDF, see the module note). */
36
+ export declare const MAC_ROMAN_ENCODING: EncodingTable;
37
+ /** Annex D.4 (expert character set: small caps, old-style figures, superiors...). */
38
+ export declare const MAC_EXPERT_ENCODING: EncodingTable;
39
+ /** Annex D.2 PDF column plus D.3 (the encoding of text strings outside content streams). */
40
+ export declare const PDF_DOC_ENCODING: EncodingTable;
41
+ /** Annex D.5: built-in encoding of the standard Symbol font. */
42
+ export declare const SYMBOL_ENCODING: EncodingTable;
43
+ /** Annex D.6: built-in encoding of the standard ZapfDingbats font. */
44
+ export declare const ZAPF_DINGBATS_ENCODING: EncodingTable;
45
+ /**
46
+ * Resolves a predefined encoding name as used in a font dictionary's
47
+ * `/Encoding` entry (or `/BaseEncoding`). Returns undefined for any other name.
48
+ */
49
+ export declare function encodingByName(name: string): EncodingTable | undefined;
@@ -0,0 +1,181 @@
1
+ /**
2
+ * @doccloak/core/pdf - simple-font encodings (T207).
3
+ *
4
+ * Code -> glyph-name tables for the predefined simple-font encodings of
5
+ * ISO 32000-1:2008 Annex D: D.2 (StandardEncoding, WinAnsiEncoding,
6
+ * MacRomanEncoding, PDFDocEncoding), D.4 (MacExpertEncoding), D.5 (Symbol)
7
+ * and D.6 (ZapfDingbats). The tables are owned by this module; nothing here
8
+ * depends on the shape of a third-party library.
9
+ *
10
+ * Each table is stored as a run string: an `@XX` token sets the current code
11
+ * (hex), every other token is the glyph name of the current code and advances
12
+ * it by one. Codes never mentioned are undefined (no glyph).
13
+ *
14
+ * Annex D notes applied:
15
+ * - WinAnsi: unused codes above 040 (octal) map to `bullet` (0x7F, 0x80..0x9F
16
+ * gaps), 0xA0 is `space` (non-breaking space), 0xAD is `hyphen` (soft hyphen).
17
+ * - MacRoman: 0xCA is `space`, 0xDB is `currency` (Mac OS Roman shows Euro
18
+ * there). The 15 Mac OS Roman characters the spec table leaves undefined
19
+ * (notequal, infinity, lessequal, greaterequal, partialdiff, summation,
20
+ * product, pi, integral, Omega, radical, approxequal, Delta, lozenge, apple)
21
+ * are filled in as every major viewer does; they occupy codes that Annex D
22
+ * leaves unassigned, so no spec-defined code is changed.
23
+ * - Standard: 0x27 is `quoteright` and 0x60 `quoteleft`; `quotesingle` lives at
24
+ * 0xA9 and `grave` at 0xC1.
25
+ * - PDFDoc: 0x18..0x1F carry the accents, 0x80..0x9E the typographic block,
26
+ * 0xA0 is `Euro`, 0xAD is undefined (D.3), everything else follows Latin-1.
27
+ * - Symbol: 0xA0 is `Euro`; 0xF0 (apple) and 0xFF are undefined.
28
+ */
29
+ function table(runs) {
30
+ const out = new Array(256).fill(undefined);
31
+ let code = 0;
32
+ for (const tok of runs.split(' ')) {
33
+ if (tok === '')
34
+ continue;
35
+ if (tok.charCodeAt(0) === 0x40 /* @ */) {
36
+ code = parseInt(tok.slice(1), 16);
37
+ }
38
+ else {
39
+ out[code++] = tok;
40
+ }
41
+ }
42
+ return out;
43
+ }
44
+ /** Annex D.2, STD column (Adobe standard Latin encoding, the Type 1 built-in default). */
45
+ export const STANDARD_ENCODING = table('@20 space exclam quotedbl numbersign dollar percent ampersand quoteright parenleft parenright ' +
46
+ 'asterisk plus comma hyphen period slash zero one two three four five six seven eight nine colon ' +
47
+ 'semicolon less equal greater question at A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ' +
48
+ 'bracketleft backslash bracketright asciicircum underscore quoteleft a b c d e f g h i j k l m n ' +
49
+ 'o p q r s t u v w x y z braceleft bar braceright asciitilde @A1 exclamdown cent sterling ' +
50
+ 'fraction yen florin section currency quotesingle quotedblleft guillemotleft guilsinglleft ' +
51
+ 'guilsinglright fi fl @B1 endash dagger daggerdbl periodcentered @B6 paragraph bullet ' +
52
+ 'quotesinglbase quotedblbase quotedblright guillemotright ellipsis perthousand @BF questiondown ' +
53
+ '@C1 grave acute circumflex tilde macron breve dotaccent dieresis @CA ring cedilla @CD ' +
54
+ 'hungarumlaut ogonek caron emdash @E1 AE @E3 ordfeminine @E8 Lslash Oslash OE ordmasculine @F1 ae ' +
55
+ '@F5 dotlessi @F8 lslash oslash oe germandbls');
56
+ /** Annex D.2, WIN column (Windows code page 1252 as used by PDF). */
57
+ export const WIN_ANSI_ENCODING = table('@20 space exclam quotedbl numbersign dollar percent ampersand quotesingle parenleft parenright ' +
58
+ 'asterisk plus comma hyphen period slash zero one two three four five six seven eight nine colon ' +
59
+ 'semicolon less equal greater question at A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ' +
60
+ 'bracketleft backslash bracketright asciicircum underscore grave a b c d e f g h i j k l m n o p ' +
61
+ 'q r s t u v w x y z braceleft bar braceright asciitilde bullet Euro bullet quotesinglbase florin ' +
62
+ 'quotedblbase ellipsis dagger daggerdbl circumflex perthousand Scaron guilsinglleft OE bullet ' +
63
+ 'Zcaron bullet bullet quoteleft quoteright quotedblleft quotedblright bullet endash emdash tilde ' +
64
+ 'trademark scaron guilsinglright oe bullet zcaron Ydieresis space exclamdown cent sterling ' +
65
+ 'currency yen brokenbar section dieresis copyright ordfeminine guillemotleft logicalnot hyphen ' +
66
+ 'registered macron degree plusminus twosuperior threesuperior acute mu paragraph periodcentered ' +
67
+ 'cedilla onesuperior ordmasculine guillemotright onequarter onehalf threequarters questiondown ' +
68
+ 'Agrave Aacute Acircumflex Atilde Adieresis Aring AE Ccedilla Egrave Eacute Ecircumflex Edieresis ' +
69
+ 'Igrave Iacute Icircumflex Idieresis Eth Ntilde Ograve Oacute Ocircumflex Otilde Odieresis ' +
70
+ 'multiply Oslash Ugrave Uacute Ucircumflex Udieresis Yacute Thorn germandbls agrave aacute ' +
71
+ 'acircumflex atilde adieresis aring ae ccedilla egrave eacute ecircumflex edieresis igrave iacute ' +
72
+ 'icircumflex idieresis eth ntilde ograve oacute ocircumflex otilde odieresis divide oslash ugrave ' +
73
+ 'uacute ucircumflex udieresis yacute thorn ydieresis');
74
+ /** Annex D.2, MAC column (Mac OS Roman as used by PDF, see the module note). */
75
+ export const MAC_ROMAN_ENCODING = table('@20 space exclam quotedbl numbersign dollar percent ampersand quotesingle parenleft parenright ' +
76
+ 'asterisk plus comma hyphen period slash zero one two three four five six seven eight nine colon ' +
77
+ 'semicolon less equal greater question at A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ' +
78
+ 'bracketleft backslash bracketright asciicircum underscore grave a b c d e f g h i j k l m n o p ' +
79
+ 'q r s t u v w x y z braceleft bar braceright asciitilde @80 Adieresis Aring Ccedilla Eacute ' +
80
+ 'Ntilde Odieresis Udieresis aacute agrave acircumflex adieresis atilde aring ccedilla eacute ' +
81
+ 'egrave ecircumflex edieresis iacute igrave icircumflex idieresis ntilde oacute ograve ' +
82
+ 'ocircumflex odieresis otilde uacute ugrave ucircumflex udieresis dagger degree cent sterling ' +
83
+ 'section bullet paragraph germandbls registered copyright trademark acute dieresis notequal AE ' +
84
+ 'Oslash infinity plusminus lessequal greaterequal yen mu partialdiff summation product pi ' +
85
+ 'integral ordfeminine ordmasculine Omega ae oslash questiondown exclamdown logicalnot radical ' +
86
+ 'florin approxequal Delta guillemotleft guillemotright ellipsis space Agrave Atilde Otilde OE oe ' +
87
+ 'endash emdash quotedblleft quotedblright quoteleft quoteright divide lozenge ydieresis Ydieresis ' +
88
+ 'fraction currency guilsinglleft guilsinglright fi fl daggerdbl periodcentered quotesinglbase ' +
89
+ 'quotedblbase perthousand Acircumflex Ecircumflex Aacute Edieresis Egrave Iacute Icircumflex ' +
90
+ 'Idieresis Igrave Oacute Ocircumflex apple Ograve Uacute Ucircumflex Ugrave dotlessi circumflex ' +
91
+ 'tilde macron breve dotaccent ring cedilla hungarumlaut ogonek caron');
92
+ /** Annex D.4 (expert character set: small caps, old-style figures, superiors...). */
93
+ export const MAC_EXPERT_ENCODING = table('@20 space exclamsmall Hungarumlautsmall centoldstyle dollaroldstyle dollarsuperior ' +
94
+ 'ampersandsmall Acutesmall parenleftsuperior parenrightsuperior twodotenleader onedotenleader ' +
95
+ 'comma hyphen period fraction zerooldstyle oneoldstyle twooldstyle threeoldstyle fouroldstyle ' +
96
+ 'fiveoldstyle sixoldstyle sevenoldstyle eightoldstyle nineoldstyle colon semicolon @3D ' +
97
+ 'threequartersemdash @3F questionsmall @44 Ethsmall @47 onequarter onehalf threequarters ' +
98
+ 'oneeighth threeeighths fiveeighths seveneighths onethird twothirds @56 ff fi fl ffi ffl ' +
99
+ 'parenleftinferior @5D parenrightinferior Circumflexsmall hypheninferior Gravesmall Asmall Bsmall ' +
100
+ 'Csmall Dsmall Esmall Fsmall Gsmall Hsmall Ismall Jsmall Ksmall Lsmall Msmall Nsmall Osmall ' +
101
+ 'Psmall Qsmall Rsmall Ssmall Tsmall Usmall Vsmall Wsmall Xsmall Ysmall Zsmall colonmonetary ' +
102
+ 'onefitted rupiah Tildesmall @81 asuperior centsuperior @87 Aacutesmall Agravesmall ' +
103
+ 'Acircumflexsmall Adieresissmall Atildesmall Aringsmall Ccedillasmall Eacutesmall Egravesmall ' +
104
+ 'Ecircumflexsmall Edieresissmall Iacutesmall Igravesmall Icircumflexsmall Idieresissmall ' +
105
+ 'Ntildesmall Oacutesmall Ogravesmall Ocircumflexsmall Odieresissmall Otildesmall Uacutesmall ' +
106
+ 'Ugravesmall Ucircumflexsmall Udieresissmall @A1 eightsuperior fourinferior threeinferior ' +
107
+ 'sixinferior eightinferior seveninferior Scaronsmall @A9 centinferior twoinferior @AC ' +
108
+ 'Dieresissmall @AE Caronsmall osuperior fiveinferior @B2 commainferior periodinferior Yacutesmall ' +
109
+ '@B6 dollarinferior @B9 Thornsmall @BB nineinferior zeroinferior Zcaronsmall AEsmall Oslashsmall ' +
110
+ 'questiondownsmall oneinferior Lslashsmall @C9 Cedillasmall @CF OEsmall figuredash hyphensuperior ' +
111
+ '@D6 exclamdownsmall @D8 Ydieresissmall @DA onesuperior twosuperior threesuperior foursuperior ' +
112
+ 'fivesuperior sixsuperior sevensuperior ninesuperior zerosuperior @E4 esuperior rsuperior ' +
113
+ 'tsuperior @E9 isuperior ssuperior dsuperior @F1 lsuperior Ogoneksmall Brevesmall Macronsmall ' +
114
+ 'bsuperior nsuperior msuperior commasuperior periodsuperior Dotaccentsmall Ringsmall');
115
+ /** Annex D.2 PDF column plus D.3 (the encoding of text strings outside content streams). */
116
+ export const PDF_DOC_ENCODING = table('@18 breve caron circumflex dotaccent hungarumlaut ogonek ring tilde space exclam quotedbl ' +
117
+ 'numbersign dollar percent ampersand quotesingle parenleft parenright asterisk plus comma hyphen ' +
118
+ 'period slash zero one two three four five six seven eight nine colon semicolon less equal ' +
119
+ 'greater question at A B C D E F G H I J K L M N O P Q R S T U V W X Y Z bracketleft backslash ' +
120
+ 'bracketright asciicircum underscore grave a b c d e f g h i j k l m n o p q r s t u v w x y z ' +
121
+ 'braceleft bar braceright asciitilde @80 bullet dagger daggerdbl ellipsis emdash endash florin ' +
122
+ 'fraction guilsinglleft guilsinglright minus perthousand quotedblbase quotedblleft quotedblright ' +
123
+ 'quoteleft quoteright quotesinglbase trademark fi fl Lslash OE Scaron Ydieresis Zcaron dotlessi ' +
124
+ 'lslash oe scaron zcaron @A0 Euro exclamdown cent sterling currency yen brokenbar section ' +
125
+ 'dieresis copyright ordfeminine guillemotleft logicalnot @AE registered macron degree plusminus ' +
126
+ 'twosuperior threesuperior acute mu paragraph periodcentered cedilla onesuperior ordmasculine ' +
127
+ 'guillemotright onequarter onehalf threequarters questiondown Agrave Aacute Acircumflex Atilde ' +
128
+ 'Adieresis Aring AE Ccedilla Egrave Eacute Ecircumflex Edieresis Igrave Iacute Icircumflex ' +
129
+ 'Idieresis Eth Ntilde Ograve Oacute Ocircumflex Otilde Odieresis multiply Oslash Ugrave Uacute ' +
130
+ 'Ucircumflex Udieresis Yacute Thorn germandbls agrave aacute acircumflex atilde adieresis aring ' +
131
+ 'ae ccedilla egrave eacute ecircumflex edieresis igrave iacute icircumflex idieresis eth ntilde ' +
132
+ 'ograve oacute ocircumflex otilde odieresis divide oslash ugrave uacute ucircumflex udieresis ' +
133
+ 'yacute thorn ydieresis');
134
+ /** Annex D.5: built-in encoding of the standard Symbol font. */
135
+ export const SYMBOL_ENCODING = table('@20 space exclam universal numbersign existential percent ampersand suchthat parenleft ' +
136
+ 'parenright asteriskmath plus comma minus period slash zero one two three four five six seven ' +
137
+ 'eight nine colon semicolon less equal greater question congruent Alpha Beta Chi Delta Epsilon ' +
138
+ 'Phi Gamma Eta Iota theta1 Kappa Lambda Mu Nu Omicron Pi Theta Rho Sigma Tau Upsilon sigma1 Omega ' +
139
+ 'Xi Psi Zeta bracketleft therefore bracketright perpendicular underscore radicalex alpha beta chi ' +
140
+ 'delta epsilon phi gamma eta iota phi1 kappa lambda mu nu omicron pi theta rho sigma tau upsilon ' +
141
+ 'omega1 omega xi psi zeta braceleft bar braceright similar @A0 Euro Upsilon1 minute lessequal ' +
142
+ 'fraction infinity florin club diamond heart spade arrowboth arrowleft arrowup arrowright ' +
143
+ 'arrowdown degree plusminus second greaterequal multiply proportional partialdiff bullet divide ' +
144
+ 'notequal equivalence approxequal ellipsis arrowvertex arrowhorizex carriagereturn aleph Ifraktur ' +
145
+ 'Rfraktur weierstrass circlemultiply circleplus emptyset intersection union propersuperset ' +
146
+ 'reflexsuperset notsubset propersubset reflexsubset element notelement angle gradient ' +
147
+ 'registerserif copyrightserif trademarkserif product radical dotmath logicalnot logicaland ' +
148
+ 'logicalor arrowdblboth arrowdblleft arrowdblup arrowdblright arrowdbldown lozenge angleleft ' +
149
+ 'registersans copyrightsans trademarksans summation parenlefttp parenleftex parenleftbt ' +
150
+ 'bracketlefttp bracketleftex bracketleftbt bracelefttp braceleftmid braceleftbt braceex @F1 ' +
151
+ 'angleright integral integraltp integralex integralbt parenrighttp parenrightex parenrightbt ' +
152
+ 'bracketrighttp bracketrightex bracketrightbt bracerighttp bracerightmid bracerightbt');
153
+ /** Annex D.6: built-in encoding of the standard ZapfDingbats font. */
154
+ export const ZAPF_DINGBATS_ENCODING = table('@20 space a1 a2 a202 a3 a4 a5 a119 a118 a117 a11 a12 a13 a14 a15 a16 a105 a17 a18 a19 a20 a21 ' +
155
+ 'a22 a23 a24 a25 a26 a27 a28 a6 a7 a8 a9 a10 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39 a40 a41 ' +
156
+ 'a42 a43 a44 a45 a46 a47 a48 a49 a50 a51 a52 a53 a54 a55 a56 a57 a58 a59 a60 a61 a62 a63 a64 a65 ' +
157
+ 'a66 a67 a68 a69 a70 a71 a72 a73 a74 a203 a75 a204 a76 a77 a78 a79 a81 a82 a83 a84 a97 a98 a99 ' +
158
+ 'a100 @80 a89 a90 a93 a94 a91 a92 a205 a85 a206 a86 a87 a88 a95 a96 @A1 a101 a102 a103 a104 a106 ' +
159
+ 'a107 a108 a112 a111 a110 a109 a120 a121 a122 a123 a124 a125 a126 a127 a128 a129 a130 a131 a132 ' +
160
+ 'a133 a134 a135 a136 a137 a138 a139 a140 a141 a142 a143 a144 a145 a146 a147 a148 a149 a150 a151 ' +
161
+ 'a152 a153 a154 a155 a156 a157 a158 a159 a160 a161 a163 a164 a196 a165 a192 a166 a167 a168 a169 ' +
162
+ 'a170 a171 a172 a173 a162 a174 a175 a176 a177 a178 a179 a193 a180 a199 a181 a200 a182 @F1 a201 ' +
163
+ 'a183 a184 a197 a185 a194 a198 a186 a195 a187 a188 a189 a190 a191');
164
+ /**
165
+ * Resolves a predefined encoding name as used in a font dictionary's
166
+ * `/Encoding` entry (or `/BaseEncoding`). Returns undefined for any other name.
167
+ */
168
+ export function encodingByName(name) {
169
+ switch (name) {
170
+ case 'StandardEncoding':
171
+ return STANDARD_ENCODING;
172
+ case 'WinAnsiEncoding':
173
+ return WIN_ANSI_ENCODING;
174
+ case 'MacRomanEncoding':
175
+ return MAC_ROMAN_ENCODING;
176
+ case 'MacExpertEncoding':
177
+ return MAC_EXPERT_ENCODING;
178
+ default:
179
+ return undefined;
180
+ }
181
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @doccloak/core/pdf - extraction with glyph geometry (T210).
3
+ *
4
+ * Walks every page's content (the /Contents streams joined into one operator
5
+ * list, plus form XObjects recursively) with the state machine, decodes every
6
+ * text-showing operator through the font model and records one GlyphRun per
7
+ * operator: codes, Unicode, advances and user-space origins. The flat text
8
+ * is built from the runs in content order with deterministic separators, so
9
+ * detection offsets map back to (stream, operator, glyph).
10
+ *
11
+ * Everything the writer needs later (parsed document, operator lists, fonts,
12
+ * per-page safety issues) is kept in the returned model; the input bytes are
13
+ * never modified.
14
+ */
15
+ import { PDFDocument } from '@cantoo/pdf-lib';
16
+ import type { PDFContext } from './objects.js';
17
+ import { PDFDict, PDFRef, PDFStream } from './objects.js';
18
+ import type { ContentOp } from './lexer.js';
19
+ import type { LoadedFont } from './fonts.js';
20
+ import type { GlyphRun, PdfPageInfo, RemovedPart } from './types.js';
21
+ import type { UnredactablePart } from '../dom/errors.js';
22
+ import type { OracleDocument } from './oracle.js';
23
+ /** One content stream we may rewrite: page contents (joined) or a form XObject. */
24
+ export interface StreamRecord {
25
+ key: string;
26
+ kind: 'page' | 'xobject';
27
+ page: number;
28
+ /** For xobjects: the stream object (its dict is edited in place); for pages: null (Contents is replaced). */
29
+ ref: PDFRef | null;
30
+ stream: PDFStream | null;
31
+ source: Uint8Array;
32
+ ops: ContentOp[];
33
+ resources: PDFDict | undefined;
34
+ /** False when a form XObject has no /Resources of its own and inherits the parent's (deprecated but common). */
35
+ ownResources: boolean;
36
+ /** Resource names of fonts used by text-showing operators in this stream. */
37
+ fontsUsed: Set<string>;
38
+ /** Pages this stream is drawn on (xobjects shared across pages). */
39
+ pages: Set<number>;
40
+ }
41
+ export interface PageRecord {
42
+ index: number;
43
+ dict: PDFDict;
44
+ ref: PDFRef | null;
45
+ info: PdfPageInfo;
46
+ /** Stream keys drawn on this page, in draw order (page stream first). */
47
+ streams: string[];
48
+ /** Reasons the page cannot be edited safely (empty = editable). */
49
+ issues: string[];
50
+ /** Per-page text hidden/visible flags for the UI. */
51
+ hiddenGlyphs: number;
52
+ /** True when the page text comes from the oracle (our decoder disagreed): edits rasterize the page. */
53
+ oracleText: boolean;
54
+ /** True when the page content is hostile to a viewer (exponential XObject graph, oversized content): pdf.js is never asked about it. */
55
+ hostile?: boolean;
56
+ /** Our decoder's runs and text of a raster-only page (kept for blacking out with our geometry too). */
57
+ ownRuns?: GlyphRun[];
58
+ ownText?: string;
59
+ }
60
+ export interface PdfModel {
61
+ bytes: Uint8Array;
62
+ doc: PDFDocument;
63
+ ctx: PDFContext;
64
+ pages: PageRecord[];
65
+ streams: Map<string, StreamRecord>;
66
+ fonts: Map<string, LoadedFont>;
67
+ }
68
+ export interface ExtractionResult {
69
+ plainText: string;
70
+ runs: GlyphRun[];
71
+ pages: PdfPageInfo[];
72
+ unredactable: UnredactablePart[];
73
+ removed: RemovedPart[];
74
+ warnings: string[];
75
+ empty: boolean;
76
+ model: PdfModel;
77
+ }
78
+ export interface ExtractOptions {
79
+ maxBytes?: number;
80
+ maxPages?: number;
81
+ /** Cap on glyphs in the whole document (default 1.5 million). */
82
+ maxGlyphs?: number;
83
+ password?: string;
84
+ /**
85
+ * Independent extractor. When given, every page's text is compared with
86
+ * it; a page whose text differs is marked raster-only and its text is
87
+ * taken from the oracle (so detection still sees what a viewer shows).
88
+ */
89
+ oracle?: OracleDocument;
90
+ }
91
+ export declare const DEFAULT_MAX_BYTES: number;
92
+ export declare const DEFAULT_MAX_PAGES = 500;
93
+ /** Glyphs per document (each glyph is a JavaScript object with its geometry): beyond this the file is too large for a browser tab. */
94
+ export declare const DEFAULT_MAX_GLYPHS = 1500000;
95
+ /** Parse the file and extract text with geometry. Throws UnsupportedDocumentError for refusals. */
96
+ export declare function extractPdf(bytes: Uint8Array, options?: ExtractOptions): Promise<ExtractionResult>;
97
+ export declare function hasGarbage(text: string): boolean;
98
+ /**
99
+ * Inventory of everything outside page content that the writer drops
100
+ * (never copied to the fresh output document). Reported so the user knows.
101
+ */
102
+ export declare function scanDocumentLevelParts(ctx: PDFContext, doc: PDFDocument, model: PdfModel, warnings: string[]): RemovedPart[];
103
+ /** The trailer /Info dictionary, if any. */
104
+ export declare function infoDict(ctx: PDFContext): PDFDict | undefined;
105
+ /** Text stored in document-level side channels (Info, XMP, annotations, outlines, fields), for the verifier. */
106
+ export declare function collectSideChannelText(ctx: PDFContext, doc: PDFDocument): string[];