kumiori 0.1.1 → 0.2.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 (133) hide show
  1. package/CHANGELOG.en.md +333 -1
  2. package/CHANGELOG.md +332 -0
  3. package/README.en.md +47 -22
  4. package/README.md +48 -23
  5. package/THIRD_PARTY_NOTICES.md +894 -11
  6. package/dist-browser/THIRD_PARTY_NOTICES.md +894 -11
  7. package/dist-browser/chunks/{UTIF-BA_P1T7D.js → UTIF-DJ2yEO_P.js} +5 -2
  8. package/dist-browser/chunks/el-monoton-Bh-cSidd.js +684 -0
  9. package/dist-browser/chunks/{en-gb-c-j9Dxjw.js → en-gb-DLCXyvjY.js} +21 -2
  10. package/dist-browser/chunks/{en-us-FyKZ4pMu.js → en-us-BBLcTX9N.js} +11 -2
  11. package/dist-browser/chunks/{export-contract-BUdFW0fL.js → export-contract-DDGE_g3K.js} +4 -1
  12. package/dist-browser/chunks/{la-Cbb7zL-J.js → la-D46x91kc.js} +21 -2
  13. package/dist-browser/chunks/{pako-BWg-BM0p.js → pako-CeDDB8tF.js} +4 -1
  14. package/dist-browser/chunks/{rolldown-runtime-DfEuXgQw.js → rolldown-runtime-BXCUS5Bd.js} +3 -0
  15. package/dist-browser/chunks/ru-CkmoNumx.js +9694 -0
  16. package/dist-browser/chunks/uk-DIZr4Urv.js +6134 -0
  17. package/dist-browser/kumiori.js +54538 -37450
  18. package/dist-cli/THIRD_PARTY_NOTICES.md +894 -11
  19. package/dist-cli/cli.js +76129 -48486
  20. package/dist-lib/THIRD_PARTY_NOTICES.md +894 -11
  21. package/dist-lib/api-CQ3aOtc5.js +60782 -0
  22. package/dist-lib/api-CQ3aOtc5.js.map +1 -0
  23. package/dist-lib/index.js +11 -43698
  24. package/dist-lib/index.js.map +1 -1
  25. package/dist-lib/node.js +90 -0
  26. package/dist-lib/node.js.map +1 -0
  27. package/dist-lib/types/api.d.ts +74 -12
  28. package/dist-lib/types/arabicMarks.d.ts +16 -0
  29. package/dist-lib/types/areaResources.d.ts +20 -3
  30. package/dist-lib/types/areaTree.d.ts +2 -2
  31. package/dist-lib/types/arrayLoop.d.ts +13 -0
  32. package/dist-lib/types/assets.d.ts +29 -4
  33. package/dist-lib/types/base64.d.ts +7 -1
  34. package/dist-lib/types/canvasRenderer.d.ts +3 -3
  35. package/dist-lib/types/ccitt.d.ts +8 -0
  36. package/dist-lib/types/cff2Instancer.d.ts +45 -0
  37. package/dist-lib/types/cgm.d.ts +11 -0
  38. package/dist-lib/types/colorGlyph.d.ts +442 -0
  39. package/dist-lib/types/colorGlyphCanvas.d.ts +31 -0
  40. package/dist-lib/types/colorGlyphPdf.d.ts +115 -0
  41. package/dist-lib/types/colorGlyphSvg.d.ts +7 -0
  42. package/dist-lib/types/compat.d.ts +16 -7
  43. package/dist-lib/types/counterStyle.d.ts +14 -2
  44. package/dist-lib/types/counterStylePredefined.d.ts +1 -1
  45. package/dist-lib/types/cssCascade.d.ts +80 -6
  46. package/dist-lib/types/cssColorFunctions.d.ts +51 -0
  47. package/dist-lib/types/cssGradient.d.ts +49 -0
  48. package/dist-lib/types/cssSelector.d.ts +36 -4
  49. package/dist-lib/types/cssText.d.ts +31 -5
  50. package/dist-lib/types/cssTransform.d.ts +25 -0
  51. package/dist-lib/types/cssUnsupported.d.ts +6 -2
  52. package/dist-lib/types/cssUrlScan.d.ts +12 -0
  53. package/dist-lib/types/documentResources.d.ts +5 -5
  54. package/dist-lib/types/eps.d.ts +46 -7
  55. package/dist-lib/types/foContext.d.ts +18 -2
  56. package/dist-lib/types/foMathFallback.d.ts +11 -3
  57. package/dist-lib/types/foPageMaster.d.ts +6 -4
  58. package/dist-lib/types/fontInstancer.d.ts +56 -0
  59. package/dist-lib/types/fontLoader.d.ts +29 -0
  60. package/dist-lib/types/fontManager.d.ts +352 -10
  61. package/dist-lib/types/fontMapping.d.ts +53 -7
  62. package/dist-lib/types/fontSanity.d.ts +61 -0
  63. package/dist-lib/types/fontVariation.d.ts +45 -0
  64. package/dist-lib/types/fontkitCffFlex.d.ts +5 -0
  65. package/dist-lib/types/fontkitEmptyGlyph.d.ts +17 -0
  66. package/dist-lib/types/fontkitShaping.d.ts +135 -0
  67. package/dist-lib/types/footnotes.d.ts +9 -2
  68. package/dist-lib/types/geometry.d.ts +1 -1
  69. package/dist-lib/types/grapheme.d.ts +23 -0
  70. package/dist-lib/types/hebrewMarks.d.ts +22 -0
  71. package/dist-lib/types/htmlImport.d.ts +102 -7
  72. package/dist-lib/types/htmlPaged.d.ts +126 -16
  73. package/dist-lib/types/htmlPrepare.d.ts +91 -6
  74. package/dist-lib/types/htmlSvg.d.ts +20 -3
  75. package/dist-lib/types/hyphenation.d.ts +14 -3
  76. package/dist-lib/types/imageInfo.d.ts +6 -2
  77. package/dist-lib/types/imageLimits.d.ts +241 -0
  78. package/dist-lib/types/index.d.ts +6 -6
  79. package/dist-lib/types/indexCitation.d.ts +73 -0
  80. package/dist-lib/types/inlineFlatten.d.ts +52 -5
  81. package/dist-lib/types/inlineLayout.d.ts +229 -15
  82. package/dist-lib/types/jis.d.ts +7 -11
  83. package/dist-lib/types/layoutEngine.d.ts +92 -7
  84. package/dist-lib/types/ligature.d.ts +29 -0
  85. package/dist-lib/types/lineBreak.d.ts +24 -0
  86. package/dist-lib/types/lineMetrics.d.ts +13 -4
  87. package/dist-lib/types/linkPolicy.d.ts +80 -0
  88. package/dist-lib/types/lnode.d.ts +106 -32
  89. package/dist-lib/types/mathContent.d.ts +1 -1
  90. package/dist-lib/types/mathLayout.d.ts +14 -1
  91. package/dist-lib/types/measurer.d.ts +121 -5
  92. package/dist-lib/types/messages.d.ts +8 -2
  93. package/dist-lib/types/metafile.d.ts +7 -4
  94. package/dist-lib/types/node.d.ts +12 -0
  95. package/dist-lib/types/nodeFonts.d.ts +46 -0
  96. package/dist-lib/types/orthographicSyllable.d.ts +59 -0
  97. package/dist-lib/types/pageNumber.d.ts +7 -0
  98. package/dist-lib/types/paint.d.ts +29 -5
  99. package/dist-lib/types/paintEffect.d.ts +55 -0
  100. package/dist-lib/types/pdfLibPatches.d.ts +19 -1
  101. package/dist-lib/types/pdfRenderer.d.ts +14 -4
  102. package/dist-lib/types/pixels.d.ts +18 -2
  103. package/dist-lib/types/psCff.d.ts +10 -3
  104. package/dist-lib/types/psColorSpace.d.ts +1 -1
  105. package/dist-lib/types/psFilters.d.ts +20 -4
  106. package/dist-lib/types/psFonts.d.ts +2 -2
  107. package/dist-lib/types/psGraphics.d.ts +57 -7
  108. package/dist-lib/types/psInterp.d.ts +62 -2
  109. package/dist-lib/types/psOpsFont.d.ts +2 -2
  110. package/dist-lib/types/psOpsImage.d.ts +2 -2
  111. package/dist-lib/types/psOpsMatrix.d.ts +2 -2
  112. package/dist-lib/types/psOpsPath.d.ts +2 -2
  113. package/dist-lib/types/psOpsState.d.ts +2 -2
  114. package/dist-lib/types/psResources.d.ts +9 -1
  115. package/dist-lib/types/psShading.d.ts +19 -4
  116. package/dist-lib/types/resources.d.ts +116 -0
  117. package/dist-lib/types/sampleData.d.ts +3 -1
  118. package/dist-lib/types/sourceRef.d.ts +3 -3
  119. package/dist-lib/types/svg.d.ts +13 -2
  120. package/dist-lib/types/tableBorders.d.ts +7 -1
  121. package/dist-lib/types/tableLimits.d.ts +29 -0
  122. package/dist-lib/types/tableMarkers.d.ts +64 -0
  123. package/dist-lib/types/textJustifyTrim.d.ts +12 -0
  124. package/dist-lib/types/types.d.ts +783 -28
  125. package/dist-lib/types/unicodeData.d.ts +9 -1
  126. package/dist-lib/types/webFont.d.ts +4 -0
  127. package/dist-lib/types/webp.d.ts +2 -2
  128. package/dist-lib/types/xslfoImport.d.ts +15 -7
  129. package/package.json +9 -5
  130. package/dist-cli/apple-touch-icon.png +0 -0
  131. package/dist-cli/favicon.ico +0 -0
  132. package/dist-cli/favicon.svg +0 -4
  133. package/dist-cli/kumiori-logo-on-dark.svg +0 -6
