reamkit 1.15.0 → 1.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/core/arc-to-bezier.d.ts +23 -0
- package/dist/esm/core/arc-to-bezier.js +23 -0
- package/dist/esm/core/bidi/algorithm.d.ts +26 -0
- package/dist/esm/core/bidi/algorithm.js +21 -0
- package/dist/esm/core/bidi/char-types.d.ts +17 -0
- package/dist/esm/core/bidi/char-types.js +10 -0
- package/dist/esm/core/bidi/index.d.ts +42 -0
- package/dist/esm/core/bidi/index.js +27 -0
- package/dist/esm/core/bidi/segments.d.ts +22 -0
- package/dist/esm/core/bidi/segments.js +14 -0
- package/dist/esm/core/bytes.d.ts +9 -0
- package/dist/esm/core/bytes.js +9 -0
- package/dist/esm/core/converter/facade.d.ts +38 -1
- package/dist/esm/core/converter/facade.js +25 -0
- package/dist/esm/core/converter/project.d.ts +12 -0
- package/dist/esm/core/converter/project.js +11 -0
- package/dist/esm/core/converter/ream.d.ts +107 -0
- package/dist/esm/core/converter/ream.js +76 -0
- package/dist/esm/core/crypto/asn1.d.ts +77 -0
- package/dist/esm/core/crypto/asn1.js +65 -0
- package/dist/esm/core/crypto/cms.d.ts +25 -0
- package/dist/esm/core/crypto/cms.js +8 -0
- package/dist/esm/core/document-model/index.d.ts +7 -0
- package/dist/esm/core/document-model/types.d.ts +328 -0
- package/dist/esm/core/drawingml/chart-geometry.d.ts +125 -0
- package/dist/esm/core/drawingml/chart-geometry.js +96 -0
- package/dist/esm/core/drawingml/chart-parser.d.ts +34 -0
- package/dist/esm/core/drawingml/chart-parser.js +34 -0
- package/dist/esm/core/drawingml/chart-serializer.d.ts +12 -0
- package/dist/esm/core/drawingml/chart-serializer.js +12 -0
- package/dist/esm/core/drawingml/colors.d.ts +53 -0
- package/dist/esm/core/drawingml/colors.js +41 -0
- package/dist/esm/core/drawingml/preset-geometry.d.ts +30 -0
- package/dist/esm/core/drawingml/preset-geometry.js +30 -0
- package/dist/esm/core/drawingml/shape-render.d.ts +54 -0
- package/dist/esm/core/drawingml/shape-render.js +54 -0
- package/dist/esm/core/drawingml/sparkline-geometry.d.ts +15 -0
- package/dist/esm/core/drawingml/sparkline-geometry.js +13 -0
- package/dist/esm/core/drawingml/theme-parser.d.ts +11 -0
- package/dist/esm/core/drawingml/theme-parser.js +11 -0
- package/dist/esm/core/font/arabic-joining.d.ts +21 -0
- package/dist/esm/core/font/arabic-joining.js +16 -0
- package/dist/esm/core/font/binary-reader.d.ts +17 -0
- package/dist/esm/core/font/binary-reader.js +17 -0
- package/dist/esm/core/font/font-registry.d.ts +37 -0
- package/dist/esm/core/font/font-registry.js +31 -0
- package/dist/esm/core/font/measure.d.ts +20 -0
- package/dist/esm/core/font/measure.js +11 -0
- package/dist/esm/core/font/opentype-layout.d.ts +49 -0
- package/dist/esm/core/font/opentype-layout.js +37 -0
- package/dist/esm/core/font/ttf-parser.d.ts +32 -0
- package/dist/esm/core/font/ttf-parser.js +7 -0
- package/dist/esm/core/font/ttf-subset.d.ts +21 -0
- package/dist/esm/core/font/ttf-subset.js +21 -0
- package/dist/esm/core/fonts/provider.d.ts +8 -1
- package/dist/esm/core/fonts/provider.js +1 -0
- package/dist/esm/core/fonts/remote-fonts.d.ts +22 -0
- package/dist/esm/core/fonts/remote-fonts.js +16 -0
- package/dist/esm/core/hyphenation/index.d.ts +25 -0
- package/dist/esm/core/hyphenation/index.js +17 -0
- package/dist/esm/core/hyphenation/liang.d.ts +27 -0
- package/dist/esm/core/hyphenation/liang.js +14 -0
- package/dist/esm/core/images.d.ts +32 -0
- package/dist/esm/core/images.js +12 -0
- package/dist/esm/core/ir/adapters.d.ts +23 -0
- package/dist/esm/core/ir/features.d.ts +8 -0
- package/dist/esm/core/ir/features.js +1 -0
- package/dist/esm/core/ir/flow.d.ts +20 -0
- package/dist/esm/core/ir/index.d.ts +7 -0
- package/dist/esm/core/ir/loss.d.ts +12 -0
- package/dist/esm/core/ir/loss.js +8 -0
- package/dist/esm/core/ir/resources.d.ts +12 -0
- package/dist/esm/core/ir/resources.js +11 -0
- package/dist/esm/core/ir/sheet.d.ts +81 -0
- package/dist/esm/core/ir/units.d.ts +9 -0
- package/dist/esm/core/ir/units.js +2 -0
- package/dist/esm/core/line-breaker/cjk.d.ts +26 -0
- package/dist/esm/core/line-breaker/cjk.js +60 -0
- package/dist/esm/core/line-breaker/greedy.d.ts +14 -0
- package/dist/esm/core/line-breaker/greedy.js +14 -0
- package/dist/esm/core/line-breaker/index.d.ts +1 -0
- package/dist/esm/core/line-breaker/index.js +3 -0
- package/dist/esm/core/line-breaker/knuth-plass.d.ts +29 -5
- package/dist/esm/core/line-breaker/knuth-plass.js +10 -5
- package/dist/esm/core/numbering/apply.d.ts +19 -0
- package/dist/esm/core/numbering/apply.js +19 -0
- package/dist/esm/core/numbering/state.d.ts +15 -0
- package/dist/esm/core/numbering/state.js +15 -0
- package/dist/esm/core/ole/cfb.d.ts +19 -0
- package/dist/esm/core/ole/cfb.js +50 -4
- package/dist/esm/core/opc/core-properties.d.ts +12 -0
- package/dist/esm/core/opc/core-properties.js +5 -0
- package/dist/esm/core/opc/opc-writer.d.ts +24 -4
- package/dist/esm/core/opc/opc-writer.js +12 -0
- package/dist/esm/core/opc/package.d.ts +55 -0
- package/dist/esm/core/opc/package.js +46 -0
- package/dist/esm/core/opc/relationship-types.d.ts +8 -0
- package/dist/esm/core/opc/relationship-types.js +5 -0
- package/dist/esm/core/opc/relationships.d.ts +12 -0
- package/dist/esm/core/opc/relationships.js +7 -0
- package/dist/esm/core/po-helpers.d.ts +38 -0
- package/dist/esm/core/po-helpers.js +33 -0
- package/dist/esm/core/spreadsheet-model/types.d.ts +281 -0
- package/dist/esm/core/style-cascade/resolver.d.ts +31 -0
- package/dist/esm/core/style-cascade/resolver.js +31 -0
- package/dist/esm/core/style-cascade/table.d.ts +7 -0
- package/dist/esm/core/style-cascade/table.js +7 -0
- package/dist/esm/core/style-cascade/types.d.ts +27 -0
- package/dist/esm/core/style-cascade/types.js +2 -0
- package/dist/esm/core/vector.d.ts +67 -0
- package/dist/esm/core/vector.js +23 -0
- package/dist/esm/excel/activex-parser.d.ts +31 -0
- package/dist/esm/excel/activex-parser.js +24 -0
- package/dist/esm/excel/cell-reference.d.ts +14 -0
- package/dist/esm/excel/cell-reference.js +9 -0
- package/dist/esm/excel/column-bands.d.ts +29 -0
- package/dist/esm/excel/column-bands.js +26 -0
- package/dist/esm/excel/comments-parser.d.ts +19 -0
- package/dist/esm/excel/comments-parser.js +19 -0
- package/dist/esm/excel/conditional-format.d.ts +38 -0
- package/dist/esm/excel/conditional-format.js +25 -0
- package/dist/esm/excel/defined-name-ref.d.ts +21 -0
- package/dist/esm/excel/defined-name-ref.js +20 -0
- package/dist/esm/excel/form-control-parser.d.ts +13 -0
- package/dist/esm/excel/form-control-parser.js +5 -0
- package/dist/esm/excel/formula/context.d.ts +37 -0
- package/dist/esm/excel/formula/dates.d.ts +23 -0
- package/dist/esm/excel/formula/dates.js +20 -0
- package/dist/esm/excel/formula/eval.d.ts +21 -0
- package/dist/esm/excel/formula/eval.js +11 -0
- package/dist/esm/excel/formula/functions.d.ts +12 -0
- package/dist/esm/excel/formula/functions.js +12 -0
- package/dist/esm/excel/formula/index.d.ts +21 -0
- package/dist/esm/excel/formula/index.js +16 -0
- package/dist/esm/excel/formula/lexer.d.ts +12 -0
- package/dist/esm/excel/formula/lexer.js +10 -0
- package/dist/esm/excel/formula/parser.d.ts +20 -0
- package/dist/esm/excel/formula/parser.js +53 -0
- package/dist/esm/excel/formula/value.d.ts +53 -0
- package/dist/esm/excel/formula/value.js +30 -0
- package/dist/esm/excel/header-footer.d.ts +9 -0
- package/dist/esm/excel/header-footer.js +9 -0
- package/dist/esm/excel/number-format.d.ts +34 -0
- package/dist/esm/excel/number-format.js +34 -0
- package/dist/esm/excel/pivot-table-parser.d.ts +8 -0
- package/dist/esm/excel/pivot-table-parser.js +8 -0
- package/dist/esm/excel/print-model.d.ts +56 -0
- package/dist/esm/excel/print-model.js +43 -0
- package/dist/esm/excel/shared-strings-parser.d.ts +13 -0
- package/dist/esm/excel/shared-strings-parser.js +5 -0
- package/dist/esm/excel/sheet-drawing.d.ts +34 -0
- package/dist/esm/excel/sheet-drawing.js +21 -0
- package/dist/esm/excel/sheet-shape-parser.d.ts +12 -0
- package/dist/esm/excel/sheet-shape-parser.js +12 -0
- package/dist/esm/excel/sheet-to-flow.d.ts +19 -0
- package/dist/esm/excel/sheet-to-flow.js +10 -0
- package/dist/esm/excel/slicer-parser.d.ts +23 -0
- package/dist/esm/excel/slicer-parser.js +10 -0
- package/dist/esm/excel/styles-parser.d.ts +8 -0
- package/dist/esm/excel/styles-parser.js +8 -0
- package/dist/esm/excel/table-parser.d.ts +24 -0
- package/dist/esm/excel/table-parser.js +5 -0
- package/dist/esm/excel/workbook-parser.d.ts +17 -0
- package/dist/esm/excel/workbook-parser.js +5 -0
- package/dist/esm/excel/worksheet-parser.d.ts +9 -0
- package/dist/esm/excel/worksheet-parser.js +9 -0
- package/dist/esm/excel/xls/biff-chart.d.ts +10 -0
- package/dist/esm/excel/xls/biff-chart.js +10 -0
- package/dist/esm/excel/xls/biff-reader.d.ts +27 -0
- package/dist/esm/excel/xls/biff-reader.js +44 -0
- package/dist/esm/excel/xls/biff-styles.d.ts +20 -0
- package/dist/esm/excel/xls/biff-styles.js +20 -0
- package/dist/esm/excel/xls/escher.d.ts +27 -0
- package/dist/esm/excel/xls/escher.js +18 -0
- package/dist/esm/excel/xls/xls-reader.d.ts +6 -0
- package/dist/esm/excel/xls/xls-reader.js +6 -0
- package/dist/esm/excel/xlsx-reader.d.ts +26 -0
- package/dist/esm/excel/xlsx-reader.js +26 -0
- package/dist/esm/excel/xlsx-to-pdf.d.ts +27 -0
- package/dist/esm/excel/xlsx-writer.d.ts +14 -0
- package/dist/esm/excel/xlsx-writer.js +13 -0
- package/dist/esm/html/html-writer.d.ts +18 -0
- package/dist/esm/html/html-writer.js +18 -0
- package/dist/esm/index.d.ts +23 -0
- package/dist/esm/layout/math-layout.d.ts +39 -0
- package/dist/esm/layout/math-layout.js +18 -0
- package/dist/esm/layout/page-doc.d.ts +91 -0
- package/dist/esm/layout/styled-layout.d.ts +175 -0
- package/dist/esm/layout/styled-layout.js +117 -2
- package/dist/esm/pdf/builtin-fonts.d.ts +5 -0
- package/dist/esm/pdf/cid-font.d.ts +22 -0
- package/dist/esm/pdf/cid-font.js +10 -0
- package/dist/esm/pdf/embedded-file.d.ts +16 -0
- package/dist/esm/pdf/embedded-file.js +9 -0
- package/dist/esm/pdf/encryption.d.ts +59 -0
- package/dist/esm/pdf/encryption.js +37 -0
- package/dist/esm/pdf/icc-profile.d.ts +8 -0
- package/dist/esm/pdf/icc-profile.js +8 -0
- package/dist/esm/pdf/image-xobject.d.ts +19 -0
- package/dist/esm/pdf/image-xobject.js +9 -0
- package/dist/esm/pdf/objects.d.ts +40 -0
- package/dist/esm/pdf/objects.js +36 -0
- package/dist/esm/pdf/serialize.d.ts +18 -0
- package/dist/esm/pdf/serialize.js +18 -0
- package/dist/esm/pdf/shading.d.ts +16 -0
- package/dist/esm/pdf/shading.js +16 -0
- package/dist/esm/pdf/signature.d.ts +36 -0
- package/dist/esm/pdf/signature.js +22 -0
- package/dist/esm/pdf/struct-tree.d.ts +64 -0
- package/dist/esm/pdf/struct-tree.js +60 -0
- package/dist/esm/pdf/styled-page-emitter.d.ts +33 -0
- package/dist/esm/pdf/styled-page-emitter.js +21 -0
- package/dist/esm/pdf/styled-page-renderer.d.ts +18 -0
- package/dist/esm/pdf/styled-page-renderer.js +18 -0
- package/dist/esm/pdf/text-encoding.d.ts +16 -0
- package/dist/esm/pdf/text-page-renderer.d.ts +11 -0
- package/dist/esm/pdf/vector-graphics.d.ts +12 -0
- package/dist/esm/pdf/vector-graphics.js +12 -0
- package/dist/esm/pdf/writer.d.ts +39 -0
- package/dist/esm/pdf/writer.js +27 -0
- package/dist/esm/pdf/xmp.d.ts +16 -0
- package/dist/esm/pdf/xmp.js +9 -0
- package/dist/esm/pdf-reader/ccitt.d.ts +25 -0
- package/dist/esm/pdf-reader/ccitt.js +15 -0
- package/dist/esm/pdf-reader/cmap.d.ts +12 -0
- package/dist/esm/pdf-reader/cmap.js +9 -0
- package/dist/esm/pdf-reader/content.d.ts +69 -0
- package/dist/esm/pdf-reader/content.js +16 -0
- package/dist/esm/pdf-reader/crypto.d.ts +5 -0
- package/dist/esm/pdf-reader/crypto.js +5 -0
- package/dist/esm/pdf-reader/decrypt.d.ts +17 -0
- package/dist/esm/pdf-reader/decrypt.js +12 -0
- package/dist/esm/pdf-reader/document.d.ts +53 -0
- package/dist/esm/pdf-reader/document.js +50 -0
- package/dist/esm/pdf-reader/flow-build.d.ts +51 -2
- package/dist/esm/pdf-reader/flow-build.js +67 -2
- package/dist/esm/pdf-reader/font.d.ts +12 -0
- package/dist/esm/pdf-reader/font.js +12 -0
- package/dist/esm/pdf-reader/image-decode.d.ts +21 -0
- package/dist/esm/pdf-reader/image-decode.js +14 -0
- package/dist/esm/pdf-reader/images.d.ts +19 -0
- package/dist/esm/pdf-reader/images.js +9 -0
- package/dist/esm/pdf-reader/layout.d.ts +15 -0
- package/dist/esm/pdf-reader/layout.js +17 -2
- package/dist/esm/pdf-reader/lexer.d.ts +43 -0
- package/dist/esm/pdf-reader/lexer.js +38 -0
- package/dist/esm/pdf-reader/parser.d.ts +15 -0
- package/dist/esm/pdf-reader/parser.js +8 -0
- package/dist/esm/pdf-reader/png-encode.d.ts +9 -0
- package/dist/esm/pdf-reader/png-encode.js +8 -0
- package/dist/esm/pdf-reader/predictor.d.ts +9 -0
- package/dist/esm/pdf-reader/predictor.js +8 -0
- package/dist/esm/pdf-reader/reader.d.ts +16 -0
- package/dist/esm/pdf-reader/reader.js +16 -0
- package/dist/esm/pdf-reader/shading.d.ts +10 -0
- package/dist/esm/pdf-reader/shading.js +10 -0
- package/dist/esm/pdf-reader/struct-tree.d.ts +24 -0
- package/dist/esm/pdf-reader/struct-tree.js +12 -0
- package/dist/esm/pdf-reader/tagged.d.ts +13 -0
- package/dist/esm/pdf-reader/tagged.js +15 -2
- package/dist/esm/pdf-reader/text.d.ts +11 -0
- package/dist/esm/pdf-reader/text.js +11 -0
- package/dist/esm/pdf-reader/vector.d.ts +19 -0
- package/dist/esm/pdf-reader/vector.js +9 -0
- package/dist/esm/pptx/placeholder-cascade.d.ts +21 -0
- package/dist/esm/pptx/placeholder-cascade.js +10 -0
- package/dist/esm/pptx/ppt/ppt-reader.d.ts +16 -0
- package/dist/esm/pptx/ppt/ppt-reader.js +16 -0
- package/dist/esm/pptx/ppt/ppt-text.d.ts +55 -0
- package/dist/esm/pptx/ppt/ppt-text.js +14 -0
- package/dist/esm/pptx/pptx-reader.d.ts +21 -0
- package/dist/esm/pptx/pptx-reader.js +37 -1
- package/dist/esm/pptx/slide-parser.d.ts +102 -0
- package/dist/esm/pptx/slide-parser.js +78 -0
- package/dist/esm/pptx/sp-helpers.d.ts +28 -0
- package/dist/esm/pptx/sp-helpers.js +22 -0
- package/dist/esm/svg/svg-writer.d.ts +17 -0
- package/dist/esm/svg/svg-writer.js +16 -0
- package/dist/esm/word/doc/doc-reader.d.ts +16 -0
- package/dist/esm/word/doc/doc-reader.js +26 -4
- package/dist/esm/word/doc/doc-text.d.ts +81 -0
- package/dist/esm/word/doc/doc-text.js +38 -0
- package/dist/esm/word/document-parser.d.ts +134 -0
- package/dist/esm/word/document-parser.js +86 -0
- package/dist/esm/word/docx-reader.d.ts +16 -0
- package/dist/esm/word/docx-reader.js +16 -0
- package/dist/esm/word/docx-to-pdf.d.ts +52 -0
- package/dist/esm/word/docx-to-pdf.js +21 -0
- package/dist/esm/word/docx-writer.d.ts +17 -0
- package/dist/esm/word/docx-writer.js +17 -0
- package/dist/esm/word/drawing-parser.d.ts +88 -0
- package/dist/esm/word/drawing-parser.js +68 -0
- package/dist/esm/word/font-table.d.ts +24 -0
- package/dist/esm/word/font-table.js +24 -0
- package/dist/esm/word/numbering-parser.d.ts +11 -0
- package/dist/esm/word/numbering-parser.js +11 -0
- package/dist/esm/word/omml-parser.d.ts +15 -0
- package/dist/esm/word/omml-parser.js +15 -0
- package/dist/esm/word/omml-serializer.d.ts +9 -0
- package/dist/esm/word/omml-serializer.js +9 -0
- package/dist/esm/word/paragraph-properties.d.ts +10 -0
- package/dist/esm/word/paragraph-properties.js +10 -0
- package/dist/esm/word/po-to-flat.d.ts +11 -0
- package/dist/esm/word/po-to-flat.js +11 -0
- package/dist/esm/word/run-properties.d.ts +10 -0
- package/dist/esm/word/run-properties.js +10 -0
- package/dist/esm/word/settings-parser.d.ts +13 -0
- package/dist/esm/word/settings-parser.js +8 -0
- package/dist/esm/word/styles-parser.d.ts +10 -0
- package/dist/esm/word/styles-parser.js +10 -0
- package/dist/esm/word/table-parser.d.ts +11 -0
- package/dist/esm/word/table-parser.js +11 -0
- package/dist/esm/word/text-extractor.d.ts +9 -0
- package/dist/esm/word/xml-helpers.d.ts +44 -0
- package/dist/esm/word/xml-helpers.js +38 -0
- package/package.json +1 -1
|
@@ -1,21 +1,70 @@
|
|
|
1
|
+
/** GSUB ligature substitutions: a comma-joined input GID sequence → output GID. */
|
|
1
2
|
export type LigatureMap = ReadonlyMap<string, number>;
|
|
3
|
+
/** GPOS pair kerning: `"gid1,gid2"` → advance adjustment in font units. */
|
|
2
4
|
export type KerningMap = ReadonlyMap<string, number>;
|
|
5
|
+
/**
|
|
6
|
+
* GSUB single-substitution maps (gid → positional gid) for the Arabic cursive
|
|
7
|
+
* features init / medi / fina. Empty for fonts without Arabic shaping.
|
|
8
|
+
*/
|
|
3
9
|
export interface ArabicJoiningForms {
|
|
10
|
+
/** Initial-form substitutions. */
|
|
4
11
|
readonly init: ReadonlyMap<number, number>;
|
|
12
|
+
/** Medial-form substitutions. */
|
|
5
13
|
readonly medi: ReadonlyMap<number, number>;
|
|
14
|
+
/** Final-form substitutions. */
|
|
6
15
|
readonly fina: ReadonlyMap<number, number>;
|
|
7
16
|
}
|
|
17
|
+
/** An {@link ArabicJoiningForms} with no substitutions (a non-Arabic font). */
|
|
8
18
|
export declare const EMPTY_JOINING_FORMS: ArabicJoiningForms;
|
|
9
19
|
interface TableInfo {
|
|
10
20
|
readonly offset: number;
|
|
11
21
|
readonly length: number;
|
|
12
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Parse a GSUB table and return only the `liga`/`clig` ligature substitutions.
|
|
25
|
+
*
|
|
26
|
+
* @param raw The whole font bytes.
|
|
27
|
+
* @param table The GSUB table location, or `undefined` when the font has none.
|
|
28
|
+
* @returns The ligature map (empty when absent or on any parse error).
|
|
29
|
+
*/
|
|
13
30
|
export declare function parseGsubLigatures(raw: Uint8Array, table: TableInfo | undefined): LigatureMap;
|
|
31
|
+
/**
|
|
32
|
+
* Parse a GPOS table and return only the `kern` pair-positioning lookup.
|
|
33
|
+
*
|
|
34
|
+
* @param raw The whole font bytes.
|
|
35
|
+
* @param table The GPOS table location, or `undefined` when the font has none.
|
|
36
|
+
* @returns The kerning map keyed on `"gid1,gid2"` (empty when absent or on error).
|
|
37
|
+
*/
|
|
14
38
|
export declare function parseGposKerning(raw: Uint8Array, table: TableInfo | undefined): KerningMap;
|
|
39
|
+
/**
|
|
40
|
+
* Parse GSUB single substitutions (Lookup Type 1) for the Arabic positional
|
|
41
|
+
* features. Each of init/medi/fina yields a gid → gid map the shaper applies per
|
|
42
|
+
* cursive form.
|
|
43
|
+
*
|
|
44
|
+
* @param raw The whole font bytes.
|
|
45
|
+
* @param table The GSUB table location, or `undefined` when the font has none.
|
|
46
|
+
* @returns The per-form joining maps (empty when absent or on error).
|
|
47
|
+
*/
|
|
15
48
|
export declare function parseGsubArabicForms(raw: Uint8Array, table: TableInfo | undefined): ArabicJoiningForms;
|
|
49
|
+
/** The result of {@link shapeText}: output glyph ids and their advances. */
|
|
16
50
|
export interface ShapedRun {
|
|
51
|
+
/** Output glyph ids, after ligature, kerning and Arabic-joining substitution. */
|
|
17
52
|
readonly gids: Array<number>;
|
|
53
|
+
/** Font-unit advance per output gid (parallel to `gids`). */
|
|
18
54
|
readonly advances: Array<number>;
|
|
19
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Shape a string into glyphs: map characters to GIDs, apply Arabic cursive
|
|
58
|
+
* joining, then ligature substitution and pair kerning, returning the output
|
|
59
|
+
* glyph ids with their font-unit advances.
|
|
60
|
+
*
|
|
61
|
+
* @param text The text to shape.
|
|
62
|
+
* @param glyphForCodepoint Codepoint → glyph id (from the font's cmap).
|
|
63
|
+
* @param advanceWidths Per-glyph advance widths (font units).
|
|
64
|
+
* @param ligatures GSUB ligature map.
|
|
65
|
+
* @param kerning GPOS pair-kerning map.
|
|
66
|
+
* @param joiningForms Arabic init/medi/fina maps (default: none).
|
|
67
|
+
* @returns The shaped run (gids + advances).
|
|
68
|
+
*/
|
|
20
69
|
export declare function shapeText(text: string, glyphForCodepoint: (cp: number) => number, advanceWidths: ReadonlyArray<number>, ligatures: LigatureMap, kerning: KerningMap, joiningForms?: ArabicJoiningForms): ShapedRun;
|
|
21
70
|
export {};
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { BigEndianReader } from "./binary-reader.js";
|
|
2
2
|
import { assignArabicForms } from "./arabic-joining.js";
|
|
3
3
|
//#region src/core/font/opentype-layout.ts
|
|
4
|
+
/** An {@link ArabicJoiningForms} with no substitutions (a non-Arabic font). */
|
|
4
5
|
var EMPTY_JOINING_FORMS = {
|
|
5
6
|
init: /* @__PURE__ */ new Map(),
|
|
6
7
|
medi: /* @__PURE__ */ new Map(),
|
|
7
8
|
fina: /* @__PURE__ */ new Map()
|
|
8
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Parse a GSUB table and return only the `liga`/`clig` ligature substitutions.
|
|
12
|
+
*
|
|
13
|
+
* @param raw The whole font bytes.
|
|
14
|
+
* @param table The GSUB table location, or `undefined` when the font has none.
|
|
15
|
+
* @returns The ligature map (empty when absent or on any parse error).
|
|
16
|
+
*/
|
|
9
17
|
function parseGsubLigatures(raw, table) {
|
|
10
18
|
if (!table) return /* @__PURE__ */ new Map();
|
|
11
19
|
try {
|
|
@@ -19,6 +27,13 @@ function parseGsubLigatures(raw, table) {
|
|
|
19
27
|
return /* @__PURE__ */ new Map();
|
|
20
28
|
}
|
|
21
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Parse a GPOS table and return only the `kern` pair-positioning lookup.
|
|
32
|
+
*
|
|
33
|
+
* @param raw The whole font bytes.
|
|
34
|
+
* @param table The GPOS table location, or `undefined` when the font has none.
|
|
35
|
+
* @returns The kerning map keyed on `"gid1,gid2"` (empty when absent or on error).
|
|
36
|
+
*/
|
|
22
37
|
function parseGposKerning(raw, table) {
|
|
23
38
|
if (!table) return /* @__PURE__ */ new Map();
|
|
24
39
|
try {
|
|
@@ -32,6 +47,15 @@ function parseGposKerning(raw, table) {
|
|
|
32
47
|
return /* @__PURE__ */ new Map();
|
|
33
48
|
}
|
|
34
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Parse GSUB single substitutions (Lookup Type 1) for the Arabic positional
|
|
52
|
+
* features. Each of init/medi/fina yields a gid → gid map the shaper applies per
|
|
53
|
+
* cursive form.
|
|
54
|
+
*
|
|
55
|
+
* @param raw The whole font bytes.
|
|
56
|
+
* @param table The GSUB table location, or `undefined` when the font has none.
|
|
57
|
+
* @returns The per-form joining maps (empty when absent or on error).
|
|
58
|
+
*/
|
|
35
59
|
function parseGsubArabicForms(raw, table) {
|
|
36
60
|
if (!table) return EMPTY_JOINING_FORMS;
|
|
37
61
|
try {
|
|
@@ -286,6 +310,19 @@ function matchingGlyphs(coverage, classMap, cls) {
|
|
|
286
310
|
for (const [gid, c] of classMap) if (c === cls) out.push(gid);
|
|
287
311
|
return out;
|
|
288
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* Shape a string into glyphs: map characters to GIDs, apply Arabic cursive
|
|
315
|
+
* joining, then ligature substitution and pair kerning, returning the output
|
|
316
|
+
* glyph ids with their font-unit advances.
|
|
317
|
+
*
|
|
318
|
+
* @param text The text to shape.
|
|
319
|
+
* @param glyphForCodepoint Codepoint → glyph id (from the font's cmap).
|
|
320
|
+
* @param advanceWidths Per-glyph advance widths (font units).
|
|
321
|
+
* @param ligatures GSUB ligature map.
|
|
322
|
+
* @param kerning GPOS pair-kerning map.
|
|
323
|
+
* @param joiningForms Arabic init/medi/fina maps (default: none).
|
|
324
|
+
* @returns The shaped run (gids + advances).
|
|
325
|
+
*/
|
|
289
326
|
function shapeText(text, glyphForCodepoint, advanceWidths, ligatures, kerning, joiningForms = EMPTY_JOINING_FORMS) {
|
|
290
327
|
const cps = [];
|
|
291
328
|
for (const ch of text) cps.push(ch.codePointAt(0));
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { ArabicJoiningForms, KerningMap, LigatureMap } from './opentype-layout.js';
|
|
2
|
+
/** A table's location within the sfnt: byte offset and length. */
|
|
2
3
|
export interface TtfTableInfo {
|
|
4
|
+
/** Byte offset of the table from the start of the file. */
|
|
3
5
|
readonly offset: number;
|
|
6
|
+
/** Table length in bytes. */
|
|
4
7
|
readonly length: number;
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* A parsed TrueType / OpenType font (ISO/IEC 14496-22): metrics, the
|
|
11
|
+
* cmap-derived codepoint→glyph mapping, OpenType layout maps (ligatures,
|
|
12
|
+
* kerning, Arabic joining) and the raw bytes for embedding. Glyph outlines
|
|
13
|
+
* (glyf/CFF) are not decoded — the whole font is embedded in the PDF /FontFile2.
|
|
14
|
+
*/
|
|
6
15
|
export interface ParsedTtf {
|
|
7
16
|
readonly raw: Uint8Array;
|
|
8
17
|
readonly sfntVersion: number;
|
|
@@ -12,9 +21,19 @@ export interface ParsedTtf {
|
|
|
12
21
|
readonly fontBBox: readonly [number, number, number, number];
|
|
13
22
|
readonly ascender: number;
|
|
14
23
|
readonly descender: number;
|
|
24
|
+
/**
|
|
25
|
+
* hhea line gap (font units); with ascender/descender it forms the hhea
|
|
26
|
+
* vertical triple that drives the `'libreoffice'` line-height profile (E-PARITY).
|
|
27
|
+
*/
|
|
15
28
|
readonly lineGap: number;
|
|
16
29
|
readonly capHeight: number;
|
|
17
30
|
readonly xHeight: number;
|
|
31
|
+
/**
|
|
32
|
+
* E-PARITY line-height metrics: OS/2 win/typo verticals (font units) selected
|
|
33
|
+
* by layout profile. `'word'` uses winAscent/winDescent (the GDI cell box);
|
|
34
|
+
* `'libreoffice'` uses the hhea triple above, or typo* when `useTypoMetrics` is
|
|
35
|
+
* set. All fall back to hhea when the font has no OS/2 table.
|
|
36
|
+
*/
|
|
18
37
|
readonly vmetrics: {
|
|
19
38
|
readonly typoAscent: number;
|
|
20
39
|
readonly typoDescent: number;
|
|
@@ -31,8 +50,21 @@ export interface ParsedTtf {
|
|
|
31
50
|
readonly glyphOffsets: ReadonlyArray<number>;
|
|
32
51
|
readonly advanceWidths: ReadonlyArray<number>;
|
|
33
52
|
readonly glyphForCodepoint: (cp: number) => number;
|
|
53
|
+
/** OpenType ligature substitutions: input GID sequence `"gid1,gid2[,gid3…]"` → output GID. */
|
|
34
54
|
readonly ligatures: LigatureMap;
|
|
55
|
+
/** OpenType pair kerning: `"gid1,gid2"` → advance adjustment in font units. */
|
|
35
56
|
readonly kerning: KerningMap;
|
|
57
|
+
/**
|
|
58
|
+
* Arabic cursive-joining substitutions (init/medi/fina). Empty for non-Arabic
|
|
59
|
+
* fonts, so the shaper leaves output unchanged.
|
|
60
|
+
*/
|
|
36
61
|
readonly joiningForms: ArabicJoiningForms;
|
|
37
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Parse TrueType / OpenType font bytes into a {@link ParsedTtf}.
|
|
65
|
+
*
|
|
66
|
+
* @param raw The font bytes (sfnt: TrueType `0x00010000` or OpenType-CFF `OTTO`).
|
|
67
|
+
* @returns The parsed metrics, mappings and layout tables.
|
|
68
|
+
* @throws Error when the bytes are not a TrueType or OpenType font.
|
|
69
|
+
*/
|
|
38
70
|
export declare function parseTtf(raw: Uint8Array): ParsedTtf;
|
|
@@ -3,6 +3,13 @@ import { parseGposKerning, parseGsubArabicForms, parseGsubLigatures } from "./op
|
|
|
3
3
|
//#region src/core/font/ttf-parser.ts
|
|
4
4
|
var SFNT_TRUETYPE = 65536;
|
|
5
5
|
var SFNT_OPENTYPE_CFF = 1330926671;
|
|
6
|
+
/**
|
|
7
|
+
* Parse TrueType / OpenType font bytes into a {@link ParsedTtf}.
|
|
8
|
+
*
|
|
9
|
+
* @param raw The font bytes (sfnt: TrueType `0x00010000` or OpenType-CFF `OTTO`).
|
|
10
|
+
* @returns The parsed metrics, mappings and layout tables.
|
|
11
|
+
* @throws Error when the bytes are not a TrueType or OpenType font.
|
|
12
|
+
*/
|
|
6
13
|
function parseTtf(raw) {
|
|
7
14
|
const r = new BigEndianReader(raw);
|
|
8
15
|
const sfntVersion = r.u32();
|
|
@@ -1,3 +1,24 @@
|
|
|
1
1
|
import { ParsedTtf } from './ttf-parser.js';
|
|
2
|
+
/**
|
|
3
|
+
* Subset a TrueType font to the glyphs in `usedGids` (plus their composite
|
|
4
|
+
* components and GID 0). All tables are kept intact so the CIDFontType2
|
|
5
|
+
* `/CIDToGIDMap /Identity` contract holds; only `glyf`/`loca` are rebuilt, with
|
|
6
|
+
* unused glyphs zero-length.
|
|
7
|
+
*
|
|
8
|
+
* @param parsed The parsed source font (must have `glyf` + `loca`).
|
|
9
|
+
* @param usedGids The glyph ids actually used.
|
|
10
|
+
* @returns The subset font bytes.
|
|
11
|
+
* @throws Error when the font has no `glyf`/`loca` (e.g. a CFF/OTF font).
|
|
12
|
+
*/
|
|
2
13
|
export declare function subsetTtf(parsed: ParsedTtf, usedGids: Iterable<number>): Uint8Array;
|
|
14
|
+
/**
|
|
15
|
+
* The glyph ids actually present in a subset for `usedGids`: the seeds, their
|
|
16
|
+
* composite components (transitively) and GID 0. With Identity CID↔GID this is
|
|
17
|
+
* exactly the CID set of the embedded subset, used to build the PDF/A `/CIDSet`
|
|
18
|
+
* (ISO 19005-1 §6.3.5). Mirrors {@link subsetTtf}'s own closure.
|
|
19
|
+
*
|
|
20
|
+
* @param parsed The parsed font.
|
|
21
|
+
* @param usedGids The seed glyph ids.
|
|
22
|
+
* @returns The closed set of glyph ids.
|
|
23
|
+
*/
|
|
3
24
|
export declare function glyphClosure(parsed: ParsedTtf, usedGids: Iterable<number>): Set<number>;
|
|
@@ -7,6 +7,17 @@ var COMPOSITE_WE_HAVE_A_SCALE = 8;
|
|
|
7
7
|
var COMPOSITE_MORE_COMPONENTS = 32;
|
|
8
8
|
var COMPOSITE_WE_HAVE_AN_X_AND_Y_SCALE = 64;
|
|
9
9
|
var COMPOSITE_WE_HAVE_A_TWO_BY_TWO = 128;
|
|
10
|
+
/**
|
|
11
|
+
* Subset a TrueType font to the glyphs in `usedGids` (plus their composite
|
|
12
|
+
* components and GID 0). All tables are kept intact so the CIDFontType2
|
|
13
|
+
* `/CIDToGIDMap /Identity` contract holds; only `glyf`/`loca` are rebuilt, with
|
|
14
|
+
* unused glyphs zero-length.
|
|
15
|
+
*
|
|
16
|
+
* @param parsed The parsed source font (must have `glyf` + `loca`).
|
|
17
|
+
* @param usedGids The glyph ids actually used.
|
|
18
|
+
* @returns The subset font bytes.
|
|
19
|
+
* @throws Error when the font has no `glyf`/`loca` (e.g. a CFF/OTF font).
|
|
20
|
+
*/
|
|
10
21
|
function subsetTtf(parsed, usedGids) {
|
|
11
22
|
const glyf = parsed.tables.get("glyf");
|
|
12
23
|
const loca = parsed.tables.get("loca");
|
|
@@ -14,6 +25,16 @@ function subsetTtf(parsed, usedGids) {
|
|
|
14
25
|
const { newGlyf, newLoca } = rewriteGlyfLoca(parsed, glyf, computeGlyphClosure(parsed, glyf, usedGids));
|
|
15
26
|
return assembleSubsetTtf(parsed, newGlyf, newLoca);
|
|
16
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* The glyph ids actually present in a subset for `usedGids`: the seeds, their
|
|
30
|
+
* composite components (transitively) and GID 0. With Identity CID↔GID this is
|
|
31
|
+
* exactly the CID set of the embedded subset, used to build the PDF/A `/CIDSet`
|
|
32
|
+
* (ISO 19005-1 §6.3.5). Mirrors {@link subsetTtf}'s own closure.
|
|
33
|
+
*
|
|
34
|
+
* @param parsed The parsed font.
|
|
35
|
+
* @param usedGids The seed glyph ids.
|
|
36
|
+
* @returns The closed set of glyph ids.
|
|
37
|
+
*/
|
|
17
38
|
function glyphClosure(parsed, usedGids) {
|
|
18
39
|
const glyf = parsed.tables.get("glyf");
|
|
19
40
|
if (!glyf) return new Set([0, ...usedGids]);
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { FetchLike } from './remote-fonts.js';
|
|
2
2
|
import { FontBytesByVariant, FontRegistry } from '../font/index.js';
|
|
3
|
+
/** A font resolution request: the wanted family and style. */
|
|
3
4
|
export interface FontRequest {
|
|
4
5
|
/** Family name as the document references it (e.g. "Times New Roman"). */
|
|
5
6
|
readonly family?: string;
|
|
7
|
+
/** Whether a bold face is wanted. */
|
|
6
8
|
readonly bold: boolean;
|
|
9
|
+
/** Whether an italic face is wanted. */
|
|
7
10
|
readonly italic: boolean;
|
|
8
11
|
}
|
|
12
|
+
/** A provider's answer: resolved bytes, or `none` to fall through to the next provider. */
|
|
9
13
|
export type FontAnswer = {
|
|
10
14
|
readonly kind: 'bytes';
|
|
11
15
|
readonly bytes: Uint8Array;
|
|
@@ -16,10 +20,13 @@ export type FontAnswer = {
|
|
|
16
20
|
} | {
|
|
17
21
|
readonly kind: 'none';
|
|
18
22
|
};
|
|
23
|
+
/** The shared `none` answer — a provider that cannot satisfy a request. */
|
|
19
24
|
export declare const NO_FONT: FontAnswer;
|
|
25
|
+
/** One stage in the font-resolution chain (ir-design §8). */
|
|
20
26
|
export interface FontProvider {
|
|
21
|
-
/** 'embedded' | 'caller' | 'local' | 'remote' | custom
|
|
27
|
+
/** Provider id: `'embedded'` | `'caller'` | `'local'` | `'remote'` | a custom id. */
|
|
22
28
|
readonly id: string;
|
|
29
|
+
/** Resolve a request to bytes, or {@link NO_FONT} to defer to the next provider. */
|
|
23
30
|
resolve: (req: FontRequest) => Promise<FontAnswer>;
|
|
24
31
|
}
|
|
25
32
|
/** First byte-level answer wins; 'none' falls through to the next provider. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { fetchFontSet, resolveFamilyKey } from "./remote-fonts.js";
|
|
2
2
|
import { pickVariant } from "../font/font-registry.js";
|
|
3
3
|
//#region src/core/fonts/provider.ts
|
|
4
|
+
/** The shared `none` answer — a provider that cannot satisfy a request. */
|
|
4
5
|
var NO_FONT = { kind: "none" };
|
|
5
6
|
/** First byte-level answer wins; 'none' falls through to the next provider. */
|
|
6
7
|
function chainProviders(providers) {
|
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
import { FontBytesByVariant } from '../font/index.js';
|
|
2
|
+
/** A curated open substitute family (the Croscore + Carlito/Caladea set, like LibreOffice). */
|
|
2
3
|
export type FamilyKey = 'arimo' | 'tinos' | 'cousine' | 'carlito' | 'caladea';
|
|
4
|
+
/**
|
|
5
|
+
* Map a document-referenced font family to a curated open substitute: an exact
|
|
6
|
+
* metric twin when one is known (e.g. Calibri → Carlito), otherwise a
|
|
7
|
+
* serif/mono/sans style fallback.
|
|
8
|
+
*
|
|
9
|
+
* @param name The referenced family name (case-insensitive); empty ⇒ Arimo.
|
|
10
|
+
* @returns The chosen {@link FamilyKey}.
|
|
11
|
+
*/
|
|
3
12
|
export declare function resolveFamilyKey(name: string | undefined): FamilyKey;
|
|
13
|
+
/** A minimal `fetch`-like function (injectable for tests / offline use). */
|
|
4
14
|
export type FetchLike = (url: string) => Promise<{
|
|
5
15
|
ok: boolean;
|
|
6
16
|
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
7
17
|
}>;
|
|
18
|
+
/** Options for {@link fetchFontSet}. */
|
|
8
19
|
export interface FetchFontSetOptions {
|
|
20
|
+
/** Document font family name to substitute, or a curated {@link FamilyKey} directly. */
|
|
9
21
|
readonly family?: string | FamilyKey;
|
|
22
|
+
/** Injectable fetch (defaults to the global `fetch`); lets tests run offline. */
|
|
10
23
|
readonly fetch?: FetchLike;
|
|
11
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Download a full variant set (regular required; bold/italic/bold-italic
|
|
27
|
+
* best-effort) for the open family that best matches the requested name.
|
|
28
|
+
*
|
|
29
|
+
* @param options The family to substitute and an optional fetch override.
|
|
30
|
+
* @returns The downloaded font bytes per variant.
|
|
31
|
+
* @throws Error when the required regular face cannot be downloaded.
|
|
32
|
+
*/
|
|
12
33
|
export declare function fetchFontSet(options?: FetchFontSetOptions): Promise<FontBytesByVariant>;
|
|
34
|
+
/** Test / diagnostic helper: clear the in-memory font-download cache. */
|
|
13
35
|
export declare function clearFontCache(): void;
|
|
@@ -59,6 +59,14 @@ var MONO = new Set([
|
|
|
59
59
|
"dejavu sans mono",
|
|
60
60
|
"monospace"
|
|
61
61
|
]);
|
|
62
|
+
/**
|
|
63
|
+
* Map a document-referenced font family to a curated open substitute: an exact
|
|
64
|
+
* metric twin when one is known (e.g. Calibri → Carlito), otherwise a
|
|
65
|
+
* serif/mono/sans style fallback.
|
|
66
|
+
*
|
|
67
|
+
* @param name The referenced family name (case-insensitive); empty ⇒ Arimo.
|
|
68
|
+
* @returns The chosen {@link FamilyKey}.
|
|
69
|
+
*/
|
|
62
70
|
function resolveFamilyKey(name) {
|
|
63
71
|
if (!name) return "arimo";
|
|
64
72
|
const n = name.trim().toLowerCase();
|
|
@@ -95,6 +103,14 @@ async function fetchTtf(url, fetchImpl, required) {
|
|
|
95
103
|
}
|
|
96
104
|
return result;
|
|
97
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Download a full variant set (regular required; bold/italic/bold-italic
|
|
108
|
+
* best-effort) for the open family that best matches the requested name.
|
|
109
|
+
*
|
|
110
|
+
* @param options The family to substitute and an optional fetch override.
|
|
111
|
+
* @returns The downloaded font bytes per variant.
|
|
112
|
+
* @throws Error when the required regular face cannot be downloaded.
|
|
113
|
+
*/
|
|
98
114
|
async function fetchFontSet(options = {}) {
|
|
99
115
|
const fetchImpl = options.fetch ?? ((url) => fetch(url));
|
|
100
116
|
const family = FAMILIES[options.family && options.family in FAMILIES ? options.family : resolveFamilyKey(options.family)];
|
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
import { Hyphenator } from './liang.js';
|
|
2
2
|
export type { Hyphenator, HyphenatorOptions } from './liang.js';
|
|
3
3
|
export { createHyphenator, splitPatternBundle } from './liang.js';
|
|
4
|
+
/** A language for which bundled hyphenation patterns exist. */
|
|
4
5
|
export type SupportedLanguage = 'en-us' | 'ru';
|
|
6
|
+
/**
|
|
7
|
+
* Lazily build (and cache) a language's {@link Hyphenator}. The patterns module
|
|
8
|
+
* is dynamically imported the first time a language is requested, so callers
|
|
9
|
+
* that never hyphenate pay no cold-start cost.
|
|
10
|
+
*
|
|
11
|
+
* @param language The language to load.
|
|
12
|
+
* @returns The cached hyphenator.
|
|
13
|
+
*/
|
|
5
14
|
export declare function getHyphenator(language: SupportedLanguage): Promise<Hyphenator>;
|
|
15
|
+
/**
|
|
16
|
+
* Synchronous variant of {@link getHyphenator}: build a {@link Hyphenator} from
|
|
17
|
+
* already-loaded pattern strings (useful when patterns are bundled or fetched
|
|
18
|
+
* out-of-band).
|
|
19
|
+
*
|
|
20
|
+
* @param language The language (selects the left/right minimums).
|
|
21
|
+
* @param bundle The pattern and optional exception strings.
|
|
22
|
+
* @returns The hyphenator.
|
|
23
|
+
*/
|
|
6
24
|
export declare function createLanguageHyphenator(language: SupportedLanguage, bundle: {
|
|
7
25
|
patterns: string;
|
|
8
26
|
exceptions?: string;
|
|
9
27
|
}): Hyphenator;
|
|
28
|
+
/**
|
|
29
|
+
* Alias of {@link getHyphenator} — load a hyphenator for `language` using the
|
|
30
|
+
* patterns bundled with this package.
|
|
31
|
+
*
|
|
32
|
+
* @param language The language to load.
|
|
33
|
+
* @returns The hyphenator.
|
|
34
|
+
*/
|
|
10
35
|
export declare function loadHyphenator(language: SupportedLanguage): Promise<Hyphenator>;
|
|
@@ -13,6 +13,14 @@ var REGISTRY = {
|
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
var cache = /* @__PURE__ */ new Map();
|
|
16
|
+
/**
|
|
17
|
+
* Lazily build (and cache) a language's {@link Hyphenator}. The patterns module
|
|
18
|
+
* is dynamically imported the first time a language is requested, so callers
|
|
19
|
+
* that never hyphenate pay no cold-start cost.
|
|
20
|
+
*
|
|
21
|
+
* @param language The language to load.
|
|
22
|
+
* @returns The cached hyphenator.
|
|
23
|
+
*/
|
|
16
24
|
async function getHyphenator(language) {
|
|
17
25
|
const cached = cache.get(language);
|
|
18
26
|
if (cached) return cached;
|
|
@@ -26,6 +34,15 @@ async function getHyphenator(language) {
|
|
|
26
34
|
cache.set(language, h);
|
|
27
35
|
return h;
|
|
28
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Synchronous variant of {@link getHyphenator}: build a {@link Hyphenator} from
|
|
39
|
+
* already-loaded pattern strings (useful when patterns are bundled or fetched
|
|
40
|
+
* out-of-band).
|
|
41
|
+
*
|
|
42
|
+
* @param language The language (selects the left/right minimums).
|
|
43
|
+
* @param bundle The pattern and optional exception strings.
|
|
44
|
+
* @returns The hyphenator.
|
|
45
|
+
*/
|
|
29
46
|
function createLanguageHyphenator(language, bundle) {
|
|
30
47
|
const desc = REGISTRY[language];
|
|
31
48
|
return createHyphenator(splitPatternBundle(bundle.patterns), {
|
|
@@ -1,10 +1,37 @@
|
|
|
1
|
+
/** A configured hyphenator for one language. */
|
|
1
2
|
export interface Hyphenator {
|
|
3
|
+
/**
|
|
4
|
+
* Return the 0-indexed break positions inside `word`. A position `p` means the
|
|
5
|
+
* word can be split between `word[p-1]` and `word[p]`; e.g. "computer" with
|
|
6
|
+
* breaks `[3,5]` → "com·pu·ter".
|
|
7
|
+
*/
|
|
2
8
|
hyphenate: (word: string) => Array<number>;
|
|
3
9
|
}
|
|
10
|
+
/** Options for {@link createHyphenator}. */
|
|
4
11
|
export interface HyphenatorOptions {
|
|
12
|
+
/** Minimum characters before the first break (TeX default: 2). */
|
|
5
13
|
readonly leftMin?: number;
|
|
14
|
+
/** Minimum characters after the last break (TeX default: 3 for English, often 2 elsewhere). */
|
|
6
15
|
readonly rightMin?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Explicit exceptions that override pattern output. Each is a word with
|
|
18
|
+
* hyphens marking the allowed breaks, e.g. `"as-so-ciate"`.
|
|
19
|
+
*/
|
|
7
20
|
readonly exceptions?: ReadonlyArray<string>;
|
|
8
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Build a Liang pattern-based {@link Hyphenator} from a pattern list.
|
|
24
|
+
*
|
|
25
|
+
* @param patterns The TeX-style hyphenation patterns (e.g. `"hy3ph"`).
|
|
26
|
+
* @param options Left/right minimums and explicit exceptions.
|
|
27
|
+
* @returns The hyphenator.
|
|
28
|
+
*/
|
|
9
29
|
export declare function createHyphenator(patterns: ReadonlyArray<string>, options?: HyphenatorOptions): Hyphenator;
|
|
30
|
+
/**
|
|
31
|
+
* Split a TeX-style pattern bundle (a whitespace-separated string) into the
|
|
32
|
+
* pattern array {@link createHyphenator} expects.
|
|
33
|
+
*
|
|
34
|
+
* @param bundle The whitespace-separated patterns.
|
|
35
|
+
* @returns The pattern array (empty entries removed).
|
|
36
|
+
*/
|
|
10
37
|
export declare function splitPatternBundle(bundle: string): Array<string>;
|
|
@@ -34,6 +34,13 @@ function insertPattern(root, pattern) {
|
|
|
34
34
|
}
|
|
35
35
|
node.weights = [...weights];
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Build a Liang pattern-based {@link Hyphenator} from a pattern list.
|
|
39
|
+
*
|
|
40
|
+
* @param patterns The TeX-style hyphenation patterns (e.g. `"hy3ph"`).
|
|
41
|
+
* @param options Left/right minimums and explicit exceptions.
|
|
42
|
+
* @returns The hyphenator.
|
|
43
|
+
*/
|
|
37
44
|
function createHyphenator(patterns, options = {}) {
|
|
38
45
|
const root = makeNode();
|
|
39
46
|
for (const p of patterns) insertPattern(root, p);
|
|
@@ -72,6 +79,13 @@ function createHyphenator(patterns, options = {}) {
|
|
|
72
79
|
return breaks;
|
|
73
80
|
} };
|
|
74
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Split a TeX-style pattern bundle (a whitespace-separated string) into the
|
|
84
|
+
* pattern array {@link createHyphenator} expects.
|
|
85
|
+
*
|
|
86
|
+
* @param bundle The whitespace-separated patterns.
|
|
87
|
+
* @returns The pattern array (empty entries removed).
|
|
88
|
+
*/
|
|
75
89
|
function splitPatternBundle(bundle) {
|
|
76
90
|
return bundle.split(/\s+/).filter((s) => s.length > 0);
|
|
77
91
|
}
|
|
@@ -1,17 +1,49 @@
|
|
|
1
|
+
/** The raster formats this module recognizes and can prepare for embedding. */
|
|
1
2
|
export type ImageFormat = 'jpeg' | 'png' | 'jpeg2000';
|
|
3
|
+
/**
|
|
4
|
+
* Sniff the raster format from a file's leading magic bytes (JPEG SOI, the PNG
|
|
5
|
+
* signature, or a JP2 box / raw JPEG 2000 codestream). Returns the
|
|
6
|
+
* {@link ImageFormat}, or `null` when none matches.
|
|
7
|
+
*/
|
|
2
8
|
export declare function detectImageFormat(bytes: Uint8Array): ImageFormat | null;
|
|
9
|
+
/** Options controlling how {@link prepareImage} emits an image. */
|
|
3
10
|
export interface EmbedImageOptions {
|
|
11
|
+
/**
|
|
12
|
+
* PDF/A-1 forbids transparency (soft masks). When true, PNG alpha is
|
|
13
|
+
* composited onto an opaque white background and no `/SMask` is emitted.
|
|
14
|
+
*/
|
|
4
15
|
readonly flattenAlpha?: boolean;
|
|
5
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* The ready-to-emit result of decoding and validating one image, from the
|
|
19
|
+
* prepare/add split (oop-design §3.1): {@link prepareImage} is the pure expert —
|
|
20
|
+
* decode, validate (throws on unsupported/corrupt input) and produce the
|
|
21
|
+
* stream bytes; `addImage` only creates the PDF objects. Layout probes with
|
|
22
|
+
* `prepareImage` (no throwaway document), the emit phase replays the prepared
|
|
23
|
+
* result, and other writers (SVG) reuse the mime/dimensions.
|
|
24
|
+
*/
|
|
6
25
|
export interface PreparedImage {
|
|
7
26
|
readonly format: ImageFormat;
|
|
8
27
|
readonly mimeType: 'image/jp2' | 'image/jpeg' | 'image/png';
|
|
9
28
|
readonly widthPx: number;
|
|
10
29
|
readonly heightPx: number;
|
|
30
|
+
/**
|
|
31
|
+
* ColorSpace/BitsPerComponent are absent for JPEG 2000 (carried inside the
|
|
32
|
+
* JPX codestream).
|
|
33
|
+
*/
|
|
11
34
|
readonly colorSpace?: 'DeviceGray' | 'DeviceRGB';
|
|
12
35
|
readonly bitsPerComponent?: number;
|
|
36
|
+
/** The PDF stream filter the `data` bytes are encoded with. */
|
|
13
37
|
readonly filter: 'DCTDecode' | 'FlateDecode' | 'JPXDecode';
|
|
14
38
|
readonly data: Uint8Array;
|
|
39
|
+
/** PNG alpha channel, already FlateDecode-compressed (DeviceGray, 8 bpc). */
|
|
15
40
|
readonly smaskData?: Uint8Array;
|
|
16
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Decode and validate one image into a {@link PreparedImage} ready to embed.
|
|
44
|
+
* JPEG and JPEG 2000 pass through verbatim (readers decode them); PNG is
|
|
45
|
+
* inflated, de-filtered and re-compressed, splitting any alpha into a soft mask.
|
|
46
|
+
*
|
|
47
|
+
* @throws Error when the format is unrecognized, unsupported, or corrupt.
|
|
48
|
+
*/
|
|
17
49
|
export declare function prepareImage(bytes: Uint8Array, options?: EmbedImageOptions): PreparedImage;
|
package/dist/esm/core/images.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { unzlibSync, zlibSync } from "fflate";
|
|
2
2
|
//#region src/core/images.ts
|
|
3
|
+
/**
|
|
4
|
+
* Sniff the raster format from a file's leading magic bytes (JPEG SOI, the PNG
|
|
5
|
+
* signature, or a JP2 box / raw JPEG 2000 codestream). Returns the
|
|
6
|
+
* {@link ImageFormat}, or `null` when none matches.
|
|
7
|
+
*/
|
|
3
8
|
function detectImageFormat(bytes) {
|
|
4
9
|
if (bytes.length >= 3 && bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) return "jpeg";
|
|
5
10
|
if (bytes.length >= 8 && bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71 && bytes[4] === 13 && bytes[5] === 10 && bytes[6] === 26 && bytes[7] === 10) return "png";
|
|
@@ -7,6 +12,13 @@ function detectImageFormat(bytes) {
|
|
|
7
12
|
if (bytes.length >= 4 && bytes[0] === 255 && bytes[1] === 79 && bytes[2] === 255 && bytes[3] === 81) return "jpeg2000";
|
|
8
13
|
return null;
|
|
9
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Decode and validate one image into a {@link PreparedImage} ready to embed.
|
|
17
|
+
* JPEG and JPEG 2000 pass through verbatim (readers decode them); PNG is
|
|
18
|
+
* inflated, de-filtered and re-compressed, splitting any alpha into a soft mask.
|
|
19
|
+
*
|
|
20
|
+
* @throws Error when the format is unrecognized, unsupported, or corrupt.
|
|
21
|
+
*/
|
|
10
22
|
function prepareImage(bytes, options = {}) {
|
|
11
23
|
const format = detectImageFormat(bytes);
|
|
12
24
|
if (format === "jpeg") return prepareJpeg(bytes);
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import { Feature } from './features.js';
|
|
2
2
|
import { FlowDoc } from './flow.js';
|
|
3
3
|
import { LossReport } from './loss.js';
|
|
4
|
+
/** Reader-call options. Open-ended; per-reader limits live in the readers. */
|
|
4
5
|
export interface ReadOptions {
|
|
5
6
|
/** Reserved for reader-specific knobs (limits live in the readers). */
|
|
6
7
|
readonly [key: string]: unknown;
|
|
7
8
|
}
|
|
9
|
+
/** The result of {@link DocumentReader.read}: the parsed tree plus any losses. */
|
|
8
10
|
export interface ReadResult<TDoc> {
|
|
11
|
+
/** The parsed document tree. */
|
|
9
12
|
readonly doc: TDoc;
|
|
13
|
+
/** Losses recorded while reading. */
|
|
10
14
|
readonly losses: LossReport;
|
|
11
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* A synchronous reader for one source format (ir-design §7). All async I/O —
|
|
18
|
+
* font fetching, resource loading — lives in the conversion facade, not here.
|
|
19
|
+
*
|
|
20
|
+
* @experimental The adapter contracts may change until they stabilize against
|
|
21
|
+
* three or more adapters.
|
|
22
|
+
*/
|
|
12
23
|
export interface DocumentReader<TDoc = FlowDoc> {
|
|
13
24
|
/** Format id: 'docx', 'xlsx', 'pdf', … */
|
|
14
25
|
readonly id: string;
|
|
@@ -20,18 +31,30 @@ export interface DocumentReader<TDoc = FlowDoc> {
|
|
|
20
31
|
sniff: (bytes: Uint8Array) => boolean;
|
|
21
32
|
read: (bytes: Uint8Array, opts?: ReadOptions) => ReadResult<TDoc>;
|
|
22
33
|
}
|
|
34
|
+
/** Writer-call options. Open-ended; per-writer knobs live in the writers. */
|
|
23
35
|
export interface WriteOptions {
|
|
24
36
|
readonly [key: string]: unknown;
|
|
25
37
|
}
|
|
38
|
+
/** The result of {@link DocumentWriter.write}: the encoded bytes plus any losses. */
|
|
26
39
|
export interface WriteResult {
|
|
40
|
+
/** The encoded output bytes. */
|
|
27
41
|
readonly bytes: Uint8Array;
|
|
42
|
+
/** Losses recorded while writing. */
|
|
28
43
|
readonly losses: LossReport;
|
|
29
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* A synchronous writer for one output format (ir-design §7).
|
|
47
|
+
*
|
|
48
|
+
* @experimental The adapter contracts may change until they stabilize against
|
|
49
|
+
* three or more adapters.
|
|
50
|
+
*/
|
|
30
51
|
export interface DocumentWriter<TDoc> {
|
|
31
52
|
/** Output format id: 'pdf', 'svg', 'html', 'docx', 'xlsx', … */
|
|
32
53
|
readonly id: string;
|
|
33
54
|
/** Which tree this writer consumes ('sheet' for the native grid writer). */
|
|
34
55
|
readonly consumes: 'flow' | 'page' | 'sheet';
|
|
56
|
+
/** Feature vocabulary this writer understands. */
|
|
35
57
|
readonly supports: ReadonlySet<Feature>;
|
|
58
|
+
/** Encode `doc` to the output bytes, collecting any losses. */
|
|
36
59
|
write: (doc: TDoc, opts?: WriteOptions) => WriteResult;
|
|
37
60
|
}
|