kumiori 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.
Files changed (126) hide show
  1. package/CHANGELOG.en.md +97 -2
  2. package/CHANGELOG.md +98 -3
  3. package/NOTICE +2 -0
  4. package/README.en.md +53 -17
  5. package/README.md +53 -17
  6. package/THIRD_PARTY_NOTICES.md +364 -26
  7. package/dist-browser/NOTICE +2 -0
  8. package/dist-browser/THIRD_PARTY_NOTICES.md +364 -26
  9. package/dist-browser/chunks/{UTIF-DJ2yEO_P.js → UTIF-D5qoainF.js} +4 -4
  10. package/dist-browser/chunks/ccitt-7WmwG6OA.js +1640 -0
  11. package/dist-browser/chunks/cgm-DUIP-hbA.js +2103 -0
  12. package/dist-browser/chunks/{el-monoton-Bh-cSidd.js → el-monoton-BVsCvfmZ.js} +4 -4
  13. package/dist-browser/chunks/{en-gb-DLCXyvjY.js → en-gb-Cjtf0A6r.js} +4 -4
  14. package/dist-browser/chunks/{en-us-BBLcTX9N.js → en-us-B_UiZPbu.js} +4 -4
  15. package/dist-browser/chunks/eps-_CPowVcQ.js +5237 -0
  16. package/dist-browser/chunks/epsInfo-BUAZ97F-.js +565 -0
  17. package/dist-browser/chunks/{export-contract-DDGE_g3K.js → export-contract-OHP-GNO0.js} +3 -3
  18. package/dist-browser/chunks/{la-D46x91kc.js → la-7qtmi2aU.js} +4 -4
  19. package/dist-browser/chunks/load-BRpJTflg.js +16686 -0
  20. package/dist-browser/chunks/matrix-BcBTRcOc.js +48 -0
  21. package/dist-browser/chunks/metafile-BikFmcYd.js +1867 -0
  22. package/dist-browser/chunks/{pako-CeDDB8tF.js → pako-Dl02IHsa.js} +6 -6
  23. package/dist-browser/chunks/pixels-ByXzkjlj.js +714 -0
  24. package/dist-browser/chunks/{rolldown-runtime-BXCUS5Bd.js → rolldown-runtime-Bra2mvh4.js} +2 -2
  25. package/dist-browser/chunks/{ru-CkmoNumx.js → ru-BMiVc5Ts.js} +4 -4
  26. package/dist-browser/chunks/sniff-B_ueafAB.js +8779 -0
  27. package/dist-browser/chunks/strokeOutline-DA-aSg5C.js +1107 -0
  28. package/dist-browser/chunks/{uk-DIZr4Urv.js → uk-ChOFgYc8.js} +4 -4
  29. package/dist-browser/kumiori.js +23159 -38999
  30. package/dist-cli/NOTICE +2 -0
  31. package/dist-cli/THIRD_PARTY_NOTICES.md +364 -26
  32. package/dist-cli/assets/cgm-CVN2h83E.js +3239 -0
  33. package/dist-cli/assets/drawioStencil-Bzai2moR.js +991 -0
  34. package/dist-cli/assets/eps-BK1bEizE.js +7496 -0
  35. package/dist-cli/assets/load-BwlOZ5Bc.js +39125 -0
  36. package/dist-cli/assets/metafile-DmYDB8sR.js +2522 -0
  37. package/dist-cli/cli.js +53167 -56741
  38. package/dist-lib/NOTICE +2 -0
  39. package/dist-lib/THIRD_PARTY_NOTICES.md +364 -26
  40. package/dist-lib/{api-CQ3aOtc5.js → api-DB-5PKHp.js} +20086 -24380
  41. package/dist-lib/cgm-CkwJobkQ.js +2103 -0
  42. package/dist-lib/eps-D9WVND82.js +5236 -0
  43. package/dist-lib/epsInfo-BUAZ97F-.js +565 -0
  44. package/dist-lib/index.js +11 -12
  45. package/dist-lib/load-plWCtVUv.js +15328 -0
  46. package/dist-lib/metafile-BOfMQbwN.js +1867 -0
  47. package/dist-lib/node.js +4 -5
  48. package/dist-lib/pixels-ByXzkjlj.js +714 -0
  49. package/dist-lib/types/api.d.ts +26 -1
  50. package/dist-lib/types/areaTree.d.ts +3 -1
  51. package/dist-lib/types/assets.d.ts +57 -3
  52. package/dist-lib/types/base64.d.ts +7 -0
  53. package/dist-lib/types/ccitt.d.ts +1 -1
  54. package/dist-lib/types/cgm.d.ts +2 -2
  55. package/dist-lib/types/color.d.ts +9 -3
  56. package/dist-lib/types/colorGlyphPdf.d.ts +4 -0
  57. package/dist-lib/types/compat.d.ts +11 -2
  58. package/dist-lib/types/cssSelector.d.ts +40 -1
  59. package/dist-lib/types/documentResources.d.ts +2 -1
  60. package/dist-lib/types/drawio/base64.d.ts +6 -0
  61. package/dist-lib/types/drawio/drawio.d.ts +137 -0
  62. package/dist-lib/types/drawio/drawioCanvas.d.ts +156 -0
  63. package/dist-lib/types/drawio/drawioEdges.d.ts +89 -0
  64. package/dist-lib/types/drawio/drawioJs/archimate.d.ts +33 -0
  65. package/dist-lib/types/drawio/drawioJs/arrows.d.ts +37 -0
  66. package/dist-lib/types/drawio/drawioJs/aws3d.d.ts +18 -0
  67. package/dist-lib/types/drawio/drawioJs/basic.d.ts +29 -0
  68. package/dist-lib/types/drawio/drawioJs/bpmn.d.ts +35 -0
  69. package/dist-lib/types/drawio/drawioJs/edges.d.ts +19 -0
  70. package/dist-lib/types/drawio/drawioJs/electrical.d.ts +29 -0
  71. package/dist-lib/types/drawio/drawioJs/misc.d.ts +34 -0
  72. package/dist-lib/types/drawio/drawioJs/mockup.d.ts +27 -0
  73. package/dist-lib/types/drawio/drawioJs/mockupIos.d.ts +2 -0
  74. package/dist-lib/types/drawio/drawioJs/ui.d.ts +34 -0
  75. package/dist-lib/types/drawio/drawioShapes.d.ts +51 -0
  76. package/dist-lib/types/drawio/drawioShapesA.d.ts +23 -0
  77. package/dist-lib/types/drawio/drawioShapesB.d.ts +26 -0
  78. package/dist-lib/types/drawio/drawioSketch.d.ts +50 -0
  79. package/dist-lib/types/drawio/drawioStencil.d.ts +159 -0
  80. package/dist-lib/types/drawio/drawioTapered.d.ts +67 -0
  81. package/dist-lib/types/drawio/drawioText.d.ts +27 -0
  82. package/dist-lib/types/drawio/drawioXml.d.ts +40 -0
  83. package/dist-lib/types/drawio/index.d.ts +37 -0
  84. package/dist-lib/types/drawio/inflate.d.ts +12 -0
  85. package/dist-lib/types/drawio/load.d.ts +35 -0
  86. package/dist-lib/types/drawio/messages.d.ts +12 -0
  87. package/dist-lib/types/drawio/options.d.ts +44 -0
  88. package/dist-lib/types/drawio/prefixSums.d.ts +9 -0
  89. package/dist-lib/types/drawio/sniff.d.ts +16 -0
  90. package/dist-lib/types/eps.d.ts +2 -28
  91. package/dist-lib/types/epsInfo.d.ts +36 -0
  92. package/dist-lib/types/fontMapping.d.ts +14 -0
  93. package/dist-lib/types/fontSanity.d.ts +15 -0
  94. package/dist-lib/types/hebrewMarks.d.ts +11 -3
  95. package/dist-lib/types/htmlImport.d.ts +22 -0
  96. package/dist-lib/types/htmlPaged.d.ts +15 -2
  97. package/dist-lib/types/htmlParserStack.d.ts +26 -0
  98. package/dist-lib/types/htmlPrepare.d.ts +6 -2
  99. package/dist-lib/types/imageFormats.d.ts +138 -0
  100. package/dist-lib/types/imageInfo.d.ts +6 -1
  101. package/dist-lib/types/imageLimits.d.ts +4 -4
  102. package/dist-lib/types/index.d.ts +6 -1
  103. package/dist-lib/types/inflateFast.d.ts +12 -0
  104. package/dist-lib/types/inlineLayout.d.ts +16 -0
  105. package/dist-lib/types/jis.d.ts +19 -0
  106. package/dist-lib/types/layoutEngine.d.ts +34 -2
  107. package/dist-lib/types/linearText.d.ts +69 -0
  108. package/dist-lib/types/lnode.d.ts +10 -0
  109. package/dist-lib/types/pdfCheck.d.ts +36 -0
  110. package/dist-lib/types/pdfLibPatches.d.ts +1 -1
  111. package/dist-lib/types/pdfRenderer.d.ts +38 -12
  112. package/dist-lib/types/pdfStandard.d.ts +78 -0
  113. package/dist-lib/types/pixels.d.ts +21 -3
  114. package/dist-lib/types/psFilters.d.ts +4 -14
  115. package/dist-lib/types/psShading.d.ts +1 -24
  116. package/dist-lib/types/resources.d.ts +2 -2
  117. package/dist-lib/types/strokeOutline.d.ts +32 -0
  118. package/dist-lib/types/svg.d.ts +236 -10
  119. package/dist-lib/types/svgFilterRaster.d.ts +28 -0
  120. package/dist-lib/types/svgFilterSubregion.d.ts +46 -0
  121. package/dist-lib/types/tableBorders.d.ts +33 -4
  122. package/dist-lib/types/types.d.ts +64 -4
  123. package/package.json +5 -1
  124. package/dist-lib/api-CQ3aOtc5.js.map +0 -1
  125. package/dist-lib/index.js.map +0 -1
  126. 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 60,000 lines of TypeScript, about 1,900 tests**: Each time a feature is added, the AI adds tests, and CI (type checking, unit tests, and 15 browser integration tests) passes
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 emoji and variable fonts are in sections 5.6 and 5.7 of the HTML and CSS volume
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-3 marking (`pdfx` in the API) has been verified only for the parts defined by the PDF specification ISO 32000-2 (such as the form of the output intent dictionary). It has not been verified against the text of the PDF/X standard ISO 15930, so conformance to that standard is not guaranteed
26
+ - **Output**: Canvas preview, PDF (subset font embedding, bookmarks, links, annotations, forms, trim marks, 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 font loading
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 and the images the document references via `http(s):`). It also works when the `dist/` from `npm run build` is placed on a static web server
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
 
