reamkit 1.30.0 → 1.31.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 (78) hide show
  1. package/README.md +60 -24
  2. package/dist/esm/core/converter/project.js +3 -1
  3. package/dist/esm/core/crypto/offcrypto.js +1 -1
  4. package/dist/esm/core/document-model/index.d.ts +1 -1
  5. package/dist/esm/core/document-model/types.d.ts +63 -0
  6. package/dist/esm/core/font/index.d.ts +2 -0
  7. package/dist/esm/core/font/ttf-build.d.ts +113 -0
  8. package/dist/esm/core/font/ttf-build.js +1224 -0
  9. package/dist/esm/core/font/ttf-subset.d.ts +19 -0
  10. package/dist/esm/core/font/ttf-subset.js +14 -1
  11. package/dist/esm/core/fonts/provider.d.ts +17 -0
  12. package/dist/esm/core/fonts/provider.js +27 -2
  13. package/dist/esm/core/fonts/remote-fonts.js +8 -1
  14. package/dist/esm/core/ir/flow.d.ts +71 -1
  15. package/dist/esm/core/numbering/index.d.ts +1 -1
  16. package/dist/esm/core/numbering/state.d.ts +11 -1
  17. package/dist/esm/core/numbering/state.js +10 -1
  18. package/dist/esm/core/style-cascade/resolver.js +35 -4
  19. package/dist/esm/core/style-cascade/types.d.ts +19 -1
  20. package/dist/esm/core/style-cascade/types.js +3 -0
  21. package/dist/esm/index.d.ts +2 -2
  22. package/dist/esm/layout/page-doc.d.ts +10 -3
  23. package/dist/esm/layout/styled-layout.d.ts +48 -7
  24. package/dist/esm/layout/styled-layout.js +881 -119
  25. package/dist/esm/layout/turned-section.d.ts +38 -0
  26. package/dist/esm/layout/turned-section.js +193 -0
  27. package/dist/esm/pdf/styled-page-emitter.js +78 -2
  28. package/dist/esm/pdf-reader/cff-outline.d.ts +27 -0
  29. package/dist/esm/pdf-reader/cff-outline.js +169 -21
  30. package/dist/esm/pdf-reader/content.d.ts +53 -0
  31. package/dist/esm/pdf-reader/content.js +9 -1
  32. package/dist/esm/pdf-reader/display.d.ts +36 -0
  33. package/dist/esm/pdf-reader/display.js +66 -1
  34. package/dist/esm/pdf-reader/document.js +5 -1
  35. package/dist/esm/pdf-reader/embedded-fonts.d.ts +2 -1
  36. package/dist/esm/pdf-reader/embedded-fonts.js +32 -2
  37. package/dist/esm/pdf-reader/encodings.d.ts +8 -0
  38. package/dist/esm/pdf-reader/encodings.js +25 -3
  39. package/dist/esm/pdf-reader/face-outlines.d.ts +78 -0
  40. package/dist/esm/pdf-reader/face-outlines.js +362 -0
  41. package/dist/esm/pdf-reader/figures.d.ts +52 -0
  42. package/dist/esm/pdf-reader/figures.js +433 -0
  43. package/dist/esm/pdf-reader/flow-build.d.ts +131 -5
  44. package/dist/esm/pdf-reader/flow-build.js +345 -26
  45. package/dist/esm/pdf-reader/font.js +321 -36
  46. package/dist/esm/pdf-reader/glyf-outline.d.ts +33 -0
  47. package/dist/esm/pdf-reader/glyf-outline.js +135 -1
  48. package/dist/esm/pdf-reader/glyph-names.js +154 -1
  49. package/dist/esm/pdf-reader/layout.d.ts +93 -0
  50. package/dist/esm/pdf-reader/layout.js +1703 -214
  51. package/dist/esm/pdf-reader/page-numbers.d.ts +53 -0
  52. package/dist/esm/pdf-reader/page-numbers.js +167 -0
  53. package/dist/esm/pdf-reader/tagged.js +182 -23
  54. package/dist/esm/pdf-reader/text.d.ts +6 -3
  55. package/dist/esm/pdf-reader/text.js +98 -9
  56. package/dist/esm/pdf-reader/type1-outline.d.ts +11 -0
  57. package/dist/esm/pdf-reader/type1-outline.js +63 -8
  58. package/dist/esm/pdf-reader/vector.js +71 -1
  59. package/dist/esm/word/doc/doc-reader.js +6 -2
  60. package/dist/esm/word/doc/doc-text.d.ts +6 -0
  61. package/dist/esm/word/doc/doc-text.js +19 -1
  62. package/dist/esm/word/document-parser.d.ts +2 -2
  63. package/dist/esm/word/document-parser.js +11 -1
  64. package/dist/esm/word/docx-reader.js +5 -3
  65. package/dist/esm/word/docx-writer.js +207 -21
  66. package/dist/esm/word/drawing-parser.d.ts +5 -3
  67. package/dist/esm/word/drawing-parser.js +49 -8
  68. package/dist/esm/word/font-embed.d.ts +30 -0
  69. package/dist/esm/word/font-embed.js +173 -0
  70. package/dist/esm/word/font-table.d.ts +10 -0
  71. package/dist/esm/word/font-table.js +13 -1
  72. package/dist/esm/word/index.js +1 -1
  73. package/dist/esm/word/numbering-parser.d.ts +3 -1
  74. package/dist/esm/word/numbering-parser.js +2 -1
  75. package/dist/esm/word/paragraph-properties.d.ts +7 -6
  76. package/dist/esm/word/paragraph-properties.js +14 -2
  77. package/dist/esm/word/run-properties.js +26 -0
  78. package/package.json +8 -3
