@formancy/report-render-pdf 0.2.0 → 0.3.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/README.md CHANGED
@@ -18,7 +18,7 @@ import { renderPdf, RenderRefusal } from '@formancy/report-render-pdf'
18
18
 
19
19
  try {
20
20
  const pdf: Uint8Array = await renderPdf(document, { maxPages: 200, signal })
21
- // the whole report, every page of it
21
+ // the whole report, every page of it; with pdfa: '2b', a PDF/A-2b of it
22
22
  } catch (error) {
23
23
  if (!(error instanceof RenderRefusal)) throw error // the engine failing, not the report
24
24
  // error.code says what stopped it; error.subject names the asset, table
@@ -30,16 +30,27 @@ try {
30
30
  `renderPdf` resolves to the PDF's bytes, or rejects with a `RenderRefusal`.
31
31
  A refusal is decided before the PDF is written: a refused report has no
32
32
  PDF at all. Anything else it rejects with is a fault, and a `maxPages` that
33
- is not a whole number of pages, at least 1, is the caller's: a `RangeError`.
33
+ is not a whole number of pages, at least 1, or a `pdfa` other than `'2b'`,
34
+ is the caller's: a `RangeError`.
34
35
 
35
36
  The same document renders to the same bytes: the creation date is the
36
37
  document's own (`info.creationDate`), and nothing else in the file varies.
38
+ That includes where its images stand in the file. PDFKit decodes a PNG
39
+ with an alpha channel, a palette's transparency or interlacing before it
40
+ embeds it, and numbers its soft mask and writes it when the decode calls
41
+ back, in whatever order the decodes finish; the renderer has those images
42
+ written in the order pdfmake opened them, which `src/image-order.test.ts`
43
+ holds in both entries
44
+ ([0035](../../docs/decisions/0035-the-renderer-writes-the-images-pdfkit-decodes-in-the-order-pdfmake-opened-them.md)).
45
+ The bytes are one entry's: the browser build deflates with a zlib of its
46
+ own, and `src/browser.test.ts` holds an e-invoice from either entry to the
47
+ same objects, each stream inflated, not to the same file.
37
48
 
38
49
  ## Node and the browser
39
50
 
40
51
  | Entry | pdfmake | Fonts |
41
52
  |---|---|---|
42
- | `@formancy/report-render-pdf` | the Node build | the four Roboto files in pdfmake's package, and for a QR-bill's slip and an EPC QR code's caption the two Liberation Sans files in this package's `fonts`, read from disk; for an e-invoice, PDFKit reads its ICC profile from its own package (below) |
53
+ | `@formancy/report-render-pdf` | the Node build | the four Roboto files in pdfmake's package, and for a QR-bill's slip and an EPC QR code's caption the two Liberation Sans files in this package's `fonts`, read from disk; for a PDF/A, an e-invoice's or a PDF/A-2b, PDFKit reads its ICC profile from its own package (below) |
43
54
  | `@formancy/report-render-pdf/browser` | the browser build, `pdfmake/build/pdfmake.js` | the same Roboto, from pdfmake's `build/vfs_fonts.js`, and the same Liberation Sans from a chunk of the build's own, imported the first time a document has a bill or a captioned EPC QR code |
44
55
 
45
56
  The two entries share everything but the build of pdfmake and where the
@@ -57,6 +68,16 @@ Whether a browser fetches a chunk again after a failure, or a chunk a
57
68
  deploy removed is still there, is not the renderer's to decide: a page
58
69
  reload is.
59
70
 
71
+ A chart is laid out by Apache ECharts, which only `src/chart-draw.ts`
72
+ imports, and both entries import that module, through the same `loadOnce`,
73
+ the first time a document holds a chart with something to draw. In a
74
+ browser it is a chunk of its own, with ECharts and zrender in it, which a
75
+ page that draws no chart, or only empty ones, never loads, and
76
+ `src/browser.test.ts` counts the loads. ECharts' components are registered
77
+ at the first chart, never at import, and the package is
78
+ `sideEffects: false`. A chart's words are measured, in either entry, by
79
+ the entry's own pdfmake, in the faces it embeds (below).
80
+
60
81
  What the tests show about the browser entry, run in Node: for every fixture
61
82
  in the corpus it hands pdfmake the definitions the Node entry does, its PDFs
62
83
  pass the corpus's checks, it places every run and image where the Node entry
@@ -78,13 +99,30 @@ after a report, the renderer's configuration is in place.
78
99
  Every block of the resolved document:
79
100
 
80
101
  - **Paragraphs**, in their size, weight, slant, colour and alignment, and
81
- a run in bold inside a paragraph that is not.
82
- - **Tables**, their header row repeated on every page they span, each row
83
- in its kind's style or its own, each cell in its own when it has one, each
84
- column aligned as it says unless a cell says otherwise. A group header
102
+ a run in bold inside a paragraph that is not, or set below or above the
103
+ line (below).
104
+ - **Tables**, their header row repeated on every page they span -- a
105
+ table the runtime resolves with no header row, every title it shows
106
+ printing nothing, prints none and no band where one would stand, on any
107
+ page
108
+ ([0078](../../docs/decisions/0078-a-table-whose-every-column-title-prints-nothing-has-no-header-row.md))
109
+ -- each row in its kind's style or its own, each cell in its own when it
110
+ has one, each column aligned as it says unless a cell says otherwise. A group header
85
111
  `across` the table is one cell over every column. A group header is never
86
112
  the last row on a page, and a row that fits on a page is never split. A
87
- group's footers and the totals under the last row stand on the page of
113
+ group header row that keeps more of its group's first rows
114
+ (`keepWithRows`) stands on the page of as many of them as fit there under
115
+ the repeated column header, and of its first row where no more do: a
116
+ group no longer than its count stands whole, with its footers, where it
117
+ fits, held by the last of them that prints though a footer row after it
118
+ prints nothing; a block short of its group ends on the last of those
119
+ rows that prints, since a rule finds a row on its page by its text; a
120
+ header that prints nothing keeps no more than its first row; and a
121
+ count on a row that is
122
+ no group header, outside 2 to `MAX_KEEP_WITH_ROWS`, or past the detail
123
+ rows under the header is refused as `unsupported`, naming the table
124
+ ([0059](../../docs/decisions/0059-a-group-header-is-kept-on-its-page-with-as-many-of-its-groups-first-rows-as-the-report-states-or-as-fit.md)).
125
+ A group's footers and the totals under the last row stand on the page of
88
126
  the row before them, and with its group header when that row is its
89
127
  group's first: a subtotal or a total never stands alone at the top of a
90
128
  page. Every column is as wide as it says, a fill column its share of
@@ -94,7 +132,8 @@ Every block of the resolved document:
94
132
  `cover` fills the box, centred, and is clipped to it. A JPEG is fitted by
95
133
  the size it is shown at, after its Exif orientation. An SVG is drawn as
96
134
  vectors (below), fitted by its viewBox.
97
- - **QR codes** (ISO/IEC 18004), encoded by [uqr](https://github.com/unjs/uqr)
135
+ - **QR codes** (ISO/IEC 18004), their symbol the runtime's, which
136
+ encodes it with [uqr](https://github.com/unjs/uqr)
98
137
  in the smallest version that holds their text at the level asked for,
99
138
  never a higher level, and drawn in vectors as a square exactly their size:
100
139
  white, with the quiet zone of four modules inside it, and the dark
@@ -125,23 +164,40 @@ Every block of the resolved document:
125
164
  body, tables and page breaks included; without one, its blocks and nothing
126
165
  more.
127
166
  - **Keep-together blocks**, moved whole to the next page when they do not
128
- fit, and paragraphs **kept with the next** block.
167
+ fit, and paragraphs **kept with the next** block. A table is kept with by
168
+ its first row under the column header, and by its header only where no
169
+ row prints, or inside a keep-together block, which moves whole: pdfmake
170
+ repeats the header on every page the table continues on and writes that
171
+ page into it, so a heading over a table that runs past its page stays on
172
+ its page with the table's first rows. Where a table whose rows print
173
+ nothing runs past its page, its heading still moves with it
174
+ ([0011](../../docs/decisions/0011-report-render-pdf-draws-the-document-and-refuses-what-it-cannot.md)).
129
175
  - **The page header and footer**, on every page, with the page number and
130
176
  the page count. The body is laid out between them, after both are
131
177
  measured.
178
+ - **Page 1's own header**, where the document has one ([0060](../../docs/decisions/0060-a-reports-first-page-may-print-a-header-of-its-own-or-none-in-place-of-the-page-header.md)), on
179
+ page 1 in the page header's place; the page header then prints from page
180
+ 2 on. It is drawn in page 1's background, at the margin the page header
181
+ stands at, measured in a pass of its own, and page 1's body starts below
182
+ it and the gap, or at the top margin where it is empty, which is page 1
183
+ with no header. It holds no page field: page 1's number and count print in
184
+ the page footer, which page 1 prints as every page does.
132
185
  - **A QR-bill's payment part**, the receipt and the payment part with its
133
186
  Swiss QR Code, across the foot of the last page in place of its page
134
187
  footer (below).
188
+ - **Charts**, a bar, a line or a pie chart in its box, laid out by Apache
189
+ ECharts, its marks drawn as vectors and its words as text in the
190
+ report's faces (below).
135
191
 
136
192
  ## What it refuses
137
193
 
138
194
  | Code | When |
139
195
  |---|---|
140
196
  | `too-many-pages` | The report needs more pages than `maxPages`, a QR-bill's page included. pdfmake's own limit would return the first pages as though they were all of it. A body whose least height already needs more, the room a bill's slip keeps included, is refused before pdfmake measures it. |
141
- | `content-too-large` | Something no page can hold: a keep-together block, an image, a QR code, a rectangle, a rule, a frame's border and padding, or a line of text taller than the body where it stands; anything wider than where it stands; a word in a table cell wider than its column, or a word in a paragraph longer than 16 lines of it; images holding more than 268,443,648 bytes of image data together; SVG images past what a render may draw or a page may cost a reader (below); page regions that leave no body; a QR code's text that no version holds at its level, or a square too small for that version's modules to be 0.4 mm, the message naming the size it needs; an EPC QR code past the EPC's 331 bytes or the PSA's modules (below); a QR-bill the slip cannot hold (below). |
142
- | `invalid-asset` | An image's bytes are not the PNG, JPEG or SVG they are declared as, are cut off, or are past the limits: 20 MB, 4096 pixels a side, and for an SVG a mebibyte; a JPEG that PDFKit would read otherwise than its frame header says -- a JPG or DAC segment before the frame header, which PDFKit takes for it, as an arithmetic-coded JPEG may write its DAC segment, a second frame header, or a frame of other than 1, 3 or 4 components, which PDFKit gives no colour space (0031); an SVG is not exactly the drawing report-spec's `cleanSvg` writes (below). A PNG's or a JPEG's structure is read by report-spec's `imageHeader`, which a builder refuses an image a person adds by too, in the same words (0033); whether a PNG's image data inflates to the scanlines its header promises is read here alone, since it needs the platform's decompressor. |
197
+ | `content-too-large` | Something no page can hold: a keep-together block, an image, a QR code, a rectangle, a rule, a frame's border and padding, or a line of text taller than the body where it stands; a line of a table's row that a page does not hold under the table's repeated header with a point to spare, which pdfmake would drop, naming the table, the row and its kind and both heights (0011); anything wider than where it stands; a word in a table cell wider than its column, or a word in a paragraph longer than 16 lines of it; images holding more than 268,443,648 bytes of image data together; SVG images past what a render may draw or a page may cost a reader (below); page regions that leave no body, and page 1's own header that leaves page 1 none or is taller than the printable area, naming `firstPageHeader` (0060); where page 1 has a header of its own, a block of fixed height or a line taller than the shorter of page 1's body and the later pages', and a keep-together block or a table's line under its repeated header that the later pages' body cannot hold, though page 1's taller body could; a QR code's text that no version holds at its level, or a square too small for that version's modules to be 0.4 mm, the message naming the size it needs; an EPC QR code past the EPC's 331 bytes or the PSA's modules (below); a QR-bill the slip cannot hold (below); a chart whose words would meet, leave its box or stand in its plot, whose category labels do not fit across their slots, whose plot is too short for two tick labels, whose bars would be narrower than 3.5 pt, or whose pie would be narrower than 24.75 pt, and a bar or a line chart of more than `MAX_CHART_CATEGORIES` categories; a render whose charts together weigh more than `MAX_CHART_DRAWING`, at the chart that crossed it (below); a word that holds a run set below or above the line and is wider than its line (below). |
198
+ | `invalid-asset` | An image's bytes are not the PNG, JPEG or SVG they are declared as, are cut off, or are past the limits: 20 MB, 4096 pixels a side, and for an SVG a mebibyte; a JPEG that PDFKit would read otherwise than its frame header says -- a JPG or DAC segment before the frame header, which PDFKit takes for it, as an arithmetic-coded JPEG may write its DAC segment, a second frame header, or a frame of other than 1, 3 or 4 components, which PDFKit gives no colour space (0031); an SVG is not exactly the drawing report-spec's `cleanSvg` writes (below). A PNG's or a JPEG's structure is read by report-spec's `imageHeader`, which a builder refuses an image a person adds by too, in the same words (0033); whether a PNG's image data inflates to the scanlines its header promises is read here alone, since it needs the platform's decompressor. A host's font `readFont` refuses, one PDFKit would draw as another face, or one asset id handed in two byte strings, naming the asset (0043). |
143
199
  | `cancelled` | The signal was aborted. |
144
- | `unsupported` | What the renderer cannot draw as written: a character the font has no glyph for, a font other than `sans`, text that is not a string, a colour that is not `#rrggbb` in lower case, a QR code's level other than L, M, Q and H, an EPC QR code's caption it does not know, half of a surrogate pair without the other in a code's text, which has no UTF-8, a page field outside the page header and footer, a page break inside a page region, a keep-together block or a column, a table inside a column, a table row of the wrong number of cells, a block kind, page size or page field it does not know, blocks nested past 16 deep; a QR-bill it cannot draw as SIX prints one (below); an e-invoice it does not know, or one its PDF/A-3b cannot hold, a CMYK JPEG or an SVG whose numbers or nesting it cannot hold among them (below). |
200
+ | `unsupported` | What the renderer cannot draw as written: text set outside the format's 4 to 96 pt, which the page bound counts each line by, a character the font has no glyph for, a page field's digit included, a character of any script but Latin, Greek and Cyrillic, or a bidirectional control, a `serif` or `mono` token the report does not map or a face a mapped family lacks, text that is not a string, a colour that is not `#rrggbb` in lower case, a QR code's level other than L, M, Q and H, an EPC QR code's caption it does not know, half of a surrogate pair without the other in a code's text, which has no UTF-8, a page field outside the page header and footer, page 1's own header among them, which is drawn before the pages are counted, a page break inside a page region, a keep-together block or a column, a table inside a column, a table row of the wrong number of cells, a block kind, page size or page field it does not know, blocks nested past 16 deep; a run set below or above the line in a word with no text on the line, or set in a way it does not know (below); a QR-bill it cannot draw as SIX prints one (below); an e-invoice it does not know, or what a PDF/A cannot hold, an e-invoice's PDF/A-3b or a PDF/A-2b, a CMYK JPEG or an SVG whose numbers or nesting it cannot hold among them; as a PDF/A-2b, a Factur-X, an XRechnung's copy and a labelled preview (below); a count of kept rows (`keepWithRows`) on a table row that is no group header, outside 2 to `MAX_KEEP_WITH_ROWS`, or past the detail rows under its header, naming the table (0059); and a chart it cannot draw as written: in a page region, page 1's own header among them, past `MAX_TICK_INTERVALS` or `MAX_CHART_SERIES`, with a control character in any of its words, or whose drawing ECharts writes otherwise than it was read to write, or that ECharts lays out through another copy of zrender than the renderer's (below). |
145
201
 
146
202
  ## SVG images
147
203
 
@@ -173,34 +229,115 @@ the form that was approved.
173
229
  whatever its callbacks say; the check and the list do. The list may
174
230
  refuse more than report-spec's tables, never less: a test holds it to
175
231
  their `SVG_ELEMENTS`.
176
- - **Drawn again on every page in a page region.** pdfmake lays the page
177
- header and footer out for each page, and the converter draws the drawing
178
- each time: a PNG is embedded once, an SVG grows the PDF and the render
179
- by its drawing on every page.
232
+ - **Drawn again on every page in the page header or footer.** pdfmake
233
+ lays the page header and footer out for each page, and the converter
234
+ draws the drawing each time: a PNG is embedded once, an SVG grows the PDF
235
+ and the render by its drawing on every page. One in page 1's own header
236
+ is drawn on page 1 alone (0060).
180
237
  - **Bounded per render.** What drawing the SVGs costs the renderer is held
181
238
  to `MAX_SVG_DRAWING` units of what the converter draws -- lines, curves,
182
239
  elements, gradient stops and page-sized transparency groups, each
183
240
  weighted by what it was measured to cost beside a line, and every 32
184
241
  bytes of the drawing, which pdfmake and the converter read again each
185
242
  time it is drawn, whatever it draws -- counting an
186
- image in a page region on every one of `maxPages`, the pages the report
187
- may have, which is known before the render: a detailed header logo can
243
+ image in the page header or footer on every one of `maxPages`, the pages
244
+ the report may have, which is known before the render, and one in page
245
+ 1's own header once: a detailed header logo can
188
246
  be refused at a high page limit though the report prints two pages. At
189
247
  the budget the renderer spends about what `MAX_IMAGE_DATA`'s largest
190
248
  images cost it to decode (`assets.ts` says how both were measured, on
191
249
  what and when). What they cost a reader is held
192
250
  to what one drawing may cost, which was measured as a page's:
193
251
  `MAX_SVG_SEGMENTS` and `MAX_SVG_GROUPS` over every SVG image of the body,
194
- as though all fell on one page, and those of the page regions. A
195
- translucent logo printed twice in the body can be refused for it.
196
- - **Held to PDF/A in an e-invoice** (below): an SVG whose numbers could
197
- pass the integers a PDF/A-3 holds, or whose drawing nests deeper than
198
- its graphics state may, is refused there and drawn in any other report.
252
+ as though all fell on one page, and those of the page regions, page 1's
253
+ own header's among them. A translucent logo printed twice in the body can
254
+ be refused for it.
255
+ - **Held to PDF/A's limits in a PDF/A** (below), an e-invoice's PDF/A-3b or a
256
+ PDF/A-2b: an SVG whose numbers could pass the integers a PDF/A holds, or
257
+ whose drawing nests deeper than its graphics state may, is refused there
258
+ and drawn in a report drawn as no PDF/A.
259
+
260
+ ## Charts
261
+
262
+ A chart block, which the runtime resolves with every word it prints and
263
+ each value's exact digits, is laid out by Apache ECharts 6.1.0 and drawn
264
+ by pdfmake [0058](../../docs/decisions/0058-the-renderer-lays-a-chart-out-with-apache-echarts-and-prints-its-marks-and-its-words-where-echarts-placed-them.md). ECharts places every mark and every word; pdfmake's SVG
265
+ converter draws the marks, and each word prints as pdfmake's text where
266
+ ECharts placed it, so a chart's words are text in the PDF, in the report's
267
+ faces.
268
+
269
+ - **Its words** take the chart's style's font, size -- 8 pt where it names
270
+ none -- weight, slant and colour, the title bold; its alignment is not
271
+ read. Each is measured, for ECharts, in the width pdfmake prints it in,
272
+ in the face the render embeds, through zrender's platform replaced for
273
+ one layout and put back after it, and held to that width once pdfmake
274
+ has measured it.
275
+ - **Its numbers** are the runtime's. ECharts is handed the ticks as the
276
+ axis, each value as its place among them, worked out exactly from its
277
+ decimals, a pie's slices as their exact shares, and every word by its
278
+ index; it rounds, formats and ticks nothing. A slice of no share draws
279
+ nothing and keeps its legend entry, and a pie's arcs are drawn on its
280
+ own circle, within 0.0965 pt.
281
+ - **Its layout** is ECharts' own, three times: where the title and the
282
+ legend stand, then the plot between them, then the plot snapped so that
283
+ every gridline stands on its tick; a pie twice. The renderer reads back
284
+ where every word went, and refuses the chart as `content-too-large`
285
+ where two words would meet, a word would leave the box or stand in the
286
+ plot but a value's label, a category label would not fit across its
287
+ slot, a plot would be too short for two tick labels a line and a
288
+ quarter apart, a bar would be narrower than `MIN_BAR_WIDTH`, 3.5 pt, or
289
+ a pie than `MIN_PIE_DIAMETER`, 24.75 pt, the least at which the
290
+ Studio's Preview draws bars apart, and a slice of one percent as its own
291
+ colour, at 100 % on a screen of device pixel ratio 2, measured. A label is never turned, wrapped or cut, and nothing is
292
+ dropped.
293
+ - **On the page** it is one unbreakable stack, moved whole to the next
294
+ page where it does not fit. A chart with nothing to draw prints its
295
+ title and its empty text, without ECharts.
296
+
297
+ A render's charts are weighed together before any is laid out, and a
298
+ render past `MAX_CHART_DRAWING`, 5,000 units, is refused as
299
+ `content-too-large` at the chart that crossed it. A chart weighs its
300
+ kind's weight, a unit for each series at each category or each slice of a
301
+ pie, and each word it places by what the word is; one with nothing to
302
+ draw weighs nothing. The weights were measured on the render and on
303
+ PDF.js at a load of 12 to 20, a line's again at 3.0 to 3.2, and the
304
+ bound confirmed at quiet loads of 3.3 to 5.6 and 3.0 to 3.9, on one
305
+ machine, as the constant's comment says: two line charts of 8 series
306
+ and 200 categories fit in a render, and three do not.
307
+ The bound holds one layout pass, and a heading kept with a chart makes
308
+ pdfmake lay the document out again for each page it moves the heading
309
+ to, which it does not count.
310
+
311
+ What ECharts writes is held, before anything of it is used, to what
312
+ 6.1.0 was seen to write, and refused otherwise as `unsupported`: the
313
+ SVG's elements, attributes, entities, numbers and colours, and every word
314
+ one the block holds. The converter is handed it with no word, no style
315
+ sheet and no clip: ECharts clips every line series to its plot whatever
316
+ the series says, which the converter would draw as a soft mask a reader
317
+ composites for each series, and every value stands inside the ticks and
318
+ a line is stroked with bevelled joins and butt ends, which the reader
319
+ refuses otherwise inside a clip, so the clip cuts nothing and is taken
320
+ out. ECharts and zrender are
321
+ dependencies at exactly 6.1.0, which the repository's licence guard
322
+ admits for this package alone. zrender's platform is one for the process
323
+ or the page, and a host's own ECharts measures through it too; the
324
+ renderer replaces it for one synchronous layout and puts it back.
325
+ ECharts' registries are one for the process or the page too: a
326
+ preprocessor, a processor, a visual, a layout or an update a host
327
+ registers on the ECharts it shares with the renderer runs on the
328
+ renderer's charts, and changes their marks with nothing refused. zrender keeps the widths it measured,
329
+ up to 500 words for each of 100 fonts, after the render, and nothing it
330
+ exports clears them, so a chart's words stay in the process.
199
331
 
200
332
  ## QR codes
201
333
 
202
334
  A code is refused, naming it by its id, rather than drawn as one that may
203
- not scan:
335
+ not scan. What decides its symbol, and every refusal below but the last
336
+ part of the third, is `@formancy/report-runtime`'s `qrSymbol`, the one
337
+ rule the Word writer asks too
338
+ ([0074](../../docs/decisions/0074-a-qr-code-and-an-epc-qr-code-are-written-into-a-word-file-and-what-refuses-a-code-stands-below-both-engines.md)):
339
+ the renderer asks it once, when it checks the document, and draws the
340
+ symbol it is handed.
204
341
 
205
342
  | Code | When |
206
343
  |---|---|
@@ -219,7 +356,8 @@ whose code has a value that is null, or prints nothing.
219
356
  An `epcQrCode` block's payload, which the runtime has written and held to
220
357
  the EPC's rules, is encoded by uqr as UTF-8 at level M, its level never
221
358
  raised (`boostEcc: false`), in a symbol of version 13 at most (EPC069-12
222
- 2.1), once, when the document is checked. The renderer formats and checks nothing of what the payload says;
359
+ 2.1), once, when the document is checked, by the runtime's `epcSymbol`,
360
+ which refuses what follows as well (0074). The renderer formats and checks nothing of what the payload says;
223
361
  it decides how the code is drawn. Why it is drawn so, and what that costs,
224
362
  is [0025](../../docs/decisions/0025-a-report-prints-an-epc-qr-code-held-to-the-epc-rules-beside-the-qr-bill.md).
225
363
 
@@ -291,8 +429,9 @@ what that costs, is [0022](../../docs/decisions/0022-a-report-carries-one-swiss-
291
429
 
292
430
  - **Where.** The slip spans the paper's width and ends at its foot (IG 3.1),
293
431
  whatever the page margins. It is the last page's footer, drawn there in
294
- place of the page footer; the page header is drawn as on every page. The
295
- body keeps the slip's room at its end: when the last page has less room
432
+ place of the page footer; the page header is drawn as on every page, or
433
+ page 1's own header where the slip is on page 1 of a report that has one.
434
+ The body keeps the slip's room at its end: when the last page has less room
296
435
  left, the slip takes a page of its own, which the footers before it count.
297
436
  - **The code.** The payload as UTF-8 at level M, in the smallest version
298
437
  that holds it and none past 25 (IG 6), 46 mm square without a quiet zone
@@ -329,7 +468,7 @@ value, which may be a name, an address or an account:
329
468
  | Code | When |
330
469
  |---|---|
331
470
  | `unsupported` | A payment part of a kind the renderer does not know; a page that is not A4 in portrait; text that is not text, half of a surrogate pair in the payload, or a character Liberation Sans has no glyph for; an amount not written as the slip prints one, or outside report-spec's range, 0.01 to 999 999 999.99; a currency other than CHF and EUR; an address of more than three lines, additional information of more than two, or a value longer than 140 characters, the longest SIX allows. |
332
- | `content-too-large` | A payload of more than 997 characters, refused unencoded, or whose UTF-8 is more than version 25 holds at level M, 997 bytes (IG 6.2); a page whose top margin, with the page header and the instruction to separate, reaches into the slip, by report-spec's `qrBillPageBreak`, and a top margin alone in the editor's words; information taller than its section, 56 mm on the receipt and 85 mm in the payment part (SG 6). |
471
+ | `content-too-large` | A payload of more than 997 characters, refused unencoded, or whose UTF-8 is more than version 25 holds at level M, 997 bytes (IG 6.2); a page whose top margin, with the page header and the instruction to separate, reaches into the slip, by report-spec's `qrBillPageBreak`, the taller of the page header and page 1's own header where a report has one, since which page is the last is known only once the pages are laid out (0060), and a top margin alone in the editor's words; information taller than its section, 56 mm on the receipt and 85 mm in the payment part (SG 6). |
333
472
 
334
473
  What the slip does not do:
335
474
 
@@ -348,6 +487,80 @@ What the slip does not do:
348
487
  decides: the lines an address and the additional information print,
349
488
  each section's height, an amount's printed form, and the code's 997.
350
489
 
490
+ ## PDF/A-2b
491
+
492
+ `renderPdf(document, { maxPages, pdfa: '2b' })` draws a final render of a
493
+ report that is no e-invoice as a PDF/A-2b, in either entry
494
+ ([0057](../../docs/decisions/0057-a-report-that-is-no-e-invoice-is-drawn-as-a-pdf-a-2b-where-the-host-asks-for-one.md)):
495
+ part 2, which Switzerland's electronic patient record stores a PDF as, at
496
+ the level pdfmake and PDFKit reach. `'2b'` is the one value, and any other
497
+ is a `RangeError` before anything is read. Without `pdfa` nothing changes.
498
+
499
+ - **What it is.** The final pass's definition gets `version` 1.7 and
500
+ `subset` `PDF/A-2b`, so PDFKit writes the pdfaid identification, part 2
501
+ and level B, an sRGB output intent with its ICC profile, and the XMP, as
502
+ it does for an e-invoice's PDF/A-3b. No hook runs, and nothing is
503
+ embedded. The measuring passes have neither version nor subset, and lay
504
+ the pages out as the final pass does, so a PDF/A-2b's pages are the
505
+ plain render's. Level b alone: no structure tree, so no tagged,
506
+ accessible PDF.
507
+ - **Decided once.** `checkPdfA` (`pdfa-check.ts`) decides what a document
508
+ is drawn as -- a Factur-X's PDF/A-3b, the PDF/A-2b a host asked for, or a
509
+ plain PDF -- and the definition, the final pass's hook and the image
510
+ checks read its answer.
511
+
512
+ It refuses, as `unsupported` and before pdfmake sees the document, each
513
+ message saying what to do:
514
+
515
+ - a Factur-X e-invoice and an XRechnung's copy, naming `eInvoice`: a
516
+ Factur-X is drawn as the PDF/A-3b that embeds its XML, which a PDF/A-2b
517
+ may not embed, and an XRechnung's PDF is the copy of the XML a host
518
+ sends, never an archival PDF. Each is rendered without `pdfa`. An
519
+ e-invoice the renderer does not know is refused for what it is, with
520
+ `pdfa` or without;
521
+ - a preview the runtime labels so, naming `pageHeader`: a page header
522
+ whose first block is a paragraph of one run, the runtime's
523
+ `PREVIEW_LABEL` or `E_INVOICE_PREVIEW_LABEL`, in any style. The renderer
524
+ has no mode, so it reads the runtime's label, as it reads an XRechnung's
525
+ copy's, and a PDF/A-2b of a preview would be kept as the report. A
526
+ preview that lacks nothing and is of no e-invoice carries no label, is
527
+ the same document as its final render, as the tests show for the
528
+ quotation, and is drawn as one. A label
529
+ among other runs or below another block is not read;
530
+ - what an e-invoice's PDF/A-3b refuses (below), each message naming the
531
+ PDF/A-2b: a title holding `&`, `<`, `>` or a character XML 1.0 cannot
532
+ write, naming `info.title`, which report-spec refuses in an e-invoice
533
+ report alone, so a report that is none may hold one; a CMYK JPEG, naming
534
+ the image; and an SVG whose numbers could pass the integers a PDF/A
535
+ holds, or whose drawing nests deeper than 28 graphics states, naming it.
536
+
537
+ None of these is said before the render: whether a render is a PDF/A-2b is
538
+ the host's choice at that render, which the builders and the validator do
539
+ not know. What holds by construction: pdfmake embeds a subset of every face
540
+ it draws, and a character a face lacks is refused; the renderer hands
541
+ pdfmake no password, and neither writes JavaScript, an action, a form or
542
+ an annotation; the transparency an RGBA PNG's soft mask or an SVG's group
543
+ makes stands beside the one output intent, which veraPDF's PDF/A-2b
544
+ profile accepted in the gate's variants. What it does not
545
+ hold: the limits of ISO 32000-1 that PDF/A-2 makes rules of, a string's or
546
+ a name's length among them.
547
+
548
+ **What the tests show, and what they do not.** `src/pdfa-check.test.ts`
549
+ holds the decision and every refusal above, each document drawn without
550
+ `pdfa`, and `src/assets.test.ts` and `src/svg-pdfa.test.ts` the images,
551
+ every number of a drawn SVG read back with report-corpus's
552
+ `readPdfNumbers`. `src/pdfa-2b.test.ts` draws every starter that is no
553
+ e-invoice both ways and reads the PDF/A-2b back with readers that are not
554
+ PDFKit: PDF 1.7, its XMP part 2 and B, one sRGB output intent byte for
555
+ byte PDFKit's profile, nothing embedded, no action, form or annotation,
556
+ and the plain render's pages, faces and fonts; and the same bytes twice.
557
+ `src/browser.test.ts` holds the browser entry's to the Node entry's.
558
+ Whether a validator takes the PDF is the e-invoice gate's: veraPDF judges
559
+ every starter so drawn, four variant pages on the quotation's, a page of
560
+ charts among them, and the corpus's two fonts fixtures, with its PDF/A-2b
561
+ profile, and nothing here.
562
+ A customer's template is judged by nothing.
563
+
351
564
  ## E-invoices
352
565
 
353
566
  A document that carries an e-invoice, `document.eInvoice`, as
@@ -356,11 +569,12 @@ Germany: a PDF/A-3b that embeds the XML the runtime wrote, the hybrid
356
569
  invoice whose XML is the invoice
357
570
  ([0031](../../docs/decisions/0031-an-e-invoice-is-drawn-as-a-pdf-a-3b-that-embeds-its-xml.md)), in either entry.
358
571
 
359
- - **PDF/A-3b, for an e-invoice alone.** Its definition gets `version`
572
+ - **PDF/A-3b, for a Factur-X alone.** Its definition gets `version`
360
573
  1.7 and `subset` `PDF/A-3b`, so PDFKit writes the pdfaid identification,
361
574
  an sRGB output intent with its ICC profile, and the XMP. Level b is the
362
575
  one in reach: level a needs a structure tree pdfmake does not build, and
363
- PDFKit has no level u. Every other report is drawn as it was.
576
+ PDFKit has no level u. A report that is no e-invoice is drawn as it was,
577
+ or as a PDF/A-2b where its host asks (above).
364
578
  - **The file, changed in nothing.** On the final pass alone, through
365
579
  PDFKit's own document before it ends, `pdfa.ts` embeds the XML's UTF-8
366
580
  bytes as `factur-x.xml`, `text/xml`, related as `Alternative` -- the
@@ -376,19 +590,41 @@ invoice whose XML is the invoice
376
590
  - **A preview is a plain PDF.** The runtime writes the XML only in a final
377
591
  render; a preview carries none, embeds nothing, and is labelled on every
378
592
  page.
593
+ - **An XRechnung's copy is a plain PDF too**
594
+ ([0038](../../docs/decisions/0038-a-reports-e-invoice-may-be-an-xrechnung-3-0-whose-xml-a-host-takes-and-whose-pdf-is-its-labelled-copy.md)).
595
+ An XRechnung's XML is the invoice, which a host takes from the resolved
596
+ document and sends; its file, of the kind `xrechnung`, names its syntax,
597
+ guideline and version and nothing to embed it as. Its document is drawn
598
+ as every report is -- no PDF/A, no file, no XMP, a title of any text and
599
+ a CMYK logo drawn -- and its page header opens with the runtime's
600
+ `XRECHNUNG_COPY_PARAGRAPH`, `XRECHNUNG_COPY_LABEL` in small red bold,
601
+ and so does page 1's own header where it has one, so every page says it
602
+ is the copy. Never a ZUGFeRD hybrid of the
603
+ XRECHNUNG profile.
379
604
 
380
605
  It refuses, as `unsupported` and before pdfmake sees the document:
381
606
 
382
- - an e-invoice whose XML is not text, or whose file name, conformance level
383
- or relationship is not report-spec's;
607
+ - an e-invoice of a kind it does not know, a Factur-X file without its
608
+ kind among them; one whose XML is not text; a Factur-X file whose file
609
+ name, conformance level or relationship is not report-spec's; and an
610
+ XRechnung's whose syntax, version or guideline is not report-spec's;
611
+ - an XRechnung whose page header does not open with the copy's label as
612
+ the runtime writes it, `XRECHNUNG_COPY_PARAGRAPH`, its style and all,
613
+ naming `pageHeader`, or whose first page header, where it has one, does
614
+ not, its none among them, naming `firstPageHeader` (0060): a final picture of an invoice that says nothing of
615
+ what it is, or says it in white or at one point, where PDF.js would
616
+ still find the text. That the label names no font, and prints in the
617
+ renderer's, and that the paper is white, the renderer drawing none, are
618
+ what the check does not read;
384
619
  - XML holding a lone surrogate, which an encoder would write as another
385
620
  character;
386
621
  - a title holding `&`, `<`, `>` or a character XML 1.0 cannot write,
387
622
  naming `info.title`: PDFKit writes the title into the XMP unescaped.
388
623
  report-spec refuses such a title in an e-invoice report, so only a
389
624
  document made otherwise reaches this;
390
- - a CMYK JPEG, naming the image: PDFKit draws it in DeviceCMYK, which no
391
- PDF/A with an sRGB output intent may hold. A preview draws it, so a
625
+ - a CMYK JPEG in a Factur-X invoice, naming the image: PDFKit draws it in
626
+ DeviceCMYK, which no PDF/A with an sRGB output intent may hold. An
627
+ XRechnung's copy, no PDF/A, draws it. A preview draws it, so a
392
628
  template finds out at its final render. The component count is read
393
629
  from the frame header PDFKit reads, since a DAC segment shaped as a frame
394
630
  of four components once had an RGB JPEG drawn in DeviceCMYK past this
@@ -419,11 +655,11 @@ It refuses, as `unsupported` and before pdfmake sees the document:
419
655
  is not held for matrices built to cancel one another term by term, whose
420
656
  products floating point gets wrong.
421
657
 
422
- Every other kind of image PDFKit embeds is drawn in an e-invoice:
423
- report-corpus's `IMAGE_KINDS` -- grey and colour JPEGs, and PNGs of every
424
- colour type, with alpha, a palette, its transparency or a colour key, at
425
- 1 and 16 bits, interlaced -- which the e-invoice gate has veraPDF and
426
- Mustang judge in one. A colour key is drawn as PDFKit's PNG reader,
658
+ Every other kind of image PDFKit embeds is drawn in an e-invoice, and in
659
+ a PDF/A-2b: report-corpus's `IMAGE_KINDS` -- grey and colour JPEGs, and
660
+ PNGs of every colour type, with alpha, a palette, its transparency or a
661
+ colour key, at 1 and 16 bits, interlaced -- which the e-invoice gate has
662
+ veraPDF and Mustang judge in one e-invoice, and veraPDF in one PDF/A-2b. A colour key is drawn as PDFKit's PNG reader,
427
663
  png-js 1.1.0, reads it, in every report since 0.1.0: a grey key by its
428
664
  high byte, and an RGB key as twelve numbers where ISO 32000-1 asks two a
429
665
  component, which a viewer may ignore; report-corpus's test pins both.
@@ -436,11 +672,12 @@ and creation date.
436
672
 
437
673
  **One file besides the fonts.** PDFKit reads the output intent's profile
438
674
  from its own `data/sRGB_IEC61966_2_1.icc` with `fs`, past pdfmake's access
439
- policy, which governs only what pdfmake opens: a render of an e-invoice
440
- reads that file and the fonts, and nothing else through
441
- `fs.readFileSync`, which a test holds. A
675
+ policy, which governs only what pdfmake opens: a render of a PDF/A, an
676
+ e-invoice's or a PDF/A-2b, reads that file and the fonts, and nothing else
677
+ through `fs.readFileSync`, which a test holds, and one whose profile PDFKit
678
+ cannot read rejects with the file system's error and no PDF. A
442
679
  host that bundles the Node entry puts the profile where the bundled
443
- PDFKit's `__dirname` points, or every e-invoice render fails. The browser
680
+ PDFKit's `__dirname` points, or every PDF/A render fails. The browser
444
681
  entry's profile is the base64 copy in pdfmake's browser build, held to the
445
682
  same bytes. The profile is the ICC's sRGB2014, which the dependency-licence
446
683
  guard admits by its digest, with the ICC's licence sentence a review read
@@ -450,7 +687,10 @@ guard admits by its digest, with the ICC's licence sentence a review read
450
687
  reads each of the corpus's e-invoice samples back from its PDF with readers
451
688
  that are not PDFKit -- the file with PDF.js and pdf-lib, the XMP with saxes
452
689
  -- and `src/e-invoice-samples.test.ts` holds what the page prints to the XML
453
- read out of the same PDF. `src/svg-pdfa.test.ts` reads every number of an
690
+ read out of the same PDF, and the XRechnung sample's copy to the XML its
691
+ document carries; `src/xrechnung.test.ts` reads the copy back as a plain
692
+ PDF that embeds nothing, the label first on every page of one that runs to
693
+ two. `src/svg-pdfa.test.ts` reads every number of an
454
694
  SVG's e-invoice back with report-corpus's `readPdfNumbers`, content streams
455
695
  included, which veraPDF does not read, and holds the bound to at least
456
696
  every number each drawing's PDF writes. Whether a validator takes the PDF
@@ -459,9 +699,57 @@ there, an SVG at every bound among the variants, and nothing here. The fx namesp
459
699
  transcription of the specification, which no validator reads; the tests
460
700
  compare them with the transcription's values, and say so.
461
701
 
702
+ ## Runs below or above the line
703
+
704
+ A paragraph's run set below or above the line
705
+ ([0061](../../docs/decisions/0061-a-paragraphs-run-may-be-set-below-or-above-the-line-in-any-character-its-face-draws-and-prints-only-beside-a-run-on-the-line.md))
706
+ is handed to pdfmake with pdfmake's own `sub` or `sup`, and nothing
707
+ else: pdfmake sets it at 0.58 of its paragraph's size, in the paragraph's
708
+ face, and moves its baseline 0.435 of that size up or 0.203 down, the
709
+ runtime's `SHIFTED_SIZE` and `SHIFTED_RISE`. The page bound counts its
710
+ line at that size.
711
+
712
+ pdfmake makes no room for such a run in its line. The renderer makes room
713
+ below a line that holds a run set below the line, for a raised run on the
714
+ next: it asks pdfmake for that run's own line as `LOWERED_LINE` of the
715
+ paragraph's size, 1.218 -- the lowered run's drop, a raised run's rise
716
+ and the small run's own size -- through its `lineHeight`, which pdfmake
717
+ lays out below the baseline, so the two are set solid and their boxes
718
+ meet nowhere. A face whose line is that tall needs none, and a line that
719
+ holds no lowered run is laid out as it was, so a wrapped paragraph's lines
720
+ stand apart unevenly: in Roboto 0.046 of the size farther under such a
721
+ line, in Liberation Serif 0.111. The page bound counts the room.
722
+
723
+ pdfmake lays a line out as tall as its runs' own lines and moves such a
724
+ run only when it draws it, so a line of nothing but such runs would be
725
+ laid out small and drawn into the line before. Once pdfmake has measured a
726
+ paragraph that holds one, and before it lays out a line, the renderer
727
+ reads pdfmake's own words -- the runs it chains with `noNewLine`, which
728
+ no line break separates -- and refuses, naming the paragraph:
729
+
730
+ - **as `unsupported`**, a word that holds such a run and no run on the
731
+ line that prints a character other than a space: a footnote's mark
732
+ after a space, or at the head of its text before one, a word of nothing
733
+ but such runs, and one whose only neighbour prints nothing, as an empty
734
+ field does. A mark is written against its word, or with a no-break
735
+ space, U+00A0. A value read from the data decides it too, in a preview
736
+ as in a final render.
737
+ - **as `content-too-large`**, a word that holds one and is wider than its
738
+ line, measured as pdfmake measures a word that starts one, its leading
739
+ and trailing spaces left out: pdfmake would break it anywhere.
740
+
741
+ A page region's paragraph is read in the pass that measures the regions,
742
+ and a baseline the renderer does not know, or one on a page field, is
743
+ refused as `unsupported` before anything is laid out. The text layer reads
744
+ such a run on the line: PDF.js extracts "H2O", and a search or a copy finds
745
+ the digit as typed. `_inlines`, `noNewLine`, `sup`, `sub`, `width`,
746
+ `leadingCut` and `trailingCut` are pdfmake's own, not its API;
747
+ `pdfmake.test.ts` holds 0.3.11 to them.
748
+
462
749
  ## Fonts
463
750
 
464
- Every report prints in **Roboto 3.014**, from pdfmake's own package, under
751
+ A report prints its own text in **Roboto 3.014** by default, from pdfmake's
752
+ own package, under
465
753
  the SIL Open Font License 1.1, which allows embedding fonts in documents.
466
754
  The dependency-licence guard reads that licence from the font files
467
755
  themselves ([0006](../../docs/decisions/0006-dependencies-and-fonts-allow-public-source-and-licensed-production.md)).
@@ -469,19 +757,60 @@ The browser entry's copy in `vfs_fonts.js` is base64 inside a script, which
469
757
  the guard cannot read; a test holds it to the very bytes of those files.
470
758
  Each PDF embeds the subset of each face it uses.
471
759
 
472
- - `sans` is Roboto. **`serif` and `mono` are refused** as `unsupported`:
473
- pdfmake ships no serif or monospaced font, and printing one in Roboto would
474
- be a substitution nobody sees until they read the PDF. They need fonts
475
- whose licence the guard allows, and none is shipped yet.
760
+ A report that **maps** a font token to a host's font prints that token's
761
+ text in the host's face instead ([0043](../../docs/decisions/0043-a-report-maps-its-font-tokens-to-fonts-the-host-approved-pinned-by-digest-and-the-renderer-embeds-them.md)).
762
+ The runtime hands the face's bytes over; the renderer reads each with
763
+ report-spec's `readFont` in every render, keeping nothing of it for the
764
+ next, refusing a font it cannot embed as `invalid-asset` naming the asset,
765
+ strips the layout tables fontkit runs at print -- GSUB, GPOS, GDEF, kern and
766
+ `morx`, read from fontkit 2.0.4, which a test pins -- so that a crafted one
767
+ neither hangs nor crashes a render, and embeds the stripped bytes through
768
+ pdfmake's virtual files under names of the render's own, removed from
769
+ pdfmake's storage after each pass. A face a report prints but does not map
770
+ is refused as `unsupported`. Each line counts toward the page limit by the
771
+ face it prints in, a paragraph's by its tallest run's, so a host face of a
772
+ short line lowers the bound of its own text alone; a table's cells are walked
773
+ once, by `styledRows`, for their text, their tallest line and that bound,
774
+ each in the style and at the size `tableContent` prints it in. PDFKit draws
775
+ two faces of one PostScript name as whichever it opened first, so a host face
776
+ is refused as `invalid-asset` where any of its PostScript names is another
777
+ face's of the render with other bytes -- another host asset's, or the
778
+ renderer's own Roboto's or Liberation Sans's, a host's own copy of another
779
+ release among them -- or is `null` or a name every object has, which PDFKit's
780
+ font table holds already (`face-identity.ts`); a face of the renderer's own
781
+ bytes is embedded whole, kerned, and prints as the renderer's. A CFF `.otf`
782
+ is refused until report-spec reads CFF outlines and a PDF/A-3b proves one.
783
+
784
+ - **Latin, Greek and Cyrillic print, and nothing else**, in any face,
785
+ Roboto's included: report-spec's `refusedCharacter` allows the Unicode
786
+ blocks of those scripts and of the punctuation, symbols and marks written
787
+ with them, and refuses every other character as `unsupported` --
788
+ right-to-left, shaping and CJK scripts, simple alphabets such as Armenian
789
+ and Georgian, and the bidirectional controls, which fontkit would draw as
790
+ a space -- since pdfmake reorders nothing and the renderer shapes nothing.
791
+ Every character Roboto maps prints, so a report that maps nothing refuses
792
+ what 0.2.0 refused, in new words for another script.
793
+
794
+ - `sans` is **Roboto** where a report does not map it. **`serif` and `mono`
795
+ are refused** as `unsupported` where a report does not map them: pdfmake
796
+ ships no serif or monospaced font, and printing one in Roboto would be a
797
+ substitution nobody sees until they read the PDF. No serif or mono face is
798
+ shipped; a host supplies them.
476
799
  - Bold is **Roboto Medium**, the heaviest face pdfmake ships, and italic is
477
- Roboto Italic.
800
+ Roboto Italic; a host's family maps its own bold and italic faces, and a
801
+ face it does not map is refused, never synthesised.
478
802
  - **Every character is held to the face it prints in**, read from the
479
- faces' own character maps, and one without a glyph is refused as
480
- `unsupported`, naming the block and the code point: pdfmake would print
481
- it as an empty box, and as U+0000 in the PDF's text. One font means no
482
- fallback: CJK, Hebrew, Arabic, Thai and emoji are refused, and so is an
483
- fr-FR amount, which Intl groups with a narrow no-break space (U+202F)
484
- that Roboto lacks. Swiss amounts, de-CH and fr-CH alike, print.
803
+ faces' own character maps by report-spec's `characterMap`, through the
804
+ runtime, as fontkit, which PDFKit lays text out with, reads them
805
+ ([0040](../../docs/decisions/0040-a-font-is-read-by-report-specs-own-reader-which-says-what-it-may-be-embedded-as-and-which-characters-it-draws.md)),
806
+ and one without a glyph is refused as
807
+ `unsupported`, naming the face and the code point: pdfmake would print
808
+ it as an empty box, and as U+0000 in the PDF's text. A page number's and
809
+ a page count's digits are held to their paragraph's face too. There is no fallback
810
+ across faces: a character a mapped face lacks is refused, not drawn in
811
+ another. An fr-FR amount, which Intl groups with a narrow no-break space
812
+ (U+202F) that Roboto lacks, is refused where `sans` is Roboto; Swiss
813
+ amounts, de-CH and fr-CH alike, print.
485
814
 
486
815
  A QR-bill's slip and an EPC QR code's caption, and nothing else, print in
487
816
  **Liberation Sans 2.1.5**, regular and bold, under the SIL Open Font
@@ -513,11 +842,35 @@ bytes by a test. Both faces map every character SIX allows in a bill (IG
513
842
  keep-together block, a column or a page region, and not past the end of a
514
843
  framed section: a heading that ends a framed section is not kept with
515
844
  what follows it.
845
+ - **Say when a group header keeps fewer rows than its row says.** Where
846
+ the rows it keeps do not fit on a page with it under the repeated column
847
+ header, it is kept with as many as fit, and nothing says so: the heights
848
+ are the data's, and a render has no warning to give (0059).
516
849
  - **Refuse a spacer at the foot of a page.** One that does not fit what is
517
850
  left of a page moves to the next and starts there, without its space.
518
851
  - **Measure page regions per page.** They are measured once, every page
519
852
  field printed as `maxPages`, so a region that wraps only for some page
520
- numbers is measured at its widest.
853
+ numbers is measured at its widest. Page 1's own header, which holds no
854
+ page field, is measured once, in a pass of its own.
855
+ - **Print a page number in page 1's own header, or a footer of page 1's
856
+ own.** Page 1's own header is drawn when page 1 is added, before the
857
+ pages are counted, and page 1 prints the page footer every page prints.
858
+ Where page 1's own header is taller than the page header, a block page
859
+ 1's body cannot hold whole starts page 2, page 1 printing its header
860
+ alone; where it is shorter, or none, a kept block, a table's line under
861
+ its repeated header or an image that only page 1's taller body could
862
+ hold is refused, even in a report that would end on page 1, since where
863
+ a block lands is known only once the body is laid out; and where a
864
+ report has one, the page header is still measured and held to leaving a
865
+ body, though a report of one page prints it on no page
866
+ ([0060](../../docs/decisions/0060-a-reports-first-page-may-print-a-header-of-its-own-or-none-in-place-of-the-page-header.md)).
867
+ - **Make room above a raised run.** pdfmake places a line's baseline its
868
+ tallest ascender down, and room above cannot be asked of it, so a raised
869
+ run reaches above its line's text: by the corpus's boxes it stays clear
870
+ of the line above in Roboto and Liberation Serif, and in a host face
871
+ whose line is shorter than 1.099 ems it is not proved. A line that holds
872
+ a lowered run is given room below it (above); the glyphs themselves can
873
+ still touch an accent, which the boxes do not see.
521
874
  - **Draw an SVG as a browser does, compared.** That the PDF shows what a
522
875
  browser draws of the same cleaned drawing is held by report-spec's allow
523
876
  lists and by review; no browser's rendering is compared with the PDF.
@@ -538,7 +891,15 @@ bytes by a test. Both faces map every character SIX allows in a bill (IG
538
891
  `@formancy/report-corpus` and proves each PDF with the corpus's checks, or
539
892
  holds a refusal to the one the fixture allows
540
893
  ([0003](../../docs/decisions/0003-a-rendered-report-is-proved-on-the-pdf-it-produced.md)).
541
- These are the tests decision 0005 names. Each block kind is read back from
894
+ These are the tests decision 0005 names; the corpus's kept rows' fixture
895
+ (`KEEP_WITH_FIXTURES`), which the trial never drew, is rendered beside
896
+ them, and `group-rows.test.ts` holds a group header to the rows its row
897
+ keeps, or as many as fit, on the PDFs (0059); and so is its kept headings'
898
+ fixture (`KEPT_HEADING_FIXTURES`), a heading and a run of two over tables
899
+ longer than any plausible page, the heading on the page of the line it
900
+ stands under and of its table's first row, the run on its table's first
901
+ row's, which `flow.test.ts` holds through a framed section and over a kept
902
+ group header too (0011). Each block kind is read back from
542
903
  the PDF it produced: its text and images with PDF.js, through the corpus's
543
904
  reader, and its lines, rectangles, clips and text colours from the PDF's own
544
905
  content streams (`src/testing/drawing.ts`), which PDF.js's text does not
@@ -547,13 +908,49 @@ decoded by ZXing (`readCodes` in the corpus), for its text, its bytes, its
547
908
  level, its version and where it stands. `starters.test.ts` resolves the
548
909
  starters with the runtime and proves their PDFs: plan 7's three swept
549
910
  across page ends, the invoice down to its bill's code, decoded from the
550
- page and asking for the total the page prints, and the euro invoice down
911
+ page and asking for the total the page prints, the euro invoice down
551
912
  to its EPC QR code, decoded from the page, asking for that total and
552
913
  standing beside the payment details it holds, each printed in plain
553
- text. `samples.test.ts` does the same for the corpus's invoice samples,
914
+ text, and the site visit generated from a formancy form down to each
915
+ answer's line, each box and each finding's row, over pages at 80 of
916
+ them. `order-confirmation.test.ts` proves the order confirmation's three
917
+ tables line by line across its page break, each total recomputed in
918
+ BigInt, its letterhead on page 1 alone and its running header from page
919
+ 2, and its third delivery's header kept on page 2 with its first three
920
+ lines where kept with one it stands at the foot of page 1; and
921
+ `product-data-sheet.test.ts` the product data sheet in each of its four
922
+ languages, its powers, index and marks off the line by the corpus's
923
+ `shiftedRuns`, every line of the page in that language and its values as
924
+ that locale writes them
925
+ ([0064](../../docs/decisions/0064-an-order-confirmation-and-a-product-data-sheet-are-starters-that-print-what-0059-to-0063-added.md)).
926
+ `payment-reminder.test.ts` proves the payment reminder in each of its
927
+ four languages: both tables line by line, every total and what is due
928
+ recomputed in BigInt, the slip's headings in that language alone, and its
929
+ code, decoded from the page, asking for what is due by the reminder's
930
+ reference; and, with forty invoices more, its running header from page 2
931
+ and its slip on the last page alone
932
+ ([0066](../../docs/decisions/0066-a-payment-reminder-is-a-starter-that-pays-the-balance-of-a-customers-overdue-invoices-by-a-qr-bill-in-the-customers-language.md)).
933
+ `sales-report.test.ts` proves the monthly sales report: its table line by
934
+ line across its page break, every total recomputed in BigInt; each bar
935
+ measured against the gridlines the PDF draws, as tall as its product
936
+ line's total and labelled with the digits that group's total prints in
937
+ the table; each slice by the turn it sweeps, its legend entry its region's
938
+ total and its share rounded once; and its letterhead on page 1 alone and
939
+ its running header from page 2
940
+ ([0067](../../docs/decisions/0067-a-monthly-sales-report-is-a-starter-whose-bar-chart-and-pie-print-the-totals-its-table-prints.md)).
941
+ `samples.test.ts` does the same for the corpus's invoice samples,
554
942
  the invoice in German, French, Italian and English: one page each, its
555
943
  totals in its locale's format, its slip's headings in its language and in
556
944
  no other's, and its code asking for the total it prints.
945
+ `languages.test.ts` prints the corpus's invoice written in the same four
946
+ languages as one report, in each of them: that language's words and none
947
+ of the report's own in another, its total in that locale's format, its
948
+ slip's headings in its language and its code carrying the message in it,
949
+ each PDF equal by `inflatedDigest` to the invoice written in that language
950
+ alone; and every starter and sample prints the same bytes with its own
951
+ locale named as with none. The renderer draws a translated report's
952
+ document as it draws any other, and the PDF names no language of its own
953
+ ([0063](../../docs/decisions/0063-a-reports-own-words-are-written-in-each-language-it-declares-and-a-render-names-the-one-it-prints-in.md)).
557
954
  `euro-samples.test.ts` does it for the euro invoice's samples, the
558
955
  starter and the invoice from Austria, France, Italy, Spain, the
559
956
  Netherlands and Ireland: one page each, its totals as `Intl` formats its
@@ -586,7 +983,7 @@ corpus's reader through the transparency groups a clip path draws into,
586
983
  `contain`'s proportions, and from the pixels `cover` and a
587
984
  root's transform painting nothing outside the box, each beside the same
588
985
  drawing as it came, which does; and the budget at its bound and one past
589
- it, an image in a page region counted on every page. `svg-threats.test.ts`
986
+ it, an image in the page header or footer counted on every page. `svg-threats.test.ts`
590
987
  refuses each hazard svg-to-pdfkit meets in an SVG as it came -- a local
591
988
  image, text, a style sheet, an entity, a `use` fan-out, a link -- before
592
989
  pdfmake runs, and shows each guard behind the check hold without it; holds
@@ -604,9 +1001,49 @@ xmldoc hands it, its warnings, its clip and the page-sized groups it draws
604
1001
  for every reference. Every SVG the renderer draws in these tests is held
605
1002
  to carrying no annotation.
606
1003
 
607
- `scripts/readme-pictures.ts` draws the repository README's pictures of the
608
- starters and of both invoices' samples with PDF.js, and `pictures.test.ts`
609
- holds each to the page it was drawn from: its lines and where each
1004
+ `first-page-header.test.ts` proves page 1's own header on its PDF (0060):
1005
+ each of the corpus's `FIRST_PAGE_FIXTURES`, a long grouped table under a
1006
+ letterhead taller than the page header, under none and under a header
1007
+ shorter than it, reads on page 1, line by line and drawing by drawing,
1008
+ exactly as the same document under a page header like its own, and on every
1009
+ later page exactly as under the page header alone; a one-page report prints
1010
+ its own header and the page header nowhere, with a QR-bill's slip under it,
1011
+ its code decoded; a heading kept with the next block stays first on page 1,
1012
+ a kept block page 1 cannot hold starts page 2 whole, and the slip is held
1013
+ below the taller header; its SVG counts once, and a heading in it names no
1014
+ destination. `pdfmake.test.ts` pins what that rests on: the background laid
1015
+ out in a box as large as the page, an empty node's top margin moving the
1016
+ next line up or down by itself, a header function returning null, as the
1017
+ renderer's does, and a table's fill painted under its own text beneath the
1018
+ background.
1019
+
1020
+ `shifted.test.ts` proves a run set below or above the line on its PDF,
1021
+ read from PDF.js's runs and not through a line reader: drawn at
1022
+ `SHIFTED_SIZE` of its paragraph's size and moved by `SHIFTED_RISE`, to a
1023
+ hundredth of a point, in Roboto at two sizes and in the corpus's
1024
+ Liberation Serif; clear of the lines above and below where its paragraph
1025
+ wraps; in page 1's own header, page 1's body starting below the room its
1026
+ lowered run takes (0060); in the language a render names, the translation's
1027
+ word at the baseline the report's run sets (0063); and each way a word
1028
+ could leave it alone on a line refused, naming the paragraph, a page
1029
+ region's and page 1's own header's among them. The corpus's
1030
+ `SHIFTED_FIXTURES` are rendered and proved with the rest, page 1 held to
1031
+ its own header's runs and every later page to the page header's.
1032
+
1033
+ `fonts.test.ts` reads the faces the package embeds, Roboto's four and
1034
+ Liberation Sans's two, through report-spec's reader to the values measured
1035
+ from their files, holds the line constants to their own lines, and holds
1036
+ the reader to fontkit, loaded from the PDFKit pdfmake loads: every code
1037
+ point of each face mapped alike; every recorded length of the tables the
1038
+ reader reads, of two of them, refused or drawn alike, glyph for glyph; and
1039
+ seeded corruptions of the same two, each refused by the reader or mapped
1040
+ and named alike and embedded by PDFKit (0040). It holds glyphs.ts to the
1041
+ reader on a face whose maps disagree, too.
1042
+
1043
+ `scripts/readme-pictures.ts` draws the pictures of the starters and of
1044
+ both invoices' samples with PDF.js, which the repository's
1045
+ [`docs/starters.md`](../../docs/starters.md) shows and its README two of,
1046
+ and `pictures.test.ts` holds each to the page it was drawn from: its lines and where each
610
1047
  starts, and its drawings, path by path:
611
1048
 
612
1049
  ```bash