@@ -96,20 +96,25 @@ cat book.html | node dist-cli/cli.js - -o - --base . > book.pdf
96
96
  - 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
97
  - `--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
98
  - `--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
- - `--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) 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
99
+ - `--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
100
+ - `--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
101
  - `--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
102
  - `--no-font-cache`: neither reads nor writes the font cache (fetches from Google Fonts every time)
102
103
  - `--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
104
  - `--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
105
  - `--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"`
106
+ - `--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)
107
+ - `--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
108
  - `--print`: trim marks and bleed (3mm)
106
109
  - `--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)
110
+ - `--pdfx x3|x4`: write 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). With PDF/X-3, using transparency is reported in a warning; PDF/X-4 keeps transparency as is and writes the version marker in the XMP metadata. Japanese printers mainly use PDF/X-4 (and PDF/X-1a)
111
+ - `--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
112
  - `--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
113
  - 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
114
  - 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
115
  - 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
116
  - 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. filters other than shadows and blur) is drawn as a placeholder frame with a warning (the web app rasterizes and draws it)
117
+ - 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
118
 
114
119
  ### Using as a library (from TypeScript or JavaScript)
115
120
 
@@ -139,12 +144,14 @@ result.renderPage(canvas, 0); // draw page 1 on
139
144
 
140
145
  - `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
146
  - `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)
147
+ - 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
148
  - 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-3 marking (`pdfx`; RGB colors and images are converted to CMYK), the upper limit of JPEG resolution. `result.renderPage(canvas, i, { scale, devicePixelRatio, guides })`: the scale, the device pixel density, and guide lines for the trim box and bleed
149
+ - `result.toPdf({ title, pdfx, imageMaxDpi })`: the PDF title, the PDF/X marking (`pdfx: { version: '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`; 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
145
150
  - Internal entities declared in the internal subset of the FO's DOCTYPE (such as `<!ENTITY nbsp "&#160;">`) are expanded before import (external entities are not read)
146
151
  - 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
152
  - `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`)
153
+ - `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)
154
+ - `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
155
  - 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
156
 
150
157
  ```ts
@@ -155,11 +162,11 @@ result.renderPage(canvas, 0); // draw page 1 on
155
162
  - The fonts used by default can be found in `DEFAULT_FONTS` (the `family`, `weight` and `urls` of the `spec` passed to `loadFont`)
156
163
  - 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
164
  - `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.7MB, 0.9MB gzipped; the hyphenation dictionaries 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:
165
+ - 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
166
 
160
167
  ```html
161
168
  <script type="module">
162
- import { typesetHtml } from 'https://cdn.jsdelivr.net/npm/kumiori@0.2.0/dist-browser/kumiori.js';
169
+ import { typesetHtml } from 'https://cdn.jsdelivr.net/npm/kumiori@0.3.0/dist-browser/kumiori.js';
163
170
  const result = await typesetHtml(html, { name: 'a.html' });
164
171
  result.renderPage(document.querySelector('canvas'), 0);
165
172
  </script>
@@ -222,10 +229,15 @@ async function showPreview(bodyHtml: string, container: HTMLElement) {
222
229
  | `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
230
  | `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
231
  | `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 |
232
+ | `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 |
233
+ | `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
234
  | `src/epub.ts`, `src/xhtml.ts` | EPUB extraction, XHTML import |
228
235
  | `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 |
236
+ | `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 |
237
+ | `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) |
238
+ | `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-3 and PDF/X-4 |
239
+ | `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) |
240
+ | `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
241
 
230
242
  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
243
  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 +253,7 @@ The fonts for typesetting are not included in this repository. They are fetched
241
253
  | Cousine | When monospace is specified | Apache License 2.0 |
242
254
  | 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
255
  | Noto Sans Symbols 2 | When the document contains symbols (such as ✈) found in none of the loaded fonts | SIL Open Font License 1.1 |
256
+ | 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
257
 
245
258
  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
259
 
@@ -255,6 +268,10 @@ The fonts used are embedded in the PDF. Check the license terms of each font wit
255
268
  - Absolute positioning (`absolutePosition`) is relative to the **top left of the trim box**. To reach into the bleed, specify negative `top/left`.
256
269
  - `width/height` default to `content-box`. `boxSizing: 'border-box'` makes them include padding/border.
257
270
 
271
+ ## Reporting vulnerabilities
272
+
273
+ 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).
274
+
258
275
  ## License
259
276
 
260
277
  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 +282,9 @@ The licenses and copyright notices of the third-party software Kumiori uses (pdf
265
282
 
266
283
  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
284
 
268
- 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.).
285
+ 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.
286
+
287
+ 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
288
 
270
289
  ## About the development method
271
290
 
