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,9 +1,14 @@
|
|
|
1
1
|
import { PathBuilder } from "../vector.js";
|
|
2
2
|
import { arcToBeziers, ellipseSegments, roundRectSegments } from "../arc-to-bezier.js";
|
|
3
3
|
//#region src/core/drawingml/preset-geometry.ts
|
|
4
|
+
/**
|
|
5
|
+
* The four closed segments of the `w`×`h` bounding rectangle, in the local y-up
|
|
6
|
+
* frame (origin bottom-left). The fallback geometry for unknown presets.
|
|
7
|
+
*/
|
|
4
8
|
function rectSegments(w, h) {
|
|
5
9
|
return new PathBuilder().moveTo(0, 0).lineTo(w, 0).lineTo(w, h).lineTo(0, h).close().build().segments;
|
|
6
10
|
}
|
|
11
|
+
/** The `w`×`h` bounding rectangle as a {@link VectorPath}. */
|
|
7
12
|
function rectPath(w, h) {
|
|
8
13
|
return { segments: rectSegments(w, h) };
|
|
9
14
|
}
|
|
@@ -14,6 +19,19 @@ function polygon(points) {
|
|
|
14
19
|
}
|
|
15
20
|
var clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
|
|
16
21
|
var frac = (adjust, key, def) => (adjust.get(key) ?? def) / 1e5;
|
|
22
|
+
/**
|
|
23
|
+
* Map a preset shape name (§20.1.10.55) to its vector path(s) in the local y-up
|
|
24
|
+
* frame, sized `w`×`h` points and shaped by the `adjust` guides. Returns `null`
|
|
25
|
+
* for an unknown preset so the caller falls back to the bounding rectangle —
|
|
26
|
+
* graceful degradation that keeps even unimplemented presets visible (with the
|
|
27
|
+
* right fill/line) and never throws.
|
|
28
|
+
*
|
|
29
|
+
* @param preset The preset geometry name (e.g. `'roundRect'`, `'rightArrow'`).
|
|
30
|
+
* @param w Box width in points.
|
|
31
|
+
* @param h Box height in points.
|
|
32
|
+
* @param adjust Raw `a:gd` adjust guides by name (thousandths of a percent).
|
|
33
|
+
* @returns The path(s), or `null` for an unrecognised preset.
|
|
34
|
+
*/
|
|
17
35
|
function presetPaths(preset, w, h, adjust) {
|
|
18
36
|
switch (preset) {
|
|
19
37
|
case "rect": return [rectPath(w, h)];
|
|
@@ -77,6 +95,18 @@ function presetPaths(preset, w, h, adjust) {
|
|
|
77
95
|
default: return null;
|
|
78
96
|
}
|
|
79
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Convert a custom geometry (§20.1.9) to a vector path. Path-space coordinates
|
|
100
|
+
* (y-down, origin top-left) are scaled to the shape box and flipped to the local
|
|
101
|
+
* y-up frame; quadratics are elevated to cubics; `arcTo` is decomposed via the
|
|
102
|
+
* shared arc helper. Angles are 1/60000° clockwise in y-down, which becomes
|
|
103
|
+
* negative (CCW) once y is flipped.
|
|
104
|
+
*
|
|
105
|
+
* @param geom The parsed custom geometry (path size + draw commands).
|
|
106
|
+
* @param wPt Box width in points.
|
|
107
|
+
* @param hPt Box height in points.
|
|
108
|
+
* @returns A single-element array holding the built path.
|
|
109
|
+
*/
|
|
80
110
|
function customPaths(geom, wPt, hPt) {
|
|
81
111
|
const sx = geom.pathWidth > 0 ? wPt / geom.pathWidth : 1;
|
|
82
112
|
const sy = geom.pathHeight > 0 ? hPt / geom.pathHeight : 1;
|
|
@@ -1,10 +1,64 @@
|
|
|
1
1
|
import { ShapeGeometry, ShapeLine } from '../document-model/index.js';
|
|
2
2
|
import { ShapeGradient, StrokeStyle, VectorPath } from '../vector.js';
|
|
3
|
+
/** EMU per point: 1 inch = 914400 EMU = 72 pt, so 1 pt = 12700 EMU. */
|
|
3
4
|
export declare const EMU_PER_PT = 12700;
|
|
5
|
+
/** Word's default left/right text-box inset (§20.1.2.1) — 0.1", in points. */
|
|
4
6
|
export declare const DEFAULT_INSET_LR_PT: number;
|
|
7
|
+
/** Word's default top/bottom text-box inset (§20.1.2.1) — 0.05", in points. */
|
|
5
8
|
export declare const DEFAULT_INSET_TB_PT: number;
|
|
9
|
+
/**
|
|
10
|
+
* Build the vector path(s) for a shape's geometry, sized `widthPt`×`heightPt`.
|
|
11
|
+
* Dispatches preset geometries to {@link presetPaths} (falling back to the
|
|
12
|
+
* bounding rectangle for unknown presets) and custom geometries to
|
|
13
|
+
* {@link customPaths}.
|
|
14
|
+
*
|
|
15
|
+
* @param geometry The shape geometry (preset or custom).
|
|
16
|
+
* @param widthPt Box width in points.
|
|
17
|
+
* @param heightPt Box height in points.
|
|
18
|
+
* @returns The path(s) in the local y-up frame.
|
|
19
|
+
*/
|
|
6
20
|
export declare function buildShapePaths(geometry: ShapeGeometry, widthPt: number, heightPt: number): Array<VectorPath>;
|
|
21
|
+
/**
|
|
22
|
+
* A gradient's solid approximation: the per-channel average of its stop colours
|
|
23
|
+
* (EP16). Writers without gradient support (the plain PDF emitter) paint this.
|
|
24
|
+
*
|
|
25
|
+
* @param gradient The gradient fill.
|
|
26
|
+
* @returns The averaged colour as uppercase RRGGBB (`'000000'` if no valid stops).
|
|
27
|
+
*/
|
|
7
28
|
export declare function gradientToSolid(gradient: ShapeGradient): string;
|
|
29
|
+
/**
|
|
30
|
+
* An SVG `<linearGradient>` / `<radialGradient>` definition for a gradient fill
|
|
31
|
+
* (EP16), shared by the SVG and HTML writers. The linear vector is expressed in
|
|
32
|
+
* `objectBoundingBox` space; the angle is negated because the shape's own path
|
|
33
|
+
* transform flips y (local y-up → page y-down).
|
|
34
|
+
*
|
|
35
|
+
* @param id The gradient element id (referenced by `fill="url(#id)"`).
|
|
36
|
+
* @param g The gradient fill.
|
|
37
|
+
* @returns The `<linearGradient>` or `<radialGradient>` markup.
|
|
38
|
+
*/
|
|
8
39
|
export declare function gradientSvgDef(id: string, g: ShapeGradient): string;
|
|
40
|
+
/**
|
|
41
|
+
* Build a {@link StrokeStyle} from a shape's `a:ln` line, resolving the default
|
|
42
|
+
* width (0.75pt), dash pattern and line cap. Returns `undefined` for no line or
|
|
43
|
+
* an explicit no-fill stroke.
|
|
44
|
+
*
|
|
45
|
+
* @param line The parsed line, or `undefined`.
|
|
46
|
+
* @returns The stroke style, or `undefined` when nothing should be stroked.
|
|
47
|
+
*/
|
|
9
48
|
export declare function buildStroke(line: ShapeLine | undefined): StrokeStyle | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Build the 2×3 affine placement matrix `[a, b, c, d, e, f]` that positions a
|
|
51
|
+
* shape's local y-up box at `(pageX, pageY)`, applying rotation and h/v flips
|
|
52
|
+
* about the box centre. DrawingML `rot` is clockwise in y-down space ⇒ a
|
|
53
|
+
* negative angle in PDF y-up.
|
|
54
|
+
*
|
|
55
|
+
* @param pageX Box left, in page points.
|
|
56
|
+
* @param pageY Box bottom, in page points.
|
|
57
|
+
* @param widthPt Box width in points.
|
|
58
|
+
* @param heightPt Box height in points.
|
|
59
|
+
* @param rotation60k Rotation in 1/60000°, clockwise.
|
|
60
|
+
* @param flipH Mirror horizontally.
|
|
61
|
+
* @param flipV Mirror vertically.
|
|
62
|
+
* @returns The affine matrix as `[a, b, c, d, e, f]`.
|
|
63
|
+
*/
|
|
10
64
|
export declare function buildShapeTransform(pageX: number, pageY: number, widthPt: number, heightPt: number, rotation60k: number, flipH: boolean, flipV: boolean): [number, number, number, number, number, number];
|
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
import { customPaths, presetPaths, rectPath } from "./preset-geometry.js";
|
|
2
2
|
//#region src/core/drawingml/shape-render.ts
|
|
3
|
+
/** EMU per point: 1 inch = 914400 EMU = 72 pt, so 1 pt = 12700 EMU. */
|
|
3
4
|
var EMU_PER_PT = 12700;
|
|
4
5
|
var DEFAULT_LINE_WIDTH_EMU = 9525;
|
|
6
|
+
/** Word's default left/right text-box inset (§20.1.2.1) — 0.1", in points. */
|
|
5
7
|
var DEFAULT_INSET_LR_PT = 91440 / EMU_PER_PT;
|
|
8
|
+
/** Word's default top/bottom text-box inset (§20.1.2.1) — 0.05", in points. */
|
|
6
9
|
var DEFAULT_INSET_TB_PT = 45720 / EMU_PER_PT;
|
|
10
|
+
/**
|
|
11
|
+
* Build the vector path(s) for a shape's geometry, sized `widthPt`×`heightPt`.
|
|
12
|
+
* Dispatches preset geometries to {@link presetPaths} (falling back to the
|
|
13
|
+
* bounding rectangle for unknown presets) and custom geometries to
|
|
14
|
+
* {@link customPaths}.
|
|
15
|
+
*
|
|
16
|
+
* @param geometry The shape geometry (preset or custom).
|
|
17
|
+
* @param widthPt Box width in points.
|
|
18
|
+
* @param heightPt Box height in points.
|
|
19
|
+
* @returns The path(s) in the local y-up frame.
|
|
20
|
+
*/
|
|
7
21
|
function buildShapePaths(geometry, widthPt, heightPt) {
|
|
8
22
|
if (geometry.kind === "preset") return presetPaths(geometry.preset ?? "rect", widthPt, heightPt, geometry.adjust ?? /* @__PURE__ */ new Map()) ?? [rectPath(widthPt, heightPt)];
|
|
9
23
|
if (geometry.custom) return customPaths(geometry.custom, widthPt, heightPt);
|
|
10
24
|
return [rectPath(widthPt, heightPt)];
|
|
11
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* A gradient's solid approximation: the per-channel average of its stop colours
|
|
28
|
+
* (EP16). Writers without gradient support (the plain PDF emitter) paint this.
|
|
29
|
+
*
|
|
30
|
+
* @param gradient The gradient fill.
|
|
31
|
+
* @returns The averaged colour as uppercase RRGGBB (`'000000'` if no valid stops).
|
|
32
|
+
*/
|
|
12
33
|
function gradientToSolid(gradient) {
|
|
13
34
|
let r = 0;
|
|
14
35
|
let g = 0;
|
|
@@ -26,6 +47,16 @@ function gradientToSolid(gradient) {
|
|
|
26
47
|
const hx = (x) => Math.round(x / n).toString(16).padStart(2, "0");
|
|
27
48
|
return (hx(r) + hx(g) + hx(b)).toUpperCase();
|
|
28
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* An SVG `<linearGradient>` / `<radialGradient>` definition for a gradient fill
|
|
52
|
+
* (EP16), shared by the SVG and HTML writers. The linear vector is expressed in
|
|
53
|
+
* `objectBoundingBox` space; the angle is negated because the shape's own path
|
|
54
|
+
* transform flips y (local y-up → page y-down).
|
|
55
|
+
*
|
|
56
|
+
* @param id The gradient element id (referenced by `fill="url(#id)"`).
|
|
57
|
+
* @param g The gradient fill.
|
|
58
|
+
* @returns The `<linearGradient>` or `<radialGradient>` markup.
|
|
59
|
+
*/
|
|
29
60
|
function gradientSvgDef(id, g) {
|
|
30
61
|
const n = (x) => String(Math.round(x * 1e4) / 1e4);
|
|
31
62
|
const stops = g.stops.map((s) => `<stop offset="${n(s.offset)}" stop-color="#${s.colorHex}"/>`).join("");
|
|
@@ -35,6 +66,14 @@ function gradientSvgDef(id, g) {
|
|
|
35
66
|
const dy = Math.sin(rad) / 2;
|
|
36
67
|
return `<linearGradient id="${id}" x1="${n(.5 - dx)}" y1="${n(.5 - dy)}" x2="${n(.5 + dx)}" y2="${n(.5 + dy)}">${stops}</linearGradient>`;
|
|
37
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Build a {@link StrokeStyle} from a shape's `a:ln` line, resolving the default
|
|
71
|
+
* width (0.75pt), dash pattern and line cap. Returns `undefined` for no line or
|
|
72
|
+
* an explicit no-fill stroke.
|
|
73
|
+
*
|
|
74
|
+
* @param line The parsed line, or `undefined`.
|
|
75
|
+
* @returns The stroke style, or `undefined` when nothing should be stroked.
|
|
76
|
+
*/
|
|
38
77
|
function buildStroke(line) {
|
|
39
78
|
if (!line || line.fill === "none") return void 0;
|
|
40
79
|
const widthPt = line.width ?? DEFAULT_LINE_WIDTH_EMU / 12700;
|
|
@@ -70,6 +109,21 @@ function dashPattern(dash, w) {
|
|
|
70
109
|
case "sysDot": return [u, u];
|
|
71
110
|
}
|
|
72
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Build the 2×3 affine placement matrix `[a, b, c, d, e, f]` that positions a
|
|
114
|
+
* shape's local y-up box at `(pageX, pageY)`, applying rotation and h/v flips
|
|
115
|
+
* about the box centre. DrawingML `rot` is clockwise in y-down space ⇒ a
|
|
116
|
+
* negative angle in PDF y-up.
|
|
117
|
+
*
|
|
118
|
+
* @param pageX Box left, in page points.
|
|
119
|
+
* @param pageY Box bottom, in page points.
|
|
120
|
+
* @param widthPt Box width in points.
|
|
121
|
+
* @param heightPt Box height in points.
|
|
122
|
+
* @param rotation60k Rotation in 1/60000°, clockwise.
|
|
123
|
+
* @param flipH Mirror horizontally.
|
|
124
|
+
* @param flipV Mirror vertically.
|
|
125
|
+
* @returns The affine matrix as `[a, b, c, d, e, f]`.
|
|
126
|
+
*/
|
|
73
127
|
function buildShapeTransform(pageX, pageY, widthPt, heightPt, rotation60k, flipH, flipV) {
|
|
74
128
|
const theta = -rotation60k / 6e4 * (Math.PI / 180);
|
|
75
129
|
const sx = flipH ? -1 : 1;
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { StrokeStyle, VectorPath } from '../vector.js';
|
|
2
|
+
/** The sparkline type: a trend `line`, a `column` bar chart, or `winLoss` bars. */
|
|
2
3
|
export type SparklineKind = 'line' | 'column' | 'winLoss';
|
|
4
|
+
/** One drawable layer of a sparkline: paths sharing a fill and/or stroke. */
|
|
3
5
|
export interface SparklinePrim {
|
|
4
6
|
readonly paths: ReadonlyArray<VectorPath>;
|
|
5
7
|
readonly fillColorHex?: string;
|
|
6
8
|
readonly stroke?: StrokeStyle;
|
|
7
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Build sparkline primitives (E-SHEET SC2) for a single cell in a local y-up
|
|
12
|
+
* `[0,width]×[0,height]` frame — a bare trend glyph with no axes, legend or
|
|
13
|
+
* labels. Gaps (`null`) break a line and skip a bar while preserving the slot.
|
|
14
|
+
* Returns an empty array for a non-positive box or an all-null series.
|
|
15
|
+
*
|
|
16
|
+
* @param kind The sparkline type.
|
|
17
|
+
* @param values The data points, in order; `null` marks a gap.
|
|
18
|
+
* @param width Frame width in points.
|
|
19
|
+
* @param height Frame height in points.
|
|
20
|
+
* @param colorHex Series colour (RRGGBB); defaults to Excel's sparkline blue.
|
|
21
|
+
* @returns The drawable layers (win/loss yields separate win and loss layers).
|
|
22
|
+
*/
|
|
8
23
|
export declare function buildSparkline(kind: SparklineKind, values: ReadonlyArray<number | null>, width: number, height: number, colorHex?: string): Array<SparklinePrim>;
|
|
@@ -2,6 +2,19 @@ import { PathBuilder } from "../vector.js";
|
|
|
2
2
|
//#region src/core/drawingml/sparkline-geometry.ts
|
|
3
3
|
var DEFAULT_SERIES_HEX = "376092";
|
|
4
4
|
var LOSS_HEX = "D00000";
|
|
5
|
+
/**
|
|
6
|
+
* Build sparkline primitives (E-SHEET SC2) for a single cell in a local y-up
|
|
7
|
+
* `[0,width]×[0,height]` frame — a bare trend glyph with no axes, legend or
|
|
8
|
+
* labels. Gaps (`null`) break a line and skip a bar while preserving the slot.
|
|
9
|
+
* Returns an empty array for a non-positive box or an all-null series.
|
|
10
|
+
*
|
|
11
|
+
* @param kind The sparkline type.
|
|
12
|
+
* @param values The data points, in order; `null` marks a gap.
|
|
13
|
+
* @param width Frame width in points.
|
|
14
|
+
* @param height Frame height in points.
|
|
15
|
+
* @param colorHex Series colour (RRGGBB); defaults to Excel's sparkline blue.
|
|
16
|
+
* @returns The drawable layers (win/loss yields separate win and loss layers).
|
|
17
|
+
*/
|
|
5
18
|
function buildSparkline(kind, values, width, height, colorHex) {
|
|
6
19
|
if (width <= 0 || height <= 0 || values.every((v) => v === null)) return [];
|
|
7
20
|
const color = colorHex ?? DEFAULT_SERIES_HEX;
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a DrawingML theme part (ECMA-376 §20.1.6.2, `a:clrScheme`) into a
|
|
3
|
+
* `name → hex` colour map. Reads the twelve scheme slots — `dk1`/`lt1`/`dk2`/
|
|
4
|
+
* `lt2`, `accent1`–`accent6`, `hlink`/`folHlink` — taking each slot's
|
|
5
|
+
* `a:srgbClr@val` or, for a system colour, its resolved `a:sysClr@lastClr`.
|
|
6
|
+
* Unknown slots and slots with no resolvable colour are skipped.
|
|
7
|
+
*
|
|
8
|
+
* @param themeXml The raw `word/theme/theme1.xml` (or sibling) bytes, UTF-8.
|
|
9
|
+
* @returns A map keyed by slot name (`'accent1'`, …) to uppercase RRGGBB hex;
|
|
10
|
+
* empty when no `a:clrScheme` is present.
|
|
11
|
+
*/
|
|
1
12
|
export declare function parseTheme(themeXml: Uint8Array): Map<string, string>;
|
|
@@ -24,6 +24,17 @@ var SCHEME_SLOTS = new Set([
|
|
|
24
24
|
"hlink",
|
|
25
25
|
"folHlink"
|
|
26
26
|
]);
|
|
27
|
+
/**
|
|
28
|
+
* Parse a DrawingML theme part (ECMA-376 §20.1.6.2, `a:clrScheme`) into a
|
|
29
|
+
* `name → hex` colour map. Reads the twelve scheme slots — `dk1`/`lt1`/`dk2`/
|
|
30
|
+
* `lt2`, `accent1`–`accent6`, `hlink`/`folHlink` — taking each slot's
|
|
31
|
+
* `a:srgbClr@val` or, for a system colour, its resolved `a:sysClr@lastClr`.
|
|
32
|
+
* Unknown slots and slots with no resolvable colour are skipped.
|
|
33
|
+
*
|
|
34
|
+
* @param themeXml The raw `word/theme/theme1.xml` (or sibling) bytes, UTF-8.
|
|
35
|
+
* @returns A map keyed by slot name (`'accent1'`, …) to uppercase RRGGBB hex;
|
|
36
|
+
* empty when no `a:clrScheme` is present.
|
|
37
|
+
*/
|
|
27
38
|
function parseTheme(themeXml) {
|
|
28
39
|
const out = /* @__PURE__ */ new Map();
|
|
29
40
|
const clrScheme = poFindByPath(parser.parse(decoder.decode(themeXml)), [
|
|
@@ -1,4 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A character's Arabic joining class (ArabicShaping.txt): Right-, Left-,
|
|
3
|
+
* Dual-joining, join-Causing, Non-joining, or Transparent (combining marks).
|
|
4
|
+
*/
|
|
1
5
|
export type JoiningType = 'R' | 'L' | 'D' | 'C' | 'U' | 'T';
|
|
6
|
+
/** The contextual cursive form a letter takes: isolated, initial, medial or final. */
|
|
2
7
|
export type ArabicForm = 'isol' | 'init' | 'medi' | 'fina';
|
|
8
|
+
/**
|
|
9
|
+
* Classify a code point's Arabic {@link JoiningType}. Covers the standard Arabic
|
|
10
|
+
* block plus tatweel and the ZWJ/ZWNJ controls; everything else is non-joining.
|
|
11
|
+
*
|
|
12
|
+
* @param cp The Unicode code point.
|
|
13
|
+
* @returns Its joining type.
|
|
14
|
+
*/
|
|
3
15
|
export declare function arabicJoiningType(cp: number): JoiningType;
|
|
16
|
+
/**
|
|
17
|
+
* Assign a cursive {@link ArabicForm} to each code point in a run, from the
|
|
18
|
+
* joining types of the surrounding letters (transparent marks are skipped).
|
|
19
|
+
* Non-joining characters get `'isol'` — a harmless default, since their glyph is
|
|
20
|
+
* never in the positional maps.
|
|
21
|
+
*
|
|
22
|
+
* @param cps The run's code points, in logical order.
|
|
23
|
+
* @returns The per-code-point form, parallel to `cps`.
|
|
24
|
+
*/
|
|
4
25
|
export declare function assignArabicForms(cps: ReadonlyArray<number>): Array<ArabicForm>;
|
|
@@ -56,6 +56,13 @@ var RIGHT_JOINING = new Set([
|
|
|
56
56
|
function isTransparentMark(cp) {
|
|
57
57
|
return cp >= 1552 && cp <= 1562 || cp >= 1611 && cp <= 1631 || cp === 1648 || cp >= 1750 && cp <= 1756 || cp >= 1759 && cp <= 1764 || cp === 1767 || cp === 1768 || cp >= 1770 && cp <= 1773;
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Classify a code point's Arabic {@link JoiningType}. Covers the standard Arabic
|
|
61
|
+
* block plus tatweel and the ZWJ/ZWNJ controls; everything else is non-joining.
|
|
62
|
+
*
|
|
63
|
+
* @param cp The Unicode code point.
|
|
64
|
+
* @returns Its joining type.
|
|
65
|
+
*/
|
|
59
66
|
function arabicJoiningType(cp) {
|
|
60
67
|
if (cp === 1600) return "C";
|
|
61
68
|
if (cp === 8205) return "C";
|
|
@@ -67,6 +74,15 @@ function arabicJoiningType(cp) {
|
|
|
67
74
|
}
|
|
68
75
|
var canJoinRight = (t) => t === "R" || t === "D" || t === "C";
|
|
69
76
|
var canJoinLeft = (t) => t === "L" || t === "D" || t === "C";
|
|
77
|
+
/**
|
|
78
|
+
* Assign a cursive {@link ArabicForm} to each code point in a run, from the
|
|
79
|
+
* joining types of the surrounding letters (transparent marks are skipped).
|
|
80
|
+
* Non-joining characters get `'isol'` — a harmless default, since their glyph is
|
|
81
|
+
* never in the positional maps.
|
|
82
|
+
*
|
|
83
|
+
* @param cps The run's code points, in logical order.
|
|
84
|
+
* @returns The per-code-point form, parallel to `cps`.
|
|
85
|
+
*/
|
|
70
86
|
function assignArabicForms(cps) {
|
|
71
87
|
const types = cps.map(arabicJoiningType);
|
|
72
88
|
const forms = new Array(cps.length).fill("isol");
|
|
@@ -1,13 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cursor over a byte buffer that reads big-endian integers — the byte order
|
|
3
|
+
* TrueType / OpenType (ISO/IEC 14496-22) files use for every multi-byte value.
|
|
4
|
+
* Each read advances {@link BigEndianReader.offset}.
|
|
5
|
+
*/
|
|
1
6
|
export declare class BigEndianReader {
|
|
2
7
|
readonly data: Uint8Array;
|
|
3
8
|
offset: number;
|
|
9
|
+
/**
|
|
10
|
+
* @param data The buffer to read from.
|
|
11
|
+
* @param offset The starting byte offset (default 0).
|
|
12
|
+
*/
|
|
4
13
|
constructor(data: Uint8Array, offset?: number);
|
|
14
|
+
/** Move the cursor to an absolute byte offset. */
|
|
5
15
|
seek(offset: number): void;
|
|
16
|
+
/** Advance the cursor by `bytes` without reading. */
|
|
6
17
|
skip(bytes: number): void;
|
|
18
|
+
/** Read an unsigned 8-bit integer; advances 1 byte. */
|
|
7
19
|
u8(): number;
|
|
20
|
+
/** Read an unsigned 16-bit big-endian integer; advances 2 bytes. */
|
|
8
21
|
u16(): number;
|
|
22
|
+
/** Read a signed 16-bit big-endian integer; advances 2 bytes. */
|
|
9
23
|
i16(): number;
|
|
24
|
+
/** Read an unsigned 32-bit big-endian integer; advances 4 bytes. */
|
|
10
25
|
u32(): number;
|
|
26
|
+
/** Read a signed 32-bit big-endian integer; advances 4 bytes. */
|
|
11
27
|
i32(): number;
|
|
28
|
+
/** Read a 4-byte ASCII tag (e.g. a TrueType table tag); advances 4 bytes. */
|
|
12
29
|
tag(): string;
|
|
13
30
|
}
|
|
@@ -1,38 +1,55 @@
|
|
|
1
1
|
//#region src/core/font/binary-reader.ts
|
|
2
|
+
/**
|
|
3
|
+
* A cursor over a byte buffer that reads big-endian integers — the byte order
|
|
4
|
+
* TrueType / OpenType (ISO/IEC 14496-22) files use for every multi-byte value.
|
|
5
|
+
* Each read advances {@link BigEndianReader.offset}.
|
|
6
|
+
*/
|
|
2
7
|
var BigEndianReader = class {
|
|
8
|
+
/**
|
|
9
|
+
* @param data The buffer to read from.
|
|
10
|
+
* @param offset The starting byte offset (default 0).
|
|
11
|
+
*/
|
|
3
12
|
constructor(data, offset = 0) {
|
|
4
13
|
this.data = data;
|
|
5
14
|
this.offset = offset;
|
|
6
15
|
}
|
|
16
|
+
/** Move the cursor to an absolute byte offset. */
|
|
7
17
|
seek(offset) {
|
|
8
18
|
this.offset = offset;
|
|
9
19
|
}
|
|
20
|
+
/** Advance the cursor by `bytes` without reading. */
|
|
10
21
|
skip(bytes) {
|
|
11
22
|
this.offset += bytes;
|
|
12
23
|
}
|
|
24
|
+
/** Read an unsigned 8-bit integer; advances 1 byte. */
|
|
13
25
|
u8() {
|
|
14
26
|
return this.data[this.offset++];
|
|
15
27
|
}
|
|
28
|
+
/** Read an unsigned 16-bit big-endian integer; advances 2 bytes. */
|
|
16
29
|
u16() {
|
|
17
30
|
const d = this.data;
|
|
18
31
|
const p = this.offset;
|
|
19
32
|
this.offset += 2;
|
|
20
33
|
return d[p] << 8 | d[p + 1];
|
|
21
34
|
}
|
|
35
|
+
/** Read a signed 16-bit big-endian integer; advances 2 bytes. */
|
|
22
36
|
i16() {
|
|
23
37
|
const v = this.u16();
|
|
24
38
|
return v >= 32768 ? v - 65536 : v;
|
|
25
39
|
}
|
|
40
|
+
/** Read an unsigned 32-bit big-endian integer; advances 4 bytes. */
|
|
26
41
|
u32() {
|
|
27
42
|
const d = this.data;
|
|
28
43
|
const p = this.offset;
|
|
29
44
|
this.offset += 4;
|
|
30
45
|
return d[p] * 16777216 + (d[p + 1] << 16 | d[p + 2] << 8 | d[p + 3]);
|
|
31
46
|
}
|
|
47
|
+
/** Read a signed 32-bit big-endian integer; advances 4 bytes. */
|
|
32
48
|
i32() {
|
|
33
49
|
const v = this.u32();
|
|
34
50
|
return v >= 2147483648 ? v - 4294967296 : v;
|
|
35
51
|
}
|
|
52
|
+
/** Read a 4-byte ASCII tag (e.g. a TrueType table tag); advances 4 bytes. */
|
|
36
53
|
tag() {
|
|
37
54
|
const d = this.data;
|
|
38
55
|
const p = this.offset;
|
|
@@ -1,20 +1,57 @@
|
|
|
1
1
|
import { ParsedTtf } from './ttf-parser.js';
|
|
2
|
+
/** A font style slot: regular, bold, italic or bold-italic. */
|
|
2
3
|
export type FontVariant = 'regular' | 'bold' | 'italic' | 'boldItalic';
|
|
4
|
+
/**
|
|
5
|
+
* The single owner of face fallback (oop-design §8, A4): the candidate cascade a
|
|
6
|
+
* missing variant degrades through (`boldItalic → bold → italic → regular`),
|
|
7
|
+
* shared by the registry and every font provider.
|
|
8
|
+
*
|
|
9
|
+
* @param has Predicate — does a given variant exist?
|
|
10
|
+
* @param bold Whether bold was requested.
|
|
11
|
+
* @param italic Whether italic was requested.
|
|
12
|
+
* @returns The best available variant, or `undefined` when even `regular` is missing.
|
|
13
|
+
*/
|
|
3
14
|
export declare function pickVariant(has: (variant: FontVariant) => boolean, bold: boolean, italic: boolean): FontVariant | undefined;
|
|
15
|
+
/** Raw TTF/OTF bytes per style variant; only `regular` is required. */
|
|
4
16
|
export interface FontBytesByVariant {
|
|
17
|
+
/** The regular (upright, normal-weight) face — required. */
|
|
5
18
|
readonly regular: Uint8Array;
|
|
19
|
+
/** The bold face, if available. */
|
|
6
20
|
readonly bold?: Uint8Array;
|
|
21
|
+
/** The italic face, if available. */
|
|
7
22
|
readonly italic?: Uint8Array;
|
|
23
|
+
/** The bold-italic face, if available. */
|
|
8
24
|
readonly boldItalic?: Uint8Array;
|
|
9
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* A registry of parsed font variants. The renderer resolves a `(bold, italic)`
|
|
28
|
+
* request to the closest available face via {@link pickVariant}, degrading
|
|
29
|
+
* through `bold → italic → regular` when an exact match is missing.
|
|
30
|
+
*/
|
|
10
31
|
export declare class FontRegistry {
|
|
11
32
|
private readonly fonts;
|
|
12
33
|
private constructor();
|
|
34
|
+
/**
|
|
35
|
+
* Parse a set of font bytes into a registry.
|
|
36
|
+
*
|
|
37
|
+
* @param input The bytes per variant (`regular` required).
|
|
38
|
+
* @returns A registry holding the parsed faces.
|
|
39
|
+
*/
|
|
13
40
|
static fromBytes(input: FontBytesByVariant): FontRegistry;
|
|
41
|
+
/**
|
|
42
|
+
* Resolve a style request to the closest available face.
|
|
43
|
+
*
|
|
44
|
+
* @param bold Whether bold was requested.
|
|
45
|
+
* @param italic Whether italic was requested.
|
|
46
|
+
* @returns The chosen variant and its parsed font.
|
|
47
|
+
* @throws Error when the registry has no usable (regular) font.
|
|
48
|
+
*/
|
|
14
49
|
resolveByStyle(bold: boolean, italic: boolean): {
|
|
15
50
|
variant: FontVariant;
|
|
16
51
|
parsed: ParsedTtf;
|
|
17
52
|
};
|
|
53
|
+
/** Iterate the `[variant, parsed font]` pairs the registry holds. */
|
|
18
54
|
entries(): IterableIterator<[FontVariant, ParsedTtf]>;
|
|
55
|
+
/** Whether a given variant is present. */
|
|
19
56
|
hasVariant(v: FontVariant): boolean;
|
|
20
57
|
}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { parseTtf } from "./ttf-parser.js";
|
|
2
2
|
//#region src/core/font/font-registry.ts
|
|
3
|
+
/**
|
|
4
|
+
* The single owner of face fallback (oop-design §8, A4): the candidate cascade a
|
|
5
|
+
* missing variant degrades through (`boldItalic → bold → italic → regular`),
|
|
6
|
+
* shared by the registry and every font provider.
|
|
7
|
+
*
|
|
8
|
+
* @param has Predicate — does a given variant exist?
|
|
9
|
+
* @param bold Whether bold was requested.
|
|
10
|
+
* @param italic Whether italic was requested.
|
|
11
|
+
* @returns The best available variant, or `undefined` when even `regular` is missing.
|
|
12
|
+
*/
|
|
3
13
|
function pickVariant(has, bold, italic) {
|
|
4
14
|
return (bold && italic ? [
|
|
5
15
|
"boldItalic",
|
|
@@ -8,10 +18,21 @@ function pickVariant(has, bold, italic) {
|
|
|
8
18
|
"regular"
|
|
9
19
|
] : bold ? ["bold", "regular"] : italic ? ["italic", "regular"] : ["regular"]).find(has);
|
|
10
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* A registry of parsed font variants. The renderer resolves a `(bold, italic)`
|
|
23
|
+
* request to the closest available face via {@link pickVariant}, degrading
|
|
24
|
+
* through `bold → italic → regular` when an exact match is missing.
|
|
25
|
+
*/
|
|
11
26
|
var FontRegistry = class FontRegistry {
|
|
12
27
|
constructor(fonts) {
|
|
13
28
|
this.fonts = fonts;
|
|
14
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Parse a set of font bytes into a registry.
|
|
32
|
+
*
|
|
33
|
+
* @param input The bytes per variant (`regular` required).
|
|
34
|
+
* @returns A registry holding the parsed faces.
|
|
35
|
+
*/
|
|
15
36
|
static fromBytes(input) {
|
|
16
37
|
const map = /* @__PURE__ */ new Map();
|
|
17
38
|
map.set("regular", parseTtf(input.regular));
|
|
@@ -20,6 +41,14 @@ var FontRegistry = class FontRegistry {
|
|
|
20
41
|
if (input.boldItalic) map.set("boldItalic", parseTtf(input.boldItalic));
|
|
21
42
|
return new FontRegistry(map);
|
|
22
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Resolve a style request to the closest available face.
|
|
46
|
+
*
|
|
47
|
+
* @param bold Whether bold was requested.
|
|
48
|
+
* @param italic Whether italic was requested.
|
|
49
|
+
* @returns The chosen variant and its parsed font.
|
|
50
|
+
* @throws Error when the registry has no usable (regular) font.
|
|
51
|
+
*/
|
|
23
52
|
resolveByStyle(bold, italic) {
|
|
24
53
|
const variant = pickVariant((v) => this.fonts.has(v), bold, italic);
|
|
25
54
|
const parsed = variant ? this.fonts.get(variant) : void 0;
|
|
@@ -29,9 +58,11 @@ var FontRegistry = class FontRegistry {
|
|
|
29
58
|
parsed
|
|
30
59
|
};
|
|
31
60
|
}
|
|
61
|
+
/** Iterate the `[variant, parsed font]` pairs the registry holds. */
|
|
32
62
|
entries() {
|
|
33
63
|
return this.fonts.entries();
|
|
34
64
|
}
|
|
65
|
+
/** Whether a given variant is present. */
|
|
35
66
|
hasVariant(v) {
|
|
36
67
|
return this.fonts.has(v);
|
|
37
68
|
}
|
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
import { ParsedTtf } from './ttf-parser.js';
|
|
2
|
+
/**
|
|
3
|
+
* Text measurement and glyph encoding derived purely from a parsed font (no PDF
|
|
4
|
+
* involved). Layout measures with these, and the PDF emitter reuses the same
|
|
5
|
+
* functions, so emit encodes exactly what layout measured. CIDs are GIDs
|
|
6
|
+
* (Identity ordering), so the hex encoding is writer-agnostic glyph addressing.
|
|
7
|
+
*/
|
|
2
8
|
export interface FontMeasure {
|
|
9
|
+
/** Glyph advance width in 1000-unit PDF text space, for a glyph id. */
|
|
3
10
|
readonly pdfWidthForGid: (gid: number) => number;
|
|
11
|
+
/** Shaped width of `text` at `fontSize`, in points. */
|
|
4
12
|
readonly textWidthPt: (text: string, fontSize: number) => number;
|
|
13
|
+
/** Encode `text` as a hex string of 4-digit glyph ids (Identity-H addressing). */
|
|
5
14
|
readonly encodeTextAsCidHex: (text: string) => string;
|
|
6
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Build a {@link FontMeasure} over a parsed font.
|
|
18
|
+
*
|
|
19
|
+
* @param parsed The parsed TTF/OTF.
|
|
20
|
+
* @param kern Whether to apply pair kerning to measured advances (E-PARITY
|
|
21
|
+
* FP4). The default keeps it; the `'word'` layout profile turns it
|
|
22
|
+
* off (Word leaves font kerning off by default, and Ream's `Tj`
|
|
23
|
+
* output is un-kerned anyway). Glyph identity is kern-independent,
|
|
24
|
+
* so only the widths change.
|
|
25
|
+
* @returns The measurement / encoding closures.
|
|
26
|
+
*/
|
|
7
27
|
export declare function createFontMeasure(parsed: ParsedTtf, kern?: boolean): FontMeasure;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { shapeText } from "./opentype-layout.js";
|
|
2
2
|
//#region src/core/font/measure.ts
|
|
3
3
|
var EMPTY_KERNING = /* @__PURE__ */ new Map();
|
|
4
|
+
/**
|
|
5
|
+
* Build a {@link FontMeasure} over a parsed font.
|
|
6
|
+
*
|
|
7
|
+
* @param parsed The parsed TTF/OTF.
|
|
8
|
+
* @param kern Whether to apply pair kerning to measured advances (E-PARITY
|
|
9
|
+
* FP4). The default keeps it; the `'word'` layout profile turns it
|
|
10
|
+
* off (Word leaves font kerning off by default, and Ream's `Tj`
|
|
11
|
+
* output is un-kerned anyway). Glyph identity is kern-independent,
|
|
12
|
+
* so only the widths change.
|
|
13
|
+
* @returns The measurement / encoding closures.
|
|
14
|
+
*/
|
|
4
15
|
function createFontMeasure(parsed, kern = true) {
|
|
5
16
|
const scale = 1e3 / parsed.unitsPerEm;
|
|
6
17
|
const kerning = kern ? parsed.kerning : EMPTY_KERNING;
|