package/README.en.md CHANGED
@@ -13,7 +13,7 @@ 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 54,000 lines of TypeScript, about 1,500 tests**: Each time a feature is added, the AI adds tests, and CI (type checking, unit tests, and 13 browser integration tests) passes
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
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
 
@@ -21,7 +21,7 @@ Kumiori is developed with an AI coding assistant ([Claude Code](https://claude.c
21
21
 
22
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
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"`), Latin hyphenation, and mixed Japanese and Latin text. Fonts for Arabic and other scripts are passed with `--font` or `fonts` (the default fonts do not include them)
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
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
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
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
@@ -51,12 +51,13 @@ npm run build # type check + production build (dist/; the web app)
51
51
  npm run build:dist # build the library (dist-lib), the Node CLI (dist-cli) and the single browser file (dist-browser) together
52
52
  ```
53
53
 
54
- Node 20 or later is required (CI tests with 22; recursive watching for `--watch` needs Node 20 or later). The release procedure is in [`docs/en/RELEASING.md`](docs/en/RELEASING.md), and the changes in each version are in [`CHANGELOG.en.md`](CHANGELOG.en.md).
54
+ Node 20.19.0 or later in the 20 line, or 22.12.0 or later, is required (CI tests with 20.19.0 and 22; the dependencies used to read HTML, such as css-select used by linkedom, require Node 20.19.0 or later. 22.0 to 22.11 are excluded because they cannot load ES modules with `require()`). The release procedure is in [`docs/en/RELEASING.md`](docs/en/RELEASING.md), and the changes in each version are in [`CHANGELOG.en.md`](CHANGELOG.en.md).
55
55
 
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 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 and font loading
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)
60
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
62
 
62
63
  ### Node CLI (HTML+CSS and XSL-FO to PDF without a browser)
@@ -82,22 +83,28 @@ cat book.html | node dist-cli/cli.js - -o - --base . > book.pdf
82
83
  - With several inputs, `-o` (`--output`) is the output directory (if omitted, a `.pdf` is written next to each input). If one fails, the others are still produced (the exit code is 1). Even with a single input, if `-o` is an existing directory, `<input name>.pdf` is written inside it
83
84
  - `-` reads from standard input (CSS, images and fonts come from the `--base` directory (default: the current directory); whether the input is FO is detected from its content). `-o -` writes the PDF to standard output
84
85
  - The character encoding of the input is determined from the BOM, the XML declaration's `encoding` (`Shift_JIS`, `EUC-JP`, etc.) and HTML's `<meta charset>` (UTF-8 if none)
85
- - Images the document references via `http(s):` are fetched from the network by default. `--no-fetch-images` disables this (e.g. when typesetting documents written by others on a server; they are typeset as unreadable images)
86
+ - Images the document references via `http(s):` are fetched from the network by default. `--no-fetch-images` disables this (e.g. when typesetting documents written by others on a server; they are typeset as unreadable images). Network images are fetched up to 8 at a time, and fetching the images of a document also has an overall time limit (10 times the limit of a single fetch, 5 minutes by default; images not fetched by then are typeset as unreadable images)
87
+ - Stylesheets the document references via `http(s):` (`<link rel="stylesheet">`, `@import`) and the fonts of their `@font-face` rules (only those whose `unicode-range` overlaps the characters of the document) are also fetched by default. `--no-fetch-styles` disables this
88
+ - Image sizes are limited (so that a small file cannot consume large amounts of memory and time; the values and their rationale are in `src/imageLimits.ts`). One image may have up to 100 million pixels. The images inside a WMF, EMF or CGM file (DIBs, cell arrays, tile arrays, patterns) may total up to 64 million pixels per file, and also no more than "260 thousand pixels (512 × 512) + 1,024 pixels per byte of the file" (a file of a few hundred bytes cannot produce a huge image; a file larger than about 61 KB may use the full 64 million pixels). Images beyond the limits are not drawn, and the rest of the document is typeset. GIF, WebP, JPEG, CCITT TIFF and RLE BMP images also have their pixel count bounded by the file size (per format, a value derived from the densest coding a legitimate file can have; a large, almost single-colour lossless WebP, a blank CCITT image wider than 16,384 pixels, or a large, almost blank RLE BMP is not drawn when it exceeds the limit), and a PNG whose decompressed size exceeds 1,032 times its compressed data (the deflate limit) is not drawn. A font unpacked from WOFF or WOFF2 may be up to 128 MB, and no more than 100 times the file size + 1 MB
89
+ - When typesetting documents written by others on a server, also put a time limit and a memory limit on the typesetting of each document, separately from the limits above (typeset each document in a separate process or worker and stop it when the time is up; use `node --max-old-space-size=…` or a container memory limit, and so on). The limits above apply to one image or font at a time: a single image at the limit can still take several seconds to over ten seconds and about 2 GB, and a document that references many images and fonts costs correspondingly more
90
+ - Of the links that leave the document (HTML `<a href>`, and `external-destination` of XSL-FO `fo:basic-link` and `fo:bookmark`), by default only URLs whose scheme is `http`, `https`, `mailto` or `tel`, and relative references to a PDF (the action that opens another PDF), get an action in the PDF. Other schemes (`javascript:`, `data:`, `file:` and so on) and actions that open a file (relative non-PDF files, absolute paths, scheme-less `//host/…`) are typeset as plain text and counted in a "warning:" (to protect whoever opens a PDF made from a document written by someone else). `--link-schemes http,https,ftp` chooses the allowed schemes (`*` means all), and `--link-launch` also writes the actions that open a file (`--link-schemes '*' --link-launch` writes everything). `--link-relative uri` writes scheme-less relative links (`x.pdf`, `a.mp3`) as a URI action with the reference as written (`/S /URI /URI (x.pdf)`; `%xx` is not decoded) instead of the actions that open a file (GoToR, Launch): many PDF viewers inside browsers do not handle GoToR and Launch. Relative non-PDF files are then written without `--link-launch`; absolute paths and `//host/…` still need `--link-launch`. In the API it is `links: { relative: 'uri' }`
91
+ - Files the document or the CSS references with a `file:` URL (`file:///…/style.css` etc.) are read from that file, even outside the input's directory. Relative references that point outside the input's directory (`url(../fonts/a.ttf)` in `sub/a.html` etc.) are read the same way (as when a browser opens a local HTML file). `--no-outside-files` stops reading files outside the input's directory (for documents written by others: an image, font or SVG the document points at is drawn into the PDF when it can be read, so this keeps other files of the machine from being copied out; files inside the input's directory are still read). When none of the files in the `src` of an `@font-face` is found, a warning is reported
86
92
  - `--watch`: re-typesets whenever the HTML, FO, CSS, images or fonts in the input's directory change
87
93
  - `--help` (`-h`) prints the usage, `--version` (`-v`) prints the version
88
94
  - Unsupported CSS properties and values (listed in chapter 16 of the Conformance Guide), properties unknown to Kumiori (misspelled or unsupported), XSL-FO elements and properties that cannot be read, unreadable images and so on are not silently ignored but reported as `警告:` ("warning:") messages (in the library, `result.warnings`)
89
95
 
90
- - 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. `--css a.css,b.css` selects the CSS to use (comma-separated for several; `@import` targets are used too. CSS not referenced from the HTML is added as a user stylesheet)
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)
91
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)
92
- - `--font-dir <dir>`: the directory from which the default fonts (`NotoSerifJP-Regular.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
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
93
100
  - `--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
94
101
  - `--no-font-cache`: neither reads nor writes the font cache (fetches from Google Fonts every time)
95
102
  - `--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
96
- - `--font <font file>` (repeatable): adds a font file (TTF, OTF, TTC) (for a TTC, each font inside is added). Fonts are registered by the family name in the font's name table and the weight in its OS/2 table, and used from `font-family` like fonts installed on the system (italic files are not registered). In compatibility styles such as `--style ah`, fonts are also selected by the PostScript name written in SVG's `font-family` (e.g. `'CenturyGothic'`)
97
- - `--generic-font serif=<font name>`, `--generic-font sans-serif=<font name>`: the font used for Latin text of the generic fonts (serif, sans-serif) (the family name of a font added with `--font`)
103
+ - `--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
+ - `--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"`
98
105
  - `--print`: trim marks and bleed (3mm)
99
106
  - `--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)
100
- - `--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). 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
107
+ - `--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
101
108
  - 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)
102
109
  - 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
103
110
  - 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
@@ -130,20 +137,29 @@ const pdf = await result.toPdf(); // Uint8Array
130
137
  result.renderPage(canvas, 0); // draw page 1 onto a canvas (browser)
131
138
  ```