@@ -21,6 +21,15 @@ export interface ContentFont {
21
21
  decode: (codes: ReadonlyArray<number>) => string;
22
22
  /** Glyph advance for one code, in 1000-unit text space. */
23
23
  width: (code: number) => number;
24
+ /**
25
+ * §9.6.2.1 — the advance of the face's SPACE as the file states it, in
26
+ * 1000-unit text space: the code its encoding names `space`. Absent where
27
+ * the font states none — not the fallback {@link width} gives a code with no
28
+ * width of its own.
29
+ */
30
+ readonly spaceWidth?: number;
31
+ /** §9.8.2 — every glyph of the face is as wide as the next: a typewriter's. */
32
+ readonly fixedPitch?: boolean;
24
33
  /**
25
34
  * §9.4.4 / §9.7.4.3 — the face sets its text DOWN the page, not across, and
26
35
  * the pen advances by the vertical displacement `w1` rather than by `w0`.
@@ -47,6 +56,43 @@ export interface ContentFont {
47
56
  * this is the last resort before a blank page.
48
57
  */
49
58
  readonly outline?: GlyphOutline;
59
+ /**
60
+ * §9.9 — the face's embedded program, for a writer that embeds the face:
61
+ * the outline EVERY code draws, the program's licence, the descriptor's
62
+ * metrics. Only a face whose program this reads has one.
63
+ */
64
+ readonly program?: FaceProgram;
65
+ }
66
+ /**
67
+ * §9.9 — what a writer that embeds a face needs from its program: the outline
68
+ * each code draws, what the licence allows, and the metrics the descriptor
69
+ * states (§9.8.1).
70
+ */
71
+ export interface FaceProgram {
72
+ /**
73
+ * The contours a code draws, in a one-unit em — empty for a glyph the program
74
+ * holds that draws nothing, `undefined` where it holds none for the code.
75
+ */
76
+ readonly glyph: (code: number) => ReadonlyArray<PathSeg> | undefined;
77
+ /**
78
+ * OS/2 `fsType` — or the `/FSType` a CFF or Type 1 program writes in its
79
+ * place — where the program states one.
80
+ */
81
+ readonly fsType?: number;
82
+ /**
83
+ * How far the program's own space advances, in thousandths of an em — the
84
+ * width a writer gives a space the page never showed as a glyph.
85
+ */
86
+ readonly spaceAdvance?: number;
87
+ /** The program's PostScript name: the `/BaseFont` less its subset tag. */
88
+ readonly postScriptName: string;
89
+ /** §9.8.1 `/CapHeight` and `/XHeight`, in thousandths of an em, where stated. */
90
+ readonly capHeight?: number;
91
+ readonly xHeight?: number;
92
+ /** §9.8.1 `/ItalicAngle`, in degrees counterclockwise from the vertical. */
93
+ readonly italicAngle: number;
94
+ /** §9.8.2 `/Flags` bit 1 — every glyph has the same width. */
95
+ readonly fixedPitch: boolean;
50
96
  }
51
97
  /** §9.6.6 — the outlines of a face read by glyph index, and their glyph space. */
