kumiori 0.2.0 → 0.4.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/CHANGELOG.en.md +201 -2
- package/CHANGELOG.md +202 -3
- package/NOTICE +2 -0
- package/README.en.md +58 -18
- package/README.md +58 -18
- package/THIRD_PARTY_NOTICES.md +364 -26
- package/dist-browser/NOTICE +2 -0
- package/dist-browser/THIRD_PARTY_NOTICES.md +364 -26
- package/dist-browser/chunks/{UTIF-DJ2yEO_P.js → UTIF-Br536cfi.js} +4 -4
- package/dist-browser/chunks/ccitt-DuYpUkox.js +1640 -0
- package/dist-browser/chunks/cgm-Blvzv6Sp.js +2103 -0
- package/dist-browser/chunks/{el-monoton-Bh-cSidd.js → el-monoton-vcesHl--.js} +4 -4
- package/dist-browser/chunks/{en-gb-DLCXyvjY.js → en-gb-DAIgCw5-.js} +4 -4
- package/dist-browser/chunks/{en-us-BBLcTX9N.js → en-us-BzUSGdOw.js} +4 -4
- package/dist-browser/chunks/eps-BFOW93N0.js +5237 -0
- package/dist-browser/chunks/epsInfo-D7b8OFlX.js +565 -0
- package/dist-browser/chunks/{export-contract-DDGE_g3K.js → export-contract-J-x2aLjv.js} +3 -3
- package/dist-browser/chunks/{la-D46x91kc.js → la-DRKqnbhl.js} +4 -4
- package/dist-browser/chunks/load-ftVKpJYM.js +16686 -0
- package/dist-browser/chunks/matrix-DxjvN-4S.js +48 -0
- package/dist-browser/chunks/metafile-CdWE2Vpy.js +1867 -0
- package/dist-browser/chunks/{pako-CeDDB8tF.js → pako-BwlM3ygd.js} +6 -6
- package/dist-browser/chunks/pixels-BvYSA32R.js +714 -0
- package/dist-browser/chunks/{rolldown-runtime-BXCUS5Bd.js → rolldown-runtime-BV67vctc.js} +2 -2
- package/dist-browser/chunks/{ru-CkmoNumx.js → ru-C-K8QVC6.js} +4 -4
- package/dist-browser/chunks/sniff-CqYWlxhA.js +8779 -0
- package/dist-browser/chunks/strokeOutline-yLvGVz8Y.js +1107 -0
- package/dist-browser/chunks/{uk-DIZr4Urv.js → uk-DsJ1E5t7.js} +4 -4
- package/dist-browser/kumiori.js +41493 -52444
- package/dist-cli/NOTICE +2 -0
- package/dist-cli/THIRD_PARTY_NOTICES.md +364 -26
- package/dist-cli/assets/cgm-DNhYr9YE.js +3239 -0
- package/dist-cli/assets/drawioStencil-FTgn0IEy.js +991 -0
- package/dist-cli/assets/eps-L8amQ51W.js +7496 -0
- package/dist-cli/assets/load-O0H7f7JT.js +39125 -0
- package/dist-cli/assets/metafile-xjD5AdL9.js +2522 -0
- package/dist-cli/cli.js +51358 -47290
- package/dist-lib/NOTICE +2 -0
- package/dist-lib/THIRD_PARTY_NOTICES.md +364 -26
- package/dist-lib/{api-CQ3aOtc5.js → api-DG-iGARW.js} +38568 -37973
- package/dist-lib/cgm-CAP3l6Ps.js +2103 -0
- package/dist-lib/eps-BVpP3M6Z.js +5236 -0
- package/dist-lib/epsInfo-D7b8OFlX.js +565 -0
- package/dist-lib/index.js +11 -12
- package/dist-lib/load-WPgVW8G9.js +15328 -0
- package/dist-lib/metafile-DIpYelkX.js +1867 -0
- package/dist-lib/node.js +4 -5
- package/dist-lib/pixels-BvYSA32R.js +714 -0
- package/dist-lib/types/api.d.ts +61 -2
- package/dist-lib/types/areaResources.d.ts +9 -1
- package/dist-lib/types/areaTree.d.ts +3 -1
- package/dist-lib/types/assets.d.ts +78 -3
- package/dist-lib/types/base64.d.ts +7 -0
- package/dist-lib/types/ccitt.d.ts +1 -1
- package/dist-lib/types/cgm.d.ts +2 -2
- package/dist-lib/types/color.d.ts +13 -4
- package/dist-lib/types/colorGlyphPdf.d.ts +11 -1
- package/dist-lib/types/compat.d.ts +23 -2
- package/dist-lib/types/cssCascade.d.ts +35 -1
- package/dist-lib/types/cssSelector.d.ts +80 -2
- package/dist-lib/types/cssText.d.ts +23 -0
- package/dist-lib/types/documentResources.d.ts +2 -1
- package/dist-lib/types/drawio/base64.d.ts +6 -0
- package/dist-lib/types/drawio/drawio.d.ts +137 -0
- package/dist-lib/types/drawio/drawioCanvas.d.ts +156 -0
- package/dist-lib/types/drawio/drawioEdges.d.ts +89 -0
- package/dist-lib/types/drawio/drawioJs/archimate.d.ts +33 -0
- package/dist-lib/types/drawio/drawioJs/arrows.d.ts +37 -0
- package/dist-lib/types/drawio/drawioJs/aws3d.d.ts +18 -0
- package/dist-lib/types/drawio/drawioJs/basic.d.ts +29 -0
- package/dist-lib/types/drawio/drawioJs/bpmn.d.ts +35 -0
- package/dist-lib/types/drawio/drawioJs/edges.d.ts +19 -0
- package/dist-lib/types/drawio/drawioJs/electrical.d.ts +29 -0
- package/dist-lib/types/drawio/drawioJs/misc.d.ts +34 -0
- package/dist-lib/types/drawio/drawioJs/mockup.d.ts +27 -0
- package/dist-lib/types/drawio/drawioJs/mockupIos.d.ts +2 -0
- package/dist-lib/types/drawio/drawioJs/ui.d.ts +34 -0
- package/dist-lib/types/drawio/drawioShapes.d.ts +51 -0
- package/dist-lib/types/drawio/drawioShapesA.d.ts +23 -0
- package/dist-lib/types/drawio/drawioShapesB.d.ts +26 -0
- package/dist-lib/types/drawio/drawioSketch.d.ts +50 -0
- package/dist-lib/types/drawio/drawioStencil.d.ts +159 -0
- package/dist-lib/types/drawio/drawioTapered.d.ts +67 -0
- package/dist-lib/types/drawio/drawioText.d.ts +27 -0
- package/dist-lib/types/drawio/drawioXml.d.ts +40 -0
- package/dist-lib/types/drawio/index.d.ts +37 -0
- package/dist-lib/types/drawio/inflate.d.ts +12 -0
- package/dist-lib/types/drawio/load.d.ts +35 -0
- package/dist-lib/types/drawio/messages.d.ts +12 -0
- package/dist-lib/types/drawio/options.d.ts +44 -0
- package/dist-lib/types/drawio/prefixSums.d.ts +9 -0
- package/dist-lib/types/drawio/sniff.d.ts +16 -0
- package/dist-lib/types/eps.d.ts +2 -28
- package/dist-lib/types/epsInfo.d.ts +36 -0
- package/dist-lib/types/foContext.d.ts +19 -0
- package/dist-lib/types/foExpr.d.ts +7 -0
- package/dist-lib/types/fontMapping.d.ts +14 -0
- package/dist-lib/types/fontSanity.d.ts +15 -0
- package/dist-lib/types/footnotes.d.ts +17 -1
- package/dist-lib/types/geometry.d.ts +5 -0
- package/dist-lib/types/gridTracks.d.ts +51 -0
- package/dist-lib/types/hebrewMarks.d.ts +11 -3
- package/dist-lib/types/htmlImport.d.ts +84 -15
- package/dist-lib/types/htmlPaged.d.ts +20 -2
- package/dist-lib/types/htmlParserStack.d.ts +26 -0
- package/dist-lib/types/htmlPrepare.d.ts +14 -3
- package/dist-lib/types/imageFormats.d.ts +138 -0
- package/dist-lib/types/imageInfo.d.ts +6 -1
- package/dist-lib/types/imageLimits.d.ts +4 -4
- package/dist-lib/types/index.d.ts +9 -3
- package/dist-lib/types/inflateFast.d.ts +12 -0
- package/dist-lib/types/inlineLayout.d.ts +34 -1
- package/dist-lib/types/jis.d.ts +19 -0
- package/dist-lib/types/layoutEngine.d.ts +191 -6
- package/dist-lib/types/linearText.d.ts +69 -0
- package/dist-lib/types/lnode.d.ts +36 -0
- package/dist-lib/types/pageFlow.d.ts +34 -0
- package/dist-lib/types/paint.d.ts +3 -1
- package/dist-lib/types/pdfCheck.d.ts +36 -0
- package/dist-lib/types/pdfFlatten.d.ts +165 -0
- package/dist-lib/types/pdfLibPatches.d.ts +29 -5
- package/dist-lib/types/pdfRenderer.d.ts +61 -12
- package/dist-lib/types/pdfStandard.d.ts +88 -0
- package/dist-lib/types/pdfxVerify.d.ts +4 -0
- package/dist-lib/types/pixels.d.ts +21 -3
- package/dist-lib/types/psFilters.d.ts +4 -14
- package/dist-lib/types/psShading.d.ts +1 -24
- package/dist-lib/types/resources.d.ts +2 -2
- package/dist-lib/types/sourceRef.d.ts +20 -1
- package/dist-lib/types/strokeOutline.d.ts +32 -0
- package/dist-lib/types/svg.d.ts +236 -10
- package/dist-lib/types/svgFilterRaster.d.ts +88 -0
- package/dist-lib/types/svgFilterSubregion.d.ts +46 -0
- package/dist-lib/types/tableBorders.d.ts +33 -4
- package/dist-lib/types/types.d.ts +396 -11
- package/package.json +5 -1
- package/dist-lib/api-CQ3aOtc5.js.map +0 -1
- package/dist-lib/index.js.map +0 -1
- package/dist-lib/node.js.map +0 -1
package/README.en.md
CHANGED
|
@@ -13,18 +13,18 @@ and outputs a Canvas preview and PDF.
|
|
|
13
13
|
|
|
14
14
|
Kumiori is developed with an AI coding assistant ([Claude Code](https://claude.com/claude-code)) (see "[About the development method](#about-the-development-method)").
|
|
15
15
|
|
|
16
|
-
- **About
|
|
16
|
+
- **About 136,000 lines of TypeScript, about 4,400 tests**: Each time a feature is added, the AI adds tests, and CI (type checking, unit tests, and 26 browser integration tests) passes
|
|
17
17
|
- **Implemented from the standards and specifications**: Kumiori is implemented by reading the standards and specifications as thoroughly as possible, including XSL-FO 1.1, the CSS modules (Paged Media, GCPM, Writing Modes, Text, Ruby, Fragmentation and others), MathML Core, the Unicode UAX #9 (bidirectional text) and UAX #14 (line breaking), W3C's JLREQ (Requirements for Japanese Text Layout, based on JIS X 4051) and PDF (ISO 32000), and following their definitions. The fine details of Japanese typesetting, such as punctuation compression, hanging punctuation and ruby overhang, are also based on these standards. The support status of each property, with the specification's definition and how Kumiori handles it, is collected in the Conformance Guide ([`docs/en/conformance.md`](docs/en/conformance.md))
|
|
18
18
|
- **Behaviour checked against published PDFs**: The interpretation of the specifications and the finer points of layout are checked by comparing Kumiori's output with sample PDFs that XSL-FO and CSS typesetting tools have published
|
|
19
19
|
|
|
20
20
|
## Features
|
|
21
21
|
|
|
22
|
-
- **Input**: HTML+CSS (own CSS cascade; no browser needed), XSL-FO (supports part of Antenna House's `axf:*` extensions, focusing on the commonly used ones), JSON logical tree
|
|
22
|
+
- **Input**: HTML+CSS (own CSS cascade; no browser needed), XSL-FO (supports part of Antenna House's `axf:*` extensions, focusing on the commonly used ones), JSON logical tree. Images in PNG, JPEG, GIF, BMP, TIFF, WebP, SVG, WMF, EMF, EPS (PostScript) and CGM, and draw.io diagrams (`.drawio`, `.dio`; [`docs/en/drawio.md`](docs/en/drawio.md))
|
|
23
23
|
- **Japanese typesetting**: vertical and horizontal writing, ruby, tate-chu-yoko, emphasis marks (kenten), line-breaking rules (kinsoku), hanging punctuation and pushing out, punctuation compression, spacing between Japanese and Latin text
|
|
24
|
-
- **Other scripts**: right-to-left scripts such as Arabic and Hebrew (reordered with the Unicode Bidirectional Algorithm, UAX #9; Arabic letters take their joined forms. CSS `direction: rtl`, XSL-FO `writing-mode="rl-tb"`), Thai (wrapped at word boundaries found with the dictionary of the runtime's `Intl.Segmenter`), Devanagari (Hindi and others; conjuncts and other shaping by the font), Korean (Hangul), other Indic scripts (Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada, Malayalam, Sinhala), Lao, Khmer, Burmese (Myanmar script) and Tibetan, Mongolian script (horizontal and vertical), Chinese (Simplified and Traditional), Vietnamese, Greek and Cyrillic, hyphenation (English, Latin, Russian, Ukrainian, Modern Greek), and mixed Japanese and Latin text. Fonts for Arabic, Thai, Devanagari, Hangul, Simplified and Traditional Chinese, emoji and other scripts are passed with `--font` or `fonts` (the default fonts do not include them; color emoji fonts are typeset in color; Hebrew, Greek, Cyrillic and Vietnamese letters can be set with the default Latin fonts). A table of the font each language and script needs, how it wraps, vertical writing and limitations is in the section "Supported languages and scripts" of the Conformance Guide ([`docs/en/conformance.md`](docs/en/conformance.md); section 5.6 of the XSL-FO 1.1 volume, section 5.8 of the HTML and CSS volume). The same section has typeset samples for each script (Article 1 of the Universal Declaration of Human Rights set in the font of each script), and samples of
|
|
24
|
+
- **Other scripts**: right-to-left scripts such as Arabic and Hebrew (reordered with the Unicode Bidirectional Algorithm, UAX #9; Arabic letters take their joined forms. CSS `direction: rtl`, XSL-FO `writing-mode="rl-tb"`), Thai (wrapped at word boundaries found with the dictionary of the runtime's `Intl.Segmenter`), Devanagari (Hindi and others; conjuncts and other shaping by the font), Korean (Hangul), other Indic scripts (Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada, Malayalam, Sinhala), Lao, Khmer, Burmese (Myanmar script) and Tibetan, Mongolian script (horizontal and vertical), Chinese (Simplified and Traditional), Vietnamese, Greek and Cyrillic, hyphenation (English, Latin, Russian, Ukrainian, Modern Greek), and mixed Japanese and Latin text. Fonts for Arabic, Thai, Devanagari, Hangul, Simplified and Traditional Chinese, emoji and other scripts are passed with `--font` or `fonts` (the default fonts do not include them; color emoji fonts are typeset in color; Hebrew, Greek, Cyrillic and Vietnamese letters can be set with the default Latin fonts). A table of the font each language and script needs, how it wraps, vertical writing and limitations is in the section "Supported languages and scripts" of the Conformance Guide ([`docs/en/conformance.md`](docs/en/conformance.md); section 5.6 of the XSL-FO 1.1 volume, section 5.8 of the HTML and CSS volume). The same section has typeset samples for each script (Article 1 of the Universal Declaration of Human Rights set in the font of each script), and samples of variable fonts and emoji are in sections 5.6 and 5.7 of the HTML and CSS volume
|
|
25
25
|
- **Pages**: page masters, running heads and page numbers (folios), footnotes, multi-column layout, floats, tables (splitting across rows and pages, repeated headers, automatic column width), page number references
|
|
26
|
-
- **Output**: Canvas preview, PDF (subset font embedding, bookmarks, links, annotations, forms, trim marks, PDF/X-3 marking with conversion of RGB colors and images to CMYK)
|
|
27
|
-
- The PDF/X
|
|
26
|
+
- **Output**: Canvas preview, PDF (subset font embedding, bookmarks, links, annotations, forms, trim marks, PDF/X-1a, PDF/X-3 and PDF/X-4 marking with conversion of RGB colors and images to CMYK)
|
|
27
|
+
- The PDF/X marking (`pdfx` in the API, `--pdfx` on the command line) has been verified only for the parts defined by the PDF specification ISO 32000-2 (such as the form of the output intent dictionary and the XMP metadata). It has not been verified against the text of the PDF/X standard ISO 15930, so conformance to that standard is not guaranteed. Check the output with a preflight tool (such as Acrobat Pro) before submitting it
|
|
28
28
|
- **Environments**: browser (Vite) and the Node CLI (`dist-cli/cli.js`)
|
|
29
29
|
|
|
30
30
|
Internally, every box is computed in pt following the XSL-FO **Area Model**, a **physical tree (Area Tree)** is assembled, and then it is drawn to
|
|
@@ -56,9 +56,9 @@ Node 20.19.0 or later in the 20 line, or 22.12.0 or later, is required (CI tests
|
|
|
56
56
|
### Web app (browser)
|
|
57
57
|
|
|
58
58
|
- "Open" (開く) lets you select HTML, XSL-FO or EPUB files together with the CSS, images and fonts they use (several can be selected). "Open folder" (フォルダを開く) selects a whole folder; you can also open files or folders by dragging and dropping them onto the page. When a folder contains several documents, index.html (or, failing that, the document at the shallowest location) is opened
|
|
59
|
-
- "Save PDF" (PDF を保存) writes out the PDF. On the left are page thumbnails and warnings (collapsible); "Settings" (設定) on the right has the default style, the default page size (the paper for HTML that does not specify `size` in `@page`: A4, A5, B5, JIS-B5, letter or free input; the same as the CLI's `--page-size`), the CSS interpretation, "Typeset with the spec's default values" (the XSL-FO default-value convention; the same as the CLI's `--compat`), trim marks and
|
|
59
|
+
- "Save PDF" (PDF を保存) writes out the PDF. On the left are page thumbnails and warnings (collapsible); "Settings" (設定) on the right has the default style, the default page size (the paper for HTML that does not specify `size` in `@page`: A4, A5, B5, JIS-B5, letter or free input; the same as the CLI's `--page-size`), the CSS interpretation, "Typeset with the spec's default values" (the XSL-FO default-value convention; the same as the CLI's `--compat`), trim marks, font loading and draw.io diagrams (reading them or not, shape libraries; [`docs/en/drawio.md`](docs/en/drawio.md))
|
|
60
60
|
- Warnings are listed one by one in the left column (identical messages are merged; four or more are collapsed to a count and can be opened; the count also appears in the top bar). They are the same warnings as the CLI and the API give: layout warnings, unsupported CSS / XSL-FO and unknown CSS properties, links whose actions were not written to the PDF for safety, nesting deeper than 128 levels and too many `@import`s, EPUB items skipped for exceeding the limits, images not fetched, and font notices (fonts that could not be fetched and so on)
|
|
61
|
-
- All typesetting happens inside the browser; documents and fonts are never sent out (the only things fetched from outside are the default fonts
|
|
61
|
+
- All typesetting happens inside the browser; documents and fonts are never sent out (the only things fetched from outside are the default fonts, the images the document references via `http(s):`, and the draw.io shape libraries when allowed in "設定" (Settings)). It also works when the `dist/` from `npm run build` is placed on a static web server
|
|
62
62
|
|
|
63
63
|
### Node CLI (HTML+CSS and XSL-FO to PDF without a browser)
|
|
64
64
|
|
|
@@ -86,9 +86,11 @@ cat book.html | node dist-cli/cli.js - -o - --base . > book.pdf
|
|
|
86
86
|
- Images the document references via `http(s):` are fetched from the network by default. `--no-fetch-images` disables this (e.g. when typesetting documents written by others on a server; they are typeset as unreadable images). Network images are fetched up to 8 at a time, and fetching the images of a document also has an overall time limit (10 times the limit of a single fetch, 5 minutes by default; images not fetched by then are typeset as unreadable images)
|
|
87
87
|
- Stylesheets the document references via `http(s):` (`<link rel="stylesheet">`, `@import`) and the fonts of their `@font-face` rules (only those whose `unicode-range` overlaps the characters of the document) are also fetched by default. `--no-fetch-styles` disables this
|
|
88
88
|
- Image sizes are limited (so that a small file cannot consume large amounts of memory and time; the values and their rationale are in `src/imageLimits.ts`). One image may have up to 100 million pixels. The images inside a WMF, EMF or CGM file (DIBs, cell arrays, tile arrays, patterns) may total up to 64 million pixels per file, and also no more than "260 thousand pixels (512 × 512) + 1,024 pixels per byte of the file" (a file of a few hundred bytes cannot produce a huge image; a file larger than about 61 KB may use the full 64 million pixels). Images beyond the limits are not drawn, and the rest of the document is typeset. GIF, WebP, JPEG, CCITT TIFF and RLE BMP images also have their pixel count bounded by the file size (per format, a value derived from the densest coding a legitimate file can have; a large, almost single-colour lossless WebP, a blank CCITT image wider than 16,384 pixels, or a large, almost blank RLE BMP is not drawn when it exceeds the limit), and a PNG whose decompressed size exceeds 1,032 times its compressed data (the deflate limit) is not drawn. A font unpacked from WOFF or WOFF2 may be up to 128 MB, and no more than 100 times the file size + 1 MB
|
|
89
|
+
- Documents of thousands of pages use memory in proportion to the number of pages. The command and the API's `typesetToPdf` write the PDF page by page and release the layout results of each page once it is written, so the most memory is used when layout has finished, by the intermediate layout results (about 0.7MB per text-heavy page). `typeset`, which also returns the layout results (`areaTree`, `toPdf`, `renderPage`), holds the area tree of the whole document and uses correspondingly more (for the FO of the PostgreSQL documentation, 3,231 pages, the command peaks at about 2.3GB of live heap, and typesetting with `typeset` and calling `toPdf` at about 2.8GB). If Node stops at its heap limit (`JavaScript heap out of memory`; by default the limit depends on the machine's memory and is at most about 4GB), add `--low-memory` (see below) or raise the limit, as in `node --max-old-space-size=8192 dist-cli/cli.js book.fo -o book.pdf` (in MB). Image bytes are kept outside the V8 heap, so they do not count towards `--max-old-space-size`, but they use the machine's memory. When only the PDF is made (the command, `typesetToPdf`), the original bytes of each image are released once it has been embedded in the PDF, so a document with many images uses about 3 times the amount of image data (the size of the image files read; the embedded copies, the finished PDF and so on. With `typeset` the original bytes are also kept, about 3.5 times)
|
|
89
90
|
- When typesetting documents written by others on a server, also put a time limit and a memory limit on the typesetting of each document, separately from the limits above (typeset each document in a separate process or worker and stop it when the time is up; use `node --max-old-space-size=…` or a container memory limit, and so on). The limits above apply to one image or font at a time: a single image at the limit can still take several seconds to over ten seconds and about 2 GB, and a document that references many images and fonts costs correspondingly more
|
|
90
91
|
- Of the links that leave the document (HTML `<a href>`, and `external-destination` of XSL-FO `fo:basic-link` and `fo:bookmark`), by default only URLs whose scheme is `http`, `https`, `mailto` or `tel`, and relative references to a PDF (the action that opens another PDF), get an action in the PDF. Other schemes (`javascript:`, `data:`, `file:` and so on) and actions that open a file (relative non-PDF files, absolute paths, scheme-less `//host/…`) are typeset as plain text and counted in a "warning:" (to protect whoever opens a PDF made from a document written by someone else). `--link-schemes http,https,ftp` chooses the allowed schemes (`*` means all), and `--link-launch` also writes the actions that open a file (`--link-schemes '*' --link-launch` writes everything). `--link-relative uri` writes scheme-less relative links (`x.pdf`, `a.mp3`) as a URI action with the reference as written (`/S /URI /URI (x.pdf)`; `%xx` is not decoded) instead of the actions that open a file (GoToR, Launch): many PDF viewers inside browsers do not handle GoToR and Launch. Relative non-PDF files are then written without `--link-launch`; absolute paths and `//host/…` still need `--link-launch`. In the API it is `links: { relative: 'uri' }`
|
|
91
92
|
- Files the document or the CSS references with a `file:` URL (`file:///…/style.css` etc.) are read from that file, even outside the input's directory. Relative references that point outside the input's directory (`url(../fonts/a.ttf)` in `sub/a.html` etc.) are read the same way (as when a browser opens a local HTML file). `--no-outside-files` stops reading files outside the input's directory (for documents written by others: an image, font or SVG the document points at is drawn into the PDF when it can be read, so this keeps other files of the machine from being copied out; files inside the input's directory are still read). When none of the files in the `src` of an `@font-face` is found, a warning is reported
|
|
93
|
+
- `--low-memory`: typeset with less memory. The re-layouts that settle page number references (tables of contents and so on) do not reuse the pages of the previous pass, and the intermediate layout results of each page-sequence (for HTML, the document) are released once it has been laid out. The document is therefore laid out once more after the re-layouts to write the PDF. The PDF is the same. For the FO of the PostgreSQL documentation (3,231 pages), the maximum live heap goes from about 2.3GB to about 0.9GB (the most is used while reading the FO; it can be typeset with a 1GB heap limit), and the time from 160 s to 231 s. In the API, `lowMemory` of `typesetToPdf`
|
|
92
94
|
- `--watch`: re-typesets whenever the HTML, FO, CSS, images or fonts in the input's directory change
|
|
93
95
|
- `--help` (`-h`) prints the usage, `--version` (`-v`) prints the version
|
|
94
96
|
- Unsupported CSS properties and values (listed in chapter 16 of the Conformance Guide), properties unknown to Kumiori (misspelled or unsupported), XSL-FO elements and properties that cannot be read, unreadable images and so on are not silently ignored but reported as `警告:` ("warning:") messages (in the library, `result.warnings`)
|
|
@@ -96,20 +98,25 @@ cat book.html | node dist-cli/cli.js - -o - --base . > book.pdf
|
|
|
96
98
|
- CSS, images and fonts in the same directory as the HTML (and in subdirectories) are used (the same as selecting them together in the web app). Only images whose names appear in the document and the CSS are read. Only CSS referenced by the HTML (`<link>`, `@import`) is used (unreferenced CSS is not applied, and a warning says so). `--css a.css,b.css` selects the CSS to use (comma-separated for several; `@import` targets are used too. CSS named there is added as a user stylesheet even if the HTML does not reference it)
|
|
97
99
|
- `--style kumiori|browser|browser-margin|ah|vivliostyle|weasyprint`: the default style (the same as "Default style" under "Settings" in the web app; the default is kumiori)
|
|
98
100
|
- `--page-size <size>`: the default paper for HTML (the paper of a document that does not specify `size` in `@page`; the default is A4). Written like the CSS `size` property: a paper name (`A5`, `JIS-B5`, `letter`, etc.), a name with an orientation (`"A5 landscape"`), or a width and height (`148mm,210mm`; separated by a space or a comma). A `@page { size: … }` in the document wins. `width` and `height` in `@media` are also evaluated against this paper. Not used for XSL-FO
|
|
99
|
-
- `--
|
|
101
|
+
- `--svg-lang <ja,en>`: languages to match SVG `systemLanguage` (the condition that picks a child of `switch`) against (language tags separated by commas, in order of preference). A language given where the SVG is placed (`lang`, `xml:lang`, `language`) wins. The default is the environment language
|
|
102
|
+
- `--font-dir <dir>`: the directory from which the default fonts (`NotoSerifJP-Regular.ttf`, `NotoSerifJP-Bold.ttf`, `NotoSansJP-Regular.ttf`, `NotoSansJP-Bold.ttf`, `Tinos-*.ttf`, `Arimo-*.ttf`, `Cousine-*.ttf` when monospace is specified, `STIXTwoMath-Regular.ttf` when there is MathML, and `NotoSansSymbols2-Regular.ttf` when there are symbols found in none of the fonts, and `NotoEmoji-Regular.ttf` when there are emoji found in none of them either) are read. If absent, the font cache is tried, then Google Fonts. If a bold file (`-Bold`) has the same contents as the `-Regular` file of the same font, the font is treated as having no bold face and bold text is drawn by emboldening Regular (for replacing a default font with one that has no bold face). When replacing the default fonts with your own, place the bold files too (`NotoSerifJP-Bold.ttf`, `NotoSansJP-Bold.ttf` and so on): a file that is not there comes from the cache or the network as the default font, and gets mixed with the replaced fonts
|
|
100
103
|
- `--font-cache <dir>`: the directory in which the default fonts fetched from Google Fonts are saved and reused. The default is the environment variable `KUMIORI_FONT_CACHE`, or else the OS cache (on Linux `kumiori/fonts` under `$XDG_CACHE_HOME` or `~/.cache`, on macOS `~/Library/Caches/kumiori/fonts`, on Windows `%LOCALAPPDATA%\kumiori\fonts`). Fonts are fetched from the network only the first time, with the message `書体 … を取得して … に保存しました` ("fetched font … and saved it to …"). From the second run on, the network is not used. Anything that is not a font file, such as an interrupted download, is not saved, and a corrupt cache is discarded and fetched again. Conversion continues even where the cache cannot be written
|
|
101
104
|
- `--no-font-cache`: neither reads nor writes the font cache (fetches from Google Fonts every time)
|
|
102
105
|
- `--lang ja|en`: language of the usage text, reports, warnings and error messages. Without it, the environment variable `KUMIORI_LANG` is used, then the OS locale (`LC_ALL`, `LC_MESSAGES`, `LANG` starting with `en` means English). The default is Japanese
|
|
103
106
|
- `--font <font file>` (repeatable): adds a font file (TTF, OTF, TTC, WOFF, WOFF2) (for a TTC, each font inside is added). Fonts are registered by the family name in the font's name table and the weight, width and slant in its OS/2 table, and used from `font-family` like fonts installed on the system. Faces within a family are matched by width (`font-stretch`), then slant (`font-style`), then weight (`font-weight`) (CSS Fonts 4 §5.2). When an italic or oblique font file is given, `font-style: italic` / `oblique` text is set in that face (otherwise the upright glyphs are slanted). A face of a different width (such as Arial Narrow, which shares the family name and has a narrower width) is selected by `font-stretch`, or by the name of that face alone (`font-family: "Arial Narrow"`); when the family has no face of another width, the glyphs are scaled horizontally. A variable font (OpenType Font Variations, with TrueType outlines or CFF2 outlines) is used over the full range of its axes such as weight and width: the shape matching `font-weight`, `font-stretch`, `font-variation-settings` and so on is built and used (each shape in use is embedded in the PDF as a static font; a CFF2 variable font is rebuilt as static CFF fonts). The `font-family` list is tried in order for each character, and the first font that has the character is used (generic names and the names of the default fonts are also looked up at their position in the list). Characters that no font in the list has are looked up in the default fonts and then in added fonts that are not in the list. In compatibility styles such as `--style ah`, fonts are also selected by the PostScript name written in SVG's `font-family` (e.g. `'CenturyGothic'`)
|
|
104
107
|
- `--generic-font <generic>=<font name>`: the font used for a generic font family (the family name of a font added with `--font` or of a default font; repeatable). `serif`, `sans-serif` and `monospace` set the font for Latin text (by default Tinos, Arimo and Cousine); `serif-cjk` and `sans-serif-cjk` set the font for Japanese text (by default Noto Serif JP and Noto Sans JP). Japanese text in monospace uses the `sans-serif-cjk` font in HTML and the `serif-cjk` font in XSL-FO. Example: `--font BIZUDMincho-Regular.ttf --generic-font serif-cjk="BIZ UDMincho"`
|
|
108
|
+
- `--drawio-stencils <files or directories,…>`: shape libraries (draw.io's `js/stencils.min.js` or library XML) and distributed images (`.svg`, `.png`, `.jpg`) for draw.io diagrams, separated by `,` (repeatable). `--fetch-drawio-stencils`: allows fetching the shape libraries and images a diagram needs from draw.io's distribution (v24.7.5) when they are missing (fetched files are saved in the font cache directory; not saved with `--no-font-cache`). `--drawio-stencils-url <URL>`: the URL of the `stencils.min.js` to fetch (implies `--fetch-drawio-stencils`). `--no-drawio`: do not read draw.io diagrams (`.drawio`, `.dio`) as images. See [`docs/en/drawio.md`](docs/en/drawio.md)
|
|
109
|
+
- `--plugin <module>`: loads a plugin (the API's `plugins`): a file path or a package name, searched in this order: (1) a spec starting with `./` or `../`, an absolute path or a `file:` URL is a file path (`./plugin.js` and so on); (2) any other spec is first resolved as a package name, as `import()` does (from the current directory with the same conditions as `import()`: the `import`, `node` and `default` conditions of `exports`; `@scope/name`, `name/sub` and specs ending in an extension, such as `kp/dist/plugin.js` or `chart.js`, work too; a directory of the same name in the current directory does not make it a path); (3) if it cannot be loaded as a package (no such package, and also when the package does not export that subpath in `exports` or its entry file is missing), the file of that name in the current directory is loaded (`--plugin myplugin.js`). Whenever it can be loaded as a package, the package is loaded, so write `./` to be sure the file is loaded. When nothing is found, the error message says what was searched, in order. Repeatable. The module's `default` export is a plugin or a function returning one (`(options, { cacheDir, lang }) => plugin`; `lang` is the message language chosen by `--lang` or the environment). `--plugin-option <name>=<value>` passes an option to the function of the preceding `--plugin` (repeatable). A plugin is a program that runs with the same rights as Kumiori, so give only ones you trust
|
|
105
110
|
- `--print`: trim marks and bleed (3mm)
|
|
106
111
|
- `--image-max-dpi <dpi>`: JPEG photos finer than this relative to the size they are placed at are downscaled to this resolution and re-encoded (makes the PDF smaller; by default they are left as they are)
|
|
112
|
+
- `--pdfx x1a|x1a:2003|x3|x4`: write PDF/X-1a:2001, PDF/X-1a:2003, PDF/X-3:2003 or PDF/X-4 markers for print submission. RGB colors and images are converted to CMYK, gray text, lines and fills become K-only CMYK, K-only black body text under 12pt (including text in the page margins) and lines and rules under 2pt are overprinted (as recommended by the Ghent Workgroup submission specification GWG 2022; text and lines inside images such as SVG and EPS are not), pages get a TrimBox only, and links, annotations and form fields on the pages are left out, with their number reported in a warning (anything that overlaps the area up to the bleed (BleedBox) even slightly is left out; the BleedBox encloses the whole artwork of the page, so practically all links are lost, both internal ones such as those of a table of contents and those to external URLs; bookmarks are kept; write PDFs for reading on screen without `--pdfx`). Of the GWG 2022 requirements, differing finished page sizes, spot colors and coarse images (149ppi or less, and 224ppi or less) are also reported as warnings (with the values of the sheet-fed commercial variant). PDF/X-4 keeps transparency as is and writes the version marker in the XMP metadata. For PDF/X-1a (CMYK and spot colors only, no transparency; :2001 is PDF 1.3, :2003 is PDF 1.4) and PDF/X-3 (no transparency; device-independent color (ICC, Lab) is allowed; PDF 1.4), the written PDF is read back and checked against the rules (version, markers, color spaces, transparency, font embedding, boxes, annotations), and writing fails if it does not meet them. Transparency is flattened: when only a single-color fill (a box background or the white page) lies under a transparent object (opacity, colors with alpha, images with alpha, translucency and masks in SVG), it is drawn as an opaque vector object in the composited CMYK color; otherwise that area is rasterized together with what lies under it into a CMYK image (300ppi; 600ppi where text under 12pt is involved), with a warning (also warning that text within rasterized areas loses quality and can no longer be selected as text). Writing fails if transparency that cannot be flattened remains (such as the transparency of color glyphs). Overlapping areas are composited in CMYK (as in printing), so they look slightly different from screen viewers that composite in RGB. Japanese printers mainly use PDF/X-4 and PDF/X-1a
|
|
113
|
+
- `--output-profile <ICC file>`: the output CMYK ICC profile (the one the printer specifies, such as Japan Color 2001 Coated). It is embedded in the PDF, and RGB colors and images are converted to CMYK with its tables. Required with `--pdfx x4` (an error if missing or not a CMYK profile). `--output-condition <name>` gives the printing condition name (default: the ICC registry name JC200103)
|
|
107
114
|
- `--spot-colors <JSON file>`: the names of spot colors and the alternate CMYK at 100% tint (`{"name": "cmyk(20%,40%,60%,80%)"}` or `{"name": [0.2,0.4,0.6,0.8]}`; the array holds numbers from 0 to 1, and a value over 1 is an error). Among `rgb-icc(r,g,b,#Separation,'name',tint)` colors, those whose name is listed here are written as a PDF Separation (the alternate color space is DeviceCMYK, and the tint transform is linear). `rgb-icc()` is read with either `--compat` in XSL-FO, and only with `--style ah` in HTML (it is an Antenna House form, not a CSS color function; with the other styles the declaration is ignored as an invalid value and reported in a warning). Those whose name is not listed are written with the alternate RGB as before. Names are written in UTF-8 (ISO 32000-2 §7.3.5). Spot color values (such as those of swatch books) are not included in Kumiori; the user supplies them
|
|
108
115
|
- HTML is read with linkedom, and the CSS computed values come from the own cascade (the same as "CSS interpretation: Kumiori" in the web app)
|
|
109
116
|
- XHTML (`.xhtml`, `.xht`) is read with XML syntax, rewritten according to namespaces, and then typeset the same as HTML (prefixed elements such as `<s:svg xmlns:s="http://www.w3.org/2000/svg">` also become SVG; `src/xhtml.ts`). `.html` is read with HTML syntax, so prefixed elements do not become SVG. With `--xhtml`, XML syntax is used regardless of the extension
|
|
110
117
|
- MathML (`<math>`) is typeset with the math font (`STIXTwoMath-Regular.ttf`) and turned into glyph outline shapes (`src/mathLayout.ts`, shared with XSL-FO). Formulas with `display="block"` are centered on the line
|
|
111
118
|
- XSL-FO (`.fo`, `.xml`, or `--fo`) is typeset the same as XSL-FO import in the web app. `--compat spec|antenna` is the default-value convention (XSL-FO 1.1 initial values (default) / AH Formatter compatible defaults; other values are an error). Font files (TTF, OTF, TTC) in the same directory are used by the name in the FO's `font-family`
|
|
112
|
-
- Images in PNG, JPEG, GIF, BMP, TIFF, WebP, SVG, WMF, EMF, EPS (PostScript) and CGM are placed in the PDF. SVG that cannot be converted to shapes (e.g.
|
|
119
|
+
- Images in PNG, JPEG, GIF, BMP, TIFF, WebP, SVG, WMF, EMF, EPS (PostScript) and CGM, and draw.io diagrams (`.drawio`, `.dio`; as shapes and text; [`docs/en/drawio.md`](docs/en/drawio.md)), are placed in the PDF. SVG filters are either approximated with shapes (shadows, blur, color changes, compositing) or computed in pixels and placed as an image (feTurbulence, lighting and so on; the web app has the browser rasterize them). HTML in foreignObject is approximated as text in Node. SVG that cannot be converted to shapes (e.g. foreignObject with non-HTML content) is drawn as a placeholder frame with a warning
|
|
113
120
|
|
|
114
121
|
### Using as a library (from TypeScript or JavaScript)
|
|
115
122
|
|
|
@@ -120,7 +127,7 @@ npm install kumiori
|
|
|
120
127
|
When building in this repository, `npm run build:lib` (dist-lib/; ES modules and type declarations).
|
|
121
128
|
|
|
122
129
|
```ts
|
|
123
|
-
import { typeset, walkAreaTree } from 'kumiori';
|
|
130
|
+
import { typeset, typesetToPdf, walkAreaTree } from 'kumiori';
|
|
124
131
|
|
|
125
132
|
// HTML+CSS (XSL-FO is typeset with the same function; the kind is detected from the extension of name or from the content)
|
|
126
133
|
const result = await typeset(html, {
|
|
@@ -134,17 +141,21 @@ const result = await typeset(html, {
|
|
|
134
141
|
console.log(result.pageCount, result.warnings);
|
|
135
142
|
walkAreaTree(result.areaTree, (area) => { /* walk the typeset result (Area Tree) */ });
|
|
136
143
|
const pdf = await result.toPdf(); // Uint8Array
|
|
144
|
+
const { pdf: bytes } = await typesetToPdf(html, { name: 'book.html' }); // when only the PDF is needed (it keeps no layout result, so large documents use less memory)
|
|
137
145
|
result.renderPage(canvas, 0); // draw page 1 onto a canvas (browser)
|
|
138
146
|
```
|
|
139
147
|
|
|
140
148
|
- `typeset(text, options)` is the entry point (`typesetHtml` and `typesetFo` are variants that fix the kind). It does not touch the file system, and uses the network only to fetch the default fonts (replaceable with `loadFont`) and the images and stylesheets the document references via `http(s):` (can be stopped with `fetchImages` and `fetchStyles`), so it runs both in the browser and in Node
|
|
141
149
|
- `text` is a string. When reading from a file, converting it to a string with `decodeDocumentText(bytes)` decodes it according to the BOM, the XML declaration's `encoding` and `<meta charset>` (reading as fixed UTF-8 garbles Shift_JIS FO and the like)
|
|
142
|
-
- Main `options`: `kind` (`html`, `xhtml`, `fo`; if omitted, determined from `name` and the content), `name` (the input file name), `files` (CSS, images, fonts; fonts may be TTF, OTF, TTC, WOFF or WOFF2), `fonts` (fonts to add), `genericFonts` (fonts for the generic font families; the names are the same as for `--generic-font`: `serif`, `sans-serif`, `monospace`, `serif-cjk`, `sans-serif-cjk`), `style` (the default style for HTML), `pageSize` (the default paper for HTML: the paper of a document that does not specify `size` in `@page`, written like the CSS `size` property: `"A5"`, `"A5 landscape"`, `"148mm 210mm"`; the default is A4; a `@page { size }` in the document wins; `width` and `height` in `@media` are also evaluated against this paper), `compat` (the XSL-FO default-value convention), `print` (bleed and trim marks), `spotColors` (alternate CMYK for spot colors), `loadFont`, `fetchTimeoutMs` (timeout for fetching fonts and images; default 30 seconds), `fetchImages` (whether to fetch the images the document references via `http(s):`; default `true`; `false`, or a function that takes a URL and returns a boolean; when typesetting others' documents on a server, disable it or allow only certain URLs), `fetchStyles` (whether to fetch the stylesheets the document references via `http(s):` and the fonts of their `@font-face` rules; the same form as `fetchImages`), `resolveResource` (a function that returns the content of files the document or the CSS references that are not in `files`; see below), `links` (which links that leave the document get an action in the PDF: `{ schemes?: string[]; launch?: boolean }`; by default only URLs whose scheme is `http`, `https`, `mailto` or `tel` and relative references to a PDF are written, and the rest are typeset as plain text and reported in `warnings`; `schemes` is the list of allowed schemes (it replaces the default; `'*'` means all), and `launch: true` also writes the actions that open a file (relative non-PDF files, absolute paths, `//host/…`); `{ schemes: ['*'], launch: true }` writes everything), `lang` (language of `warnings` and error messages: `ja` or `en`; default Japanese), `deflate` (in Node, passing `zlib.deflateSync` speeds up PDF output)
|
|
150
|
+
- Main `options`: `kind` (`html`, `xhtml`, `fo`; if omitted, determined from `name` and the content), `name` (the input file name), `files` (CSS, images, fonts; fonts may be TTF, OTF, TTC, WOFF or WOFF2), `fonts` (fonts to add), `genericFonts` (fonts for the generic font families; the names are the same as for `--generic-font`: `serif`, `sans-serif`, `monospace`, `serif-cjk`, `sans-serif-cjk`), `style` (the default style for HTML), `pageSize` (the default paper for HTML: the paper of a document that does not specify `size` in `@page`, written like the CSS `size` property: `"A5"`, `"A5 landscape"`, `"148mm 210mm"`; the default is A4; a `@page { size }` in the document wins; `width` and `height` in `@media` are also evaluated against this paper), `compat` (the XSL-FO default-value convention), `print` (bleed and trim marks), `spotColors` (alternate CMYK for spot colors), `loadFont`, `fetchTimeoutMs` (timeout for fetching fonts and images; default 30 seconds), `fetchImages` (whether to fetch the images the document references via `http(s):`; default `true`; `false`, or a function that takes a URL and returns a boolean; when typesetting others' documents on a server, disable it or allow only certain URLs), `fetchStyles` (whether to fetch the stylesheets the document references via `http(s):` and the fonts of their `@font-face` rules; the same form as `fetchImages`), `resolveResource` (a function that returns the content of files the document or the CSS references that are not in `files`; see below), `links` (which links that leave the document get an action in the PDF: `{ schemes?: string[]; launch?: boolean; relative?: 'file' | 'uri' }`; by default only URLs whose scheme is `http`, `https`, `mailto` or `tel` and relative references to a PDF are written, and the rest are typeset as plain text and reported in `warnings`; `schemes` is the list of allowed schemes (it replaces the default; `'*'` means all), and `launch: true` also writes the actions that open a file (relative non-PDF files, absolute paths, `//host/…`); `{ schemes: ['*'], launch: true }` writes everything), `svgLanguages` (an array of language tags to match SVG `systemLanguage` against; the same as `--svg-lang`), `lang` (language of `warnings` and error messages: `ja` or `en`; default Japanese), `deflate` (in Node, passing `zlib.deflateSync` speeds up PDF output)
|
|
143
151
|
- The function passed to `fetchImages` / `fetchStyles` is asked not only about the URL written in the document but also about every redirect target. On Node, redirects are followed one hop at a time (up to 20), and no request is sent to a target the function refuses. Redirects from `https:` to `http:` and redirects to non-`http(s):` targets are refused without asking the function (also when the option is `true`). In browsers, scripts cannot read a redirect target in advance, so the function is asked about the final URL after the browser has followed the redirects, and the response is discarded if it is refused (the request itself has already reached the redirect target). The function only sees the URL string: a host name that resolves to an internal address (including DNS rebinding) cannot be stopped by it. To protect an internal network when typesetting documents written by others on a server, also restrict the runtime itself (egress rules, an outbound proxy). Resources fetched from the network have size limits (images 256 MB, CSS 16 MB, fonts 128 MB); anything larger is abandoned mid-read and treated as an unreadable resource, even when the response has no `Content-Length`. The `fetchTimeoutMs` time limit applies until the body has been read completely
|
|
144
|
-
- `result.toPdf({ title, pdfx, imageMaxDpi })`: the PDF title, the PDF/X
|
|
152
|
+
- `result.toPdf({ title, pdfx, imageMaxDpi })`: the PDF title, the PDF/X marking (`pdfx: { version: 'X-1a' | 'X-1a:2003' | 'X-3' | 'X-4', condition, info, profile, warnings }`; RGB colors and images are converted to CMYK; X-3 by default; X-4 needs a CMYK ICC profile in `profile`; X-1a and X-3 flatten transparency and check the written PDF against their rules (see `--pdfx` on the command line); as with `--pdfx` on the command line, links, annotations and form fields on the pages are not written, and their number is added to `warnings`; bookmarks are kept), the upper limit of JPEG resolution. Warnings raised while writing the PDF (characters that cannot be drawn, color glyphs that cannot be drawn in color, etc.) are added to `result.warnings`. `result.renderPage(canvas, i, { scale, devicePixelRatio, guides })`: the scale, the device pixel density, and guide lines for the trim box and bleed
|
|
153
|
+
- `typesetToPdf(text, options, pdfOptions)`: makes only the PDF (the same PDF, warnings and page count as calling `toPdf(pdfOptions)` after `typeset`). The result is `{ pdf, pageCount, warnings, layoutMs }` (type `TypesetPdfResult`; `pdfOptions` has the type `PdfOptions`, the same as for `toPdf`). It turns the pages into the layout result (Area Tree) one at a time, writes each to the PDF and releases it, so it never holds the layout result of the whole document, and documents of thousands of pages use less memory (the layout result of a page is built twice, once to collect the fonts and images used and once to draw it). There is no `areaTree` or `renderPage`. `layoutMs` does not include the time to turn the pages into layout results (it is part of writing the PDF). The Node command also makes PDFs with it. With `lowMemory: true` in `pdfOptions`, it typesets with less memory (type `TypesetPdfOptions`; the same as the command's `--low-memory`). The container from `createTypesetter()` also has `typesetter.typesetToPdf(text, options, pdfOptions)`
|
|
145
154
|
- Internal entities declared in the internal subset of the FO's DOCTYPE (such as `<!ENTITY nbsp " ">`) are expanded before import (external entities are not read)
|
|
146
155
|
- Exceptions: `typeset` throws when the FO's XML cannot be parsed (`XML の解析に失敗しました: …`, "failed to parse XML: …") and when the default fonts cannot be read (`書体を読めません: …`, "cannot read font: …"). A corrupt font file passed in `fonts` does not throw but goes into `warnings`. A nonexistent page number for `renderPage` is a `RangeError`. Typesetting warnings (unreadable images, overflow, etc.) do not throw but go into `result.warnings` (an array of strings)
|
|
147
156
|
- `resolveResource(url)`: asked for each file the document or the CSS references (`<link rel="stylesheet">`, `@import`, `url()`, `<img src>`, etc.) that is not in `files`. `url` is the reference as written (`file:///…/a.css`, `img/a.png`, `https://…`); relative references inside a CSS file are resolved against that CSS file's URL. If it returns content (a string, `Uint8Array` or `ArrayBuffer`), that is used; if it returns `undefined`, things work as before (`http(s):` images and stylesheets are fetched from the network). There is no need to rewrite the references and put the files into `files`. An image is recognized from the leading bytes of the returned content, even when its URL has no extension (such as `https://example.com/img?id=1`)
|
|
157
|
+
- `drawio`: options for draw.io (diagrams.net) diagram files (`.drawio`, `.dio`; the type is `DrawioOptions`). By default, draw.io diagrams are read as images, and a page is converted to SVG and placed in the PDF as shapes and text (the code that draws diagrams is loaded only when a diagram appears). It has `stencils` (shape library and distributed image files), `fetchStencils` (whether to fetch missing shape libraries and images from draw.io's distribution; default `false`), `stencilsUrl` and `provideStencils`. With `false`, draw.io diagrams are not read as images. The syntax, page selection and what is drawn are described in [`docs/en/drawio.md`](docs/en/drawio.md)
|
|
158
|
+
- `plugins`: an array of plugins. For now plugins can only add image formats (`{ apiVersion: 1, name, imageFormats: [{ name, mime, extensions, sniff, load }] }`; the types are `KumioriPlugin` and `ImageFormat`). When an image file matches a format's `sniff` (a synchronous check of the content), its `load` (asynchronous) returns SVG and a size, and Kumiori draws it as an SVG image (it goes into the PDF as shapes). Files named with the `extensions` are also read as images when the document mentions them. `load` receives `measureText` (measures text with the fonts that draw it), `fetchResource` (fetches under the same rules as the document's images: `resolveResource` and `fetchImages`), `fetch` (fetches what the user allowed through the plugin's own options), `warn` (reports a warning) `lang` (the language for warnings, `ja` or `en`; `TypesetOptions.lang`) and `fragment` (the part of the image reference after `#`, to select which diagram or page of a file to draw; when the same file is referenced with different fragments, `load` is called once per reference and each becomes its own image). Heavy code can be loaded with `import()` inside `load`, so that it is loaded only when a file of that format appears. `apiVersion` is the version of the plugin interface (`PLUGIN_API_VERSION`), raised on incompatible changes. The results of `load` have limits (the same applies to draw.io diagrams; `src/imageFormats.ts`): the size must be finite and at most 10 million px, the SVG may be about 33.6 million characters plus 128 characters per byte of the file (at most about 134 million characters), the time limit is 60 seconds plus three times the fetch time limit (`fetchTimeoutMs`) (150 seconds by default), and one file can be read through at most 64 references with different fragments after `#`. Anything beyond these is treated as an unreadable image, with a warning. A plugin runs with the same rights as Kumiori, so pass only plugins you chose and trust. Plugin formats are checked before the core's formats (draw.io diagrams)
|
|
148
159
|
- In Node, the helpers in `kumiori/node` can be used: `createFontLoader({ fontDir, cacheDir, log, timeoutMs })` returns a `loadFont` that reads the default fonts the same way as the Node CLI (`fontDir` → the font cache → the network; fetched fonts are saved in the cache. `cacheDir` defaults to `defaultFontCacheDir()`; `null` disables the cache). `createFileResolver({ root })` returns a `resolveResource` that reads files referenced with `file:` URLs (with `root`, only files inside it are read; `root` may also be a list of directories, and containment is checked on the real paths after resolving symbolic links)
|
|
149
160
|
|
|
150
161
|
```ts
|
|
@@ -155,11 +166,11 @@ result.renderPage(canvas, 0); // draw page 1 on
|
|
|
155
166
|
- The fonts used by default can be found in `DEFAULT_FONTS` (the `family`, `weight` and `urls` of the `spec` passed to `loadFont`)
|
|
156
167
|
- Only what is exported from `src/index.ts` (and `src/node.ts` for Node) is public (the functions and types of other modules may change between versions)
|
|
157
168
|
- `kumiori` (`dist-lib/index.js`) is an ES module that does not bundle its dependencies (pdf-lib, fontkit, xmldom, etc.). Use it with a bundler such as Vite or webpack, or load it from Node. It is ES module only, but `require('kumiori')` also works (on Node 20.19.0 or later and 22.12.0 or later, which can load ES modules with `require()`; Node 22.0 to 22.11 needs `--experimental-require-module`)
|
|
158
|
-
- In a browser without a bundler, use `kumiori/browser`, a single file with the dependencies bundled (`dist-browser/kumiori.js`; about 2.
|
|
169
|
+
- In a browser without a bundler, use `kumiori/browser`, a single file with the dependencies bundled (`dist-browser/kumiori.js`; about 2.8MB, 0.9MB gzipped, or about 3.4MB together with the separate files it loads at start (`chunks/`, such as pdf-lib and pako; pdf-lib is a separate file because it is shared with the code for draw.io diagrams); the hyphenation dictionaries, the CGM, EPS, WMF, EMF and draw.io diagram processing and the like are loaded as separate files only when used). The version published on npm can be loaded directly from the jsDelivr or unpkg CDN:
|
|
159
170
|
|
|
160
171
|
```html
|
|
161
172
|
<script type="module">
|
|
162
|
-
import { typesetHtml } from 'https://cdn.jsdelivr.net/npm/kumiori@0.
|
|
173
|
+
import { typesetHtml } from 'https://cdn.jsdelivr.net/npm/kumiori@0.4.0/dist-browser/kumiori.js';
|
|
163
174
|
const result = await typesetHtml(html, { name: 'a.html' });
|
|
164
175
|
result.renderPage(document.querySelector('canvas'), 0);
|
|
165
176
|
</script>
|
|
@@ -222,10 +233,15 @@ async function showPreview(bodyHtml: string, container: HTMLElement) {
|
|
|
222
233
|
| `src/htmlImport.ts`, `src/htmlPaged.ts`, `src/htmlPrepare.ts`, `src/htmlFrame.ts` | HTML+CSS import (computed values → logical tree, CSS for paged typesetting, collecting the CSS, import in the web app (the own cascade by default, a browser iframe for comparison)) |
|
|
223
234
|
| `src/cssCascade.ts`, `src/cssSelector.ts`, `src/cssText.ts` | CSS interpretation without a browser (cascade, computed values, selectors), CSS lexical helpers (separators, lengths, colors) |
|
|
224
235
|
| `src/xslfoImport.ts`, `src/foExpr.ts`, `src/foDom.ts`, `src/foContext.ts`, `src/foPageMaster.ts`, `src/foMathFallback.ts` | XSL-FO import (attributes → logical tree, expression evaluation, minimal DOM, page masters, MathML typesetting when no math font is available) |
|
|
225
|
-
| `src/svg.ts`, `src/mathLayout.ts` | Converting SVG to shapes, MathML typesetting |
|
|
226
|
-
| `src/jpeg.ts`, `src/webp.ts`, `src/vp8.ts`, `src/pixels.ts`, `src/ccitt.ts`, `src/imageLimits.ts`, `src/metafile.ts`, `src/cgm.ts`, `src/eps.ts`, `src/ps*.ts` (`psInterp`, `psGraphics`, `psOps*` per operator group, `psResources`, `psColorSpace`, `psFonts`, `psCff`, `psEncodings`, `psShading`, `psFilters`), `src/imageInfo.ts`, `src/base64.ts` | Image decoding (JPEG, WebP, GIF, BMP, TIFF) and limits, conversion of WMF/EMF, CGM and EPS (PostScript interpreter) to shapes, reading image dimensions |
|
|
236
|
+
| `src/svg.ts`, `src/svgFilterRaster.ts`, `src/mathLayout.ts` | Converting SVG to shapes (filters that cannot be approximated with shapes are computed in pixels), MathML typesetting |
|
|
237
|
+
| `src/jpeg.ts`, `src/webp.ts`, `src/vp8.ts`, `src/pixels.ts`, `src/ccitt.ts`, `src/imageLimits.ts`, `src/metafile.ts`, `src/cgm.ts`, `src/eps.ts`, `src/ps*.ts` (`psInterp`, `psGraphics`, `psOps*` per operator group, `psResources`, `psColorSpace`, `psFonts`, `psCff`, `psEncodings`, `psShading`, `psFilters`), `src/imageInfo.ts`, `src/imageFormats.ts`, `src/base64.ts` | Image decoding (JPEG, WebP, GIF, BMP, TIFF) and limits, conversion of WMF/EMF, CGM and EPS (PostScript interpreter) to shapes, reading image dimensions, and the hook for image formats kept outside the core and loaded only when needed |
|
|
227
238
|
| `src/epub.ts`, `src/xhtml.ts` | EPUB extraction, XHTML import |
|
|
228
239
|
| `src/fontMapping.ts`, `src/compat.ts`, `src/documentResources.ts`, `src/documentText.ts`, `src/cli.ts` | Font assignment, compatibility mode settings, fetching the math font and images, character encoding detection (shared by the web app and Node); the Node CLI |
|
|
240
|
+
| `src/webFont.ts`, `src/fontLoader.ts`, `src/userFonts.ts` | Converting WOFF and WOFF2 back to TTF and OTF, splitting the user's font files (including TTC) into single fonts and reading their names, storing the fonts loaded in the web app |
|
|
241
|
+
| `src/colorGlyph.ts`, `src/colorGlyphPdf.ts`, `src/colorGlyphCanvas.ts`, `src/colorGlyphSvg.ts` | Reading color glyphs (color emoji and the like) from the font tables and drawing them to PDF and Canvas (including glyphs in the OpenType SVG table) |
|
|
242
|
+
| `src/color.ts`, `src/cssColorFunctions.ts`, `src/cssGradient.ts`, `src/icc.ts`, `src/pdfStandard.ts` | Parsing color values, the CSS Color 4 and 5 color functions, CSS gradients, conversion to CMYK with an ICC profile, the policies for PDF/X-1a, PDF/X-3 and PDF/X-4 |
|
|
243
|
+
| `src/assets.ts`, `src/linkPolicy.ts`, `src/messages.ts` | The image registry (shared by layout, Canvas and PDF), the policy for which PDF action a link leaving the document becomes, the user-facing messages (Japanese and English) |
|
|
244
|
+
| `src/drawio/` | Reads draw.io diagrams (`.drawio`, `.dio`) and converts them to SVG (shape and edge drawing ported from the source of draw.io and mxGraph; loaded only when a diagram appears; [`docs/en/drawio.md`](docs/en/drawio.md)) |
|
|
229
245
|
|
|
230
246
|
For details of the typesetting algorithms see [`docs/en/REPORT.md`](docs/en/REPORT.md), for XSL-FO import [`docs/en/xslfo-import.md`](docs/en/xslfo-import.md), and for the plan for HTML+CSS import [`docs/en/html-css-plan.md`](docs/en/html-css-plan.md).
|
|
231
247
|
Per-item descriptions of the supported specifications are in the Conformance Guide ([`docs/conformance/`](docs/en/conformance.md); `npm run docs:conformance` turns it into PDFs; the PDFs for each version are attached to the GitHub release), features not yet available and known limitations are in [`docs/en/BACKLOG.md`](docs/en/BACKLOG.md), and the JSON of the typeset result (Area Tree) is described in [`docs/en/area-tree.md`](docs/en/area-tree.md).
|
|
@@ -241,6 +257,7 @@ The fonts for typesetting are not included in this repository. They are fetched
|
|
|
241
257
|
| Cousine | When monospace is specified | Apache License 2.0 |
|
|
242
258
|
| STIX Two Math | When there are formulas (MathML). MathML is typeset with the values of this font's MATH table | SIL Open Font License 1.1 |
|
|
243
259
|
| Noto Sans Symbols 2 | When the document contains symbols (such as ✈) found in none of the loaded fonts | SIL Open Font License 1.1 |
|
|
260
|
+
| Noto Emoji | When the document contains emoji (such as 😀 or flags) not found in the symbol font either. Monochrome outline emoji (for colour emoji, pass a font such as Noto Color Emoji with `--font` or `@font-face`) | SIL Open Font License 1.1 |
|
|
244
261
|
|
|
245
262
|
Every document loads the eight files of the first two rows (four Japanese and four Latin; about 29MB in total, of which Noto Serif JP is 8.0MB per file and Noto Sans JP 5.7MB per file); the others are loaded only when the document needs them. Bold text is typeset in the Bold of the same font (bold text in Mincho uses Noto Serif JP Bold).
|
|
246
263
|
|
|
@@ -255,6 +272,10 @@ The fonts used are embedded in the PDF. Check the license terms of each font wit
|
|
|
255
272
|
- Absolute positioning (`absolutePosition`) is relative to the **top left of the trim box**. To reach into the bleed, specify negative `top/left`.
|
|
256
273
|
- `width/height` default to `content-box`. `boxSizing: 'border-box'` makes them include padding/border.
|
|
257
274
|
|
|
275
|
+
## Reporting vulnerabilities
|
|
276
|
+
|
|
277
|
+
If you find a vulnerability, please do not post it in a public issue. Report it privately as described in [SECURITY.en.md](SECURITY.en.md).
|
|
278
|
+
|
|
258
279
|
## License
|
|
259
280
|
|
|
260
281
|
The code is under the [Apache License 2.0](LICENSE) (Copyright 2026 Northern Lights Co.; see [NOTICE](NOTICE)). The fonts for typesetting are not bundled in this repository (for the fonts and their licenses, see the "[Fonts](#fonts)" section).
|
|
@@ -265,7 +286,9 @@ The licenses and copyright notices of the third-party software Kumiori uses (pdf
|
|
|
265
286
|
|
|
266
287
|
Kumiori is an independent project, unrelated to Antenna House's products or to typesetting software such as WeasyPrint and Vivliostyle. It has not received approval or support from these companies or projects.
|
|
267
288
|
|
|
268
|
-
|
|
289
|
+
Kumiori is also not affiliated with draw.io (JGraph Ltd, draw.io AG); draw.io is a registered trademark. The feature that reads draw.io diagram files was built by porting draw.io's public source code (section 13 of `THIRD_PARTY_NOTICES.md`), and is not approved or supported by draw.io.
|
|
290
|
+
|
|
291
|
+
The product and company names appearing in the README and docs are the trademarks or names of their respective owners. Kumiori uses these names to describe its compatibility features (import of the `axf:*` extensions, the default values of `--compat antenna`, etc.). The name draw.io is used to describe the feature that reads draw.io diagram files (`.drawio`, `.dio`).
|
|
269
292
|
|
|
270
293
|
## About the development method
|
|
271
294
|
|
|
@@ -280,11 +303,15 @@ Third-party code and licenses are checked with tools before each release (see [T
|
|
|
280
303
|
```bash
|
|
281
304
|
npm test # unit tests (Node + fontkit; fetches Noto Serif JP into .cache/fonts)
|
|
282
305
|
npm run e2e # browser integration tests (Playwright; on first run, npx playwright install chromium)
|
|
306
|
+
npm run ci:local # the same steps as the build and e2e jobs of CI (.github/workflows/ci.yml) and the web app build of GitHub Pages (.github/workflows/pages.yml): npm ci, the three builds, the web app build with the asset base changed, unit tests and integration tests
|
|
283
307
|
```
|
|
284
308
|
|
|
309
|
+
`npm run ci:local` (`scripts/ci-local.mjs`) runs the steps of the CI jobs locally in order and lists the result of each step at the end. Choose the jobs with `-- --job build|pages|node-min|e2e` (repeatable; build, pages and e2e when none is given; for node-min, switch to Node 20.19.x, the lowest supported version, first). Like `pages.yml`, pages builds the web app with the asset base set to the repository name (taken from `repository.url` in `package.json`: `/kumiori/`), and checks that the asset references in the output `index.html` start with that base (the output goes to a temporary place and is removed, so `dist/` is not changed). With `-- --worktree`, the current commit (HEAD) is checked out to a temporary place and tested there (as in CI, uncommitted changes and earlier build outputs are not mixed in). `-- --no-install` skips the initial `npm ci`.
|
|
310
|
+
|
|
285
311
|
The fonts used by the tests are fetched on first run into `.cache/fonts` (changeable with `KUMIORI_FONT_DIR`). They come from Google Fonts (`fonts.gstatic.com`) and, for the PostScript font tests, Source Sans 3 (adobe-fonts/source-sans on `raw.githubusercontent.com`). Fetching is done in one place, `test/helpers.ts`; when a test needs another font, add it to the list there (the list is part of the CI cache key).
|
|
286
312
|
The official Unicode conformance tests (`LineBreakTest.txt` for UAX #14, `GraphemeBreakTest.txt` for UAX #29, `BidiTest.txt` and `BidiCharacterTest.txt` for UAX #9) are likewise fetched on first run from `unicode.org` (`https://www.unicode.org/Public/<version>/ucd/`) into `.cache/unicode` (changeable with `KUMIORI_UCD_DIR`). Fetching is done in one place, `test/ucdTestData.ts`, and the version follows the UCD version the tables in `src/unicodeData.ts` were generated from. Where they cannot be fetched, the tests check only a small hand-written set of sequences in place of the official data.
|
|
287
313
|
For the integration tests, setting `KUMIORI_E2E_FONT_CACHE` to a directory makes the browser's fetched fonts be stored there, so later runs do not use the network (CI uses this). `KUMIORI_E2E_FONT_DIR` is for supplying fonts by hand under fixed file names.
|
|
314
|
+
The integration tests and the comparison scripts (`scripts/compare-pdf.mjs`, `scripts/compare-css.mjs`) use the Chromium executable that `KUMIORI_CHROMIUM` points at instead of the Chromium Playwright downloaded (for environments where the Playwright version and the installed Chromium do not match; for example `KUMIORI_CHROMIUM=/opt/pw-browsers/chromium npm run e2e`). Without it, they use the Chromium Playwright downloaded.
|
|
288
315
|
|
|
289
316
|
Comparison with sample PDFs (prepare the sample FO and PDF files yourself; they are not in the repository. poppler's pdftoppm is required):
|
|
290
317
|
|
|
@@ -292,12 +319,25 @@ Comparison with sample PDFs (prepare the sample FO and PDF files yourself; they
|
|
|
292
319
|
node scripts/compare-pdf.mjs --fo <FO directory> --ref <sample PDF directory> --img <image directory> --out compare-pdf-out
|
|
293
320
|
```
|
|
294
321
|
|
|
322
|
+
`scripts/fetch-samples.mjs` fetches the samples from their publishers into `.cache/samples` (ignored by git; add `NODE_USE_ENV_PROXY=1` when going through a proxy). It fetches Antenna House's "Sample FO collection" (the FO files and the PDFs AH Formatter produced) and the 4th edition of "CSS Page Composition Primer" (the PDF and its source files), and writes the source URL, size and SHA-256 of each file to `manifest.json`. The fetched files are laid out so they can be passed to compare-pdf.mjs as they are:
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
node scripts/fetch-samples.mjs
|
|
326
|
+
node scripts/compare-pdf.mjs --fo .cache/samples/fo/fo --ref .cache/samples/fo/ref --img .cache/samples/fo/img --compat antenna --out compare-pdf-out
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
`.cache/samples/fo/groups.json` lists the sample names split by category into four groups (the grouping of the published comparison pages).
|
|
330
|
+
`--pack <directory>` bundles the fetched files (the zips, the PDFs and `manifest.json`) into a tar, splits it into 10MB pieces and wraps each in base64 JavaScript (for stores that do not accept zip or tar files, such as a claude.ai Artifact). `--unpack <directory>` checks the pieces' SHA-256, restores them and extracts them without using the network (the same as `--offline`).
|
|
331
|
+
When the comparison scripts cannot find the Chromium Playwright downloaded (when the Playwright version and the installed Chromium do not match), point `KUMIORI_CHROMIUM` at a Chromium executable, as for the integration tests.
|
|
332
|
+
|
|
295
333
|
Each FO is paired with the PDF of the same name. `compare-pdf-out/report.md` lists the page count of each sample and the difference of each page (largest differences first). Add `--compat antenna` when comparing with Antenna House samples (the default is spec mode). To typeset with the same fonts as the samples, pass the font files with `--fonts <directory>`, and replace the default fonts used for the generic families (`serif`, `sans-serif`) with `--web-fonts <directory>` (put MS Mincho, MS Gothic, Times New Roman, Arial and Courier New under names such as `notoserif.ttf`, `notosans.ttf`, `tinos400.ttf`, `arimo400.ttf` and `cousine400.ttf`; extract the first font of a TTC as a TTF; fonts not in the directory are fetched from their source).
|
|
296
334
|
|
|
335
|
+
When the samples are painted with spot colors (PDF Separation colors, such as PANTONE 627 PC in the 4th edition of "CSS Page Composition Primer"), extract the spot color names and the alternate CMYK at 100% tint written in the sample PDF with `node scripts/spot-colors-from-pdf.mjs <sample PDF> -o spot-colors.json`, and typeset with `--spot-colors spot-colors.json` on the Node command (Kumiori has no spot color values, so without it the colors are painted with the alternate RGB and differ from the samples). Compare the resulting PDF with `--pdf`.
|
|
336
|
+
|
|
297
337
|
To build a page for comparing the samples and Kumiori's output by eye (the sample PDFs and Kumiori's PDFs are paired by the same name):
|
|
298
338
|
|
|
299
339
|
```bash
|
|
300
340
|
node scripts/compare-view.mjs --ref <sample PDF directory> --pdf <Kumiori PDF directory> --out compare-view-out
|
|
301
341
|
```
|
|
302
342
|
|
|
303
|
-
Open `compare-view-out/index.html` in a browser. The samples are sorted with the largest differences first, and for each page you can switch between "Side by side", "Overlay" (with adjustable opacity), "Blink" and "Diff" (blue where only the sample has text or lines, red where only Kumiori does). `--inline` produces a single HTML file with the images embedded. `--jpeg` makes the page images JPEG to reduce their size. `--artifact` writes it out in a form for publishing as a claude.ai Artifact (the diff images are drawn in the browser).
|
|
343
|
+
Open `compare-view-out/index.html` in a browser. The samples are sorted with the largest differences first, and for each page you can switch between "Side by side", "Overlay" (with adjustable opacity), "Blink" and "Diff" (blue where only the sample has text or lines, red where only Kumiori does). `--inline` produces a single HTML file with the images embedded. `--jpeg` makes the page images JPEG to reduce their size. `--artifact` writes it out in a form for publishing as a claude.ai Artifact (the diff images are drawn in the browser). `--ref-label` and `--pdf-label` change the names of the left and right sides (default "見本" (sample) and "Kumiori"), and `--title` changes the page title (for comparing home-made FO documents that have no sample, rendered in Kumiori's two modes or by another formatter; the home-made samples are in `samples/check/`).
|