@ggraphic/editor 0.1.0-alpha.4 → 0.1.0-alpha.6

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 (131) hide show
  1. package/dist/CanvasEditorProvider.d.ts +6 -1
  2. package/dist/collab/useYjsPageStateSync.d.ts +1 -1
  3. package/dist/collab/useYjsPageStateSync.js +5 -2
  4. package/dist/components/CanvasEditor/CanvasEditorShell.js +139 -36
  5. package/dist/components/CanvasEditor/editorShell.d.ts +6 -0
  6. package/dist/components/CanvasEditor/types.d.ts +28 -0
  7. package/dist/components/GenericCanvas.d.ts +19 -2
  8. package/dist/components/GenericCanvas.js +30 -5
  9. package/dist/components/PagePreview.d.ts +8 -1
  10. package/dist/components/PagePreview.js +4 -1
  11. package/dist/components/TopBar/DownloadSection.d.ts +24 -3
  12. package/dist/components/TopBar/DownloadSection.js +45 -7
  13. package/dist/components/TopBar/ShareDropdown.d.ts +4 -2
  14. package/dist/components/TopBar/ShareDropdown.js +2 -2
  15. package/dist/entries/export.d.ts +14 -1
  16. package/dist/entries/export.js +14 -1
  17. package/dist/entries/services.d.ts +1 -1
  18. package/dist/export/fonts/fontFiles.d.ts +100 -0
  19. package/dist/export/fonts/fontFiles.js +333 -0
  20. package/dist/export/fonts/glyphs.d.ts +113 -0
  21. package/dist/export/fonts/glyphs.js +120 -0
  22. package/dist/export/fonts/variation.d.ts +23 -0
  23. package/dist/export/fonts/variation.js +43 -0
  24. package/dist/export/pdf/pdfContent.d.ts +108 -0
  25. package/dist/export/pdf/pdfContent.js +566 -0
  26. package/dist/export/pdf/pdfFontkit.d.ts +54 -0
  27. package/dist/export/pdf/pdfFontkit.js +159 -0
  28. package/dist/export/pdf/pdfGeometry.d.ts +54 -0
  29. package/dist/export/pdf/pdfGeometry.js +228 -0
  30. package/dist/export/pdf/pdfResources.d.ts +109 -0
  31. package/dist/export/pdf/pdfResources.js +314 -0
  32. package/dist/export/pdf/writePdf.d.ts +34 -0
  33. package/dist/export/pdf/writePdf.js +165 -0
  34. package/dist/export/pptx/exportPptxDeck.d.ts +10 -2
  35. package/dist/export/pptx/exportPptxDeck.js +5 -2
  36. package/dist/export/pptx/svgPicture.d.ts +19 -0
  37. package/dist/export/pptx/svgPicture.js +64 -0
  38. package/dist/export/pptx/vectorizeElement.d.ts +9 -0
  39. package/dist/export/pptx/vectorizeElement.js +118 -0
  40. package/dist/export/pptx/writePptx.d.ts +13 -0
  41. package/dist/export/pptx/writePptx.js +17 -0
  42. package/dist/export/printPdf.d.ts +1 -0
  43. package/dist/export/printPdf.js +1 -1
  44. package/dist/export/scene/browserDeps.d.ts +32 -0
  45. package/dist/export/scene/browserDeps.js +174 -0
  46. package/dist/export/scene/imageBytes.d.ts +79 -0
  47. package/dist/export/scene/imageBytes.js +330 -0
  48. package/dist/export/scene/itemBounds.d.ts +9 -0
  49. package/dist/export/scene/itemBounds.js +40 -0
  50. package/dist/export/scene/matrix.d.ts +13 -0
  51. package/dist/export/scene/matrix.js +32 -0
  52. package/dist/export/scene/rasterLimit.d.ts +13 -0
  53. package/dist/export/scene/rasterLimit.js +24 -0
  54. package/dist/export/scene/rebaseOps.d.ts +8 -0
  55. package/dist/export/scene/rebaseOps.js +51 -0
  56. package/dist/export/scene/recordPageScene.d.ts +28 -0
  57. package/dist/export/scene/recordPageScene.js +224 -0
  58. package/dist/export/scene/recordingCanvas.d.ts +55 -0
  59. package/dist/export/scene/recordingCanvas.js +71 -0
  60. package/dist/export/scene/recordingContext.d.ts +162 -0
  61. package/dist/export/scene/recordingContext.js +1031 -0
  62. package/dist/export/scene/replayScene.d.ts +31 -0
  63. package/dist/export/scene/replayScene.js +213 -0
  64. package/dist/export/scene/resolveScene.d.ts +48 -0
  65. package/dist/export/scene/resolveScene.js +236 -0
  66. package/dist/export/scene/trustedSvgImages.d.ts +3 -0
  67. package/dist/export/scene/trustedSvgImages.js +21 -0
  68. package/dist/export/scene/types.d.ts +241 -0
  69. package/dist/export/scene/types.js +38 -0
  70. package/dist/export/slidesPdf.d.ts +10 -2
  71. package/dist/export/slidesPdf.js +8 -4
  72. package/dist/export/svg/__fixtures__/barChart.svg +1 -0
  73. package/dist/export/svg/__golden__/fixture-editable.svg +87 -0
  74. package/dist/export/svg/__golden__/fixture-outlines.svg +88 -0
  75. package/dist/export/svg/inlineSvg.d.ts +10 -0
  76. package/dist/export/svg/inlineSvg.js +119 -0
  77. package/dist/export/svg/scopeCss.d.ts +45 -0
  78. package/dist/export/svg/scopeCss.js +214 -0
  79. package/dist/export/svg/svgColor.d.ts +8 -0
  80. package/dist/export/svg/svgColor.js +46 -0
  81. package/dist/export/svg/svgImageScene.d.ts +41 -0
  82. package/dist/export/svg/svgImageScene.js +128 -0
  83. package/dist/export/svg/svgPathData.d.ts +31 -0
  84. package/dist/export/svg/svgPathData.js +466 -0
  85. package/dist/export/svg/svgToScene.d.ts +19 -0
  86. package/dist/export/svg/svgToScene.js +1183 -0
  87. package/dist/export/svg/writeSvg.d.ts +33 -0
  88. package/dist/export/svg/writeSvg.js +594 -0
  89. package/dist/export/svg/xml.d.ts +23 -0
  90. package/dist/export/svg/xml.js +49 -0
  91. package/dist/export/vectorDeps.d.ts +27 -0
  92. package/dist/export/vectorDeps.js +37 -0
  93. package/dist/export/vectorExport.d.ts +85 -0
  94. package/dist/export/vectorExport.js +287 -0
  95. package/dist/hostServices.d.ts +15 -0
  96. package/dist/i18n/de.d.ts +26 -9
  97. package/dist/i18n/de.js +26 -10
  98. package/dist/i18n/en.js +24 -0
  99. package/dist/primitives/AssetPrimitive.js +7 -2
  100. package/dist/primitives/CanvasIcons.js +6 -0
  101. package/dist/primitives/CanvasStage.js +2 -2
  102. package/dist/primitives/ChartPrimitive.d.ts +11 -1
  103. package/dist/primitives/ChartPrimitive.js +73 -19
  104. package/dist/primitives/IconPrimitive.js +3 -0
  105. package/dist/primitives/IllustrationPrimitive.js +14 -1
  106. package/dist/primitives/chartFont.d.ts +30 -0
  107. package/dist/primitives/chartFont.js +127 -0
  108. package/dist/sidebar/sections/ImageAdjustSection.js +5 -4
  109. package/dist/sidebar/sections/assets/ElementsPanel.js +4 -2
  110. package/dist/sidebar/sections/assets/assetAudience.d.ts +12 -0
  111. package/dist/sidebar/sections/assets/assetAudience.js +18 -0
  112. package/dist/sidebar/sections/assets/useElementCatalog.js +3 -2
  113. package/dist/stores/createCanvasEditorStore.d.ts +5 -2
  114. package/dist/stores/createCanvasEditorStore.js +9 -5
  115. package/dist/styles/compiled.css +1 -1
  116. package/dist/utils/canvasAssets.d.ts +11 -1
  117. package/dist/utils/canvasAssets.js +8 -0
  118. package/dist/utils/canvasIcons.js +5 -3
  119. package/dist/utils/captureStage.d.ts +19 -0
  120. package/dist/utils/captureStage.js +14 -1
  121. package/dist/utils/externalIcons.d.ts +7 -0
  122. package/dist/utils/externalIcons.js +70 -3
  123. package/dist/utils/illustrations/svgCache.js +6 -1
  124. package/dist/utils/imageFilters.d.ts +13 -0
  125. package/dist/utils/imageFilters.js +11 -0
  126. package/dist/utils/rebaseHistoryState.d.ts +9 -0
  127. package/dist/utils/rebaseHistoryState.js +26 -0
  128. package/dist/utils/zipPageImages.d.ts +8 -0
  129. package/dist/utils/zipPageImages.js +16 -4
  130. package/package.json +6 -2
  131. package/skills/ggraphic-embed/SKILL.md +33 -1
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Glyphs for the vector export: the fontkit boundary, the split of a text op into runs by the
3
+ * font file that covers each code point, and glyph outlines as scene paths.
4
+ */
5
+ import type * as FontkitModule from '@pdf-lib/fontkit';
6
+ import type { PathCommand } from '../scene/types.js';
7
+ import type { FontFile, FontFileSet } from './fontFiles.js';
8
+ /**
9
+ * The part of a fontkit font the export reads. This is the boundary to an untyped module:
10
+ * `@pdf-lib/fontkit` ships declarations, but they leave out `OS/2.fsType` (decoded into the flag
11
+ * object below, not the number the spec names) and `path.commands`, and type `OS/2` as something
12
+ * else. `parseFont` in `fontFiles.ts` is the one place that casts into this.
13
+ */
14
+ export interface FontkitFont {
15
+ postscriptName: string | null;
16
+ unitsPerEm: number;
17
+ /** Every code point the font's cmap maps to a glyph. */
18
+ characterSet: readonly number[];
19
+ /** The table is absent in fonts that never declare a licence flag. */
20
+ 'OS/2'?: {
21
+ fsType?: FontkitFsType;
22
+ usWeightClass?: number;
23
+ };
24
+ hasGlyphForCodePoint(codePoint: number): boolean;
25
+ /** One glyph for one code point, no shaping; code points outside the font give `.notdef`. */
26
+ glyphForCodePoint(codePoint: number): FontkitGlyph;
27
+ /** The shaped glyphs of a string, with the default features (what `pdf-lib` embeds). */
28
+ layout(text: string): {
29
+ glyphs: readonly FontkitGlyph[];
30
+ };
31
+ /** The axes of a variable font, by tag; `{}` for any other. */
32
+ variationAxes?: Readonly<Record<string, {
33
+ min: number;
34
+ default: number;
35
+ max: number;
36
+ }>>;
37
+ /** The font with the axes set, for a variable font with `glyf` outlines (not for WOFF2: see `variation.ts`). */
38
+ getVariation?(settings: Record<string, number>): FontkitFont;
39
+ /** Which tables the file holds; `glyf.transformed` is WOFF2's. */
40
+ directory?: {
41
+ tables?: {
42
+ glyf?: {
43
+ transformed?: boolean;
44
+ };
45
+ CFF2?: unknown;
46
+ };
47
+ };
48
+ }
49
+ /** What fontkit makes of `OS/2.fsType`: the bits it names (a number if a future version stops decoding them). */
50
+ export type FontkitFsType = number | {
51
+ noEmbedding?: boolean;
52
+ viewOnly?: boolean;
53
+ editable?: boolean;
54
+ noSubsetting?: boolean;
55
+ bitmapOnly?: boolean;
56
+ };
57
+ export interface FontkitGlyph {
58
+ advanceWidth: number;
59
+ /** y up, in font units. */
60
+ path: {
61
+ commands: readonly FontkitPathSegment[];
62
+ };
63
+ }
64
+ export interface FontkitPathSegment {
65
+ command: 'moveTo' | 'lineTo' | 'quadraticCurveTo' | 'bezierCurveTo' | 'closePath';
66
+ args: readonly number[];
67
+ }
68
+ /**
69
+ * fontkit is large; it loads when an export needs a font, never with the editor. The result is the
70
+ * object `pdf-lib`'s `registerFontkit` takes.
71
+ */
72
+ export declare function loadFontkit(): Promise<typeof FontkitModule>;
73
+ /**
74
+ * The glyphs a font draws for one code point on its own: what the browser shapes it to and what
75
+ * `pdf-lib` embeds (it encodes text through `layout`), not the glyph the cmap names. They differ
76
+ * in a font with required variation alternates: Fraunces Italic draws its 'w' with a glyph of 1491
77
+ * units where the cmap one has 1644, and the x positions the browser measured are those of the
78
+ * shaped glyph. Never empty.
79
+ */
80
+ export declare function glyphsFor(font: FontkitFont, codePoint: number): readonly FontkitGlyph[];
81
+ /** The advance of `codePoint` in font units: that of the glyphs `glyphsFor` gives, and so of the glyphs a PDF holds. */
82
+ export declare function advanceOf(font: FontkitFont, codePoint: number): number;
83
+ /**
84
+ * The width of the outline a browser adds to a regular cut it draws for a bold nobody ships
85
+ * (Skia's fake bold): `size / 24` at 9 px and below, `size / 32` at 36 px and above, in between
86
+ * the factor falls linearly.
87
+ */
88
+ export declare function fakeBoldWidth(size: number): number;
89
+ /** A stretch of a text op that one font file draws; `file` is null where no file has the glyphs. */
90
+ export interface GlyphRun {
91
+ file: FontFile | null;
92
+ text: string;
93
+ /** One x per code point of `text`, the slice of the op's `xs`. */
94
+ xs: number[];
95
+ }
96
+ /**
97
+ * Cuts `text` into maximal runs of code points the same file covers, so a writer draws each run
98
+ * with its own font and can report the runs nobody covers. `xs` has one entry per code point, as
99
+ * in the scene's text ops.
100
+ */
101
+ export declare function splitRuns(set: FontFileSet, text: string, xs: number[]): GlyphRun[];
102
+ /**
103
+ * The outline of every code point of `text` in `file`, scaled to `size` px, y down, baseline at 0
104
+ * and the pen at x = 0 (the writer moves each glyph to its own x). One entry per code point, in
105
+ * the order of the op's `xs`, so a ligature is not formed and kerning is left to the positions
106
+ * the browser measured. A glyph is the one the font shapes the code point to on its own (see
107
+ * `glyphsFor`). A combining mark gets no base to attach to: precomposed text is exact.
108
+ * A file with a `slant` (an upright cut standing in for an italic) is sheared about the baseline.
109
+ */
110
+ export declare function glyphOutline(file: FontFile, text: string, size: number): {
111
+ advance: number;
112
+ path: PathCommand[];
113
+ }[];
@@ -0,0 +1,120 @@
1
+ /**
2
+ * fontkit is large; it loads when an export needs a font, never with the editor. The result is the
3
+ * object `pdf-lib`'s `registerFontkit` takes.
4
+ */
5
+ export async function loadFontkit() {
6
+ // Boundary cast: the module's default export is the object the shipped declarations describe
7
+ // as the module namespace (`create`, ...), and the declarations do not list `default`.
8
+ const module = (await import('@pdf-lib/fontkit'));
9
+ return module.default;
10
+ }
11
+ const shaped = new WeakMap();
12
+ /**
13
+ * The glyphs a font draws for one code point on its own: what the browser shapes it to and what
14
+ * `pdf-lib` embeds (it encodes text through `layout`), not the glyph the cmap names. They differ
15
+ * in a font with required variation alternates: Fraunces Italic draws its 'w' with a glyph of 1491
16
+ * units where the cmap one has 1644, and the x positions the browser measured are those of the
17
+ * shaped glyph. Never empty.
18
+ */
19
+ export function glyphsFor(font, codePoint) {
20
+ let known = shaped.get(font);
21
+ if (!known)
22
+ shaped.set(font, (known = new Map()));
23
+ let glyphs = known.get(codePoint);
24
+ if (!glyphs) {
25
+ const laidOut = font.layout(String.fromCodePoint(codePoint)).glyphs;
26
+ glyphs = laidOut.length > 0 ? laidOut : [font.glyphForCodePoint(codePoint)];
27
+ known.set(codePoint, glyphs);
28
+ }
29
+ return glyphs;
30
+ }
31
+ /** The advance of `codePoint` in font units: that of the glyphs `glyphsFor` gives, and so of the glyphs a PDF holds. */
32
+ export function advanceOf(font, codePoint) {
33
+ return glyphsFor(font, codePoint).reduce((sum, glyph) => sum + glyph.advanceWidth, 0);
34
+ }
35
+ /**
36
+ * The width of the outline a browser adds to a regular cut it draws for a bold nobody ships
37
+ * (Skia's fake bold): `size / 24` at 9 px and below, `size / 32` at 36 px and above, in between
38
+ * the factor falls linearly.
39
+ */
40
+ export function fakeBoldWidth(size) {
41
+ const t = Math.min(Math.max((size - 9) / (36 - 9), 0), 1);
42
+ return size * (1 / 24 + t * (1 / 32 - 1 / 24));
43
+ }
44
+ /**
45
+ * Cuts `text` into maximal runs of code points the same file covers, so a writer draws each run
46
+ * with its own font and can report the runs nobody covers. `xs` has one entry per code point, as
47
+ * in the scene's text ops.
48
+ */
49
+ export function splitRuns(set, text, xs) {
50
+ const runs = [];
51
+ let index = 0;
52
+ for (const char of text) {
53
+ const file = set.fileFor(char.codePointAt(0) ?? 0);
54
+ const x = xs[index++];
55
+ const last = runs.at(-1);
56
+ if (last && last.file === file) {
57
+ last.text += char;
58
+ last.xs.push(x);
59
+ }
60
+ else {
61
+ runs.push({ file, text: char, xs: [x] });
62
+ }
63
+ }
64
+ return runs;
65
+ }
66
+ /**
67
+ * The outline of every code point of `text` in `file`, scaled to `size` px, y down, baseline at 0
68
+ * and the pen at x = 0 (the writer moves each glyph to its own x). One entry per code point, in
69
+ * the order of the op's `xs`, so a ligature is not formed and kerning is left to the positions
70
+ * the browser measured. A glyph is the one the font shapes the code point to on its own (see
71
+ * `glyphsFor`). A combining mark gets no base to attach to: precomposed text is exact.
72
+ * A file with a `slant` (an upright cut standing in for an italic) is sheared about the baseline.
73
+ */
74
+ export function glyphOutline(file, text, size) {
75
+ const { font, slant } = file;
76
+ const scale = size / font.unitsPerEm;
77
+ // `0 - y` rather than `-y`: a flipped 0 must stay +0, or the output differs by a "-0".
78
+ const x = (fx, fy) => (slant === 0 ? fx * scale : (fx + slant * fy) * scale);
79
+ const y = (fy) => 0 - fy * scale;
80
+ return Array.from(text, (char) => {
81
+ const codePoint = char.codePointAt(0) ?? 0;
82
+ // A soft hyphen is not drawn by a canvas (it only shows at a line break) and is 0 wide.
83
+ if (codePoint === 0xad)
84
+ return { advance: 0, path: [] };
85
+ // The shaped glyph, as the browser draws it; one that shapes into several (a decomposition)
86
+ // keeps the glyph of the cmap, which has the whole character in one outline.
87
+ const shapedGlyphs = glyphsFor(font, codePoint);
88
+ const glyph = shapedGlyphs.length === 1 ? shapedGlyphs[0] : font.glyphForCodePoint(codePoint);
89
+ const path = glyph.path.commands.map((segment) => {
90
+ const a = segment.args;
91
+ switch (segment.command) {
92
+ case 'moveTo':
93
+ return { op: 'M', x: x(a[0], a[1]), y: y(a[1]) };
94
+ case 'lineTo':
95
+ return { op: 'L', x: x(a[0], a[1]), y: y(a[1]) };
96
+ case 'quadraticCurveTo':
97
+ return {
98
+ op: 'Q',
99
+ x1: x(a[0], a[1]),
100
+ y1: y(a[1]),
101
+ x: x(a[2], a[3]),
102
+ y: y(a[3]),
103
+ };
104
+ case 'bezierCurveTo':
105
+ return {
106
+ op: 'C',
107
+ x1: x(a[0], a[1]),
108
+ y1: y(a[1]),
109
+ x2: x(a[2], a[3]),
110
+ y2: y(a[3]),
111
+ x: x(a[4], a[5]),
112
+ y: y(a[5]),
113
+ };
114
+ case 'closePath':
115
+ return { op: 'Z' };
116
+ }
117
+ });
118
+ return { advance: glyph.advanceWidth * scale, path };
119
+ });
120
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The instance of a variable font for the weight a text asks for. A font file with a `wght` axis
3
+ * draws its default instance when fontkit is not told otherwise (Bricolage Grotesque: ExtraBold),
4
+ * so a regular text would come out bold, with the advances of a bold.
5
+ *
6
+ * `font.getVariation` makes the instance for a font file that is plain TrueType (TTF). It cannot
7
+ * for a webfont: it re-reads the file as plain TrueType, which a WOFF is not and fails at the
8
+ * first glyph (the probe in `makeInstance` catches that), and fontkit decodes the glyphs of a
9
+ * WOFF2, which is what most webfonts are, in advance, with no variations applied. (Measured on 1.1.1: instancing it by hand gets the advances of the weight, from
10
+ * `HVAR`, but the outlines of the default; that is worse than the default for both.) Such a font
11
+ * stays at its default instance and is reported (`ExportReport.defaultInstanceFonts`).
12
+ */
13
+ import type { FontkitFont } from './glyphs.js';
14
+ /**
15
+ * `none`: the font as parsed is the one asked for (not variable, or the weight is the default).
16
+ * `instance`: `font` is the instance for the weight. `default-only`: the font is variable and the
17
+ * weight differs from its default, but no instance could be made; `font` is the default instance.
18
+ */
19
+ export type Variation = 'none' | 'instance' | 'default-only';
20
+ export declare function variationInstance(font: FontkitFont, weight: number): {
21
+ font: FontkitFont;
22
+ variation: Variation;
23
+ };
@@ -0,0 +1,43 @@
1
+ const instances = new WeakMap();
2
+ export function variationInstance(font, weight) {
3
+ const axes = font.variationAxes;
4
+ const wght = axes?.['wght'];
5
+ if (!axes || !wght)
6
+ return { font, variation: 'none' };
7
+ const asked = Math.min(Math.max(weight, wght.min), wght.max);
8
+ if (asked === wght.default)
9
+ return { font, variation: 'none' };
10
+ let known = instances.get(font);
11
+ if (!known)
12
+ instances.set(font, (known = new Map()));
13
+ let made = known.get(asked);
14
+ if (!made) {
15
+ const instance = makeInstance(font, axes, asked);
16
+ made = instance
17
+ ? { font: instance, variation: 'instance' }
18
+ : { font, variation: 'default-only' };
19
+ known.set(asked, made);
20
+ }
21
+ return made;
22
+ }
23
+ function makeInstance(font, axes, weight) {
24
+ const tables = font.directory?.tables;
25
+ // Cubic outlines cannot be written into a PDF font program, see `pdfFontkit.ts`. A WOFF2
26
+ // font's glyphs are decoded in advance, without the variations, so fontkit cannot instance it.
27
+ if (!tables || tables.CFF2 || !tables.glyf || tables.glyf.transformed)
28
+ return null;
29
+ const settings = Object.fromEntries(Object.entries(axes).map(([tag, axis]) => [tag, tag === 'wght' ? weight : axis.default]));
30
+ try {
31
+ const instance = font.getVariation?.(settings);
32
+ if (!instance)
33
+ return null;
34
+ // Draw one glyph: an instance that fontkit cannot decode fails here, not later in a writer.
35
+ const [first] = instance.characterSet;
36
+ if (first !== undefined)
37
+ void instance.glyphForCodePoint(first).path.commands;
38
+ return instance;
39
+ }
40
+ catch {
41
+ return null;
42
+ }
43
+ }
@@ -0,0 +1,108 @@
1
+ import { type PageResources, type PdfAssets } from './pdfResources.js';
2
+ import type { FontFileSet } from '../fonts/fontFiles.js';
3
+ import type { ExportReport, Matrix, SceneOp } from '../scene/types.js';
4
+ import type { SvgToSceneDefaults } from '../svg/svgToScene.js';
5
+ /** A box of the page in px. */
6
+ export interface RasterBox {
7
+ x: number;
8
+ y: number;
9
+ width: number;
10
+ height: number;
11
+ }
12
+ /**
13
+ * Draws `ops` (in page px, each with its own state) on a canvas that shows `box` at `pixelRatio`
14
+ * and returns it as PNG, transparent where nothing is drawn; null if it cannot. See `rebaseOps`.
15
+ */
16
+ export type RasterizeOps = (ops: SceneOp[], box: RasterBox, pixelRatio: number) => Promise<Uint8Array | null>;
17
+ /** What the writer of one page needs from the document. */
18
+ export interface PageEnv {
19
+ assets: PdfAssets;
20
+ resources: PageResources;
21
+ /** The page's number in the report (1-based). */
22
+ page: number;
23
+ width: number;
24
+ height: number;
25
+ fonts: ReadonlyMap<string, FontFileSet>;
26
+ /** The entries this writer adds; the caller merges them with the scenes' own. */
27
+ report: ExportReport;
28
+ rasterize: RasterizeOps;
29
+ pixelRatio: number;
30
+ svgDefaults: SvgToSceneDefaults;
31
+ /** The item being written, for the report. */
32
+ elementId: string | null;
33
+ }
34
+ export declare class ContentWriter {
35
+ private readonly env;
36
+ private readonly base;
37
+ private readonly lines;
38
+ /**
39
+ * @param base maps the page px space the ops are in to the default space of the stream this
40
+ * writes: the page flip for the page, the identity inside a form drawn after that flip.
41
+ */
42
+ constructor(env: PageEnv, base: Matrix);
43
+ raw(line: string): void;
44
+ text(): string;
45
+ ops(ops: readonly SceneOp[]): Promise<void>;
46
+ op(op: SceneOp): Promise<void>;
47
+ /** `q`, the clips, and the matrix. Every `begin` has an `end`. */
48
+ private begin;
49
+ private end;
50
+ /** The clip path in page px: its own matrix applied here, so it needs no `cm` of its own. */
51
+ private clip;
52
+ private alpha;
53
+ private strokeState;
54
+ /**
55
+ * The operators that set alpha and the colour of a fill or a stroke, or null if the paint draws
56
+ * nothing. `matrix` is the op's, `bounds` the area it touches in its user space (a soft mask is
57
+ * as large as that and no larger).
58
+ */
59
+ private paint;
60
+ /**
61
+ * The operator that sets a fill or stroke colour: DeviceCMYK with the brand's exact values if it
62
+ * has them for this colour, else RGB (which `report.rgbBrandColors` is made from).
63
+ */
64
+ private colour;
65
+ /**
66
+ * An SVG tile cannot be a PDF image: it is drawn once, at its size, by the rasteriser. Once per
67
+ * document, however many paints use it; it is an island only if there is a picture.
68
+ */
69
+ private rasterTile;
70
+ private missing;
71
+ private path;
72
+ /** `commands` painted with the op's paint, in the op's space; `pad` is how far a stroke reaches. */
73
+ private paintPath;
74
+ private textOp;
75
+ /** Real text: the glyphs of `run` in the embedded subset of `file`, each at its measured x. */
76
+ private textRun;
77
+ /** A font whose licence forbids embedding: its glyph shapes as paths, crisp but not selectable. */
78
+ private outlineRun;
79
+ /** The run as a picture: what no font file covers, drawn by whoever has a font for it. */
80
+ private rasterRun;
81
+ /**
82
+ * A shadow is a picture under the op, which stays vector. The picture holds the shadow alone:
83
+ * the op is replayed 'big' px to the left with its shadow offset by 'big' to the right, so the
84
+ * shape lands off the picture and only its shadow stays (a canvas draws the shadow of a shape
85
+ * wherever it is). The op's own alpha and clips are part of the picture.
86
+ */
87
+ private shadowIsland;
88
+ /** The part of `rect` (page px) the clips and the page let through. */
89
+ private visible;
90
+ /** Asks for the picture, places it, reports it; if there is none, reports that instead. */
91
+ private island;
92
+ /** An image XObject over a rect of the (y down) page: the unit square, y up, stood on its head. */
93
+ private picture;
94
+ private image;
95
+ /**
96
+ * An SVG source is drawn as the ops `svgToScene` makes of it, with the image op's alpha, clips
97
+ * and a crop around them as a group (`svgImageGroup`). A source it cannot reproduce completely
98
+ * is one raster island, as a whole.
99
+ */
100
+ private svgImage;
101
+ private raster;
102
+ /**
103
+ * The children in the group's clips. A group is composited from a buffer, so its alpha applies
104
+ * to all of it at once: a transparency group when there are several children and an alpha. One
105
+ * child takes the alpha itself, which comes out the same.
106
+ */
107
+ private group;
108
+ }