@@ -280,11 +299,15 @@ Third-party code and licenses are checked with tools before each release (see [T
280
299
  ```bash
281
300
  npm test # unit tests (Node + fontkit; fetches Noto Serif JP into .cache/fonts)
282
301
  npm run e2e # browser integration tests (Playwright; on first run, npx playwright install chromium)
302
+ 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
303
  ```
284
304
 
305
+ `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`.
306
+
285
307
  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
308
  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
309
  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.
310
+ 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
311
 
289
312
  Comparison with sample PDFs (prepare the sample FO and PDF files yourself; they are not in the repository. poppler's pdftoppm is required):
290
313
 
@@ -292,12 +315,25 @@ Comparison with sample PDFs (prepare the sample FO and PDF files yourself; they
292
315
  node scripts/compare-pdf.mjs --fo <FO directory> --ref <sample PDF directory> --img <image directory> --out compare-pdf-out
293
316
  ```
294
317
 
318
+ `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:
319
+
320
+ ```bash
321
+ node scripts/fetch-samples.mjs
322
+ 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
323
+ ```
324
+
325
+ `.cache/samples/fo/groups.json` lists the sample names split by category into four groups (the grouping of the published comparison pages).
326
+ `--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`).
327
+ 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.
328
+
295
329
  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
330
 
331
+ 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`.
332
+
297
333
  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
334
 
299
335
  ```bash
300
336
  node scripts/compare-view.mjs --ref <sample PDF directory> --pdf <Kumiori PDF directory> --out compare-view-out
301
337
  ```
302
338
 
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).
339
+ 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/`).
package/README.md CHANGED
@@ -13,18 +13,18 @@ Canvas のプレビューと PDF に出力します。
13
13
 
14
14
  Kumiori は、AI のコーディング支援 ([Claude Code](https://claude.com/claude-code)) を使って開発しています (「[開発の方法について](#開発の方法について)」)。
15
15
 
16
- - **TypeScript 約 6 万行・テスト約 1,900 件**: 機能を足すたびに AI がテストを書き足し、CI (型チェック・単体テスト・ブラウザでの結合テスト 15 件) を通しています
16
+ - **TypeScript 約 13.6 万行・テスト約 4,400 件**: 機能を足すたびに AI がテストを書き足し、CI (型チェック・単体テスト・ブラウザでの結合テスト 26 件) を通しています
17
17
  - **規格・仕様書を読んで実装する**: XSL-FO 1.1、CSS の各モジュール (Paged Media・GCPM・Writing Modes・Text・Ruby・Fragmentation など)、MathML Core、Unicode の UAX #9 (双方向) と UAX #14 (改行)、W3C の JLREQ (日本語組版処理の要件。JIS X 4051 に基づく)、PDF (ISO 32000) などの規格・仕様書を可能な限り読み、その定義に沿って実装しています。約物の詰め・ぶら下げ・ルビのはみ出しなど、日本語組版の細部も規格に基づいています。プロパティごとの対応状況と、仕様の定義・Kumiori での扱いは、対応仕様説明書 ([`docs/conformance/`](docs/conformance/README.md)) にまとめています
18
18
  - **公開されている PDF と比べて仕様を把握**: XSL-FO や CSS の組版ソフトが公開している見本の PDF と、Kumiori で組んだ結果を見比べて、仕様の解釈や細かな組み方を確かめています
19
19
 
20
20
  ## できること
21
21
 
22
- - **入力**: HTML+CSS (自前の CSS カスケード。ブラウザ不要)、XSL-FO (アンテナハウスの拡張 `axf:*` のうち、よく使われるものを中心に一部に対応)、JSON の論理ツリー
22
+ - **入力**: HTML+CSS (自前の CSS カスケード。ブラウザ不要)、XSL-FO (アンテナハウスの拡張 `axf:*` のうち、よく使われるものを中心に一部に対応)、JSON の論理ツリー。画像は PNG・JPEG・GIF・BMP・TIFF・WebP・SVG・WMF・EMF・EPS (PostScript)・CGM と、draw.io の図 (`.drawio`・`.dio`。[`docs/drawio.md`](docs/drawio.md))
23
23
  - **日本語組版**: 縦書き・横書き、ルビ、縦中横、圏点、禁則、ぶら下げ・追い出し、約物の詰め、和欧間のアキ
24
- - **多言語**: アラビア語・ヘブライ語などの右から左の文字 (Unicode の双方向アルゴリズム UAX #9 で並べ替え、アラビア文字は前後につながる字形にする。CSS の `direction: rtl`、XSL-FO の `writing-mode="rl-tb"`)、タイ語 (語の境目は実行環境の `Intl.Segmenter` の辞書で決めて折り返す)・デーヴァナーガリー (ヒンディー語など。結合子音などの書体の整形)・韓国語 (ハングル)、ほかのインド系の文字 (ベンガル・グルムキー・グジャラート・オリヤー・タミル・テルグ・カンナダ・マラヤーラム・シンハラ)、ラオ語・クメール語・ビルマ語 (ミャンマー文字)・チベット語、モンゴル文字 (横書きと縦書き)、中国語 (簡体字・繁体字)、ベトナム語・ギリシャ文字・キリル文字、欧文のハイフネーション (英語・ラテン語・ロシア語・ウクライナ語・現代ギリシャ語)、欧文と和文の混在。アラビア文字・タイ文字・デーヴァナーガリー・ハングル・簡体字と繁体字・絵文字などの書体は `--font` や `fonts` で渡す (既定の書体には無い。カラーの絵文字の書体は、色の付いたまま組める。ヘブライ文字・ギリシャ文字・キリル文字・ベトナム語の字は、既定の欧文の書体で組める)。言語と文字ごとの、要る書体・折り返し・縦書き・制限の一覧は、対応仕様説明書 ([`docs/conformance/`](docs/conformance/README.md)) の「対応している言語と文字」の節 (XSL-FO 1.1 編の 5.6 節、HTML と CSS 編の 5.8 節) にある。同じ節に、文字ごとの組版の見本 (世界人権宣言の第 1 条を、それぞれの文字の書体で組んだもの) があり、絵文字と可変フォントの見本は、HTML と CSS 編の 5.6 節・5.7 節にある
24
+ - **多言語**: アラビア語・ヘブライ語などの右から左の文字 (Unicode の双方向アルゴリズム UAX #9 で並べ替え、アラビア文字は前後につながる字形にする。CSS の `direction: rtl`、XSL-FO の `writing-mode="rl-tb"`)、タイ語 (語の境目は実行環境の `Intl.Segmenter` の辞書で決めて折り返す)・デーヴァナーガリー (ヒンディー語など。結合子音などの書体の整形)・韓国語 (ハングル)、ほかのインド系の文字 (ベンガル・グルムキー・グジャラート・オリヤー・タミル・テルグ・カンナダ・マラヤーラム・シンハラ)、ラオ語・クメール語・ビルマ語 (ミャンマー文字)・チベット語、モンゴル文字 (横書きと縦書き)、中国語 (簡体字・繁体字)、ベトナム語・ギリシャ文字・キリル文字、欧文のハイフネーション (英語・ラテン語・ロシア語・ウクライナ語・現代ギリシャ語)、欧文と和文の混在。アラビア文字・タイ文字・デーヴァナーガリー・ハングル・簡体字と繁体字・絵文字などの書体は `--font` や `fonts` で渡す (既定の書体には無い。カラーの絵文字の書体は、色の付いたまま組める。ヘブライ文字・ギリシャ文字・キリル文字・ベトナム語の字は、既定の欧文の書体で組める)。言語と文字ごとの、要る書体・折り返し・縦書き・制限の一覧は、対応仕様説明書 ([`docs/conformance/`](docs/conformance/README.md)) の「対応している言語と文字」の節 (XSL-FO 1.1 編の 5.6 節、HTML と CSS 編の 5.8 節) にある。同じ節に、文字ごとの組版の見本 (世界人権宣言の第 1 条を、それぞれの文字の書体で組んだもの) があり、可変フォントと絵文字の見本は、HTML と CSS 編の 5.6 節・5.7 節にある
25
25
  - **ページ**: ページマスター、柱・ノンブル、脚注、段組、回り込み、表 (行・ページをまたぐ分割、ヘッダーの繰り返し、列の幅の自動決定)、ページ番号の参照
26
- - **出力**: Canvas のプレビュー、PDF (書体のサブセット埋め込み、しおり、リンク、注釈、フォーム、トンボ、PDF/X-3 の印と、RGB の色・画像の CMYK への変換)
27
- - PDF/X-3 の印 (API の `pdfx`) は、PDF の仕様 ISO 32000-2 で決まっている部分 (出力意図の辞書の形など) だけを確かめています。PDF/X の規格 ISO 15930 の本文では確かめていないので、規格への適合は保証しません
26
+ - **出力**: Canvas のプレビュー、PDF (書体のサブセット埋め込み、しおり、リンク、注釈、フォーム、トンボ、PDF/X-3・PDF/X-4 の印と、RGB の色・画像の CMYK への変換)
27
+ - PDF/X の印 (API の `pdfx`、コマンドの `--pdfx`) は、PDF の仕様 ISO 32000-2 で決まっている部分 (出力意図の辞書の形、XMP のメタデータなど) だけを確かめています。PDF/X の規格 ISO 15930 の本文では確かめていないので、規格への適合は保証しません。入稿の前に、プリフライト (Acrobat Pro など) で確かめてください
28
28
  - **環境**: ブラウザ (Vite) と Node のコマンド (`dist-cli/cli.js`)
29
29
 
30
30
  内部では、XSL-FO の **Area Model** に従って全ボックスを pt 単位で計算し、**物理ツリー(Area Tree)** を組み上げてから
@@ -56,9 +56,9 @@ Node は 20.19.0 以上の 20 系か、22.12.0 以上 (CI は 20.19.0 と 22 で
56
56
  ### 画面 (ブラウザ)
57
57
 
58
58
  - 「開く」で HTML・XSL-FO・EPUB を、使う CSS・画像・書体と一緒に選ぶ (複数選べる)。「フォルダを開く」でフォルダごと選ぶか、ファイルやフォルダを画面にドラッグ&ドロップしても開ける。フォルダに文書が複数あるときは index.html (無ければ浅い場所の文書) を開く
59
- - 「PDF を保存」で PDF を書き出す。左にページの縮小画像と警告 (たためる)、右の「設定」に既定のスタイル・既定の用紙 (`@page` で `size` を指定していない HTML の用紙。A4・A5・B5・JIS-B5・letter と自由入力。コマンドの `--page-size` と同じ)・CSS の解釈・「仕様どおりの既定値で組む」(XSL-FO の既定値の流儀。コマンドの `--compat` と同じ)・トンボ・書体の読み込みがある
59
+ - 「PDF を保存」で PDF を書き出す。左にページの縮小画像と警告 (たためる)、右の「設定」に既定のスタイル・既定の用紙 (`@page` で `size` を指定していない HTML の用紙。A4・A5・B5・JIS-B5・letter と自由入力。コマンドの `--page-size` と同じ)・CSS の解釈・「仕様どおりの既定値で組む」(XSL-FO の既定値の流儀。コマンドの `--compat` と同じ)・トンボ・書体の読み込み・draw.io の図 (読む・読まない、図形ライブラリ。[`docs/drawio.md`](docs/drawio.md)) がある
60
60
  - 警告は、左の欄に 1 件ずつ並ぶ (同じ文はまとめる。4 件以上は畳んで件数だけを見せ、開けば読める。件数は上の帯にも出る)。出るのは、コマンド・API の警告と同じもの: 組版の警告、未対応の CSS・XSL-FO と知らない CSS のプロパティ、安全のため PDF に動作を書かなかったリンク、128 段より深い入れ子・多すぎる `@import`、EPUB の上限を超えて飛ばした項目、取らなかった画像、書体の知らせ (取得できなかった書体など)
61
- - 組版はすべてブラウザの中で行い、文書や書体を外へ送らない (外から取るのは、既定の書体と、文書が `http(s):` で参照する画像だけ)。`npm run build` の `dist/` を静的なウェブサーバーに置いても動く
61
+ - 組版はすべてブラウザの中で行い、文書や書体を外へ送らない (外から取るのは、既定の書体と、文書が `http(s):` で参照する画像と、「設定」で許したときの draw.io の図形ライブラリだけ)。`npm run build` の `dist/` を静的なウェブサーバーに置いても動く
62
62
 
63
63
  ### Node のコマンド (ブラウザを使わずに HTML+CSS・XSL-FO を PDF に)
64
64
 
@@ -96,20 +96,25 @@ cat book.html | node dist-cli/cli.js - -o - --base . > book.pdf
96
96
  - HTML と同じディレクトリ (と下のディレクトリ) の CSS・画像・書体を使う (画面で一緒に選ぶのと同じ)。画像は、文書と CSS に名前が出てくるものだけを読む。CSS は、HTML が参照するもの (`<link>`・`@import`) だけを使う (参照していない CSS は当てずに、警告で知らせる)。`--css a.css,b.css` で使う CSS を選ぶ (カンマ区切りで複数。`@import` 先も使う。HTML から参照されていない CSS も、名指ししたものは利用者のスタイルシートとして足す)
97
97
  - `--style kumiori|browser|browser-margin|ah|vivliostyle|weasyprint`: 既定のスタイル (画面の「設定」の「既定のスタイル」と同じ。既定は kumiori)
98
98
  - `--page-size <用紙>`: HTML の既定の用紙 (`@page` で `size` を指定していない文書の用紙。既定は A4)。CSS の `size` と同じ書き方で、用紙の名前 (`A5`・`JIS-B5`・`letter` など)、向きを付けたもの (`"A5 landscape"`)、幅と高さ (`148mm,210mm`。区切りは空白かカンマ) を書く。文書の `@page { size: … }` があれば、そちらが勝つ。`@media` の `width`・`height` も、この用紙で評価する。XSL-FO では使わない
99
- - `--font-dir <dir>`: 既定の書体 (`NotoSerifJP-Regular.ttf`・`NotoSerifJP-Bold.ttf`・`NotoSansJP-Regular.ttf`・`NotoSansJP-Bold.ttf`・`Tinos-*.ttf`・`Arimo-*.ttf`、等幅の指定があれば `Cousine-*.ttf`、MathML があれば `STIXTwoMath-Regular.ttf`、どの書体にも無い記号があれば `NotoSansSymbols2-Regular.ttf`) を読むディレクトリ。無ければ書体のキャッシュ、次に Google Fonts から読む。太字のファイル (`-Bold`) に、同じ書体の `-Regular` と同じ中身のファイルを置くと、太字の書体は無いものとして、太字の字は Regular を太らせて描く (太字を持たない書体に入れ替えるとき)。既定の書体を手元の書体に入れ替えるときは、太字のファイル (`NotoSerifJP-Bold.ttf`・`NotoSansJP-Bold.ttf` など) も置く: 置かなかったファイルは、キャッシュかネットワークの既定の書体になり、入れ替えた書体と混ざる
99
+ - `--svg-lang <ja,en>`: SVG の `systemLanguage` (`switch` の子を選ぶ条件) を照らす言語 (言語タグをカンマで区切る。好む順)。SVG を置いた所に言語の指定 (`lang`・`xml:lang`・`language`) があれば、そちらが勝つ。既定は実行環境の言語
100
+ - `--font-dir <dir>`: 既定の書体 (`NotoSerifJP-Regular.ttf`・`NotoSerifJP-Bold.ttf`・`NotoSansJP-Regular.ttf`・`NotoSansJP-Bold.ttf`・`Tinos-*.ttf`・`Arimo-*.ttf`、等幅の指定があれば `Cousine-*.ttf`、MathML があれば `STIXTwoMath-Regular.ttf`、どの書体にも無い記号があれば `NotoSansSymbols2-Regular.ttf`、それにも無い絵文字があれば `NotoEmoji-Regular.ttf`) を読むディレクトリ。無ければ書体のキャッシュ、次に Google Fonts から読む。太字のファイル (`-Bold`) に、同じ書体の `-Regular` と同じ中身のファイルを置くと、太字の書体は無いものとして、太字の字は Regular を太らせて描く (太字を持たない書体に入れ替えるとき)。既定の書体を手元の書体に入れ替えるときは、太字のファイル (`NotoSerifJP-Bold.ttf`・`NotoSansJP-Bold.ttf` など) も置く: 置かなかったファイルは、キャッシュかネットワークの既定の書体になり、入れ替えた書体と混ざる
100
101
  - `--font-cache <dir>`: Google Fonts から取った既定の書体を保存して使い回すディレクトリ。既定は環境変数 `KUMIORI_FONT_CACHE`、無ければ OS のキャッシュ (Linux は `$XDG_CACHE_HOME` か `~/.cache` の `kumiori/fonts`、macOS は `~/Library/Caches/kumiori/fonts`、Windows は `%LOCALAPPDATA%\kumiori\fonts`)。初回だけネットワークから取り、`書体 … を取得して … に保存しました` と知らせる。2 回目からはネットワークに行かない。途中で切れた取得など、書体のファイルでないものは保存せず、壊れたキャッシュは捨てて取り直す。保存できない場所でも変換は続ける
101
102
  - `--no-font-cache`: 書体のキャッシュを読まず、保存もしない (毎回 Google Fonts から取る)
102
103
  - `--lang ja|en`: 使い方・報告・警告・誤りの文の言語。無ければ環境変数 `KUMIORI_LANG`、次に OS のロケール (`LC_ALL`・`LC_MESSAGES`・`LANG` が `en…` なら英語) で決める。既定は日本語
103
104
  - `--font <書体ファイル>` (何度でも): 書体のファイル (TTF・OTF・TTC・WOFF・WOFF2) を足す (TTC は中の書体をそれぞれ足す)。書体の name 表のファミリー名と OS/2 の太さ・幅・傾きで登録し、システムに入れた書体のように `font-family` から使う。同じファミリーの中の書体は、幅 (`font-stretch`) → 傾き (`font-style`) → 太さ (`font-weight`) の順に選ぶ (CSS Fonts 4 §5.2)。斜体の書体のファイル (Italic・Oblique) を渡せば、`font-style: italic`・`oblique` の字はその書体で組む (渡さなければ、立体の字を傾けて描く)。幅の違う書体 (Arial Narrow のように、ファミリー名が同じで幅が狭い・広い書体) は、`font-stretch` の指定か、その書体だけの名前 (`font-family: "Arial Narrow"`) で選ぶ (幅の違う書体が無ければ、字形を水平に伸縮する)。可変フォント (OpenType Font Variations。TrueType の輪郭と、CFF2 の輪郭) は、太さ・幅などの軸の範囲の全体を使い、`font-weight`・`font-stretch`・`font-variation-settings` などに合う形を作って組む (PDF には、使った形ごとに静的な書体として埋め込む。CFF2 の可変フォントは、静的な CFF の書体に作り直す)。`font-family` の並びは、字ごとに前から順に引き、その字を持つ最初の書体で組む (総称と既定の書体の名前も、並びの中の位置で引く)。並びのどの書体も持たない字は、既定の書体、並びに無い足した書体の順に探す。`--style ah` などの互換のスタイルでは、SVG の `font-family` に書いた PostScript 名 (`'CenturyGothic'` など) でも選ぶ
104
105
  - `--generic-font <総称>=<書体名>`: 総称の書体に使う書体 (`--font` で足した書体か既定の書体のファミリー名。何度でも書ける)。`serif`・`sans-serif`・`monospace` は欧文の字の書体 (既定は Tinos・Arimo・Cousine)、`serif-cjk`・`sans-serif-cjk` は和文の字の書体 (既定は Noto Serif JP・Noto Sans JP)。等幅の和文は、HTML は `sans-serif-cjk`、XSL-FO は `serif-cjk` の書体になる。例: `--font BIZUDMincho-Regular.ttf --generic-font serif-cjk="BIZ UDMincho"`
106
+ - `--drawio-stencils <ファイルかディレクトリ,…>`: draw.io の図の図形ライブラリ (draw.io の `js/stencils.min.js` かライブラリの XML) と配布物の画像 (`.svg`・`.png`・`.jpg`)。`,` で区切る (何度でも書ける)。`--fetch-drawio-stencils`: 図に要る図形ライブラリ・画像が無ければ、draw.io の配布物 (v24.7.5) から取るのを許す (取ったものは書体のキャッシュの場所に保存する。`--no-font-cache` なら保存しない)。`--drawio-stencils-url <URL>`: 取り先の `stencils.min.js` の URL (`--fetch-drawio-stencils` も付けたことになる)。`--no-drawio`: draw.io の図 (`.drawio`・`.dio`) を画像として読まない。詳しくは [`docs/drawio.md`](docs/drawio.md)
107
+ - `--plugin <モジュール>`: プラグイン (API の `plugins`) を読み込む。ファイルの道か、パッケージの名前。探す順は、(1) `./`・`../` で始まるもの、絶対の道、`file:` の URL は、ファイルの道 (`./plugin.js` など)。(2) それ以外は、`import()` と同じに、まずパッケージの名前として探す (`import()` と同じ条件 (`exports` の `import`・`node`・`default`) で、今のディレクトリから。`@scope/name`・`name/sub` も、`kp/dist/plugin.js`・`chart.js` のような拡張子で終わるものも書ける。今のディレクトリに同じ名前のディレクトリがあっても、パッケージとして探す)。(3) パッケージとして読めなければ (パッケージが無いときのほか、指したサブパスをそのパッケージが `exports` で出していないときや、パッケージの入口のファイルが無いときも)、今のディレクトリのその名前のファイルを読む (`--plugin myplugin.js`)。パッケージとして読めるときはパッケージを読むので、確実にファイルを読ませたいときは `./` を付ける。見つからないときは、何をどの順に探したかを誤りの文に書く。何度でも書ける。モジュールの `default` は、プラグインか、プラグインを返す関数 (`(選択肢, { cacheDir, lang }) => プラグイン`。`lang` は `--lang`・環境で決めた文言の言語)。`--plugin-option <名前>=<値>` は、その前の `--plugin` の関数に渡す選択肢 (何度でも)。プラグインはプログラムそのもので、Kumiori と同じ権限で動くので、信頼できるものだけを書く
105
108
  - `--print`: トンボと塗り足し (3mm)
106
109
  - `--image-max-dpi <dpi>`: 置かれる大きさに対してこれより細かい JPEG の写真を、この解像度に縮めて符号化し直す (PDF を小さくする。既定は元のまま)
110
+ - `--pdfx x3|x4`: 入稿用の PDF/X-3:2003・PDF/X-4 の印を付ける。RGB の色・画像は CMYK に、灰色の字・線・塗りは K だけの CMYK にし、本文 (ページの余白の字も) の K だけの黒の 12pt 未満の字と、2pt 未満の線・罫線にはノセ (overprint) を付け (Ghent Workgroup の入稿の仕様 GWG 2022 の推奨。図 (SVG・EPS など) の中の字・線には付けない)、ページには TrimBox だけを書き、ページの中のリンク・注釈・フォームの欄は書かずに、件数を警告に出す (塗り足しまでの範囲 (BleedBox) と少しでも重なるものを書かない。BleedBox はページの絵柄の全体を囲むので、目次などの内部のリンクも外の URL へのリンクも、ほぼ全部が無くなる。しおりは残る。画面で読むための PDF は、`--pdfx` を付けずに書き出す)。GWG 2022 の要件のうち、ページの仕上がりの大きさの違い・特色・画像の粗さ (149ppi 以下、と 224ppi 以下) も警告に出す (商業印刷の枚葉の用途の値)。PDF/X-3 では透明を使うと警告に出す。PDF/X-4 は透明をそのまま出し、XMP のメタデータに版の印を書く。日本の印刷所で主に使われているのは PDF/X-4 (と PDF/X-1a)
111
+ - `--output-profile <ICC ファイル>`: 出力の CMYK の ICC プロファイル (印刷所の指定するもの。Japan Color 2001 Coated など)。PDF に埋め込み、RGB の色・画像はこの表で CMYK にする。`--pdfx x4` では必須 (無いか CMYK のものでなければ誤り)。`--output-condition <名前>` で印刷条件の名前 (既定は ICC の登録名 JC200103) を渡す
107
112
  - `--spot-colors <JSON ファイル>`: 特色の名前と、濃度 100% のときの代わりの CMYK (`{"名前": "cmyk(20%,40%,60%,80%)"}` か `{"名前": [0.2,0.4,0.6,0.8]}`。配列は 0〜1 の数で、1 を超える値は誤り)。`rgb-icc(r,g,b,#Separation,'名前',濃度)` の色のうち、ここに名前のあるものを PDF の Separation (代わりの色空間は DeviceCMYK、濃度の変換は線形) で書く。`rgb-icc()` は、XSL-FO ではどちらの `--compat` でも読み、HTML では `--style ah` のときだけ読む (CSS の色の関数に無い、アンテナハウスの書き方のため。ほかのスタイルでは、読めない値として宣言ごと無視し、警告に出す)。名前の無いものは、これまでどおり代わりの RGB で書く。名前の字は UTF-8 で書く (ISO 32000-2 §7.3.5)。特色の値 (色見本帳の値など) は Kumiori には入っていないので、使う人が渡す
108
113
  - HTML は linkedom で読み、CSS の計算値は自前のカスケード (画面の「CSS の解釈: Kumiori」と同じ)
109
114
  - XHTML (`.xhtml`・`.xht`) は XML の構文で読み、名前空間に従って書き直してから HTML と同じに組む (`<s:svg xmlns:s="http://www.w3.org/2000/svg">` のような接頭辞の付いた要素も SVG になる。`src/xhtml.ts`)。`.html` は HTML の構文で読むので、接頭辞の付いた要素は SVG にならない。`--xhtml` を付けると、拡張子によらず XML の構文で読む
110
115
  - MathML (`<math>`) は、数式用の書体 (`STIXTwoMath-Regular.ttf`) で組み、字の輪郭の図形にする (XSL-FO と同じ `src/mathLayout.ts`)。`display="block"` の数式は行の中央に置く
111
116
  - XSL-FO (`.fo`・`.xml`、または `--fo`) は、画面の XSL-FO の読み込みと同じに組む。`--compat spec|antenna` は既定値の流儀 (XSL-FO 1.1 の初期値 (既定) / AH Formatter 互換の既定値。ほかの値は誤り)。同じディレクトリの書体ファイル (TTF・OTF・TTC) は、FO の `font-family` の名前で使う
112
- - 画像は PNG・JPEG・GIF・BMP・TIFF・WebP・SVG・WMF・EMF・EPS (PostScript)・CGM を PDF に入れる。図形にできない SVG (影・ぼかし以外の filter など) は、仮の枠で描いて警告する (画面ではラスタライズして描く)
117
+ - 画像は PNG・JPEG・GIF・BMP・TIFF・WebP・SVG・WMF・EMF・EPS (PostScript)・CGM と、draw.io の図 (`.drawio`・`.dio`。図形と文字のまま。[`docs/drawio.md`](docs/drawio.md)) を PDF に入れる。SVG の filter は、図形で近似するか (影・ぼかし・色の変換・重ね)、画素で計算して画像にする (feTurbulence・光の効果など。画面ではブラウザがラスタライズして描く)。foreignObject の HTML は、Node では文字を近似して描く。図形にできない SVG (HTML でない foreignObject など) は、仮の枠で描いて警告する
113
118
 
114
119
  ### ライブラリとして使う (TypeScript・JavaScript から)
115
120
 
@@ -139,12 +144,14 @@ result.renderPage(canvas, 0); // 1 ページ目
139
144
 
140
145
  - `typeset(text, options)` が入口です (`typesetHtml`・`typesetFo` は種類を決め打ちする版)。ファイルシステムには触らず、ネットワークは既定の書体の取得 (`loadFont` で差し替えられる) と、文書が `http(s):` で参照する画像・CSS の取得 (`fetchImages`・`fetchStyles` で止められる) にだけ使うので、ブラウザでも Node でも動きます
141
146
  - `text` は文字列です。ファイルから読むときは `decodeDocumentText(bytes)` で文字列にすると、BOM・XML 宣言の `encoding`・`<meta charset>` に従って復号します (UTF-8 固定で読むと、Shift_JIS の FO などが化けます)
142
- - 主な `options`: `kind` (`html`・`xhtml`・`fo`。省略すれば `name` と中身で決める)、`name` (入力のファイル名)、`files` (CSS・画像・書体。書体は TTF・OTF・TTC・WOFF・WOFF2)、`fonts` (足す書体)、`genericFonts` (総称の書体に使う書体。名前は `--generic-font` と同じ `serif`・`sans-serif`・`monospace`・`serif-cjk`・`sans-serif-cjk`)、`style` (HTML の既定のスタイル)、`pageSize` (HTML の既定の用紙。`@page` で `size` を指定していない文書の用紙を、CSS の `size` の書き方で: `"A5"`・`"A5 landscape"`・`"148mm 210mm"`。既定は A4。文書の `@page { size }` が勝つ。`@media` の `width`・`height` もこの用紙で評価する)、`compat` (XSL-FO の既定値の流儀)、`print` (塗り足しとトンボ)、`spotColors` (特色の代わりの CMYK)、`loadFont`、`fetchTimeoutMs` (書体・画像の取得の時限。既定 30 秒)、`fetchImages` (文書が `http(s):` で参照する画像を取るか。既定 `true`。`false` か、URL を受けて真偽を返す関数。他人の文書をサーバーで組むときは止めるか、許す URL だけにする)、`fetchStyles` (文書が `http(s):` で参照する CSS と、その `@font-face` の書体を取るか。`fetchImages` と同じ形)、`resolveResource` (文書・CSS が参照するファイルのうち `files` に無いものの中身を返す関数。下を見てください)、`links` (文書の外へのリンクのうち、PDF に動作を書くもの。`{ schemes?: string[]; launch?: boolean }`。既定では、スキームが `http`・`https`・`mailto`・`tel` の URL と相対参照の PDF だけを書き、ほかは字だけを組んで `warnings` に知らせる。`schemes` は許すスキームの一覧 (既定と置き換わる。`'*'` はすべて)、`launch: true` はファイルを開く動作 (PDF でない相対のファイル・絶対パス・`//host/…`) も書く。すべて書くには `{ schemes: ['*'], launch: true }`)、`lang` (`warnings` と誤りの文の言語。`ja` か `en`。既定は日本語)、`deflate` (Node なら `zlib.deflateSync` を渡すと PDF の書き出しが速い)
147
+ - 主な `options`: `kind` (`html`・`xhtml`・`fo`。省略すれば `name` と中身で決める)、`name` (入力のファイル名)、`files` (CSS・画像・書体。書体は TTF・OTF・TTC・WOFF・WOFF2)、`fonts` (足す書体)、`genericFonts` (総称の書体に使う書体。名前は `--generic-font` と同じ `serif`・`sans-serif`・`monospace`・`serif-cjk`・`sans-serif-cjk`)、`style` (HTML の既定のスタイル)、`pageSize` (HTML の既定の用紙。`@page` で `size` を指定していない文書の用紙を、CSS の `size` の書き方で: `"A5"`・`"A5 landscape"`・`"148mm 210mm"`。既定は A4。文書の `@page { size }` が勝つ。`@media` の `width`・`height` もこの用紙で評価する)、`compat` (XSL-FO の既定値の流儀)、`print` (塗り足しとトンボ)、`spotColors` (特色の代わりの CMYK)、`loadFont`、`fetchTimeoutMs` (書体・画像の取得の時限。既定 30 秒)、`fetchImages` (文書が `http(s):` で参照する画像を取るか。既定 `true`。`false` か、URL を受けて真偽を返す関数。他人の文書をサーバーで組むときは止めるか、許す URL だけにする)、`fetchStyles` (文書が `http(s):` で参照する CSS と、その `@font-face` の書体を取るか。`fetchImages` と同じ形)、`resolveResource` (文書・CSS が参照するファイルのうち `files` に無いものの中身を返す関数。下を見てください)、`links` (文書の外へのリンクのうち、PDF に動作を書くもの。`{ schemes?: string[]; launch?: boolean; relative?: 'file' | 'uri' }`。既定では、スキームが `http`・`https`・`mailto`・`tel` の URL と相対参照の PDF だけを書き、ほかは字だけを組んで `warnings` に知らせる。`schemes` は許すスキームの一覧 (既定と置き換わる。`'*'` はすべて)、`launch: true` はファイルを開く動作 (PDF でない相対のファイル・絶対パス・`//host/…`) も書く。すべて書くには `{ schemes: ['*'], launch: true }`)、`svgLanguages` (SVG の `systemLanguage` を照らす言語タグの配列。`--svg-lang` と同じ)、`lang` (`warnings` と誤りの文の言語。`ja` か `en`。既定は日本語)、`deflate` (Node なら `zlib.deflateSync` を渡すと PDF の書き出しが速い)
143
148
  - `fetchImages`・`fetchStyles` に渡す関数には、文書に書かれた URL のほか、転送 (redirect) の先の URL も聞きます。Node では、転送を 1 つずつ確かめてたどり (20 回まで)、許されない先へは要求を出しません。`https:` から `http:` への転送と、`http(s):` でない先への転送は、関数に聞かずに断ります (真偽の `true` のときも同じ)。ブラウザでは、転送の先をスクリプトから前もって読めないので、たどった後の最後の URL を関数に聞き、許されなければ応答を使いません (このとき、要求そのものは転送の先に届いています)。関数が見るのは URL の文字列だけです。内部のアドレスに解決されるホスト名 (DNS rebinding を含む) は、関数では防げません。他人の書いた文書をサーバーで組むときに内部の網を守るには、実行環境の側 (外向きの通信の制限・外向きのプロキシ) でも絞ってください。ネットワークから取るものの大きさには上限があります (画像 256MB・CSS 16MB・書体 128MB)。超えたものは、読むのを途中でやめて、読めない資源として扱います (`Content-Length` の無い応答でも同じ)。`fetchTimeoutMs` の時限は、本体を読み終えるまで効きます
144
- - `result.toPdf({ title, pdfx, imageMaxDpi })`: PDF の題名、PDF/X-3 の印 (`pdfx`。RGB の色・画像を CMYK にする)、JPEG の解像度の上限。`result.renderPage(canvas, i, { scale, devicePixelRatio, guides })`: 倍率、画面の画素の細かさ、仕上がり・塗り足しのガイド線
149
+ - `result.toPdf({ title, pdfx, imageMaxDpi })`: PDF の題名、PDF/X の印 (`pdfx: { version: 'X-3' | 'X-4', condition, info, profile, warnings }`。RGB の色・画像を CMYK にする。既定は X-3。X-4 は CMYK の ICC プロファイル `profile` が要る。コマンドの `--pdfx` と同じく、ページの中のリンク・注釈・フォームの欄は書かずに、件数を `warnings` に足す。しおりは残る)、JPEG の解像度の上限。PDF を書く途中の警告 (描けない字・色つきの字形を色つきで描けないことなど) は、`result.warnings` に足す。`result.renderPage(canvas, i, { scale, devicePixelRatio, guides })`: 倍率、画面の画素の細かさ、仕上がり・塗り足しのガイド線
145
150
  - FO の DOCTYPE の内部サブセットに宣言した内部実体 (`<!ENTITY nbsp "&#160;">` など) は、読み込みの前に展開します (外部実体は読みません)
146
151
  - 例外: FO の XML が読めない (`XML の解析に失敗しました: …`)、既定の書体が読めない (`書体を読めません: …`) は `typeset` が投げる。`fonts` に渡した壊れた書体ファイルは投げずに `warnings` に入る。`renderPage` の無いページ番号は `RangeError`。組版の警告 (読めない画像・溢れなど) は投げずに `result.warnings` (文字列の配列) に入る
147
152
  - `resolveResource(url)`: 文書・CSS が参照するファイル (`<link rel="stylesheet">`・`@import`・`url()`・`<img src>` など) のうち、`files` に無いものを問い合わせます。`url` は書かれた参照 (`file:///…/a.css`・`img/a.png`・`https://…`) で、CSS の中の相対参照は、その CSS の URL を基準に解決したものです。中身 (文字列・`Uint8Array`・`ArrayBuffer`) を返せばそれを使い、`undefined` ならこれまでどおり (`http(s):` の画像・CSS はネットワークから取る) です。参照を書き換えて `files` に入れ直す手間が要りません。画像は、URL に拡張子が無くても (`https://example.com/img?id=1` など)、返した中身の先頭のバイト列で画像と見分けて使います
153
+ - `drawio`: draw.io (diagrams.net) の図のファイル (`.drawio`・`.dio`) の選択肢 (型は `DrawioOptions`)。既定で、draw.io の図を画像として読み、ページを SVG にして PDF に図形と文字のまま入れます (図を描く処理は、図が出てきたときだけ読み込む)。`stencils` (図形ライブラリと配布物の画像のファイル)、`fetchStencils` (足りない図形ライブラリ・画像を draw.io の配布物から取るか。既定 `false`)、`stencilsUrl`、`provideStencils` を持ちます。`false` なら draw.io の図を画像として読みません。書き方・ページの選び方・描くものは [`docs/drawio.md`](docs/drawio.md) にあります
154
+ - `plugins`: プラグインの配列。いまは画像の形式を足すものだけです (`{ apiVersion: 1, name, imageFormats: [{ name, mime, extensions, sniff, load }] }`。型は `KumioriPlugin`・`ImageFormat`)。画像のファイルが形式の `sniff` (中身の判定。同期) に当たれば、`load` (非同期) が SVG と大きさを返し、Kumiori はそれを SVG の画像として描きます (PDF には図形のまま入る)。`extensions` の拡張子の名前のファイルも、文書に名前が出てくれば画像として読みます。`load` には、文字の幅を描く書体で測る `measureText`、文書の画像と同じ決まり (`resolveResource`・`fetchImages`) で取る `fetchResource`、プラグインの選択肢で利用者が許したものを取る `fetch`、警告を出す `warn`、警告の文の言語 `lang` (`ja`・`en`。`TypesetOptions.lang`)、画像の参照の `#` の後ろ `fragment` (1 つのファイルの中の、どの図・ページを描くか。同じファイルを `#` の後ろの違う参照で指すと、参照ごとに `load` を呼び、別の画像になります) が渡ります。重い処理は `load` の中で `import()` すれば、その形式のファイルが出てきたときだけ読み込まれます。`apiVersion` は受け口の版 (`PLUGIN_API_VERSION`) で、互換の無い形に変えたら上げます。`load` の結果には上限があります (draw.io の図も同じ。`src/imageFormats.ts`): 大きさは有限で 1,000 万 px まで、SVG の長さは約 3,360 万字 + ファイルの 1 バイトあたり 128 字 (最大約 1 億 3,400 万字)、時限は 60 秒 + 取得の時限 (`fetchTimeoutMs`) の 3 倍 (既定 150 秒)、1 つのファイルを `#` の後ろの違う参照で読むのは 64 個まで。超えたものは読めない画像として扱い、警告を出します。プラグインは Kumiori と同じ権限で動くので、自分で選んだ、信頼できるものだけを渡してください。プラグインの形式は、本体の形式 (draw.io の図) より先に判定します
148
155
  - Node では、`kumiori/node` の部品が使えます: `createFontLoader({ fontDir, cacheDir, log, timeoutMs })` は `loadFont` に渡す既定の書体の読み込み (Node のコマンドと同じ: `fontDir` → 書体のキャッシュ → ネットワーク。取った書体はキャッシュに保存する。`cacheDir` の既定は `defaultFontCacheDir()`、`null` でキャッシュしない)。`createFileResolver({ root })` は `resolveResource` に渡す、`file:` の URL のファイルを読む関数 (`root` を渡すと、その中のファイルだけを読む。`root` はいくつかの並びでもよく、中にあるかはシンボリックリンクをたどった実体のパスで見る)
149
156
 
150
157
  ```ts
@@ -155,11 +162,11 @@ result.renderPage(canvas, 0); // 1 ページ目
155
162
  - 既定で使う書体は `DEFAULT_FONTS` で分かります (`loadFont` に渡される `spec` の `family`・`weight`・`urls`)
156
163
  - 公開しているのは `src/index.ts` (と Node 用の `src/node.ts`) から出しているものだけです (ほかのモジュールの関数・型は、版の間で変わることがあります)
157
164
  - `kumiori` (`dist-lib/index.js`) は依存パッケージ (pdf-lib・fontkit・xmldom など) を取り込んでいない ES モジュールです。Vite・webpack などのバンドラーで使うか、Node から読んでください。ES モジュールだけですが、`require('kumiori')` でも読めます (ES モジュールを `require()` で読める Node 20.19.0 以降・22.12.0 以降。Node 22.0〜22.11 では `--experimental-require-module` が要ります)
158
- - バンドラーを使わないブラウザでは、依存まで 1 つにまとめたファイル `kumiori/browser` (`dist-browser/kumiori.js`。約 2.7MB、gzip で 0.9MB。ハイフネーションの辞書などは使うときだけ別ファイルを読む) を使います。npm に公開したものは jsDelivr や unpkg の CDN からそのまま読めます:
165
+ - バンドラーを使わないブラウザでは、依存まで 1 つにまとめたファイル `kumiori/browser` (`dist-browser/kumiori.js`。約 2.8MB、gzip で 0.9MB。最初に一緒に読む別ファイル (`chunks/` の pdf-lib・pako など。pdf-lib は draw.io の図の処理と分け合うので別ファイルになる) と合わせて約 3.4MB。ハイフネーションの辞書と、CGM・EPS・WMF・EMF・draw.io の図の処理などは、使うときだけ別ファイルを読む) を使います。npm に公開したものは jsDelivr や unpkg の CDN からそのまま読めます:
159
166
 
160
167
  ```html
161
168
  <script type="module">
162
- import { typesetHtml } from 'https://cdn.jsdelivr.net/npm/kumiori@0.2.0/dist-browser/kumiori.js';
169
+ import { typesetHtml } from 'https://cdn.jsdelivr.net/npm/kumiori@0.3.0/dist-browser/kumiori.js';
163
170
  const result = await typesetHtml(html, { name: 'a.html' });
164
171
  result.renderPage(document.querySelector('canvas'), 0);
165
172
  </script>
@@ -222,10 +229,15 @@ async function showPreview(bodyHtml: string, container: HTMLElement) {
222
229
  | `src/htmlImport.ts`, `src/htmlPaged.ts`, `src/htmlPrepare.ts`, `src/htmlFrame.ts` | HTML+CSS の読み込み (計算値 → 論理ツリー、ページの組版の CSS、CSS の集め方、画面での読み込み (既定は自前のカスケード、比較用にブラウザの iframe)) |
223
230
  | `src/cssCascade.ts`, `src/cssSelector.ts`, `src/cssText.ts` | ブラウザを使わない CSS の解釈 (カスケード・計算値・セレクタ)、CSS の字句の補助 (区切り・長さ・色) |
224
231
  | `src/xslfoImport.ts`, `src/foExpr.ts`, `src/foDom.ts`, `src/foContext.ts`, `src/foPageMaster.ts`, `src/foMathFallback.ts` | XSL-FO の読み込み (属性 → 論理ツリー、式の評価、最小 DOM、ページマスター、数式書体が無いときの MathML の組版) |
225
- | `src/svg.ts`, `src/mathLayout.ts` | SVG を図形にする、MathML の組版 |
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*`・`psResources`・`psColorSpace`・`psFonts`・`psCff`・`psEncodings`・`psShading`・`psFilters`), `src/imageInfo.ts`, `src/base64.ts` | 画像の復号 (JPEG・WebP・GIF・BMP・TIFF) と上限、WMF/EMF・CGM・EPS (PostScript の解釈器) の図形化、画像の大きさの読み取り |
232
+ | `src/svg.ts`, `src/svgFilterRaster.ts`, `src/mathLayout.ts` | SVG を図形にする (図形で近似できない filter は画素で計算する)、MathML の組版 |
233
+ | `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*`・`psResources`・`psColorSpace`・`psFonts`・`psCff`・`psEncodings`・`psShading`・`psFilters`), `src/imageInfo.ts`, `src/imageFormats.ts`, `src/base64.ts` | 画像の復号 (JPEG・WebP・GIF・BMP・TIFF) と上限、WMF/EMF・CGM・EPS (PostScript の解釈器) の図形化、画像の大きさの読み取り、本体の外に置いて要るときだけ読み込む画像の形式の受け口 |
227
234
  | `src/epub.ts`, `src/xhtml.ts` | EPUB の展開、XHTML の読み込み |
228
235
  | `src/fontMapping.ts`, `src/compat.ts`, `src/documentResources.ts`, `src/documentText.ts`, `src/cli.ts` | 書体の割り当て・互換モードの設定・数式書体と画像の取得・文字の符号化の判定 (画面と Node で共通)、Node のコマンド |
236
+ | `src/webFont.ts`, `src/fontLoader.ts`, `src/userFonts.ts` | WOFF・WOFF2 を TTF・OTF に戻す、利用者の書体のファイル (TTC を含む) を書体ごとに分けて名前を読む、画面で読み込んだ書体の保存 |
237
+ | `src/colorGlyph.ts`, `src/colorGlyphPdf.ts`, `src/colorGlyphCanvas.ts`, `src/colorGlyphSvg.ts` | 色つきの字形 (カラーの絵文字など) を書体の表から読み、PDF と Canvas に描く (OpenType の SVG の表の字形を含む) |
238
+ | `src/color.ts`, `src/cssColorFunctions.ts`, `src/cssGradient.ts`, `src/icc.ts`, `src/pdfStandard.ts` | 色の指定の読み取り、CSS Color 4・5 の色の関数、CSS のグラデーション、ICC プロファイルでの CMYK への変換、PDF/X-3・PDF/X-4 の方針 |
239
+ | `src/assets.ts`, `src/linkPolicy.ts`, `src/messages.ts` | 画像の登録所 (組版・Canvas・PDF で共有)、文書の外へのリンクを PDF のどの動作にするかの方針、利用者に見せる文言 (日本語・英語) |
240
+ | `src/drawio/` | draw.io の図 (`.drawio`・`.dio`) を読んで SVG にする (draw.io と mxGraph のソースから移した形・線の描き方。図が出てきたときだけ読み込む。[`docs/drawio.md`](docs/drawio.md)) |
229
241
 
230
242
  組版アルゴリズムの詳細は [`docs/REPORT.md`](docs/REPORT.md)、XSL-FO の読み込みは [`docs/xslfo-import.md`](docs/xslfo-import.md)、HTML+CSS の読み込みの計画は [`docs/html-css-plan.md`](docs/html-css-plan.md) を参照。
231
243
  対応している仕様の項目ごとの説明は対応仕様説明書 ([`docs/conformance/`](docs/conformance/README.md)。`npm run docs:conformance` で PDF にする。版ごとの PDF は GitHub のリリースに付ける)、まだ無い機能・既知の制限は [`docs/BACKLOG.md`](docs/BACKLOG.md)、組んだ結果 (Area Tree) の JSON は [`docs/area-tree.md`](docs/area-tree.md)。
@@ -241,6 +253,7 @@ async function showPreview(bodyHtml: string, container: HTMLElement) {
241
253
  | Cousine | 等幅の指定があるとき | Apache License 2.0 |
242
254
  | STIX Two Math | 数式 (MathML) があるとき。MathML を、この書体の MATH 表の値で組む | SIL Open Font License 1.1 |
243
255
  | Noto Sans Symbols 2 | 読み込んだどの書体にも無い記号 (✈ など) が文書にあるとき | SIL Open Font License 1.1 |
256
+ | Noto Emoji | 記号の書体にも無い絵文字 (😀・国旗など) が文書にあるとき。単色の輪郭の絵文字 (色つきにするには、Noto Color Emoji などの書体を `--font`・`@font-face` で渡します) | SIL Open Font License 1.1 |
244
257
 
245
258
  どの文書でも読むのは、上の 2 行の 8 つのファイル (和文 4 つ・欧文 4 つ。合わせて約 29MB。うち Noto Serif JP が 8.0MB ずつ、Noto Sans JP が 5.7MB ずつ) で、ほかは文書に必要なときだけ読みます。太字の指定の字は、同じ書体の Bold で組みます (明朝の文の太字は Noto Serif JP の Bold)。
246
259
 
@@ -255,6 +268,10 @@ Node のコマンドは、取った書体を OS のキャッシュ (`~/.cache/ku
255
268
  - 絶対配置 (`absolutePosition`) は **仕上がり(trim)左上** 基準。塗り足しへ届かせるには負の `top/left` を指定する。
256
269
  - `width/height` は既定 `content-box`。`boxSizing: 'border-box'` で padding/border 込みにできる。
257
270
 
271
+ ## 脆弱性の報告
272
+
273
+ 脆弱性を見つけたときは、公開の Issue には書かず、[SECURITY.md](SECURITY.md) の手順で非公開で知らせてください。
274
+
258
275
  ## ライセンス
259
276
 
260
277
  コードは [Apache License 2.0](LICENSE) (Copyright 2026 Northern Lights Co.。[NOTICE](NOTICE))。組版用の書体は、本リポジトリには同梱していません (書体とそのライセンスは「[フォント](#フォント)」の節)。
@@ -265,7 +282,9 @@ Kumiori が使う第三者のソフトウェア (pdf-lib・pako・utif・hyphen
265
282
 
266
283
  Kumiori は、アンテナハウスの製品や、WeasyPrint・Vivliostyle などの組版ソフトとは関係のない、独立したプロジェクトです。これらの会社やプロジェクトから、承認や支援を受けているものではありません。
267
284
 
268
- README や docs に出てくる製品名・会社名は、各社の商標または名称です。Kumiori は、互換のための機能 (`axf:*` の拡張の読み込み、`--compat antenna` の既定値など) を説明するために、これらの名前を使っています。
285
+ Kumiori は draw.io (JGraph Ltd・draw.io AG) とも関係がありません (draw.io は登録商標です)。draw.io の図のファイルを読む機能は、draw.io の公開のソースを移して作ったもので (`THIRD_PARTY_NOTICES.md` の 13 節)、draw.io の承認や支援を受けたものではありません。
286
+
287
+ README や docs に出てくる製品名・会社名は、各社の商標または名称です。Kumiori は、互換のための機能 (`axf:*` の拡張の読み込み、`--compat antenna` の既定値など) を説明するために、これらの名前を使っています。draw.io の名前は、draw.io の図のファイル (`.drawio`・`.dio`) を読む機能を説明するために使っています。
269
288
 
270
289
  ## 開発の方法について
271
290
 
@@ -280,11 +299,15 @@ Kumiori は、AI のコーディング支援 (Anthropic の Claude Code) を使
280
299
  ```bash
281
300
  npm test # 単体テスト (Node + fontkit。Noto Serif JP を .cache/fonts に取得)
282
301
  npm run e2e # ブラウザでの結合テスト (Playwright。初回は npx playwright install chromium)
302
+ npm run ci:local # CI (.github/workflows/ci.yml) の build と e2e のジョブと、GitHub Pages (.github/workflows/pages.yml) の画面のビルドと同じ手順 (npm ci・3 つのビルド・土台を変えた画面のビルド・単体テスト・結合テスト)
283
303
  ```
284
304
 
305
+ `npm run ci:local` (`scripts/ci-local.mjs`) は、CI のジョブの手順を手元で順に走らせ、最後に手順ごとの結果を並べる。`-- --job build|pages|node-min|e2e` で走らせるジョブを選ぶ (何度でも書ける。選ばなければ build・pages・e2e。node-min は、動かせる Node の下限の 20.19.x に切り替えてから走らせる)。pages は、`pages.yml` と同じく、アセットの土台 (base) をリポジトリ名 (`package.json` の `repository.url` から取る。`/kumiori/`) にして画面を作り、出力の `index.html` のアセットの参照が土台で始まることを確かめる (出力は一時的な場所に出して消すので、`dist/` は変わらない)。`-- --worktree` を付けると、いまのコミット (HEAD) を一時的な場所に取り出して試す (CI と同じく、まだコミットしていない変更や前のビルドの出力が混ざらない)。`-- --no-install` で初めの `npm ci` を飛ばす。
306
+
285
307
  テストが使う書体は、初回に取得して `.cache/fonts` (`KUMIORI_FONT_DIR` で変えられる) に置く。配信元は Google Fonts (`fonts.gstatic.com`) と、PostScript の書体のテスト用の Source Sans 3 (`raw.githubusercontent.com` の adobe-fonts/source-sans)。取得は `test/helpers.ts` の 1 か所にまとめてあり、テストに書体を足すときは、そこの一覧に足す (CI のキャッシュの鍵になる)。
286
308
  Unicode の公式の適合試験 (UAX #14 の `LineBreakTest.txt`、UAX #29 の `GraphemeBreakTest.txt`、UAX #9 の `BidiTest.txt`・`BidiCharacterTest.txt`) も、初回に `unicode.org` (`https://www.unicode.org/Public/<版>/ucd/`) から取得して `.cache/unicode` (`KUMIORI_UCD_DIR` で変えられる) に置く。取得は `test/ucdTestData.ts` の 1 か所にまとめてあり、版は `src/unicodeData.ts` の表を作った UCD の版に合わせる。取得できない環境では、公式の試験の代わりに、テストの中の手書きの小さな並びだけを確かめる。
287
309
  結合テストは、`KUMIORI_E2E_FONT_CACHE` にディレクトリを指定すると、ブラウザが取った書体をそこに覚えて、次からはネットワークに行かない (CI はこれを使う)。`KUMIORI_E2E_FONT_DIR` は、決まった名前の書体を手で用意して使うときの口。
310
+ 結合テストと比較のスクリプト (`scripts/compare-pdf.mjs`・`scripts/compare-css.mjs`) は、`KUMIORI_CHROMIUM` に Chromium の実行ファイルを指すと、Playwright の取った Chromium ではなく、それを使う (Playwright の版と、入っている Chromium の版が合わない環境のため。例: `KUMIORI_CHROMIUM=/opt/pw-browsers/chromium npm run e2e`)。指さないときは Playwright の取った Chromium を使う。
288
311
 
289
312
  見本の PDF との比較 (比べる見本の FO と PDF は各自で用意する。リポジトリには入っていない。poppler の pdftoppm が必要):
290
313
 
@@ -292,12 +315,25 @@ Unicode の公式の適合試験 (UAX #14 の `LineBreakTest.txt`、UAX #29 の
292
315
  node scripts/compare-pdf.mjs --fo <FO のディレクトリ> --ref <見本の PDF のディレクトリ> --img <画像のディレクトリ> --out compare-pdf-out
293
316
  ```
294
317
 
318
+ 見本は `scripts/fetch-samples.mjs` で配布元から取って `.cache/samples` に置ける (`.gitignore` 済み。プロキシを通すときは `NODE_USE_ENV_PROXY=1` を付ける)。アンテナハウスの「サンプル FO 集」(FO と、AH Formatter の出した PDF) と、『CSS ページ組版入門』第 4 版 (PDF と元のファイル) を取り、`manifest.json` に元の URL・大きさ・SHA-256 を書く。取ったものは、そのまま compare-pdf.mjs に渡せる形に並べる:
319
+
320
+ ```bash
321
+ node scripts/fetch-samples.mjs
322
+ 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
323
+ ```
324
+
325
+ `.cache/samples/fo/groups.json` に、見本を分類で 4 つに分けた名前の一覧がある (公開している比較ページの分け方)。
326
+ `--pack <ディレクトリ>` は、取ったもの (zip・PDF と `manifest.json`) を tar にまとめ、10MB ずつに切って base64 の JavaScript に包む (zip や tar を受け付けない置き場、たとえば claude.ai の Artifact に預けるため)。`--unpack <ディレクトリ>` は、包みの SHA-256 を確かめて戻し、ネットを使わずに展開する (`--offline` と同じ)。
327
+ 比較のスクリプトが Playwright の取った Chromium を見つけられないとき (Playwright の版と、入っている Chromium の版が合わないとき) は、結合テストと同じく、`KUMIORI_CHROMIUM` に Chromium の実行ファイルを指す。
328
+
295
329
  FO と同じ名前の PDF を組にして比べる。`compare-pdf-out/report.md` に、見本ごとのページ数と、ページごとの差 (差の大きい順) が出る。アンテナハウスの見本と比べるときは `--compat antenna` を付ける (既定は仕様どおりのモード)。見本と同じ書体で組むには、書体のファイルを `--fonts <ディレクトリ>` で渡し、総称の書体 (`serif`・`sans-serif`) に当たる既定の書体を `--web-fonts <ディレクトリ>` で差し替える (MS 明朝・MS ゴシック・Times New Roman・Arial・Courier New を、`notoserif.ttf`・`notosans.ttf`・`tinos400.ttf`・`arimo400.ttf`・`cousine400.ttf` などの名前で置く。TTC は中の 1 つ目の書体を TTF に取り出す。ディレクトリに無い書体は配信元から取る)。
296
330
 
331
+ 見本が特色 (PDF の Separation の色。『CSS ページ組版入門』第 4 版の PANTONE 627 PC など) で塗っているときは、`node scripts/spot-colors-from-pdf.mjs <見本の PDF> -o spot-colors.json` で、見本の PDF に書かれた特色の名前と濃度 100% の代わりの CMYK を取り出し、Node のコマンドに `--spot-colors spot-colors.json` を付けて組む (特色の値は Kumiori に入っていないので、渡さないと代わりの RGB で塗り、色が見本と違う)。組んだ PDF は `--pdf` で比べる。
332
+
297
333
  見本と Kumiori の出力を、目で見比べるページを作る (見本の PDF と Kumiori の PDF を、同じ名前で組にする):
298
334
 
299
335
  ```bash
300
336
  node scripts/compare-view.mjs --ref <見本の PDF のディレクトリ> --pdf <Kumiori の PDF のディレクトリ> --out compare-view-out
301
337
  ```
302
338
 
303
- `compare-view-out/index.html` をブラウザで開く。見本は差の大きい順に並び、ページごとに「並べる」「重ねる」(不透明度を変えられる)・「点滅」・「差」(青は見本にだけ、赤は Kumiori にだけ字や線がある所) を切り替えて見られる。`--inline` を付けると、画像を埋め込んだ HTML 1 つにする。`--jpeg` を付けると、ページの画像を JPEG にして小さくする。`--artifact` を付けると、claude.ai の Artifact として公開する形 (差の画像はブラウザで描く) で書き出す。
339
+ `compare-view-out/index.html` をブラウザで開く。見本は差の大きい順に並び、ページごとに「並べる」「重ねる」(不透明度を変えられる)・「点滅」・「差」(青は見本にだけ、赤は Kumiori にだけ字や線がある所) を切り替えて見られる。`--inline` を付けると、画像を埋め込んだ HTML 1 つにする。`--jpeg` を付けると、ページの画像を JPEG にして小さくする。`--artifact` を付けると、claude.ai の Artifact として公開する形 (差の画像はブラウザで描く) で書き出す。`--ref-label`・`--pdf-label` で左右の呼び名 (既定「見本」「Kumiori」) を、`--title` でページの題を変えられる (見本の無い自作の FO を、Kumiori の 2 つのモードやほかの組版ソフトで組み比べるとき。自作の見本は `samples/check/` にある)。