132
139
 
133
- - `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 the document references via `http(s):` (can be stopped with `fetchImages`), so it runs both in the browser and in Node
140
+ - `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
134
141
  - `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)
135
- - Main `options`: `kind` (`html`, `xhtml`, `fo`; if omitted, determined from `name` and the content), `name` (the input file name), `files` (CSS, images, fonts), `fonts` (fonts to add), `genericFonts` (fonts for Latin text of the generic fonts), `style` (the default style for HTML), `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), `lang` (language of `warnings` and error messages: `ja` or `en`; default Japanese), `deflate` (in Node, passing `zlib.deflateSync` speeds up PDF output)
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)
143
+ - 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
136
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
137
145
  - 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)
138
146
  - 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
+ - `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`)
148
+ - 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
+
150
+ ```ts
151
+ import { typeset } from 'kumiori';
152
+ import { createFileResolver, createFontLoader } from 'kumiori/node';
153
+ const result = await typeset(html, { loadFont: createFontLoader(), resolveResource: createFileResolver() });
154
+ ```
139
155
  - The fonts used by default can be found in `DEFAULT_FONTS` (the `family`, `weight` and `urls` of the `spec` passed to `loadFont`)
140
- - Only what is exported from `src/index.ts` is public (the functions and types of other modules may change between versions)
141
- - `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. Since it is ES module only, loading it with `require()` requires Node 22 or later
156
+ - 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
+ - `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`)
142
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:
143
159
 
144
160
  ```html
145
161
  <script type="module">
146
- import { typesetHtml } from 'https://cdn.jsdelivr.net/npm/kumiori@0.1.1/dist-browser/kumiori.js';
162
+ import { typesetHtml } from 'https://cdn.jsdelivr.net/npm/kumiori@0.2.0/dist-browser/kumiori.js';
147
163
  const result = await typesetHtml(html, { name: 'a.html' });
148
164
  result.renderPage(document.querySelector('canvas'), 0);
149
165
  </script>