52
98
  export interface GlyphOutline {
@@ -106,6 +152,8 @@ export interface TextRun {
106
152
  * Absent where the face states no width for it.
107
153
  */
108
154
  readonly spaceWidthPt?: number;
155
+ /** §9.8.2 — the face sets every glyph as wide as the next (see `ContentFont`). */
156
+ readonly fixedPitch?: boolean;
109
157
  /** §9.8.1 — the face the glyphs were shown in is a bold one. */
110
158
  readonly bold?: boolean;
111
159
  /**
@@ -309,6 +357,11 @@ export interface InterpretResult {
309
357
  * there is something to draw.
310
358
  */
311
359
  readonly outlines: Array<VectorPlacement>;
360
+ /**
361
+ * §9.4.3 — the codes each font with a readable program showed where the
362
+ * page paints them: the glyphs a writer embedding the face has to carry.
363
+ */
364
+ readonly shown: ReadonlyMap<ContentFont, ReadonlySet<number>>;
312
365
  }
313
366
  /**
314
367
  * §9.6.5 — one showing of a Type 3 glyph: which procedure, and the matrix that
@@ -191,6 +191,7 @@ function interpretContent(bytes, fonts, initialCtm = IDENTITY, shadings = /* @__
191
191
  const glyphs = [];
192
192
  const painted = [];
193
193
  const outlines = [];
194
+ const codesShown = /* @__PURE__ */ new Map();
194
195
  const lexer = new Lexer(bytes);
195
196
  const stack = [];
196
197
  let state = initialState();
@@ -373,6 +374,11 @@ function interpretContent(bytes, fonts, initialCtm = IDENTITY, shadings = /* @__
373
374
  const bytes = toBytes(operand);
374
375
  const codes = state.font.splitCodes ? state.font.splitCodes(bytes) : splitCodes(bytes, state.font.bytesPerCode);
375
376
  for (const code of codes) advanceGlyph(code);
377
+ if (state.font.program && visible() && state.renderMode !== 3 && state.renderMode !== 7) {
378
+ let set = codesShown.get(state.font);
379
+ if (!set) codesShown.set(state.font, set = /* @__PURE__ */ new Set());
380
+ for (const code of codes) set.add(code);
381
+ }
376
382
  return state.font.decode(codes);
377
383
  };