@@ -189,9 +205,12 @@ async function showPreview(bodyHtml: string, container: HTMLElement) {
189
205
  | File | Role |
190
206
  | --- | --- |
191
207
  | `src/index.ts`, `src/api.ts` | Public API (`typeset`, `createTypesetter`, `DEFAULT_FONTS`, etc. Only what is exported from `src/index.ts` is public) |
208
+ | `src/node.ts`, `src/nodeFonts.ts`, `src/resources.ts` | Helpers for Node (`kumiori/node`: the font cache and reading `file:` references), and collecting the references of the document and the CSS (`resolveResource`, fetching stylesheets) |
192
209
  | `src/types.ts` | Types for the logical tree (Input), the physical tree (Area Tree) and page settings |
193
210
  | `src/areaTree.ts`, `src/areaResources.ts` | Walking the Area Tree and reading/writing it as JSON ([`docs/en/area-tree.md`](docs/en/area-tree.md)); the list of fonts and images used |
194
211
  | `src/fontManager.ts` | Fetches TTF/OTF → `FontFace` (Canvas) + `ArrayBuffer` (PDF) + fontkit (metrics) |
212
+ | `src/fontInstancer.ts`, `src/fontVariation.ts` | Builds a static font for an instance of a variable font (OpenType Font Variations) at given axis values (gvar, HVAR, MVAR, GPOS values, FeatureVariations); carries the requested axis values |
213
+ | `src/cff2Instancer.ts` | Turns an instance of a font with CFF2 (variable CFF) outlines into a static CFF (evaluates blend / vsindex in the glyphs and rewrites them as Type 2 CharStrings) |
195
214
  | `src/measurer.ts`, `src/jis.ts` | Character width measurement (both Canvas and fontkit backends), measurement for vertical writing, ruby and tate-chu-yoko, line-breaking rules (kinsoku) |
196
215
  | `src/geometry.ts`, `src/lnode.ts` | Conversion between logical (inline/block) and physical coordinates, intermediate layout tree |
197
216
  | `src/inlineLayout.ts`, `src/inlineFlatten.ts`, `src/lineMetrics.ts` | Line breaking (kinsoku, hanging punctuation, pushing out), inline placement, generation of line nodes for ruby/tate-chu-yoko, inline tree → sequence of characters (Atom), line height (three models: CSS, XSL and compatibility) |
@@ -204,12 +223,12 @@ async function showPreview(bodyHtml: string, container: HTMLElement) {
204
223
  | `src/cssCascade.ts`, `src/cssSelector.ts`, `src/cssText.ts` | CSS interpretation without a browser (cascade, computed values, selectors), CSS lexical helpers (separators, lengths, colors) |
205
224
  | `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) |
206
225
  | `src/svg.ts`, `src/mathLayout.ts` | Converting SVG to shapes, MathML typesetting |
207
- | `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`, `psImage`, `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 |
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 |
208
227
  | `src/epub.ts`, `src/xhtml.ts` | EPUB extraction, XHTML import |
209
228
  | `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 |
210
229
 
211
230
  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).
212
- 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), 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).
231
+ 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).
213
232
 
214
233
  ## Fonts
215
234
 
@@ -217,14 +236,16 @@ The fonts for typesetting are not included in this repository. They are fetched
217
236
 
218
237
  | Font | Use | License |
219
238
  | --- | --- | --- |
220
- | Noto Serif JP, Noto Sans JP | Japanese (Mincho, Gothic) | SIL Open Font License 1.1 |
221
- | Tinos, Arimo | Latin (serif, sans-serif) | Apache License 2.0 |
239
+ | Noto Serif JP, Noto Sans JP (Regular and Bold of each) | Japanese (Mincho, Gothic) | SIL Open Font License 1.1 |
240
+ | Tinos, Arimo (Regular and Bold of each) | Latin (serif, sans-serif) | Apache License 2.0 |
222
241
  | Cousine | When monospace is specified | Apache License 2.0 |
223
242
  | 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 |
224
243
  | Noto Sans Symbols 2 | When the document contains symbols (such as ✈) found in none of the loaded fonts | SIL Open Font License 1.1 |
225
244
 
245
+ 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
+
226
247
  The Node CLI saves the fetched fonts to the OS cache (`~/.cache/kumiori/fonts` etc.; can be changed with `--font-cache`) and does not use the network from the second run on. For offline use, in the web app (browser), TTFs with the same names placed in `public/fonts/` are used as a fallback (not tracked by git). With the Node CLI, either run once online to fill the cache, or specify the directory to read with `--font-dir`. The library's (`typeset`) default fetching tries only `https:` URLs, so pass local fonts via `loadFont`.
227
- Fonts placed in `public/fonts/` are also copied to the build output (`dist/fonts/`, `dist-cli/fonts/`). If you do not want them in what you distribute, remove them before building. The Node CLI does not read the copied `dist-cli/fonts/` automatically (it looks only at the directory passed, e.g. `--font-dir dist-cli/fonts`).
248
+ Fonts placed in `public/fonts/` are also copied to the build output of the web app (`dist/fonts/`). If you do not want them in what you distribute, remove them before building. The contents of `public/` are not copied to the output distributed through npm (`dist-cli/`, `dist-lib/`, `dist-browser/`). The Node CLI looks only at the directory passed with `--font-dir`.
228
249
 
229
250
  The fonts used are embedded in the PDF. Check the license terms of each font with its distributor.
230
251
 
@@ -238,7 +259,7 @@ The fonts used are embedded in the PDF. Check the license terms of each font wit
238
259
 
239
260
  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).
240
261
 
241
- The licenses and copyright notices of the third-party software Kumiori uses (pdf-lib, pako, utif, hyphen, etc.) are collected in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). The output of `npm run build`, `npm run build:cli`, `npm run build:lib` and `npm run build:browser` (`dist/`, `dist-cli/`, `dist-lib/`, `dist-browser/`) also contains `LICENSE`, `NOTICE` and `THIRD_PARTY_NOTICES.md`.
262
+ The licenses and copyright notices of the third-party software Kumiori uses (pdf-lib, pako, utif, hyphen, etc.) are collected in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). The output of `npm run build`, `npm run build:cli`, `npm run build:lib` and `npm run build:browser` (`dist/`, `dist-cli/`, `dist-lib/`, `dist-browser/`) also contains `LICENSE`, `NOTICE` and `THIRD_PARTY_NOTICES.md`. Every output JS file (including chunks) starts with a comment (`/*! … */`) giving the Kumiori version, its license and where `THIRD_PARTY_NOTICES.md` is (for when a single file is loaded from a CDN).
242
263
 
243
264
  ## Relationship to other companies' products
244
265
 
@@ -261,13 +282,17 @@ npm test # unit tests (Node + fontkit; fetches Noto Serif JP into .cach
261
282
  npm run e2e # browser integration tests (Playwright; on first run, npx playwright install chromium)
262
283
  ```
263
284
 
285
+ 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
+ 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
+ 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.
288
+
264
289
  Comparison with sample PDFs (prepare the sample FO and PDF files yourself; they are not in the repository. poppler's pdftoppm is required):
265
290
 
266
291
  ```bash
267
292
  node scripts/compare-pdf.mjs --fo <FO directory> --ref <sample PDF directory> --img <image directory> --out compare-pdf-out
268
293
  ```
269
294
 
270
- 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).
295
+ 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).
271
296
 
272
297
  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):
273
298
 
package/README.md CHANGED
@@ -13,7 +13,7 @@ Canvas のプレビューと PDF に出力します。
13
13
 