378
384
  const emitAt = (origin, shown, end) => {
@@ -393,6 +399,7 @@ function interpretContent(bytes, fonts, initialCtm = IDENTITY, shadings = /* @__
393
399
  fontSizePt: Math.abs(state.fontSize) * scaleY,
394
400
  spaceWidthPt: (state.font.width(32) / 1e3 * state.fontSize + state.charSpacing + state.wordSpacing) * scaleX,
395
401
  fontKey: state.fontKey,
402
+ ...state.font.fixedPitch === true ? { fixedPitch: true } : {},
396
403
  ...state.font.name !== void 0 ? { fontName: state.font.name } : {},
397
404
  ...state.font.type3 ? { type3: true } : {},
398
405
  ...state.renderMode === 3 || state.renderMode === 7 ? { invisible: true } : {},
@@ -745,7 +752,8 @@ function interpretContent(bytes, fonts, initialCtm = IDENTITY, shadings = /* @__
745
752
  vectors,
746
753
  glyphs,
747
754
  shadings: painted,
748
- outlines
755
+ outlines,
756
+ shown: codesShown
749
757
  };
750
758
  }
751
759
  /** One path segment through a matrix — the glyph's own space onto the page. */
@@ -15,6 +15,16 @@ export interface Display {
15
15
  x: number;
16
16
  y: number;
17
17
  };
18
+ /**
19
+ * §17.6.20 — present when the page is READ in a frame turned back from the
20
+ * sheet it is shown on: its words run DOWN the sheet, and they are read in
21
+ * the frame where they stand upright (see {@link textFrameOf}). `width` and
22
+ * `height` above are that frame's; these are the sheet's.
23
+ */
24
+ readonly sheet?: {
25
+ readonly width: number;
26
+ readonly height: number;
27
+ };
18
28
  }
19
29
  /**
20
30
  * The {@link Display} a page's shown box and `/Rotate` describe.
@@ -27,6 +37,32 @@ export interface Display {
27
37
  * @returns Its size, its turn, and the map onto it.
28
38
  */
29
39
  export declare function displayOf(page: PdfPage): Display;
40
+ /**
41
+ * The frame a page whose words run DOWN its sheet is read in: the sheet turned
42
+ * back a quarter, so the words stand upright in it and every line, paragraph
43
+ * and margin is found the way it is on any other page.
44
+ *
45
+ * A viewer turns such a page with its words, and so does the document it is
46
+ * read into (§17.6.20 `tbRl`; see {@link wordsTurnOf} for when a page's words
47
+ * run down it): hello_world_rotated.pdf sets "Hello world"
48
+ * upright in a portrait box and turns the page by `/Rotate 90`, and read on
49
+ * the shown sheet the words were set flat across it where every viewer shows
50
+ * them running down.
51
+ *
52
+ * @param shown The page's shown geometry.
53
+ * @returns The frame, which knows the sheet it was turned back from.
54
+ */
55
+ export declare function textFrameOf(shown: Display): Display;
56
+ /**
57
+ * How a page's words stand on its sheet: the quarter turn, counter-clockwise,
58
+ * whose words outweigh every other on it together, by their letters at their
59
+ * size — or 0 where none does. A label set on its side beside the text does
60
+ * not turn a page; a page of it does.
61
+ *
62
+ * @param runs The page's runs, placed on the shown sheet.
63
+ * @returns 0, 90, 180 or 270; 270 is a page whose words run DOWN it.
64
+ */
65
+ export declare function wordsTurnOf(runs: ReadonlyArray<TextRun>): 0 | 90 | 180 | 270;
30
66
  /**
31
67
  * The same runs, placed on the shown page.
32
68
  *
@@ -46,6 +46,71 @@ function displayOf(page) {
46
46
  };
47
47
  }
48
48
  /**
49
+ * The frame a page whose words run DOWN its sheet is read in: the sheet turned
50
+ * back a quarter, so the words stand upright in it and every line, paragraph
51
+ * and margin is found the way it is on any other page.
52
+ *
53
+ * A viewer turns such a page with its words, and so does the document it is
54
+ * read into (§17.6.20 `tbRl`; see {@link wordsTurnOf} for when a page's words
55
+ * run down it): hello_world_rotated.pdf sets "Hello world"
56
+ * upright in a portrait box and turns the page by `/Rotate 90`, and read on
57
+ * the shown sheet the words were set flat across it where every viewer shows
58
+ * them running down.
59
+ *
60
+ * @param shown The page's shown geometry.
61
+ * @returns The frame, which knows the sheet it was turned back from.
62
+ */
63
+ function textFrameOf(shown) {
64
+ return {
65
+ width: shown.height,
66
+ height: shown.width,
67
+ turnDeg: shown.turnDeg === 270 || shown.turnDeg === -90 ? 0 : shown.turnDeg + 90,
68
+ place: (x, y) => {
69
+ const p = shown.place(x, y);
70
+ return {
71
+ x: shown.height - p.y,
72
+ y: p.x
73
+ };
74
+ },
75
+ sheet: {
76
+ width: shown.width,
77
+ height: shown.height
78
+ }
79
+ };
80
+ }
81
+ /**
82
+ * How a page's words stand on its sheet: the quarter turn, counter-clockwise,
83
+ * whose words outweigh every other on it together, by their letters at their
84
+ * size — or 0 where none does. A label set on its side beside the text does
85
+ * not turn a page; a page of it does.
86
+ *
87
+ * @param runs The page's runs, placed on the shown sheet.
88
+ * @returns 0, 90, 180 or 270; 270 is a page whose words run DOWN it.
89
+ */
90
+ function wordsTurnOf(runs) {
91
+ const by = [
92
+ 0,
93
+ 0,
94
+ 0,
95
+ 0
96
+ ];
97
+ let all = 0;
98
+ for (const r of runs) {
99
+ const letters = r.text.trim().length;
100
+ if (letters === 0) continue;
101
+ const weight = letters * (r.fontSizePt || 10);
102
+ all += weight;
103
+ const angle = (Math.round(r.angleDeg ?? 0) % 360 + 360) % 360;
104
+ if (angle % 90 === 0) by[angle / 90] += weight;
105
+ }
106
+ const most = by.findIndex((w) => w * 2 > all);
107
+ return most > 0 ? [
108
+ 90,
109
+ 180,
110
+ 270
111
+ ][most - 1] : 0;
112
+ }
113
+ /**
49
114
  * The same runs, placed on the shown page.
50
115
  *
51
116
  * @param runs The runs as the content stream drew them.
@@ -230,4 +295,4 @@ function placeVectors(vectors, d) {
230
295
  }).filter((v) => shows(d, v.minX, v.minY, v.maxX, v.maxY));
231
296
  }
232
297
  //#endregion
233
- export { displayOf, placeImages, placeRuns, placeVectors };
298
+ export { displayOf, placeImages, placeRuns, placeVectors, textFrameOf, wordsTurnOf };
@@ -183,7 +183,7 @@ var PdfFile = class PdfFile {
183
183
  }
184
184
  return;
185
185
  }
186
- const media = mediaBox ?? DEFAULT_MEDIA_BOX;
186
+ const media = mediaBox !== void 0 && hasArea(mediaBox) ? mediaBox : DEFAULT_MEDIA_BOX;
187
187
  out.push({
188
188
  dict: node,
189
189
  mediaBox: media,
@@ -556,6 +556,10 @@ function lastIndexOfAscii(buf, needle) {
556
556
  * bug1844576.pdf is 612×792 of paper cropped to 181×53.75, and read as its
557
557
  * media box the form on it arrived a fifth of the way down a letter page.
558
558
  */
559
+ /** Whether a rectangle bounds anything: a point or a line is no page. */
560
+ function hasArea([x0, y0, x1, y1]) {
561
+ return Math.abs(x1 - x0) > 1 && Math.abs(y1 - y0) > 1;
562
+ }
559
563
  function shownBox(media, crop) {
560
564
  if (!crop) return media;
561
565
  const [mx0, my0, mx1, my1] = media;
@@ -62,7 +62,8 @@ export declare function hasLiftableProgram(file: PdfFile, fontDict: PdfDict): bo
62
62
  /**
63
63
  * The style a font's embedded program states for itself — the `head` table's
64
64
  * macStyle, bit 0 bold and bit 1 italic — where the file carries a TrueType
65
- * program to read it from.
65
+ * program to read it from, and the weight a Type 1 program names (see
66
+ * {@link typeOneStyle}).
66
67
  *
67
68
  * @param file The document.
68
69
  * @param fontDict The font dictionary.
@@ -119,7 +119,8 @@ function hasLiftableProgram(file, fontDict) {
119
119
  /**
120
120
  * The style a font's embedded program states for itself — the `head` table's
121
121
  * macStyle, bit 0 bold and bit 1 italic — where the file carries a TrueType
122
- * program to read it from.
122
+ * program to read it from, and the weight a Type 1 program names (see
123
+ * {@link typeOneStyle}).
123
124
  *
124
125
  * @param file The document.
125
126
  * @param fontDict The font dictionary.
@@ -128,7 +129,8 @@ function hasLiftableProgram(file, fontDict) {
128
129
  */
129
130
  function programStyle(file, fontDict) {
130
131
  const program = fontProgram(file, fontDict);
131
- if (!program || program.length < 12) return void 0;
132
+ if (!program) return typeOneStyle(file, fontDict);
133
+ if (program.length < 12) return void 0;
132
134
  const view = new DataView(program.buffer, program.byteOffset, program.byteLength);
133
135
  const tables = view.getUint16(4);
134
136
  for (let i = 0; i < tables; i++) {
@@ -144,6 +146,34 @@ function programStyle(file, fontDict) {
144
146
  };
145
147
  }
146
148
  }
149
+ /**
150
+ * §9.9 `/FontFile` — the weight a Type 1 program names in its `FontInfo`
151
+ * (`/Weight (Bold)`), read off the cleartext that opens it. pdfTeX states no
152
+ * weight in the descriptor, and names URW's bold Times "NimbusRomNo9L-Medi",
153
+ * which no rule of names reads as bold: comments.pdf's headings and captions
154
+ * came back in the body's weight. Its program says "Bold"; Computer Modern's
155
+ * say "Medium", which is their book weight.
156
+ *
157
+ * @param file The document.
158
+ * @param fontDict The font dictionary.
159
+ * @returns The style, or `undefined` where no program names a weight.
160
+ */
161
+ function typeOneStyle(file, fontDict) {
162
+ const owner = descendant(file, fontDict) ?? fontDict;
163
+ const descriptor = file.resolve(owner.get("FontDescriptor") ?? PDF_NULL);
164
+ if (!(descriptor instanceof Map)) return void 0;
165
+ const program = file.resolve(descriptor.get("FontFile") ?? PDF_NULL);
166
+ if (!(program instanceof PdfStream)) return void 0;
167
+ const bytes = file.streamData(program);
168
+ const clear = new TextDecoder("latin1").decode(bytes.subarray(0, TYPE_ONE_HEAD));
169
+ const weight = /\/Weight\s*\(([^)]*)\)/u.exec(clear)?.[1];
170
+ return weight === void 0 ? void 0 : {
171
+ bold: /bold|black|heavy|semib|demi/iu.test(weight),
172
+ italic: false
173
+ };
174
+ }
175
+ /** How far into a Type 1 program its `FontInfo` stands, at the most. */
176
+ var TYPE_ONE_HEAD = 8192;
147
177
  /** §9.9 `/FontFile2` — the TrueType program, off the font or its descendant. */
148
178
  function fontProgram(file, fontDict) {
149
179
  const owner = descendant(file, fontDict) ?? fontDict;
@@ -1,5 +1,13 @@
1
1
  /** One of the base encodings this reader has a table for (Annex D.2). */
2
2
  export type BaseEncodingName = 'StandardEncoding' | 'WinAnsiEncoding' | 'MacRomanEncoding';
3
+ /**
4
+ * The glyph a code of WinAnsiEncoding's Latin-1 half selects, by name (see
5
+ * `WIN_ANSI_LATIN`).
6
+ *
7
+ * @param code A one-byte code.
8
+ * @returns The Annex D.2 glyph name, or `undefined` outside 0xA0–0xFF.
9
+ */
10
+ export declare function winAnsiLatinName(code: number): string | undefined;
3
11
  /**
4
12
  * The glyph names of a base encoding, or `undefined` for a name this has no
5
13
  * table for — `/MacExpertEncoding`, whose repertory no reader here can set.
@@ -21,10 +21,32 @@ var STANDARD = new Map([
21
21
  ...table(96, "quoteleft"),
22
22
  ...table(160, ". exclamdown cent sterling fraction yen florin section currency quotesingle quotedblleft guillemotleft guilsinglleft guilsinglright fi fl", ". endash dagger daggerdbl periodcentered . paragraph bullet quotesinglbase quotedblbase quotedblright guillemotright ellipsis perthousand . questiondown", ". grave acute circumflex tilde macron breve dotaccent dieresis . ring cedilla . hungarumlaut ogonek caron", "emdash . . . . . . . . . . . . . . .", ". AE . ordfeminine . . . . Lslash Oslash OE ordmasculine . . . .", ". ae . . . dotlessi . . lslash oslash oe germandbls . . . .")
23
23
  ]);
24
+ /** Annex D.2 WIN — CP-1252. Only its punctuation block departs from Latin-1. */
25
+ var WIN_ANSI = new Map([...ASCII, ...table(128, "Euro . quotesinglbase florin quotedblbase ellipsis dagger daggerdbl circumflex perthousand Scaron guilsinglleft OE . Zcaron .", ". quoteleft quoteright quotedblleft quotedblright bullet endash emdash tilde trademark scaron guilsinglright oe . zcaron Ydieresis")]);
26
+ /** Annex D.2 MAC — Mac OS Roman, as the PDF variant states it. */
27
+ var MAC_ROMAN = new Map([...ASCII, ...table(128, "Adieresis Aring Ccedilla Eacute Ntilde Odieresis Udieresis aacute agrave acircumflex adieresis atilde aring ccedilla eacute egrave", "ecircumflex edieresis iacute igrave icircumflex idieresis ntilde oacute ograve ocircumflex odieresis otilde uacute ugrave ucircumflex udieresis", "dagger degree cent sterling section bullet paragraph germandbls registered copyright trademark acute dieresis notequal AE Oslash", "infinity plusminus lessequal greaterequal yen mu partialdiff summation product pi integral ordfeminine ordmasculine Omega ae oslash", "questiondown exclamdown logicalnot radical florin approxequal Delta guillemotleft guillemotright ellipsis space Agrave Atilde Otilde OE oe", "endash emdash quotedblleft quotedblright quoteleft quoteright divide lozenge ydieresis Ydieresis fraction currency guilsinglleft guilsinglright fi fl", "daggerdbl periodcentered quotesinglbase quotedblbase perthousand Acircumflex Ecircumflex Aacute Edieresis Egrave Iacute Icircumflex Idieresis Igrave Oacute Ocircumflex", ". Ograve Uacute Ucircumflex Ugrave dotlessi circumflex tilde macron breve dotaccent ring cedilla hungarumlaut ogonek caron")]);
28
+ /**
29
+ * Annex D.2 WIN — the glyph NAMES of CP-1252's upper half, which the table
30
+ * above leaves to Latin-1 for the TEXT. A program addressed by name still has
31
+ * to be told which glyph 0xE9 is: `eacute`, looked up by name or through the
32
+ * character a Unicode `cmap` keys it by. (0xA0 is `space` and 0xAD `hyphen`
33
+ * here, as Annex D names the glyphs they draw.)
34
+ */
35
+ var WIN_ANSI_LATIN = table(160, "space exclamdown cent sterling currency yen brokenbar section dieresis copyright ordfeminine guillemotleft logicalnot hyphen registered macron", "degree plusminus twosuperior threesuperior acute mu paragraph periodcentered cedilla onesuperior ordmasculine guillemotright onequarter onehalf threequarters questiondown", "Agrave Aacute Acircumflex Atilde Adieresis Aring AE Ccedilla Egrave Eacute Ecircumflex Edieresis Igrave Iacute Icircumflex Idieresis", "Eth Ntilde Ograve Oacute Ocircumflex Otilde Odieresis multiply Oslash Ugrave Uacute Ucircumflex Udieresis Yacute Thorn germandbls", "agrave aacute acircumflex atilde adieresis aring ae ccedilla egrave eacute ecircumflex edieresis igrave iacute icircumflex idieresis", "eth ntilde ograve oacute ocircumflex otilde odieresis divide oslash ugrave uacute ucircumflex udieresis yacute thorn ydieresis");
36
+ /**
37
+ * The glyph a code of WinAnsiEncoding's Latin-1 half selects, by name (see
38
+ * `WIN_ANSI_LATIN`).
39
+ *
40
+ * @param code A one-byte code.
41
+ * @returns The Annex D.2 glyph name, or `undefined` outside 0xA0–0xFF.
42
+ */
43
+ function winAnsiLatinName(code) {
44
+ return WIN_ANSI_LATIN.get(code);
45
+ }
24
46
  var TABLES = {
25
47
  StandardEncoding: STANDARD,
26
- WinAnsiEncoding: new Map([...ASCII, ...table(128, "Euro . quotesinglbase florin quotedblbase ellipsis dagger daggerdbl circumflex perthousand Scaron guilsinglleft OE . Zcaron .", ". quoteleft quoteright quotedblleft quotedblright bullet endash emdash tilde trademark scaron guilsinglright oe . zcaron Ydieresis")]),
27
- MacRomanEncoding: new Map([...ASCII, ...table(128, "Adieresis Aring Ccedilla Eacute Ntilde Odieresis Udieresis aacute agrave acircumflex adieresis atilde aring ccedilla eacute egrave", "ecircumflex edieresis iacute igrave icircumflex idieresis ntilde oacute ograve ocircumflex odieresis otilde uacute ugrave ucircumflex udieresis", "dagger degree cent sterling section bullet paragraph germandbls registered copyright trademark acute dieresis notequal AE Oslash", "infinity plusminus lessequal greaterequal yen mu partialdiff summation product pi integral ordfeminine ordmasculine Omega ae oslash", "questiondown exclamdown logicalnot radical florin approxequal Delta guillemotleft guillemotright ellipsis space Agrave Atilde Otilde OE oe", "endash emdash quotedblleft quotedblright quoteleft quoteright divide lozenge ydieresis Ydieresis fraction currency guilsinglleft guilsinglright fi fl", "daggerdbl periodcentered quotesinglbase quotedblbase perthousand Acircumflex Ecircumflex Aacute Edieresis Egrave Iacute Icircumflex Idieresis Igrave Oacute Ocircumflex", ". Ograve Uacute Ucircumflex Ugrave dotlessi circumflex tilde macron breve dotaccent ring cedilla hungarumlaut ogonek caron")])
48
+ WinAnsiEncoding: WIN_ANSI,
49
+ MacRomanEncoding: MAC_ROMAN
28
50
  };
29
51
  /**
30
52
  * The glyph names of a base encoding, or `undefined` for a name this has no
@@ -107,4 +129,4 @@ function isStandardLatinFace(baseFont) {
107
129
  return STANDARD_LATIN_FACES.has(baseFont.trim().replace(/^[A-Za-z]{6}\+/u, "").toLowerCase());
108
130
  }
109
131
  //#endregion
110
- export { baseEncodingTable, isStandardLatinFace, macGlyphName, standardEncodingTable };
132
+ export { baseEncodingTable, isStandardLatinFace, macGlyphName, standardEncodingTable, winAnsiLatinName };
@@ -0,0 +1,78 @@
1
+ import { ContentFont, TextRun } from './content.js';
2
+ import { FaceOutlines } from '../core/ir/flow.js';
3
+ /** The codes each font showed where the pages paint them, gathered across pages. */
4
+ export type ShownCodes = Map<ContentFont, Set<number>>;
5
+ /**
6
+ * Fold one content stream's shown codes into the document's.
7
+ *
8
+ * @param into The document's codes, added to.
9
+ * @param from One stream's (`InterpretResult.shown`).
10
+ */
11
+ export declare function addShown(into: ShownCodes, from: ReadonlyMap<ContentFont, ReadonlySet<number>>): void;
12
+ /**
13
+ * The outlines of every face the pages painted characters in, keyed by the name
14
+ * a run in the face carries.
15
+ *
16
+ * A face is left out where its program cannot be trusted to say what the page
17
+ * showed: where more than a fifth of its characters have no glyph the reader
18
+ * can find, the way to its glyphs is not the one the page took, and a face
19
+ * embedded that way would show the wrong letters in place of a substitute's
20
+ * right ones. A character whose glyph cannot be found is left out alone — a
21
+ * reader draws it in another face.
22
+ *
23
+ * So is a face that shows a script which is SHAPED: an Arabic letter takes one
24
+ * of four forms by its neighbours, and a face rebuilt here carries one glyph
25
+ * per character and none of the rules that choose between them. Nor can it
26
+ * carry the part of such a face it could: ArabicCIDTrueType.pdf maps half its
27
+ * glyphs to presentation forms, which are shaped already, and half to plain
28
+ * letters — embedded, each line came out in two faces, a bold word with light
29
+ * letters in it.
30
+ *
31
+ * @param shown The codes the pages painted, per font.
32
+ * @param spacing How the pages space each face's text apart where they move the
33
+ * pen rather than draw a glyph (see {@link pageSpacing}).
34
+ * @returns Run font name → the face's outlines.
35
+ */
36
+ export declare function faceOutlinesOf(shown: ShownCodes, spacing?: PageSpacing): Map<string, FaceOutlines>;
37
+ /**
38
+ * How a page spaces a face's text apart where it moves the pen rather than
39
+ * draws a glyph — between words, and between two letters of one word.
40
+ */
41
+ export interface PageSpacing {
42
+ /** Face → the white it leaves between words, in thousandths of an em. */
43
+ readonly wordGaps: ReadonlyMap<string, number>;
44
+ /**
45
+ * Face → the pairs of letters it is KERNED by: the two characters → how far
46
+ * the second stands from where the first's advance leaves it, in thousandths
47
+ * of an em (negative tightens).
48
+ */
49
+ readonly kerning: ReadonlyMap<string, ReadonlyMap<string, number>>;
50
+ }
51
+ /**
52
+ * §9.4.3 — what the gaps between a face's runs say about how it is spaced.
53
+ *
54
+ * The interpreter emits a run for every string of a `TJ` array, so where the
55
+ * page nudges the pen inside a word — which is how a producer KERNS it — two
56
+ * runs meet with the nudge between them, and the letters on either side are
57
+ * the pair. bigboundingbox.pdf kerns its Calibri by eight pairs in one short
58
+ * line, and set without them the line came out 0.67pt longer than the page's
59
+ * and no longer fit the cell it was measured into. Each pair is the median of
60
+ * every nudge the page gives it.
61
+ *
62
+ * A wider gap is the white between two words, where the page moves the pen
63
+ * instead of showing a space; the face's space is the lower quartile of them,
64
+ * which a justified line's stretched gaps do not reach.
65
+ *
66
+ * @param pages The runs each page set, in the order they were painted.
67
+ * @returns Per face, its word gap and its kerning pairs.
68
+ */
69
+ export declare function pageSpacing(pages: ReadonlyArray<ReadonlyArray<TextRun>>): PageSpacing;
70
+ /**
71
+ * The faces a page KERNED: those with kerning pairs (see {@link pageSpacing},
72
+ * which keeps a face's pairs only where there are enough of them to say it was
73
+ * kerning and not an accident of how its strings were cut).
74
+ *
75
+ * @param spacing How the pages space their faces (see {@link pageSpacing}).
76
+ * @returns The run font names of the kerned faces.
77
+ */
78
+ export declare function kernedFaces(spacing: PageSpacing): Set<string>;