14
14
  Kumiori は、AI のコーディング支援 ([Claude Code](https://claude.com/claude-code)) を使って開発しています (「[開発の方法について](#開発の方法について)」)。
15
15
 
16
- - **TypeScript 約 5 万 4 千行・テスト約 1,500 件**: 機能を足すたびに AI がテストを書き足し、CI (型チェック・単体テスト・ブラウザでの結合テスト 13 件) を通しています
16
+ - **TypeScript 約 6 万行・テスト約 1,900 件**: 機能を足すたびに AI がテストを書き足し、CI (型チェック・単体テスト・ブラウザでの結合テスト 15 件) を通しています
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
 
@@ -21,7 +21,7 @@ Kumiori は、AI のコーディング支援 ([Claude Code](https://claude.com/c
21
21
 
22
22
  - **入力**: HTML+CSS (自前の CSS カスケード。ブラウザ不要)、XSL-FO (アンテナハウスの拡張 `axf:*` のうち、よく使われるものを中心に一部に対応)、JSON の論理ツリー
23
23
  - **日本語組版**: 縦書き・横書き、ルビ、縦中横、圏点、禁則、ぶら下げ・追い出し、約物の詰め、和欧間のアキ
24
- - **多言語**: アラビア語・ヘブライ語などの右から左の文字 (Unicode の双方向アルゴリズム UAX #9 で並べ替え、アラビア文字は前後につながる字形にする。CSS の `direction: rtl`、XSL-FO の `writing-mode="rl-tb"`)、欧文のハイフネーション、欧文と和文の混在。アラビア文字などの書体は `--font` や `fonts` で渡す (既定の書体には無い)
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
26
  - **出力**: Canvas のプレビュー、PDF (書体のサブセット埋め込み、しおり、リンク、注釈、フォーム、トンボ、PDF/X-3 の印と、RGB の色・画像の CMYK への変換)
27
27
  - PDF/X-3 の印 (API の `pdfx`) は、PDF の仕様 ISO 32000-2 で決まっている部分 (出力意図の辞書の形など) だけを確かめています。PDF/X の規格 ISO 15930 の本文では確かめていないので、規格への適合は保証しません
@@ -51,12 +51,13 @@ npm run build # 型チェック + 本番ビルド (dist/。画面)
51
51
  npm run build:dist # ライブラリ (dist-lib)・Node のコマンド (dist-cli)・ブラウザ用の 1 ファイル (dist-browser) をまとめて作る
52
52
  ```
53
53
 
54
- Node は 20 以上 (CI は 22 で確かめています。`--watch` の再帰的な監視に Node 20 以降が要ります)。公開の手順は [`docs/RELEASING.md`](docs/RELEASING.md)、版ごとの変更は [`CHANGELOG.md`](CHANGELOG.md) にあります。
54
+ Node は 20.19.0 以上の 20 系か、22.12.0 以上 (CI は 20.19.0 と 22 で確かめています。HTML を読むための依存パッケージ (linkedom の使う css-select など) が Node 20.19.0 以降を求めます。22.0〜22.11 は、ES モジュールを `require()` で読めないので対象から外しています)。公開の手順は [`docs/RELEASING.md`](docs/RELEASING.md)、版ごとの変更は [`CHANGELOG.md`](CHANGELOG.md) にあります。
55
55
 
56
56
  ### 画面 (ブラウザ)
57
57
 
58
58
  - 「開く」で HTML・XSL-FO・EPUB を、使う CSS・画像・書体と一緒に選ぶ (複数選べる)。「フォルダを開く」でフォルダごと選ぶか、ファイルやフォルダを画面にドラッグ&ドロップしても開ける。フォルダに文書が複数あるときは index.html (無ければ浅い場所の文書) を開く
59
- - 「PDF を保存」で PDF を書き出す。左にページの縮小画像と警告 (たためる)、右の「設定」に既定のスタイル・CSS の解釈・「仕様どおりの既定値で組む」(XSL-FO の既定値の流儀。コマンドの `--compat` と同じ)・トンボ・書体の読み込みがある
59
+ - 「PDF を保存」で PDF を書き出す。左にページの縮小画像と警告 (たためる)、右の「設定」に既定のスタイル・既定の用紙 (`@page` で `size` を指定していない HTML の用紙。A4・A5・B5・JIS-B5・letter と自由入力。コマンドの `--page-size` と同じ)・CSS の解釈・「仕様どおりの既定値で組む」(XSL-FO の既定値の流儀。コマンドの `--compat` と同じ)・トンボ・書体の読み込みがある
60
+ - 警告は、左の欄に 1 件ずつ並ぶ (同じ文はまとめる。4 件以上は畳んで件数だけを見せ、開けば読める。件数は上の帯にも出る)。出るのは、コマンド・API の警告と同じもの: 組版の警告、未対応の CSS・XSL-FO と知らない CSS のプロパティ、安全のため PDF に動作を書かなかったリンク、128 段より深い入れ子・多すぎる `@import`、EPUB の上限を超えて飛ばした項目、取らなかった画像、書体の知らせ (取得できなかった書体など)
60
61
  - 組版はすべてブラウザの中で行い、文書や書体を外へ送らない (外から取るのは、既定の書体と、文書が `http(s):` で参照する画像だけ)。`npm run build` の `dist/` を静的なウェブサーバーに置いても動く
61
62
 
62
63
  ### Node のコマンド (ブラウザを使わずに HTML+CSS・XSL-FO を PDF に)
@@ -82,22 +83,28 @@ cat book.html | node dist-cli/cli.js - -o - --base . > book.pdf
82
83
  - 入力が複数なら、`-o` (`--output`) は出力先のディレクトリ (無ければ各入力の隣に `.pdf`)。1 つ失敗しても、ほかは作る (終了コードは 1)。入力が 1 つでも、`-o` が既存のディレクトリなら、その中に `<入力名>.pdf` を書く
83
84
  - `-` は標準入力から読む (CSS・画像・書体は `--base` のディレクトリ (既定は今のディレクトリ) から。FO かどうかは中身で見分ける)。`-o -` は PDF を標準出力へ書く
84
85
  - 入力の文字の符号化は、BOM と XML 宣言の `encoding` (`Shift_JIS`・`EUC-JP` など)・HTML の `<meta charset>` で決める (無ければ UTF-8)
85
- - 文書が `http(s):` で参照する画像は、既定ではネットワークから取る。`--no-fetch-images` で取らない (他人の書いた文書をサーバーで組むときなど。読めない画像として組む)
86
+ - 文書が `http(s):` で参照する画像は、既定ではネットワークから取る。`--no-fetch-images` で取らない (他人の書いた文書をサーバーで組むときなど。読めない画像として組む)。ネットワークの画像は同時に 8 個まで取り、文書の画像の取得の全体にも時限がある (1 つの取得の時限の 10 倍。既定では 5 分。過ぎたら、残りは読めない画像として組む)
87
+ - 文書が `http(s):` で参照する CSS (`<link rel="stylesheet">`・`@import`) と、その `@font-face` の書体 (`unicode-range` が文書の字と重なるものだけ) も、既定ではネットワークから取る。`--no-fetch-styles` で取らない
88
+ - 画像の大きさには上限がある (小さなファイルで大量のメモリ・時間を使わせないため。値と根拠は `src/imageLimits.ts`)。1 枚の画像は 1 億画素まで。WMF・EMF・CGM の中の画像 (DIB・セルの並び・タイルの並び・模様) は、1 つのファイルで合計 6,400 万画素までで、かつ「26 万画素 (512 × 512) + ファイルの 1 バイトあたり 1,024 画素」まで (数百バイトのファイルから巨大な画像を作らせない。約 61KB より大きなファイルなら 6,400 万画素まで使える)。超えた画像は描かず、文書の残りを組む。GIF・WebP・JPEG・CCITT の TIFF・RLE の BMP も、画素の数をファイルの大きさで縛り (形式ごとに、正当なファイルの符号の密度の上限から決めた値。ほぼ 1 色の大きな可逆の WebP、幅 16,384 画素より広い白紙の CCITT、ほぼ白紙の大きな RLE の BMP は、上限を超えれば描かない)、PNG は展開した大きさが圧縮したデータの 1,032 倍 (deflate の上限) を超えるものを描かない。WOFF・WOFF2 を戻した書体は 128MB まで、かつファイルの 100 倍 + 1MB まで。WMF・EMF・CGM を図にした長さ (2MB + ファイルの 1 バイトあたり 128 字) と、1 つの文書の EPS の実行時間の合計 (60 秒) にも上限がある
89
+ - 他人の書いた文書をサーバーで組むときは、上の上限とは別に、1 つの文書を組む処理にも時間とメモリの上限をかけてください (文書ごとに別のプロセスかワーカーで組み、時限を過ぎたら止める。`node --max-old-space-size=…` やコンテナのメモリの上限を付ける、など)。上の上限は 1 つの画像・書体ごとのもので、上限いっぱいの画像 1 枚でも数秒〜十数秒と 2GB ほどを使い、文書が多くの画像・書体を参照すれば、その数だけ手間が増える
90
+ - 文書の外へのリンク (HTML の `<a href>`・XSL-FO の `fo:basic-link`・`fo:bookmark` の `external-destination`) のうち、PDF に動作を書くのは、既定では、スキームが `http`・`https`・`mailto`・`tel` の URL と、相対参照の PDF (別の PDF を開く動作) だけ。ほかのスキーム (`javascript:`・`data:`・`file:` など) と、ファイルを開く動作 (PDF でない相対のファイル・絶対パス・スキームの無い `//host/…`) は、字だけを組み、「警告:」に件数を出す (他人の書いた文書から作った PDF を、別の人が開くときのため)。`--link-schemes http,https,ftp` で許すスキームを選び (`*` はすべて)、`--link-launch` でファイルを開く動作も書く (`--link-schemes '*' --link-launch` で、すべて書く)。`--link-relative uri` で、スキームの無い相対のリンク (`x.pdf`・`a.mp3`) を、ファイルを開く動作 (GoToR・Launch) ではなく、書かれた参照のままの URI の動作 (`/S /URI /URI (x.pdf)`。`%xx` は解かない) に書く (ブラウザの中の PDF ビューアは GoToR・Launch を扱わないものが多い。PDF でない相対のファイルも `--link-launch` 無しで書く。絶対パスと `//host/…` は `--link-launch` のときだけ)。API では `links: { relative: 'uri' }`
91
+ - 文書・CSS が `file:` の URL で参照するファイル (`file:///…/style.css` など) は、入力のディレクトリの外でも、そのファイルを読む。相対参照が入力のディレクトリの外を指すもの (`sub/a.html` の `url(../fonts/a.ttf)` など) も同じく読む (ブラウザで手元の HTML を開いたときと同じ)。`--no-outside-files` で、入力のディレクトリの外のファイルを読まない (他人の書いた文書を組むとき。文書が指した画像・書体・SVG は、読めた中身が PDF に描かれるので、組む側の機械のほかのファイルを写し取られないようにする。入力のディレクトリの中のファイルは、これまでどおり読む)。`@font-face` の `src` のどのファイルも見つからないときは、警告で知らせる
86
92
  - `--watch`: 入力のディレクトリの HTML・FO・CSS・画像・書体が変わるたびに組み直す
87
93
  - `--help` (`-h`) で使い方、`--version` (`-v`) で版を出す
88
94
  - 未対応の CSS のプロパティ・値 (対応仕様説明書の 16 章の一覧) と、Kumiori の知らないプロパティ (綴りの誤りか未対応)、XSL-FO の読めない要素・プロパティ、読めない画像などは、黙って無視せずに「警告:」として知らせる (ライブラリでは `result.warnings`)
89
95
 
90
- - HTML と同じディレクトリ (と下のディレクトリ) の CSS・画像・書体を使う (画面で一緒に選ぶのと同じ)。画像は、文書と CSS に名前が出てくるものだけを読む。`--css a.css,b.css` で使う CSS を選ぶ (カンマ区切りで複数。`@import` 先も使う。HTML から参照されていない CSS は利用者のスタイルシートとして足す)
96
+ - HTML と同じディレクトリ (と下のディレクトリ) の CSS・画像・書体を使う (画面で一緒に選ぶのと同じ)。画像は、文書と CSS に名前が出てくるものだけを読む。CSS は、HTML が参照するもの (`<link>`・`@import`) だけを使う (参照していない CSS は当てずに、警告で知らせる)。`--css a.css,b.css` で使う CSS を選ぶ (カンマ区切りで複数。`@import` 先も使う。HTML から参照されていない CSS も、名指ししたものは利用者のスタイルシートとして足す)
91
97
  - `--style kumiori|browser|browser-margin|ah|vivliostyle|weasyprint`: 既定のスタイル (画面の「設定」の「既定のスタイル」と同じ。既定は kumiori)
92
- - `--font-dir <dir>`: 既定の書体 (`NotoSerifJP-Regular.ttf`・`NotoSansJP-Regular.ttf`・`NotoSansJP-Bold.ttf`・`Tinos-*.ttf`・`Arimo-*.ttf`、等幅の指定があれば `Cousine-*.ttf`、MathML があれば `STIXTwoMath-Regular.ttf`、どの書体にも無い記号があれば `NotoSansSymbols2-Regular.ttf`) を読むディレクトリ。無ければ書体のキャッシュ、次に Google Fonts から読む
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` など) も置く: 置かなかったファイルは、キャッシュかネットワークの既定の書体になり、入れ替えた書体と混ざる
93
100
  - `--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 回目からはネットワークに行かない。途中で切れた取得など、書体のファイルでないものは保存せず、壊れたキャッシュは捨てて取り直す。保存できない場所でも変換は続ける
94
101
  - `--no-font-cache`: 書体のキャッシュを読まず、保存もしない (毎回 Google Fonts から取る)
95
102
  - `--lang ja|en`: 使い方・報告・警告・誤りの文の言語。無ければ環境変数 `KUMIORI_LANG`、次に OS のロケール (`LC_ALL`・`LC_MESSAGES`・`LANG` が `en…` なら英語) で決める。既定は日本語
96
- - `--font <書体ファイル>` (何度でも): 書体のファイル (TTF・OTF・TTC) を足す (TTC は中の書体をそれぞれ足す)。書体の name 表のファミリー名と OS/2 の太さで登録し、システムに入れた書体のように `font-family` から使う (斜体のファイルは登録しない)。`--style ah` などの互換のスタイルでは、SVG の `font-family` に書いた PostScript 名 (`'CenturyGothic'` など) でも選ぶ
97
- - `--generic-font serif=<書体名>`・`--generic-font sans-serif=<書体名>`: 総称の書体 (serif・sans-serif) の欧文に使う書体 (`--font` で足した書体のファミリー名)
103
+ - `--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
+ - `--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"`
98
105
  - `--print`: トンボと塗り足し (3mm)
99
106
  - `--image-max-dpi <dpi>`: 置かれる大きさに対してこれより細かい JPEG の写真を、この解像度に縮めて符号化し直す (PDF を小さくする。既定は元のまま)
100
- - `--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 で書く。名前の字は UTF-8 で書く (ISO 32000-2 §7.3.5)。特色の値 (色見本帳の値など) は Kumiori には入っていないので、使う人が渡す
107
+ - `--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 には入っていないので、使う人が渡す
101
108
  - HTML は linkedom で読み、CSS の計算値は自前のカスケード (画面の「CSS の解釈: Kumiori」と同じ)
102
109
  - XHTML (`.xhtml`・`.xht`) は XML の構文で読み、名前空間に従って書き直してから HTML と同じに組む (`<s:svg xmlns:s="http://www.w3.org/2000/svg">` のような接頭辞の付いた要素も SVG になる。`src/xhtml.ts`)。`.html` は HTML の構文で読むので、接頭辞の付いた要素は SVG にならない。`--xhtml` を付けると、拡張子によらず XML の構文で読む
103
110
  - MathML (`<math>`) は、数式用の書体 (`STIXTwoMath-Regular.ttf`) で組み、字の輪郭の図形にする (XSL-FO と同じ `src/mathLayout.ts`)。`display="block"` の数式は行の中央に置く
@@ -130,20 +137,29 @@ const pdf = await result.toPdf(); // Uint8Array
130
137
  result.renderPage(canvas, 0); // 1 ページ目を canvas に描く (ブラウザ)
131
138
  ```
132
139
 
133
- - `typeset(text, options)` が入口です (`typesetHtml`・`typesetFo` は種類を決め打ちする版)。ファイルシステムには触らず、ネットワークは既定の書体の取得 (`loadFont` で差し替えられる) と、文書が `http(s):` で参照する画像の取得 (`fetchImages` で止められる) にだけ使うので、ブラウザでも Node でも動きます
140
+ - `typeset(text, options)` が入口です (`typesetHtml`・`typesetFo` は種類を決め打ちする版)。ファイルシステムには触らず、ネットワークは既定の書体の取得 (`loadFont` で差し替えられる) と、文書が `http(s):` で参照する画像・CSS の取得 (`fetchImages`・`fetchStyles` で止められる) にだけ使うので、ブラウザでも Node でも動きます
134
141
  - `text` は文字列です。ファイルから読むときは `decodeDocumentText(bytes)` で文字列にすると、BOM・XML 宣言の `encoding`・`<meta charset>` に従って復号します (UTF-8 固定で読むと、Shift_JIS の FO などが化けます)
135
- - 主な `options`: `kind` (`html`・`xhtml`・`fo`。省略すれば `name` と中身で決める)、`name` (入力のファイル名)、`files` (CSS・画像・書体)、`fonts` (足す書体)、`genericFonts` (総称の書体の欧文に使う書体)、`style` (HTML の既定のスタイル)、`compat` (XSL-FO の既定値の流儀)、`print` (塗り足しとトンボ)、`spotColors` (特色の代わりの CMYK)、`loadFont`、`fetchTimeoutMs` (書体・画像の取得の時限。既定 30 秒)、`fetchImages` (文書が `http(s):` で参照する画像を取るか。既定 `true`。`false` か、URL を受けて真偽を返す関数。他人の文書をサーバーで組むときは止めるか、許す URL だけにする)、`lang` (`warnings` と誤りの文の言語。`ja` か `en`。既定は日本語)、`deflate` (Node なら `zlib.deflateSync` を渡すと PDF の書き出しが速い)
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 の書き出しが速い)
143
+ - `fetchImages`・`fetchStyles` に渡す関数には、文書に書かれた URL のほか、転送 (redirect) の先の URL も聞きます。Node では、転送を 1 つずつ確かめてたどり (20 回まで)、許されない先へは要求を出しません。`https:` から `http:` への転送と、`http(s):` でない先への転送は、関数に聞かずに断ります (真偽の `true` のときも同じ)。ブラウザでは、転送の先をスクリプトから前もって読めないので、たどった後の最後の URL を関数に聞き、許されなければ応答を使いません (このとき、要求そのものは転送の先に届いています)。関数が見るのは URL の文字列だけです。内部のアドレスに解決されるホスト名 (DNS rebinding を含む) は、関数では防げません。他人の書いた文書をサーバーで組むときに内部の網を守るには、実行環境の側 (外向きの通信の制限・外向きのプロキシ) でも絞ってください。ネットワークから取るものの大きさには上限があります (画像 256MB・CSS 16MB・書体 128MB)。超えたものは、読むのを途中でやめて、読めない資源として扱います (`Content-Length` の無い応答でも同じ)。`fetchTimeoutMs` の時限は、本体を読み終えるまで効きます
136
144
  - `result.toPdf({ title, pdfx, imageMaxDpi })`: PDF の題名、PDF/X-3 の印 (`pdfx`。RGB の色・画像を CMYK にする)、JPEG の解像度の上限。`result.renderPage(canvas, i, { scale, devicePixelRatio, guides })`: 倍率、画面の画素の細かさ、仕上がり・塗り足しのガイド線
137
145
  - FO の DOCTYPE の内部サブセットに宣言した内部実体 (`<!ENTITY nbsp "&#160;">` など) は、読み込みの前に展開します (外部実体は読みません)
138
146
  - 例外: FO の XML が読めない (`XML の解析に失敗しました: …`)、既定の書体が読めない (`書体を読めません: …`) は `typeset` が投げる。`fonts` に渡した壊れた書体ファイルは投げずに `warnings` に入る。`renderPage` の無いページ番号は `RangeError`。組版の警告 (読めない画像・溢れなど) は投げずに `result.warnings` (文字列の配列) に入る
147
+ - `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` など)、返した中身の先頭のバイト列で画像と見分けて使います
148
+ - Node では、`kumiori/node` の部品が使えます: `createFontLoader({ fontDir, cacheDir, log, timeoutMs })` は `loadFont` に渡す既定の書体の読み込み (Node のコマンドと同じ: `fontDir` → 書体のキャッシュ → ネットワーク。取った書体はキャッシュに保存する。`cacheDir` の既定は `defaultFontCacheDir()`、`null` でキャッシュしない)。`createFileResolver({ root })` は `resolveResource` に渡す、`file:` の URL のファイルを読む関数 (`root` を渡すと、その中のファイルだけを読む。`root` はいくつかの並びでもよく、中にあるかはシンボリックリンクをたどった実体のパスで見る)
149
+
150
+ ```ts
151
+ import { typeset } from 'kumiori';
152
+ import { createFileResolver, createFontLoader } from 'kumiori/node';
153
+ const result = await typeset(html, { loadFont: createFontLoader(), resolveResource: createFileResolver() });
154
+ ```
139
155
  - 既定で使う書体は `DEFAULT_FONTS` で分かります (`loadFont` に渡される `spec` の `family`・`weight`・`urls`)
140
- - 公開しているのは `src/index.ts` から出しているものだけです (ほかのモジュールの関数・型は、版の間で変わることがあります)
141
- - `kumiori` (`dist-lib/index.js`) は依存パッケージ (pdf-lib・fontkit・xmldom など) を束ねていない ES モジュールです。Vite・webpack などのバンドラーで使うか、Node から読んでください。ES モジュールだけなので、`require()` で読むには Node 22 以降が要ります
142
- - バンドラーを使わないブラウザでは、依存まで束ねた 1 ファイル `kumiori/browser` (`dist-browser/kumiori.js`。約 2.7MB、gzip で 0.9MB。ハイフネーションの辞書などは使うときだけ別ファイルを読む) を使います。npm に公開したものは jsDelivr や unpkg の CDN からそのまま読めます:
156
+ - 公開しているのは `src/index.ts` (と Node 用の `src/node.ts`) から出しているものだけです (ほかのモジュールの関数・型は、版の間で変わることがあります)
157
+ - `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 からそのまま読めます:
143
159
 
144
160
  ```html
145
161
  <script type="module">
146
- import { typesetHtml } from 'https://cdn.jsdelivr.net/npm/kumiori@0.1.1/dist-browser/kumiori.js';
162
+ import { typesetHtml } from 'https://cdn.jsdelivr.net/npm/kumiori@0.2.0/dist-browser/kumiori.js';
147
163
  const result = await typesetHtml(html, { name: 'a.html' });
148
164
  result.renderPage(document.querySelector('canvas'), 0);
149
165
  </script>
@@ -189,9 +205,12 @@ async function showPreview(bodyHtml: string, container: HTMLElement) {
189
205
  | ファイル | 役割 |
190
206
  | --- | --- |
191
207
  | `src/index.ts`, `src/api.ts` | 公開 API (`typeset`・`createTypesetter`・`DEFAULT_FONTS` など。公開しているのは `src/index.ts` から出しているものだけ) |
208
+ | `src/node.ts`, `src/nodeFonts.ts`, `src/resources.ts` | Node 用の部品 (`kumiori/node`: 書体のキャッシュ・`file:` の参照の読み込み)、文書と CSS の参照の集め方 (`resolveResource`・CSS の取得) |
192
209
  | `src/types.ts` | 論理ツリー (Input) / 物理ツリー (Area Tree) / ページ設定の型 |
193
210
  | `src/areaTree.ts`, `src/areaResources.ts` | Area Tree をたどる・JSON で読み書きする ([`docs/area-tree.md`](docs/area-tree.md))、使った書体・画像の一覧 |
194
211
  | `src/fontManager.ts` | TTF/OTF を fetch → `FontFace`(Canvas) + `ArrayBuffer`(PDF) + fontkit(メトリクス) |
212
+ | `src/fontInstancer.ts`, `src/fontVariation.ts` | 可変フォント (OpenType Font Variations) の、軸の値を決めた形 (実体) を静的な書体にする (gvar・HVAR・MVAR・GPOS の値・FeatureVariations)、軸の値の指定の持ち回り |
213
+ | `src/cff2Instancer.ts` | 輪郭が CFF2 (可変の CFF) の書体の実体を、静的な CFF にする (字形の blend・vsindex を計算して、Type 2 の CharString に書き直す) |
195
214
  | `src/measurer.ts`, `src/jis.ts` | 文字幅計測 (Canvas / fontkit 両バックエンド)、縦書き・ルビ・縦中横の計測、禁則 |
196
215
  | `src/geometry.ts`, `src/lnode.ts` | 論理座標(inline/block) ↔ 物理座標の変換、レイアウト中間ツリー |
197
216
  | `src/inlineLayout.ts`, `src/inlineFlatten.ts`, `src/lineMetrics.ts` | 行分割 (禁則・ぶら下げ・追い出し)、行内配置、ルビ/縦中横の行ノード生成、inline の木 → 字の並び (Atom)、行の高さ (CSS・XSL・互換の 3 モデル) |
@@ -204,12 +223,12 @@ async function showPreview(bodyHtml: string, container: HTMLElement) {
204
223
  | `src/cssCascade.ts`, `src/cssSelector.ts`, `src/cssText.ts` | ブラウザを使わない CSS の解釈 (カスケード・計算値・セレクタ)、CSS の字句の補助 (区切り・長さ・色) |
205
224
  | `src/xslfoImport.ts`, `src/foExpr.ts`, `src/foDom.ts`, `src/foContext.ts`, `src/foPageMaster.ts`, `src/foMathFallback.ts` | XSL-FO の読み込み (属性 → 論理ツリー、式の評価、最小 DOM、ページマスター、数式書体が無いときの MathML の組版) |
206
225
  | `src/svg.ts`, `src/mathLayout.ts` | SVG を図形にする、MathML の組版 |
207
- | `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`・`psImage`・`psFilters`), `src/imageInfo.ts`, `src/base64.ts` | 画像の復号 (JPEG・WebP・GIF・BMP・TIFF) と上限、WMF/EMF・CGM・EPS (PostScript の解釈器) の図形化、画像の大きさの読み取り |
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 の解釈器) の図形化、画像の大きさの読み取り |
208
227
  | `src/epub.ts`, `src/xhtml.ts` | EPUB の展開、XHTML の読み込み |
209
228
  | `src/fontMapping.ts`, `src/compat.ts`, `src/documentResources.ts`, `src/documentText.ts`, `src/cli.ts` | 書体の割り当て・互換モードの設定・数式書体と画像の取得・文字の符号化の判定 (画面と Node で共通)、Node のコマンド |
210
229
 
211
230
  組版アルゴリズムの詳細は [`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) を参照。
212
- 対応している仕様の項目ごとの説明は対応仕様説明書 ([`docs/conformance/`](docs/conformance/README.md)。`npm run docs:conformance` で PDF にする)、まだ無い機能・既知の制限は [`docs/BACKLOG.md`](docs/BACKLOG.md)、組んだ結果 (Area Tree) の JSON は [`docs/area-tree.md`](docs/area-tree.md)。
231
+ 対応している仕様の項目ごとの説明は対応仕様説明書 ([`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)。
213
232
 
214
233
  ## フォント
215
234
 
@@ -217,14 +236,16 @@ async function showPreview(bodyHtml: string, container: HTMLElement) {
217
236
 
218
237
  | 書体 | 用途 | ライセンス |
219
238
  | --- | --- | --- |
220
- | Noto Serif JP・Noto Sans JP | 和文 (明朝・ゴシック) | SIL Open Font License 1.1 |
221
- | Tinos・Arimo | 欧文 (セリフ・サンセリフ) | Apache License 2.0 |
239
+ | Noto Serif JP・Noto Sans JP (それぞれ Regular と Bold) | 和文 (明朝・ゴシック) | SIL Open Font License 1.1 |
240
+ | Tinos・Arimo (それぞれ Regular と Bold) | 欧文 (セリフ・サンセリフ) | Apache License 2.0 |
222
241
  | Cousine | 等幅の指定があるとき | Apache License 2.0 |
223
242
  | STIX Two Math | 数式 (MathML) があるとき。MathML を、この書体の MATH 表の値で組む | SIL Open Font License 1.1 |
224
243
  | Noto Sans Symbols 2 | 読み込んだどの書体にも無い記号 (✈ など) が文書にあるとき | SIL Open Font License 1.1 |
225
244
 
245
+ どの文書でも読むのは、上の 2 行の 8 つのファイル (和文 4 つ・欧文 4 つ。合わせて約 29MB。うち Noto Serif JP が 8.0MB ずつ、Noto Sans JP が 5.7MB ずつ) で、ほかは文書に必要なときだけ読みます。太字の指定の字は、同じ書体の Bold で組みます (明朝の文の太字は Noto Serif JP の Bold)。
246
+
226
247
  Node のコマンドは、取った書体を OS のキャッシュ (`~/.cache/kumiori/fonts` など。`--font-cache` で変えられます) に保存し、2 回目からはネットワークに行きません。オフラインで使うときは、画面 (ブラウザ) では同じ名前の TTF を `public/fonts/` に置けば後備として使われます(git 管理外)。Node のコマンドでは、一度オンラインで動かしてキャッシュに入れるか、`--font-dir` で読むディレクトリを指定します。ライブラリ (`typeset`) の既定の取得は `https:` の URL しか試さないので、手元の書体は `loadFont` で渡してください。
227
- `public/fonts/` に置いた書体は、ビルドの出力 (`dist/fonts/`・`dist-cli/fonts/`) にもコピーされます。配布物に含めない場合は、ビルドの前に取り除いてください。Node のコマンドは、コピーされた `dist-cli/fonts/` を自動では読みません (`--font-dir dist-cli/fonts` のように渡したディレクトリだけを見ます)。
248
+ `public/fonts/` に置いた書体は、Web アプリのビルドの出力 (`dist/fonts/`) にもコピーされます。配布物に含めない場合は、ビルドの前に取り除いてください。npm で配る出力 (`dist-cli/`・`dist-lib/`・`dist-browser/`) には `public/` の中身をコピーしません。Node のコマンドは、`--font-dir` で渡したディレクトリだけを見ます。
228
249
 
229
250
  使った書体は PDF に埋め込まれます。書体のライセンスの条件は、各書体の配布元で確認してください。
230
251
 
@@ -238,7 +259,7 @@ Node のコマンドは、取った書体を OS のキャッシュ (`~/.cache/ku
238
259
 
239
260
  コードは [Apache License 2.0](LICENSE) (Copyright 2026 Northern Lights Co.。[NOTICE](NOTICE))。組版用の書体は、本リポジトリには同梱していません (書体とそのライセンスは「[フォント](#フォント)」の節)。
240
261
 
241
- Kumiori が使う第三者のソフトウェア (pdf-lib・pako・utif・hyphen など) のライセンスと著作権表示は、[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) にまとめています。`npm run build`・`npm run build:cli`・`npm run build:lib`・`npm run build:browser` の出力 (`dist/`・`dist-cli/`・`dist-lib/`・`dist-browser/`) にも、`LICENSE`・`NOTICE`・`THIRD_PARTY_NOTICES.md` が入ります。
262
+ Kumiori が使う第三者のソフトウェア (pdf-lib・pako・utif・hyphen など) のライセンスと著作権表示は、[THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) にまとめています。`npm run build`・`npm run build:cli`・`npm run build:lib`・`npm run build:browser` の出力 (`dist/`・`dist-cli/`・`dist-lib/`・`dist-browser/`) にも、`LICENSE`・`NOTICE`・`THIRD_PARTY_NOTICES.md` が入ります。出力する JS のファイル (チャンクを含む) の先頭には、Kumiori の版とライセンス、`THIRD_PARTY_NOTICES.md` の場所を書いた注釈 (`/*! … */`) が入ります (CDN からファイルを 1 つだけ読む場合のため)。
242
263
 
243
264
  ## 他社の製品との関係
244
265
 
@@ -261,13 +282,17 @@ npm test # 単体テスト (Node + fontkit。Noto Serif JP を .cache/f
261
282
  npm run e2e # ブラウザでの結合テスト (Playwright。初回は npx playwright install chromium)
262
283
  ```
263
284
 
285
+ テストが使う書体は、初回に取得して `.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
+ 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
+ 結合テストは、`KUMIORI_E2E_FONT_CACHE` にディレクトリを指定すると、ブラウザが取った書体をそこに覚えて、次からはネットワークに行かない (CI はこれを使う)。`KUMIORI_E2E_FONT_DIR` は、決まった名前の書体を手で用意して使うときの口。
288
+
264
289
  見本の PDF との比較 (比べる見本の FO と PDF は各自で用意する。リポジトリには入っていない。poppler の pdftoppm が必要):
265
290
 
266
291
  ```bash
267
292
  node scripts/compare-pdf.mjs --fo <FO のディレクトリ> --ref <見本の PDF のディレクトリ> --img <画像のディレクトリ> --out compare-pdf-out
268
293
  ```
269
294
 
270
- FO と同じ名前の PDF を組にして比べる。`compare-pdf-out/report.md` に、見本ごとのページ数と、ページごとの差 (差の大きい順) が出る。
295
+ 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 に取り出す。ディレクトリに無い書体は配信元から取る)。
271
296
 
272
297
  見本と Kumiori の出力を、目で見比べるページを作る (見本の PDF と Kumiori の PDF を、同じ名前で組にする):
273
298