pagyra-js 0.0.1
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/.eslintrc.json +30 -0
- package/CHANGELOG.md +13 -0
- package/README.md +275 -0
- package/UA_Styles_Chromium.md +93 -0
- package/_ext/woff2_conversion/brotli-decode.d.ts +139 -0
- package/_ext/woff2_conversion/brotli-encode.d.ts +129 -0
- package/_ext/woff2_conversion/brotli-port.d.ts +12 -0
- package/_ext/woff2_conversion/brotli-shared-dictionary.d.ts +25 -0
- package/_ext/woff2_conversion/brotli-types.d.ts +15 -0
- package/_ext/woff2_conversion/woff2-common.d.ts +37 -0
- package/_ext/woff2_conversion/woff2-decode.d.ts +32 -0
- package/_ext/woff2_conversion/woff2-encode.d.ts +31 -0
- package/_ext/woff2_conversion/woff2-output.d.ts +39 -0
- package/_ext/woff2_original_cpp/brotli/brotli.c +1559 -0
- package/_ext/woff2_original_cpp/brotli/brotli.md +116 -0
- package/_ext/woff2_original_cpp/brotli/decode.h +409 -0
- package/_ext/woff2_original_cpp/brotli/encode.h +505 -0
- package/_ext/woff2_original_cpp/brotli/port.h +302 -0
- package/_ext/woff2_original_cpp/brotli/shared_dictionary.h +100 -0
- package/_ext/woff2_original_cpp/brotli/types.h +83 -0
- package/_ext/woff2_original_cpp/cmake/FindBrotliDec.cmake +35 -0
- package/_ext/woff2_original_cpp/cmake/FindBrotliEnc.cmake +35 -0
- package/_ext/woff2_original_cpp/include/woff2/decode.h +36 -0
- package/_ext/woff2_original_cpp/include/woff2/encode.h +43 -0
- package/_ext/woff2_original_cpp/include/woff2/output.h +86 -0
- package/_ext/woff2_original_cpp/src/buffer.h +164 -0
- package/_ext/woff2_original_cpp/src/convert_woff2ttf_fuzzer.cc +13 -0
- package/_ext/woff2_original_cpp/src/convert_woff2ttf_fuzzer_new_entry.cc +12 -0
- package/_ext/woff2_original_cpp/src/file.h +30 -0
- package/_ext/woff2_original_cpp/src/font.cc +400 -0
- package/_ext/woff2_original_cpp/src/font.h +105 -0
- package/_ext/woff2_original_cpp/src/glyph.cc +383 -0
- package/_ext/woff2_original_cpp/src/glyph.h +71 -0
- package/_ext/woff2_original_cpp/src/normalize.cc +314 -0
- package/_ext/woff2_original_cpp/src/normalize.h +39 -0
- package/_ext/woff2_original_cpp/src/port.h +66 -0
- package/_ext/woff2_original_cpp/src/round.h +27 -0
- package/_ext/woff2_original_cpp/src/store_bytes.h +55 -0
- package/_ext/woff2_original_cpp/src/table_tags.cc +82 -0
- package/_ext/woff2_original_cpp/src/table_tags.h +30 -0
- package/_ext/woff2_original_cpp/src/transform.cc +430 -0
- package/_ext/woff2_original_cpp/src/transform.h +26 -0
- package/_ext/woff2_original_cpp/src/variable_length.cc +129 -0
- package/_ext/woff2_original_cpp/src/variable_length.h +30 -0
- package/_ext/woff2_original_cpp/src/woff2_common.cc +50 -0
- package/_ext/woff2_original_cpp/src/woff2_common.h +64 -0
- package/_ext/woff2_original_cpp/src/woff2_compress.cc +43 -0
- package/_ext/woff2_original_cpp/src/woff2_dec.cc +1398 -0
- package/_ext/woff2_original_cpp/src/woff2_decompress.cc +41 -0
- package/_ext/woff2_original_cpp/src/woff2_enc.cc +458 -0
- package/_ext/woff2_original_cpp/src/woff2_info.cc +142 -0
- package/_ext/woff2_original_cpp/src/woff2_out.cc +63 -0
- package/assets/fonts/ttf/arimo/Arimo-Bold.ttf +0 -0
- package/assets/fonts/ttf/arimo/Arimo-BoldItalic.ttf +0 -0
- package/assets/fonts/ttf/arimo/Arimo-Italic.ttf +0 -0
- package/assets/fonts/ttf/arimo/Arimo-Regular.ttf +0 -0
- package/assets/fonts/ttf/cinzeldecorative/CinzelDecorative-Black.ttf +0 -0
- package/assets/fonts/ttf/cinzeldecorative/CinzelDecorative-Bold.ttf +0 -0
- package/assets/fonts/ttf/cinzeldecorative/CinzelDecorative-Regular.ttf +0 -0
- package/assets/fonts/ttf/dejavu/DejaVuSans.ttf +0 -0
- package/assets/fonts/ttf/firecode/FiraCode-Bold.ttf +0 -0
- package/assets/fonts/ttf/firecode/FiraCode-Light.ttf +0 -0
- package/assets/fonts/ttf/firecode/FiraCode-Medium.ttf +0 -0
- package/assets/fonts/ttf/firecode/FiraCode-Regular.ttf +0 -0
- package/assets/fonts/ttf/firecode/FiraCode-SemiBold.ttf +0 -0
- package/assets/fonts/ttf/notoemoji/NotoEmoji-Bold.ttf +0 -0
- package/assets/fonts/ttf/notoemoji/NotoEmoji-Light.ttf +0 -0
- package/assets/fonts/ttf/notoemoji/NotoEmoji-Medium.ttf +0 -0
- package/assets/fonts/ttf/notoemoji/NotoEmoji-Regular.ttf +0 -0
- package/assets/fonts/ttf/notoemoji/NotoEmoji-SemiBold.ttf +0 -0
- package/assets/fonts/ttf/notosans/NotoSans-Regular.ttf +0 -0
- package/assets/fonts/ttf/roboto/Roboto-Bold.ttf +0 -0
- package/assets/fonts/ttf/roboto/Roboto-BoldItalic.ttf +0 -0
- package/assets/fonts/ttf/roboto/Roboto-Italic.ttf +0 -0
- package/assets/fonts/ttf/roboto/Roboto-Regular.ttf +0 -0
- package/assets/fonts/ttf/stixtwomath/STIXTwoMath-Regular.ttf +0 -0
- package/assets/fonts/ttf/tinos/Tinos-Bold.ttf +0 -0
- package/assets/fonts/ttf/tinos/Tinos-BoldItalic.ttf +0 -0
- package/assets/fonts/ttf/tinos/Tinos-Italic.ttf +0 -0
- package/assets/fonts/ttf/tinos/Tinos-Regular.ttf +0 -0
- package/assets/fonts/woff/lato/lato-latin-400-italic.woff +0 -0
- package/assets/fonts/woff/lato/lato-latin-400-normal.woff +0 -0
- package/assets/fonts/woff/lato/lato-latin-700-italic.woff +0 -0
- package/assets/fonts/woff/lato/lato-latin-700-normal.woff +0 -0
- package/assets/fonts/woff2/caveat/Caveat-Bold.woff2 +0 -0
- package/assets/fonts/woff2/caveat/Caveat-Regular.woff2 +0 -0
- package/assets/fonts/woff2/lato/lato-latin-400-italic.woff2 +0 -0
- package/assets/fonts/woff2/lato/lato-latin-400-normal.woff2 +0 -0
- package/assets/fonts/woff2/lato/lato-latin-700-italic.woff2 +0 -0
- package/assets/fonts/woff2/lato/lato-latin-700-normal.woff2 +0 -0
- package/docs/AGENTS.md +288 -0
- package/docs/BACKGROUND-REPEAT-IMPLEMENTATION.md +127 -0
- package/docs/BACKGROUND-REPEAT-REFERENCE.md +127 -0
- package/docs/BACKGROUND-REPEAT-SPACE-ROUND.md +164 -0
- package/docs/css-properties-support.md +256 -0
- package/docs/src_modules_table.md +172 -0
- package/docs/text-overlap-fix.md +85 -0
- package/docs/text-overlap-investigation.md +27 -0
- package/eslint.config.js +36 -0
- package/glyph_measure.htm +1458 -0
- package/package.json +50 -0
- package/playground/browser-entry.ts +2 -0
- package/playground/exports/background-text-debug.pdf +0 -0
- package/playground/public/app.js +875 -0
- package/playground/public/assets/1.webp +0 -0
- package/playground/public/examples/accents-test.html +24 -0
- package/playground/public/examples/advanced-selectors-demo.html +118 -0
- package/playground/public/examples/background-advanced-showcase.html +82 -0
- package/playground/public/examples/background-clip-text.html +36 -0
- package/playground/public/examples/background-origin-showcase.html +137 -0
- package/playground/public/examples/background-position-showcase.html +83 -0
- package/playground/public/examples/background-repeat-showcase.html +83 -0
- package/playground/public/examples/background-repeat-space-round.html +348 -0
- package/playground/public/examples/background-size-showcase.html +82 -0
- package/playground/public/examples/background-text-debug.html +18 -0
- package/playground/public/examples/baseline-test.html +24 -0
- package/playground/public/examples/bold-showcase.html +150 -0
- package/playground/public/examples/bold-strike-example.html +12 -0
- package/playground/public/examples/border-collapse-test.html +23 -0
- package/playground/public/examples/centered-shadow-div.html +72 -0
- package/playground/public/examples/css-variables.html +50 -0
- package/playground/public/examples/debug-accents.html +11 -0
- package/playground/public/examples/debug-text-overlap.html +46 -0
- package/playground/public/examples/flex-gap-column.html +130 -0
- package/playground/public/examples/flex-gap-row.html +137 -0
- package/playground/public/examples/flex-padding-test.html +29 -0
- package/playground/public/examples/flexbox-text-test.html +193 -0
- package/playground/public/examples/fonts-demo.html +126 -0
- package/playground/public/examples/footer-example.html +4 -0
- package/playground/public/examples/gradient-text.html +54 -0
- package/playground/public/examples/grid-gap-demo.html +156 -0
- package/playground/public/examples/header-example.html +4 -0
- package/playground/public/examples/header-footer-example.html +27 -0
- package/playground/public/examples/image-showcase.html +33 -0
- package/playground/public/examples/justify-text.html +22 -0
- package/playground/public/examples/linear-gradient-example.html +38 -0
- package/playground/public/examples/lorem-span.html +14 -0
- package/playground/public/examples/margin-block-showcase.html +21 -0
- package/playground/public/examples/margin-inline-showcase.html +21 -0
- package/playground/public/examples/monthly-summary.html +95 -0
- package/playground/public/examples/multi-page-lorem.html +190 -0
- package/playground/public/examples/opacity-debug.html +39 -0
- package/playground/public/examples/opacity-example.html +70 -0
- package/playground/public/examples/png-image-example.html +13 -0
- package/playground/public/examples/red-rectangle.html +18 -0
- package/playground/public/examples/repro.html +24 -0
- package/playground/public/examples/rounded-borders-test.html +24 -0
- package/playground/public/examples/simple-list.html +89 -0
- package/playground/public/examples/simple-svg.html +37 -0
- package/playground/public/examples/simple-table.html +52 -0
- package/playground/public/examples/skew-div.html +138 -0
- package/playground/public/examples/skew-text.html +21 -0
- package/playground/public/examples/starter-report.css +51 -0
- package/playground/public/examples/starter-report.html +23 -0
- package/playground/public/examples/svg-aspect-ratio-showcase.html +116 -0
- package/playground/public/examples/svg-gradients-linear.html +28 -0
- package/playground/public/examples/svg-gradients-radial.html +29 -0
- package/playground/public/examples/svg-gradients-showcase.html +66 -0
- package/playground/public/examples/svg-image-path-test.html +43 -0
- package/playground/public/examples/svg-images-clipping.html +27 -0
- package/playground/public/examples/svg-path-gallery.html +118 -0
- package/playground/public/examples/svg-radial-transform-demo.html +78 -0
- package/playground/public/examples/svg-transform-stack.html +103 -0
- package/playground/public/examples/svg-transforms-demo.html +127 -0
- package/playground/public/examples/table-merge-test.html +34 -0
- package/playground/public/examples/text-decoration-showcase.html +138 -0
- package/playground/public/examples/text-indent-showcase.html +137 -0
- package/playground/public/examples/text-shadow-example.html +29 -0
- package/playground/public/examples/very-complex-css.html +293 -0
- package/playground/public/examples/webp-example.html +13 -0
- package/playground/public/examples/z-index-demo.html +93 -0
- package/playground/public/examples.json +240 -0
- package/playground/public/images/dice.png +0 -0
- package/playground/public/images/duck.jpg +0 -0
- package/playground/public/index.html +149 -0
- package/playground/public/mode.js +1 -0
- package/playground/public/styles.css +382 -0
- package/playground/public/tmp-h2-debug.html +33 -0
- package/playground/public/tmp-italic-debug.html +32 -0
- package/playground/public/vendor/codemirror/codemirror.min.css +1 -0
- package/playground/public/vendor/codemirror/codemirror.min.js +1 -0
- package/playground/public/vendor/codemirror/css.min.js +1 -0
- package/playground/public/vendor/codemirror/darcula.min.css +1 -0
- package/playground/public/vendor/codemirror/htmlmixed.min.js +1 -0
- package/playground/public/vendor/codemirror/javascript.min.js +1 -0
- package/playground/public/vendor/codemirror/xml.min.js +1 -0
- package/playground/public/vendor/pagyra-playground-browser.js +165966 -0
- package/playground/public/vendor/pagyra-playground-browser.js.map +7 -0
- package/playground/server.d.ts +1 -0
- package/playground/server.js +68 -0
- package/playground/server.ts +128 -0
- package/scripts/browser-build.ts +101 -0
- package/scripts/build-browser-bundle.ts +52 -0
- package/scripts/glyph-comparison/simulate.ts +744 -0
- package/scripts/playground-browser-server.ts +57 -0
- package/scripts/probe-roboto.ts +6 -0
- package/scripts/render-playground-example.ts +121 -0
- package/scripts/run-glyph-atlas-tuner-runner.mjs +113 -0
- package/scripts/run-glyph-atlas-tuner.ts +141 -0
- package/scripts/top-ts-files.ps1 +39 -0
- package/scripts/top-ts-files.sh +37 -0
- package/scripts/woff2_info.ps1 +132 -0
- package/src/browser-entry.ts +14 -0
- package/src/compression/adler32.ts +45 -0
- package/src/compression/brotli/brotli.ts +463 -0
- package/src/compression/brotli/index.ts +15 -0
- package/src/compression/brotli/transform.ts +184 -0
- package/src/compression/brotli/types.ts +58 -0
- package/src/compression/brotli/utils.ts +157 -0
- package/src/compression/brotli/vendor/bit_reader.js +124 -0
- package/src/compression/brotli/vendor/context.js +250 -0
- package/src/compression/brotli/vendor/decode.d.ts +2 -0
- package/src/compression/brotli/vendor/decode.js +938 -0
- package/src/compression/brotli/vendor/dictionary-data.js +9469 -0
- package/src/compression/brotli/vendor/dictionary.js +36 -0
- package/src/compression/brotli/vendor/huffman.js +123 -0
- package/src/compression/brotli/vendor/package.json +3 -0
- package/src/compression/brotli/vendor/prefix.js +60 -0
- package/src/compression/brotli/vendor/streams.js +31 -0
- package/src/compression/brotli/vendor/transform.js +247 -0
- package/src/compression/brotli/vendor-decode.d.ts +4 -0
- package/src/compression/brotli/woff2-glyf-transform.ts +623 -0
- package/src/compression/decompress.ts +16 -0
- package/src/compression/deflate.ts +295 -0
- package/src/compression/index.ts +4 -0
- package/src/compression/types.ts +26 -0
- package/src/compression/utils.ts +107 -0
- package/src/core.ts +18 -0
- package/src/css/apply-declarations.ts +86 -0
- package/src/css/background-types.ts +65 -0
- package/src/css/browser-defaults.ts +16 -0
- package/src/css/clip-path-types.ts +13 -0
- package/src/css/compute-style.ts +494 -0
- package/src/css/css-unit-resolver.ts +65 -0
- package/src/css/custom-properties.ts +215 -0
- package/src/css/enums.ts +127 -0
- package/src/css/font-face-parser.ts +233 -0
- package/src/css/font-weight.ts +65 -0
- package/src/css/inline-style-parser.ts +27 -0
- package/src/css/layout-property-resolver.ts +75 -0
- package/src/css/length.ts +141 -0
- package/src/css/line-height.ts +96 -0
- package/src/css/named-colors.ts +150 -0
- package/src/css/parsers/background-parser-extended.ts +111 -0
- package/src/css/parsers/background-parser.ts +456 -0
- package/src/css/parsers/border-block-parser.ts +26 -0
- package/src/css/parsers/border-inline-parser.ts +26 -0
- package/src/css/parsers/border-parser-extended.ts +256 -0
- package/src/css/parsers/border-parser.ts +175 -0
- package/src/css/parsers/box-shadow-parser.ts +106 -0
- package/src/css/parsers/clip-path-parser.ts +92 -0
- package/src/css/parsers/color-parser.ts +14 -0
- package/src/css/parsers/dimension-parser.ts +117 -0
- package/src/css/parsers/display-flex-parser.ts +59 -0
- package/src/css/parsers/flex-parser.ts +144 -0
- package/src/css/parsers/font-parser.ts +40 -0
- package/src/css/parsers/gradient-parser.ts +366 -0
- package/src/css/parsers/grid-parser-extended.ts +55 -0
- package/src/css/parsers/grid-parser.ts +218 -0
- package/src/css/parsers/length-parser.ts +95 -0
- package/src/css/parsers/list-style-parser.ts +39 -0
- package/src/css/parsers/margin-block-parser.ts +12 -0
- package/src/css/parsers/margin-inline-parser.ts +12 -0
- package/src/css/parsers/margin-parser.ts +30 -0
- package/src/css/parsers/opacity-parser.ts +32 -0
- package/src/css/parsers/overflow-wrap-parser.ts +38 -0
- package/src/css/parsers/padding-block-parser.ts +12 -0
- package/src/css/parsers/padding-inline-parser.ts +12 -0
- package/src/css/parsers/padding-parser.ts +30 -0
- package/src/css/parsers/position-parser.ts +75 -0
- package/src/css/parsers/register-parsers.ts +302 -0
- package/src/css/parsers/registry.ts +18 -0
- package/src/css/parsers/text-parser-extended.ts +144 -0
- package/src/css/parsers/text-parser.ts +25 -0
- package/src/css/parsers/text-shadow-parser.ts +94 -0
- package/src/css/properties/box-model.ts +82 -0
- package/src/css/properties/flexbox.ts +44 -0
- package/src/css/properties/gap.ts +14 -0
- package/src/css/properties/grid.ts +94 -0
- package/src/css/properties/layout.ts +59 -0
- package/src/css/properties/misc.ts +44 -0
- package/src/css/properties/typography.ts +71 -0
- package/src/css/properties/visual.ts +68 -0
- package/src/css/selectors/matcher.ts +219 -0
- package/src/css/selectors/parser.ts +163 -0
- package/src/css/selectors/simple-key.ts +31 -0
- package/src/css/selectors/specificity.ts +41 -0
- package/src/css/selectors/types.ts +31 -0
- package/src/css/shorthands/border-shorthand.ts +68 -0
- package/src/css/shorthands/box-shorthand.ts +33 -0
- package/src/css/style-inheritance.ts +50 -0
- package/src/css/style.ts +402 -0
- package/src/css/ua-defaults/base-defaults.ts +266 -0
- package/src/css/ua-defaults/browser-defaults.ts +134 -0
- package/src/css/ua-defaults/element-defaults.ts +374 -0
- package/src/css/ua-defaults/types.ts +43 -0
- package/src/css/unit-conversion.ts +24 -0
- package/src/css/utils.ts +108 -0
- package/src/css/viewport.ts +17 -0
- package/src/debug/audit.ts +20 -0
- package/src/debug/ids.ts +13 -0
- package/src/debug/log.js +28 -0
- package/src/debug/log.ts +52 -0
- package/src/debug/tree.ts +57 -0
- package/src/dom/node.ts +133 -0
- package/src/environment/browser-environment.ts +78 -0
- package/src/environment/environment.ts +35 -0
- package/src/environment/global.ts +13 -0
- package/src/environment/node-environment.browser.ts +28 -0
- package/src/environment/node-environment.ts +64 -0
- package/src/fonts/detector.ts +28 -0
- package/src/fonts/engines/ttf-engine.ts +28 -0
- package/src/fonts/engines/woff-engine.ts +38 -0
- package/src/fonts/engines/woff2-engine.ts +41 -0
- package/src/fonts/extractors/metrics-extractor.ts +362 -0
- package/src/fonts/font-registry-resolver.ts +132 -0
- package/src/fonts/index.ts +3 -0
- package/src/fonts/orchestrator.ts +92 -0
- package/src/fonts/parsers/base-parser.ts +23 -0
- package/src/fonts/types.ts +85 -0
- package/src/fonts/utils/ttf-reconstructor.ts +120 -0
- package/src/fonts/woff/decoder.ts +105 -0
- package/src/fonts/woff2/buffer.ts +106 -0
- package/src/fonts/woff2/decoder.ts +981 -0
- package/src/geometry/box.ts +48 -0
- package/src/geometry/matrix.ts +59 -0
- package/src/html/css/parse-css.ts +85 -0
- package/src/html/dom-converter.ts +433 -0
- package/src/html/image-converter.ts +200 -0
- package/src/html-to-pdf.ts +410 -0
- package/src/image/base-decoder.ts +149 -0
- package/src/image/image-service.ts +188 -0
- package/src/image/jpeg-decoder.ts +73 -0
- package/src/image/png-decoder.ts +550 -0
- package/src/image/types.ts +20 -0
- package/src/image/webp-decoder.ts +242 -0
- package/src/image/webp-huffman.ts +218 -0
- package/src/image/webp-riff-parser.ts +54 -0
- package/src/image/webp-vp8l-decoder.ts +199 -0
- package/src/index.ts +35 -0
- package/src/layout/context/float-context.ts +62 -0
- package/src/layout/context/layout-environment.ts +29 -0
- package/src/layout/debug.ts +18 -0
- package/src/layout/inline/bounding-box-calculator.ts +132 -0
- package/src/layout/inline/font-baseline-calculator.ts +76 -0
- package/src/layout/inline/inline-utils.ts +94 -0
- package/src/layout/inline/layout.ts +285 -0
- package/src/layout/inline/line_breaker.ts +109 -0
- package/src/layout/inline/measurement.ts +144 -0
- package/src/layout/inline/run-placer.ts +139 -0
- package/src/layout/inline/text-alignment.ts +70 -0
- package/src/layout/inline/tokenizer.ts +195 -0
- package/src/layout/inline/types.ts +76 -0
- package/src/layout/pipeline/context-factory.ts +16 -0
- package/src/layout/pipeline/default-engine.ts +24 -0
- package/src/layout/pipeline/engine.ts +59 -0
- package/src/layout/pipeline/layout-tree.ts +13 -0
- package/src/layout/pipeline/out-of-flow-manager.ts +73 -0
- package/src/layout/pipeline/strategy.ts +12 -0
- package/src/layout/pipeline/text-metrics-initializer.ts +13 -0
- package/src/layout/strategies/block.ts +236 -0
- package/src/layout/strategies/display-none.ts +14 -0
- package/src/layout/strategies/fallback.ts +15 -0
- package/src/layout/strategies/flex.ts +477 -0
- package/src/layout/strategies/fragmentation.ts +17 -0
- package/src/layout/strategies/grid.ts +247 -0
- package/src/layout/strategies/image.ts +342 -0
- package/src/layout/strategies/inline.ts +128 -0
- package/src/layout/strategies/table.ts +595 -0
- package/src/layout/table/cell_layout.ts +31 -0
- package/src/layout/table/diagnostics.ts +19 -0
- package/src/layout/text-run.ts +42 -0
- package/src/layout/utils/content-measurer.ts +117 -0
- package/src/layout/utils/display-utils.ts +24 -0
- package/src/layout/utils/floats.ts +98 -0
- package/src/layout/utils/gap-calculator.ts +167 -0
- package/src/layout/utils/inline-formatter.ts +31 -0
- package/src/layout/utils/inline-formatting.ts +9 -0
- package/src/layout/utils/margin.ts +140 -0
- package/src/layout/utils/node-math.ts +237 -0
- package/src/layout/utils/overflow.ts +14 -0
- package/src/layout/utils/sizing.ts +12 -0
- package/src/layout/utils/text-metrics.ts +361 -0
- package/src/logging/debug.ts +58 -0
- package/src/pdf/font/base14/widths-courier-bold.ts +159 -0
- package/src/pdf/font/base14/widths-courier.ts +159 -0
- package/src/pdf/font/base14/widths-helvetica-bold.ts +158 -0
- package/src/pdf/font/base14/widths-helvetica.ts +158 -0
- package/src/pdf/font/base14/widths-times-bold.ts +158 -0
- package/src/pdf/font/base14/widths-times-roman.ts +158 -0
- package/src/pdf/font/base14/widths-types.ts +25 -0
- package/src/pdf/font/base14-widths.ts +32 -0
- package/src/pdf/font/blur.ts +81 -0
- package/src/pdf/font/builtin-fonts.browser.ts +262 -0
- package/src/pdf/font/builtin-fonts.ts +126 -0
- package/src/pdf/font/composite-glyph-parser.ts +242 -0
- package/src/pdf/font/embedder.ts +395 -0
- package/src/pdf/font/font-config.ts +190 -0
- package/src/pdf/font/font-registry.ts +263 -0
- package/src/pdf/font/font-subset.ts +258 -0
- package/src/pdf/font/glyph-atlas-maxrects.ts +305 -0
- package/src/pdf/font/glyph-atlas-tuner.ts +98 -0
- package/src/pdf/font/glyph-atlas.ts +226 -0
- package/src/pdf/font/glyph-cache.ts +127 -0
- package/src/pdf/font/loca-reader.ts +109 -0
- package/src/pdf/font/managers/font-resource-manager.ts +73 -0
- package/src/pdf/font/managers/subset-resource-manager.ts +164 -0
- package/src/pdf/font/rasterizer.ts +270 -0
- package/src/pdf/font/resolvers/base-font-mapper.ts +77 -0
- package/src/pdf/font/resolvers/family-resolver.ts +33 -0
- package/src/pdf/font/resolvers/weight-style-applicator.ts +63 -0
- package/src/pdf/font/simple-glyph-parser.ts +289 -0
- package/src/pdf/font/to-unicode.ts +109 -0
- package/src/pdf/font/transformation-matrix.ts +136 -0
- package/src/pdf/font/ttf-cmap.ts +180 -0
- package/src/pdf/font/ttf-global-metrics.ts +58 -0
- package/src/pdf/font/ttf-glyf.ts +125 -0
- package/src/pdf/font/ttf-glyph-metrics.ts +43 -0
- package/src/pdf/font/ttf-lite.ts +269 -0
- package/src/pdf/font/ttf-table-parser.ts +132 -0
- package/src/pdf/font/ttf-table-provider.ts +61 -0
- package/src/pdf/font/widths.ts +79 -0
- package/src/pdf/font-subset/font-registry.ts +127 -0
- package/src/pdf/header-footer-layout.ts +153 -0
- package/src/pdf/header-footer-painter.ts +209 -0
- package/src/pdf/header-footer-renderer.ts +357 -0
- package/src/pdf/header-footer-tokens.ts +55 -0
- package/src/pdf/header-footer.ts +25 -0
- package/src/pdf/layout-tree-builder.ts +261 -0
- package/src/pdf/page-painter.ts +241 -0
- package/src/pdf/pagination.ts +155 -0
- package/src/pdf/primitives/pdf-builder.ts +378 -0
- package/src/pdf/primitives/pdf-bytes.ts +40 -0
- package/src/pdf/primitives/pdf-document.ts +108 -0
- package/src/pdf/primitives/pdf-reference-manager.ts +47 -0
- package/src/pdf/primitives/pdf-resource-registries.ts +255 -0
- package/src/pdf/primitives/pdf-serializers.ts +194 -0
- package/src/pdf/primitives/pdf-types.ts +73 -0
- package/src/pdf/render.ts +210 -0
- package/src/pdf/renderer/box-painter.ts +236 -0
- package/src/pdf/renderer/page-paint.ts +102 -0
- package/src/pdf/renderer/paint-box-shadows.ts +218 -0
- package/src/pdf/renderer/radius.ts +58 -0
- package/src/pdf/renderers/graphics-state-manager.ts +40 -0
- package/src/pdf/renderers/image-renderer.ts +127 -0
- package/src/pdf/renderers/radius-utils.ts +80 -0
- package/src/pdf/renderers/rectangle-renderer.ts +129 -0
- package/src/pdf/renderers/rounded-rect-path.ts +120 -0
- package/src/pdf/renderers/shape-renderer.ts +563 -0
- package/src/pdf/renderers/shape-utils.ts +194 -0
- package/src/pdf/renderers/text-decoration-renderer.ts +313 -0
- package/src/pdf/renderers/text-encoder.ts +41 -0
- package/src/pdf/renderers/text-font-resolver.ts +75 -0
- package/src/pdf/renderers/text-renderer-utils.ts +28 -0
- package/src/pdf/renderers/text-renderer.ts +391 -0
- package/src/pdf/renderers/text-shadow-renderer.ts +300 -0
- package/src/pdf/shading/gradient-service.ts +525 -0
- package/src/pdf/shading/index.ts +1 -0
- package/src/pdf/stacking/build-stacking-contexts.ts +93 -0
- package/src/pdf/stacking/resolve-paint-order.ts +157 -0
- package/src/pdf/stacking/types.ts +40 -0
- package/src/pdf/svg/aspect-ratio.ts +81 -0
- package/src/pdf/svg/coordinate-mapper.ts +81 -0
- package/src/pdf/svg/geometry-builder.ts +45 -0
- package/src/pdf/svg/render-svg.ts +296 -0
- package/src/pdf/svg/shape-renderer.ts +463 -0
- package/src/pdf/svg/style-computer.ts +246 -0
- package/src/pdf/transform-adapter.ts +26 -0
- package/src/pdf/types.ts +377 -0
- package/src/pdf/utils/background-layer-resolver.ts +439 -0
- package/src/pdf/utils/background-tiles.ts +192 -0
- package/src/pdf/utils/border-dashes.ts +109 -0
- package/src/pdf/utils/border-radius-utils.ts +86 -0
- package/src/pdf/utils/box-dimensions-utils.ts +47 -0
- package/src/pdf/utils/clip-path-resolver.ts +50 -0
- package/src/pdf/utils/clipping-path-builder.ts +190 -0
- package/src/pdf/utils/color-utils.ts +102 -0
- package/src/pdf/utils/coordinate-transformer.ts +30 -0
- package/src/pdf/utils/drop-shadow-raster.ts +233 -0
- package/src/pdf/utils/encoding.ts +98 -0
- package/src/pdf/utils/glyph-atlas-registrar.ts +13 -0
- package/src/pdf/utils/glyph-run-renderer.ts +129 -0
- package/src/pdf/utils/image-command-partitioner.ts +28 -0
- package/src/pdf/utils/image-matrix-builder.ts +31 -0
- package/src/pdf/utils/image-utils.ts +26 -0
- package/src/pdf/utils/list-utils.ts +194 -0
- package/src/pdf/utils/node-text-run-factory.ts +202 -0
- package/src/pdf/utils/page-resource-registrar.ts +46 -0
- package/src/pdf/utils/result-combiner.ts +102 -0
- package/src/pdf/utils/shadow-utils.ts +127 -0
- package/src/pdf/utils/text-alignment-resolver.ts +76 -0
- package/src/pdf/utils/text-decoration-utils.ts +64 -0
- package/src/pdf/utils/text-layout-adjuster.ts +185 -0
- package/src/pdf/utils/text-utils.ts +193 -0
- package/src/pdf/utils/transform-scope-manager.ts +69 -0
- package/src/render/offset.ts +170 -0
- package/src/shim/empty.ts +2 -0
- package/src/shim/fs-empty.ts +5 -0
- package/src/shim/url-empty.ts +7 -0
- package/src/shim/zlib-empty.ts +9 -0
- package/src/style/shorthands/index.ts +19 -0
- package/src/style/ua/defaults.ts +69 -0
- package/src/svg/index.ts +4 -0
- package/src/svg/parser-registry.ts +71 -0
- package/src/svg/parser.ts +486 -0
- package/src/svg/path-data.ts +515 -0
- package/src/svg/types.ts +194 -0
- package/src/text/line-breaker.ts +321 -0
- package/src/text/text-transform.ts +43 -0
- package/src/text/text.ts +33 -0
- package/src/transform/css-parser.ts +95 -0
- package/src/types/fonts.ts +62 -0
- package/src/types/public.ts +19 -0
- package/src/units/page-utils.ts +58 -0
- package/src/units/units.ts +50 -0
- package/src/utils/base64.ts +24 -0
- package/test-output.txt +79 -0
- package/tests/css/background-parser.spec.ts +14 -0
- package/tests/css/clip-path-parser.spec.ts +66 -0
- package/tests/environment/path-resolution.spec.ts +104 -0
- package/tests/helpers/ai-layout-diagnostics.ts +141 -0
- package/tests/helpers/render-utils.ts +52 -0
- package/tests/helpers/text-geometry.ts +56 -0
- package/tests/layout/custom-properties.test.ts +38 -0
- package/tests/layout/gap-calculator.spec.ts +196 -0
- package/tests/layout/inline-background-alignment.spec.ts +93 -0
- package/tests/layout/inline-fragments.spec.ts +26 -0
- package/tests/layout/run-placer-baseline.spec.ts +108 -0
- package/tests/pdf/alignments.spec.ts +26 -0
- package/tests/pdf/background-clip.spec.ts +57 -0
- package/tests/pdf/background-repeat-space-round.spec.ts +35 -0
- package/tests/pdf/background-repeat.spec.ts +137 -0
- package/tests/pdf/border-radius.spec.ts +151 -0
- package/tests/pdf/clip-path.spec.ts +92 -0
- package/tests/pdf/radial-gradient.spec.ts +50 -0
- package/tests/pdf/svg-stroke-dash.spec.ts +81 -0
- package/tests/pdf/text-transform-matrix.spec.ts +43 -0
- package/tsconfig.json +17 -0
- package/types/fonts.js +10 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import type { Run, TextPaintOptions, Rect } from "../types.js";
|
|
2
|
+
import type { FontRegistry, FontResource } from "../font/font-registry.js";
|
|
3
|
+
import type { PdfObjectRef } from "../primitives/pdf-document.js";
|
|
4
|
+
import { log } from "../../logging/debug.js";
|
|
5
|
+
import { CoordinateTransformer } from "../utils/coordinate-transformer.js";
|
|
6
|
+
import type { ImageRenderer } from "./image-renderer.js";
|
|
7
|
+
import type { GraphicsStateManager } from "./graphics-state-manager.js";
|
|
8
|
+
import { fillColorCommand, formatNumber } from "./text-renderer-utils.js";
|
|
9
|
+
import { TextShadowRenderer } from "./text-shadow-renderer.js";
|
|
10
|
+
import { TextDecorationRenderer } from "./text-decoration-renderer.js";
|
|
11
|
+
import { TextFontResolver } from "./text-font-resolver.js";
|
|
12
|
+
import { encodeTextPayload } from "./text-encoder.js";
|
|
13
|
+
import { drawGlyphRun } from "../utils/glyph-run-renderer.js";
|
|
14
|
+
import { GradientService } from "../shading/gradient-service.js";
|
|
15
|
+
import type { LinearGradient, RadialGradient } from "../../css/parsers/gradient-parser.js";
|
|
16
|
+
import { transformForRect } from "./shape-utils.js";
|
|
17
|
+
import type { GlyphRun } from "../../layout/text-run.js";
|
|
18
|
+
import type { UnifiedFont } from "../../fonts/types.js";
|
|
19
|
+
import type { Matrix } from "../../geometry/matrix.js";
|
|
20
|
+
import { svgMatrixToPdf } from "../transform-adapter.js";
|
|
21
|
+
|
|
22
|
+
const PINK = "\x1b[38;5;205m";
|
|
23
|
+
const RESET_COLOR = "\x1b[0m";
|
|
24
|
+
|
|
25
|
+
export interface TextRendererResult {
|
|
26
|
+
readonly commands: string[];
|
|
27
|
+
readonly fonts: Map<string, PdfObjectRef>;
|
|
28
|
+
readonly shadings: Map<string, string>;
|
|
29
|
+
readonly patterns: Map<string, string>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class TextRenderer {
|
|
33
|
+
private readonly commands: string[] = [];
|
|
34
|
+
private readonly fonts = new Map<string, PdfObjectRef>();
|
|
35
|
+
private readonly decorationRenderer: TextDecorationRenderer;
|
|
36
|
+
private readonly shadowRenderer: TextShadowRenderer;
|
|
37
|
+
private readonly graphicsStateManager?: GraphicsStateManager;
|
|
38
|
+
private readonly fontResolver: TextFontResolver;
|
|
39
|
+
private readonly gradientService: GradientService;
|
|
40
|
+
private readonly patterns = new Map<string, string>();
|
|
41
|
+
|
|
42
|
+
constructor(
|
|
43
|
+
private readonly coordinateTransformer: CoordinateTransformer,
|
|
44
|
+
private readonly fontRegistry: FontRegistry,
|
|
45
|
+
imageRenderer?: ImageRenderer,
|
|
46
|
+
graphicsStateManager?: GraphicsStateManager,
|
|
47
|
+
) {
|
|
48
|
+
this.graphicsStateManager = graphicsStateManager;
|
|
49
|
+
this.fontResolver = new TextFontResolver(fontRegistry);
|
|
50
|
+
this.shadowRenderer = new TextShadowRenderer(coordinateTransformer, fontRegistry, imageRenderer, graphicsStateManager);
|
|
51
|
+
this.decorationRenderer = new TextDecorationRenderer(coordinateTransformer, graphicsStateManager);
|
|
52
|
+
this.gradientService = new GradientService(coordinateTransformer);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async drawText(text: string, xPx: number, yPx: number, options: TextPaintOptions = { fontSizePt: 10 }): Promise<void> {
|
|
56
|
+
if (!text) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const fontFamily = options.fontFamily ?? "Times New Roman";
|
|
61
|
+
const fontWeight = options.fontWeight ?? 400;
|
|
62
|
+
const fontStyle = options.fontStyle ?? "normal";
|
|
63
|
+
const fontVariant = options.fontVariant;
|
|
64
|
+
|
|
65
|
+
// header/footer hoje passa tamanho em pt
|
|
66
|
+
const fontSizePx = this.coordinateTransformer.convertPtToPx(options.fontSizePt);
|
|
67
|
+
|
|
68
|
+
const run: Run = {
|
|
69
|
+
text,
|
|
70
|
+
fontFamily,
|
|
71
|
+
fontWeight,
|
|
72
|
+
fontStyle,
|
|
73
|
+
fontVariant,
|
|
74
|
+
fontSize: fontSizePx,
|
|
75
|
+
letterSpacing: 0,
|
|
76
|
+
wordSpacing: 0,
|
|
77
|
+
fill: options.color ?? { r: 0, g: 0, b: 0, a: 1 },
|
|
78
|
+
lineMatrix: {
|
|
79
|
+
a: 1, b: 0, c: 0, d: 1,
|
|
80
|
+
e: xPx,
|
|
81
|
+
f: yPx, // baseline em px, igual aos outros runs
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
await this.drawTextRun(run);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async drawTextRun(run: Run): Promise<void> {
|
|
89
|
+
const font = await this.fontResolver.ensureFontResource({
|
|
90
|
+
fontFamily: run.fontFamily,
|
|
91
|
+
fontWeight: run.fontWeight,
|
|
92
|
+
fontStyle: run.fontStyle,
|
|
93
|
+
fontVariant: run.fontVariant,
|
|
94
|
+
text: run.text
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
await this.drawTextRunWithGlyphs(run, font);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private async drawTextRunWithGlyphs(run: Run, font: FontResource): Promise<void> {
|
|
101
|
+
const color = run.fill ?? { r: 0, g: 0, b: 0, a: 1 };
|
|
102
|
+
const fontSizePt = this.coordinateTransformer.convertPxToPt(run.fontSize);
|
|
103
|
+
|
|
104
|
+
let glyphRun = run.glyphs;
|
|
105
|
+
if (!glyphRun && font.metrics) {
|
|
106
|
+
glyphRun = computeGlyphRunFromText(
|
|
107
|
+
font.metrics,
|
|
108
|
+
run.text,
|
|
109
|
+
run.fontSize,
|
|
110
|
+
run.letterSpacing ?? 0,
|
|
111
|
+
{
|
|
112
|
+
family: run.fontFamily,
|
|
113
|
+
weight: run.fontWeight ?? 400,
|
|
114
|
+
style: (run.fontStyle as "normal" | "italic") ?? "normal",
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!glyphRun) {
|
|
120
|
+
log("paint", "warn", "Skipping run without glyph data", {
|
|
121
|
+
text: run.text.slice(0, 32),
|
|
122
|
+
fontFamily: run.fontFamily,
|
|
123
|
+
fontSize: run.fontSize,
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
log("paint", "debug", `${PINK}USING GLYPH RUN${RESET_COLOR}`, {
|
|
129
|
+
text: run.text.slice(0, 64),
|
|
130
|
+
glyphCount: glyphRun.glyphIds.length,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const textMatrix = buildPdfTextMatrix(run, this.coordinateTransformer);
|
|
134
|
+
|
|
135
|
+
log("paint", "debug", "drawing text run with glyphs", {
|
|
136
|
+
text: run.text.slice(0, 32),
|
|
137
|
+
glyphIds: glyphRun.glyphIds.slice(0, 10),
|
|
138
|
+
fontSizePt,
|
|
139
|
+
matrix: textMatrix,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Normalize text for features like small-caps (match legacy behavior for shadows)
|
|
143
|
+
let normalizedText = run.text;
|
|
144
|
+
if (run.fontVariant === "small-caps") {
|
|
145
|
+
normalizedText = normalizedText.toUpperCase();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const { encoded } = encodeTextPayload(normalizedText, font);
|
|
149
|
+
const wordSpacingPx = run.wordSpacing ?? 0;
|
|
150
|
+
const wordSpacingPt = this.coordinateTransformer.convertPxToPt(wordSpacingPx);
|
|
151
|
+
const appliedWordSpacing = wordSpacingPx !== 0 && wordSpacingPt !== 0;
|
|
152
|
+
|
|
153
|
+
// Shadows use the base font resource (non-subset) for compatibility with Identity-H encoding
|
|
154
|
+
this.registerFont(font);
|
|
155
|
+
if (run.textShadows && run.textShadows.length > 0) {
|
|
156
|
+
const shadowCommands = await this.shadowRenderer.render({
|
|
157
|
+
run,
|
|
158
|
+
font,
|
|
159
|
+
encoded,
|
|
160
|
+
Tm: run.lineMatrix ?? { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 },
|
|
161
|
+
fontSizePt,
|
|
162
|
+
fontSizePx: run.fontSize,
|
|
163
|
+
wordSpacingPt,
|
|
164
|
+
appliedWordSpacing,
|
|
165
|
+
fontResourceName: font.resourceName,
|
|
166
|
+
});
|
|
167
|
+
this.commands.push(...shadowCommands);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const subsetResource = this.fontRegistry.ensureSubsetForGlyphRun(glyphRun, font);
|
|
171
|
+
this.registerSubsetFont(subsetResource.alias, subsetResource.ref);
|
|
172
|
+
|
|
173
|
+
const gradientBackground = run.textGradient;
|
|
174
|
+
if (gradientBackground && gradientBackground.rect && gradientBackground.rect.width > 0 && gradientBackground.rect.height > 0) {
|
|
175
|
+
log("paint", "debug", "text run has background clip gradient", {
|
|
176
|
+
text: run.text.slice(0, 32),
|
|
177
|
+
rect: gradientBackground.rect,
|
|
178
|
+
});
|
|
179
|
+
const gradientPaint = gradientBackground.gradient;
|
|
180
|
+
const isLinear = (gradientPaint as LinearGradient).type === "linear";
|
|
181
|
+
const isRadial = (gradientPaint as RadialGradient).type === "radial";
|
|
182
|
+
if (isLinear || isRadial) {
|
|
183
|
+
const pattern = this.gradientService.createPatternFromLinearGradient(
|
|
184
|
+
gradientPaint as LinearGradient,
|
|
185
|
+
{
|
|
186
|
+
width: gradientBackground.rect.width,
|
|
187
|
+
height: gradientBackground.rect.height,
|
|
188
|
+
x: gradientBackground.rect.x,
|
|
189
|
+
y: gradientBackground.rect.y,
|
|
190
|
+
},
|
|
191
|
+
);
|
|
192
|
+
this.patterns.set(pattern.patternName, pattern.dictionary);
|
|
193
|
+
|
|
194
|
+
const usePattern: string[] = [
|
|
195
|
+
"q",
|
|
196
|
+
`/Pattern cs`,
|
|
197
|
+
`/${pattern.patternName} scn`,
|
|
198
|
+
];
|
|
199
|
+
const glyphPatternCommands = drawGlyphRun(
|
|
200
|
+
glyphRun,
|
|
201
|
+
subsetResource.subset,
|
|
202
|
+
0,
|
|
203
|
+
0,
|
|
204
|
+
fontSizePt,
|
|
205
|
+
color,
|
|
206
|
+
this.graphicsStateManager,
|
|
207
|
+
wordSpacingPt,
|
|
208
|
+
{ skipColor: true, tm: textMatrix },
|
|
209
|
+
);
|
|
210
|
+
if (glyphPatternCommands.length > 0) {
|
|
211
|
+
this.commands.push(...usePattern, ...glyphPatternCommands, "Q");
|
|
212
|
+
if (run.decorations) {
|
|
213
|
+
this.commands.push(...this.decorationRenderer.render(run, color));
|
|
214
|
+
}
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const glyphCommands = drawGlyphRun(
|
|
221
|
+
glyphRun,
|
|
222
|
+
subsetResource.subset,
|
|
223
|
+
0,
|
|
224
|
+
0,
|
|
225
|
+
fontSizePt,
|
|
226
|
+
color,
|
|
227
|
+
this.graphicsStateManager,
|
|
228
|
+
wordSpacingPt,
|
|
229
|
+
{ tm: textMatrix }
|
|
230
|
+
);
|
|
231
|
+
this.commands.push(...glyphCommands);
|
|
232
|
+
|
|
233
|
+
if (run.decorations) {
|
|
234
|
+
this.commands.push(...this.decorationRenderer.render(run, color));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private registerFont(font: FontResource): void {
|
|
239
|
+
if (!this.fonts.has(font.resourceName)) {
|
|
240
|
+
this.fonts.set(font.resourceName, font.ref);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
private registerSubsetFont(alias: string, ref: PdfObjectRef): void {
|
|
245
|
+
// Always update to the latest reference so refreshed subsets are used.
|
|
246
|
+
this.fonts.set(alias, ref);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private fillGradientRect(rect: Rect, gradient: LinearGradient | RadialGradient): string[] {
|
|
250
|
+
const width = Math.max(rect.width, 0);
|
|
251
|
+
const height = Math.max(rect.height, 0);
|
|
252
|
+
if (width <= 0 || height <= 0) {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
const shading =
|
|
256
|
+
gradient.type === "radial"
|
|
257
|
+
? this.gradientService.createRadialGradient(gradient as RadialGradient, rect)
|
|
258
|
+
: this.gradientService.createLinearGradient(gradient as LinearGradient, rect);
|
|
259
|
+
|
|
260
|
+
return [
|
|
261
|
+
"q",
|
|
262
|
+
transformForRect(rect, this.coordinateTransformer, null),
|
|
263
|
+
`0 0 ${formatNumber(width)} ${formatNumber(height)} re`,
|
|
264
|
+
"W n",
|
|
265
|
+
`/${shading.shadingName} sh`,
|
|
266
|
+
"Q",
|
|
267
|
+
];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private fillPatternRect(rect: Rect): string[] {
|
|
271
|
+
const width = Math.max(rect.width, 0);
|
|
272
|
+
const height = Math.max(rect.height, 0);
|
|
273
|
+
if (width <= 0 || height <= 0) {
|
|
274
|
+
return [];
|
|
275
|
+
}
|
|
276
|
+
return [
|
|
277
|
+
transformForRect(rect, this.coordinateTransformer, null),
|
|
278
|
+
`0 0 ${formatNumber(width)} ${formatNumber(height)} re`,
|
|
279
|
+
"f",
|
|
280
|
+
];
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
getResult(): TextRendererResult {
|
|
284
|
+
return {
|
|
285
|
+
commands: [...this.commands],
|
|
286
|
+
fonts: new Map(this.fonts),
|
|
287
|
+
shadings: this.gradientService.getShadings(),
|
|
288
|
+
patterns: new Map(this.patterns),
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function buildPdfTextMatrix(run: Run, transformer: CoordinateTransformer): Matrix {
|
|
294
|
+
const base = run.lineMatrix ?? { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 };
|
|
295
|
+
if (!run.lineMatrix) {
|
|
296
|
+
log("paint", "debug", "Run provided without lineMatrix, using identity fallback", {
|
|
297
|
+
text: run.text.slice(0, 32),
|
|
298
|
+
fontFamily: run.fontFamily,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
const offsetPx = transformer.pageOffsetPx;
|
|
302
|
+
|
|
303
|
+
// Normalize to page origin (top-left), removing any page offset.
|
|
304
|
+
const local: Matrix = {
|
|
305
|
+
a: base.a,
|
|
306
|
+
b: base.b,
|
|
307
|
+
c: base.c,
|
|
308
|
+
d: base.d,
|
|
309
|
+
e: base.e,
|
|
310
|
+
f: base.f - offsetPx,
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const hasLinear =
|
|
314
|
+
Math.abs(local.a - 1) > 1e-6 ||
|
|
315
|
+
Math.abs(local.b) > 1e-6 ||
|
|
316
|
+
Math.abs(local.c) > 1e-6 ||
|
|
317
|
+
Math.abs(local.d - 1) > 1e-6;
|
|
318
|
+
|
|
319
|
+
// Fast path: no skew/rotate/scale -> just convert translation.
|
|
320
|
+
if (!hasLinear) {
|
|
321
|
+
return {
|
|
322
|
+
a: 1, b: 0, c: 0, d: 1,
|
|
323
|
+
e: transformer.convertPxToPt(local.e),
|
|
324
|
+
f: transformer.pageHeightPt - transformer.convertPxToPt(local.f),
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Full path: map entire matrix from CSS (y-down) to PDF (y-up), then shift to bottom-left origin.
|
|
329
|
+
const pdfPx = svgMatrixToPdf(local) ?? { a: 1, b: 0, c: 0, d: 1, e: local.e, f: local.f };
|
|
330
|
+
return {
|
|
331
|
+
a: pdfPx.a,
|
|
332
|
+
b: pdfPx.b,
|
|
333
|
+
c: pdfPx.c,
|
|
334
|
+
d: pdfPx.d,
|
|
335
|
+
e: transformer.convertPxToPt(pdfPx.e),
|
|
336
|
+
f: transformer.convertPxToPt(pdfPx.f + transformer.pageHeightPx),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function computeGlyphRunFromText(
|
|
341
|
+
metrics: NonNullable<FontResource["metrics"]>,
|
|
342
|
+
text: string,
|
|
343
|
+
fontSize: number,
|
|
344
|
+
letterSpacing: number,
|
|
345
|
+
css: { family?: string; weight: number; style: "normal" | "italic" },
|
|
346
|
+
): GlyphRun {
|
|
347
|
+
const glyphIds: number[] = [];
|
|
348
|
+
const positions: { x: number; y: number }[] = [];
|
|
349
|
+
const unitsPerEm = metrics.metrics.unitsPerEm;
|
|
350
|
+
let x = 0;
|
|
351
|
+
|
|
352
|
+
for (let i = 0; i < text.length; i++) {
|
|
353
|
+
const cp = text.codePointAt(i)!;
|
|
354
|
+
const gid = metrics.cmap.getGlyphId(cp);
|
|
355
|
+
glyphIds.push(gid);
|
|
356
|
+
positions.push({ x, y: 0 });
|
|
357
|
+
const advanceWidth = metrics.glyphMetrics.get(gid)?.advanceWidth ?? 0;
|
|
358
|
+
const advancePx = (advanceWidth / unitsPerEm) * fontSize + letterSpacing;
|
|
359
|
+
x += advancePx;
|
|
360
|
+
if (cp > 0xffff) i++;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const unifiedFont: UnifiedFont = {
|
|
364
|
+
metrics: {
|
|
365
|
+
metrics: metrics.metrics,
|
|
366
|
+
glyphMetrics: metrics.glyphMetrics,
|
|
367
|
+
cmap: metrics.cmap,
|
|
368
|
+
headBBox: metrics.headBBox,
|
|
369
|
+
},
|
|
370
|
+
program: {
|
|
371
|
+
sourceFormat: "ttf",
|
|
372
|
+
unitsPerEm: metrics.metrics.unitsPerEm,
|
|
373
|
+
glyphCount: metrics.glyphMetrics.size,
|
|
374
|
+
getGlyphOutline: metrics.getGlyphOutline,
|
|
375
|
+
},
|
|
376
|
+
css: {
|
|
377
|
+
family: css.family ?? "",
|
|
378
|
+
weight: css.weight,
|
|
379
|
+
style: css.style,
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
return {
|
|
384
|
+
font: unifiedFont,
|
|
385
|
+
glyphIds,
|
|
386
|
+
positions,
|
|
387
|
+
text,
|
|
388
|
+
fontSize,
|
|
389
|
+
width: x,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import type { Run, TextMatrix } from "../types.js";
|
|
2
|
+
import type { UnifiedFont } from "../../fonts/types.js";
|
|
3
|
+
import type { FontRegistry, FontResource } from "../font/font-registry.js";
|
|
4
|
+
import type { ImageRenderer } from "./image-renderer.js";
|
|
5
|
+
import type { GraphicsStateManager } from "./graphics-state-manager.js";
|
|
6
|
+
import { CoordinateTransformer } from "../utils/coordinate-transformer.js";
|
|
7
|
+
import { getGlyphMask } from "../font/glyph-cache.js";
|
|
8
|
+
import { blurAlpha } from "../font/blur.js";
|
|
9
|
+
import { fillColorCommand, formatNumber, normalizeChannel } from "./text-renderer-utils.js";
|
|
10
|
+
|
|
11
|
+
export interface TextShadowRenderContext {
|
|
12
|
+
run: Run;
|
|
13
|
+
font: FontResource;
|
|
14
|
+
encoded: string;
|
|
15
|
+
Tm: TextMatrix;
|
|
16
|
+
fontSizePt: number;
|
|
17
|
+
fontSizePx: number;
|
|
18
|
+
wordSpacingPt: number;
|
|
19
|
+
appliedWordSpacing: boolean;
|
|
20
|
+
fontResourceName?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class TextShadowRenderer {
|
|
24
|
+
private readonly runShadowCache = new Map<string, { alias: string; image: any }>();
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
private readonly coordinateTransformer: CoordinateTransformer,
|
|
28
|
+
private readonly fontRegistry: FontRegistry,
|
|
29
|
+
private readonly imageRenderer?: ImageRenderer,
|
|
30
|
+
private readonly graphicsStateManager?: GraphicsStateManager,
|
|
31
|
+
) {}
|
|
32
|
+
|
|
33
|
+
async render(context: TextShadowRenderContext): Promise<string[]> {
|
|
34
|
+
const commands: string[] = [];
|
|
35
|
+
const { run, font, encoded, Tm, fontSizePt, fontSizePx, wordSpacingPt, appliedWordSpacing, fontResourceName } = context;
|
|
36
|
+
if (!run.textShadows || run.textShadows.length === 0) {
|
|
37
|
+
return commands;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const needsRaster = run.textShadows.some(sh => (sh.blur ?? 0) > 0 || (sh.color && sh.color.a !== undefined && sh.color.a < 1));
|
|
41
|
+
|
|
42
|
+
// Prefer glyph-run supplied metrics (add outline hook) and fall back to embedder lookup.
|
|
43
|
+
const glyphMetrics = run.glyphs ? mergeMetricsWithOutline(run.glyphs.font) : null;
|
|
44
|
+
const embedder = this.fontRegistry.getEmbedder ? this.fontRegistry.getEmbedder() : undefined;
|
|
45
|
+
const faceMetrics = glyphMetrics ?? (embedder ? embedder.getMetrics((font as any).baseFont) : null);
|
|
46
|
+
|
|
47
|
+
const wordSpacingCmd = appliedWordSpacing ? `${formatNumber(wordSpacingPt)} Tw` : undefined;
|
|
48
|
+
const resetWordSpacingCmd = appliedWordSpacing ? "0 Tw" : undefined;
|
|
49
|
+
const fontName = fontResourceName ?? font.resourceName;
|
|
50
|
+
|
|
51
|
+
if (this.imageRenderer && needsRaster) {
|
|
52
|
+
if (run.glyphs && faceMetrics) {
|
|
53
|
+
try {
|
|
54
|
+
const pages = (await import("../font/glyph-atlas.js")).globalGlyphAtlas.getPages();
|
|
55
|
+
if (pages && pages.length > 0) {
|
|
56
|
+
this.imageRenderer.registerAtlasPages(pages);
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
// ignore
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const supersample = 4;
|
|
63
|
+
const glyphMasks: Array<{ mask: any; pos: { x: number; y: number } }> = [];
|
|
64
|
+
for (let gi = 0; gi < run.glyphs.glyphIds.length; gi++) {
|
|
65
|
+
const gid = run.glyphs.glyphIds[gi];
|
|
66
|
+
const pos = run.glyphs.positions[gi] ?? { x: 0, y: 0 };
|
|
67
|
+
try {
|
|
68
|
+
const gm = getGlyphMask(faceMetrics as any, gid, fontSizePx, supersample, 0);
|
|
69
|
+
if (!gm) continue;
|
|
70
|
+
glyphMasks.push({ mask: gm, pos });
|
|
71
|
+
} catch {
|
|
72
|
+
// ignore individual glyph failures
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (glyphMasks.length > 0) {
|
|
77
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
78
|
+
const maxBlurPx = run.textShadows.reduce((acc, sh) => Math.max(acc, Math.max(0, sh?.blur ?? 0)), 0);
|
|
79
|
+
for (const item of glyphMasks) {
|
|
80
|
+
const { mask, pos } = item;
|
|
81
|
+
const maskOffsetX = mask.offsetX ?? 0;
|
|
82
|
+
const maskOffsetY = mask.offsetY ?? 0;
|
|
83
|
+
const gx0 = pos.x + maskOffsetX;
|
|
84
|
+
const gy0 = pos.y + maskOffsetY;
|
|
85
|
+
const gx1 = gx0 + mask.width;
|
|
86
|
+
const gy1 = gy0 + mask.height;
|
|
87
|
+
if (gx0 < minX) minX = gx0;
|
|
88
|
+
if (gy0 < minY) minY = gy0;
|
|
89
|
+
if (gx1 > maxX) maxX = gx1;
|
|
90
|
+
if (gy1 > maxY) maxY = gy1;
|
|
91
|
+
}
|
|
92
|
+
// Pad the bounding box to leave room for blur bleed.
|
|
93
|
+
const bleedPad = Math.ceil(maxBlurPx * 2);
|
|
94
|
+
minX = Math.floor(minX - bleedPad);
|
|
95
|
+
minY = Math.floor(minY - bleedPad);
|
|
96
|
+
maxX = Math.ceil(maxX + bleedPad);
|
|
97
|
+
maxY = Math.ceil(maxY + bleedPad);
|
|
98
|
+
|
|
99
|
+
const combinedW = Math.max(0, maxX - minX);
|
|
100
|
+
const combinedH = Math.max(0, maxY - minY);
|
|
101
|
+
if (combinedW > 0 && combinedH > 0) {
|
|
102
|
+
const combinedAlpha = new Uint8Array(combinedW * combinedH);
|
|
103
|
+
for (const item of glyphMasks) {
|
|
104
|
+
const { mask, pos } = item;
|
|
105
|
+
const maskOffsetX = mask.offsetX ?? 0;
|
|
106
|
+
const maskOffsetY = mask.offsetY ?? 0;
|
|
107
|
+
const ox = Math.round(pos.x + maskOffsetX - minX);
|
|
108
|
+
const oy = Math.round(pos.y + maskOffsetY - minY);
|
|
109
|
+
for (let yy = 0; yy < mask.height; yy++) {
|
|
110
|
+
const dstRow = oy + yy;
|
|
111
|
+
if (dstRow < 0 || dstRow >= combinedH) continue;
|
|
112
|
+
const srcRow = yy;
|
|
113
|
+
const dstBase = dstRow * combinedW;
|
|
114
|
+
const srcBase = srcRow * mask.width;
|
|
115
|
+
for (let xx = 0; xx < mask.width; xx++) {
|
|
116
|
+
const dstIdx = dstBase + ox + xx;
|
|
117
|
+
if (dstIdx < 0 || dstIdx >= combinedAlpha.length) continue;
|
|
118
|
+
const a = mask.data[srcBase + xx] || 0;
|
|
119
|
+
const summed = combinedAlpha[dstIdx] + a;
|
|
120
|
+
combinedAlpha[dstIdx] = summed > 255 ? 255 : summed;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
for (const sh of run.textShadows) {
|
|
126
|
+
if (!sh || !sh.color) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const blurPx = Math.max(0, sh.blur ?? 0);
|
|
130
|
+
const clampedCombined = combinedAlpha instanceof Uint8ClampedArray ? combinedAlpha : new Uint8ClampedArray(combinedAlpha);
|
|
131
|
+
const rawAlphaBuf = blurPx > 0 ? blurAlpha(clampedCombined, combinedW, combinedH, blurPx) : clampedCombined;
|
|
132
|
+
const alphaBuf = rawAlphaBuf instanceof Uint8ClampedArray ? rawAlphaBuf : new Uint8ClampedArray(rawAlphaBuf);
|
|
133
|
+
|
|
134
|
+
const r8 = Math.round(normalizeChannel(sh.color.r) * 255);
|
|
135
|
+
const g8 = Math.round(normalizeChannel(sh.color.g) * 255);
|
|
136
|
+
const b8 = Math.round(normalizeChannel(sh.color.b) * 255);
|
|
137
|
+
const shadowAlpha = sh.color.a ?? 1;
|
|
138
|
+
|
|
139
|
+
const cacheKey = `${run.text}|${(font as any).baseFont}|size:${fontSizePx}|blur:${Math.round(blurPx)}|color:${r8},${g8},${b8},${shadowAlpha}|ss:${supersample}`;
|
|
140
|
+
let resAlias: string | undefined;
|
|
141
|
+
const cached = this.runShadowCache.get(cacheKey);
|
|
142
|
+
if (cached) {
|
|
143
|
+
resAlias = cached.alias;
|
|
144
|
+
} else {
|
|
145
|
+
const rgba = new Uint8Array(combinedW * combinedH * 4);
|
|
146
|
+
for (let i = 0, j = 0; i < alphaBuf.length; i++, j += 4) {
|
|
147
|
+
rgba[j] = r8;
|
|
148
|
+
rgba[j + 1] = g8;
|
|
149
|
+
rgba[j + 2] = b8;
|
|
150
|
+
rgba[j + 3] = Math.round(alphaBuf[i] * shadowAlpha);
|
|
151
|
+
}
|
|
152
|
+
const img: any = {
|
|
153
|
+
src: `internal:shadow:run:${(font as any).resourceName}:${Math.round(Math.random() * 1e9)}`,
|
|
154
|
+
width: combinedW,
|
|
155
|
+
height: combinedH,
|
|
156
|
+
format: "png",
|
|
157
|
+
channels: 4,
|
|
158
|
+
bitsPerComponent: 8,
|
|
159
|
+
data: rgba.buffer,
|
|
160
|
+
};
|
|
161
|
+
const res = this.imageRenderer.registerResource(img);
|
|
162
|
+
resAlias = res.alias;
|
|
163
|
+
this.runShadowCache.set(cacheKey, { alias: resAlias, image: img });
|
|
164
|
+
}
|
|
165
|
+
const offsetX = sh.offsetX ?? 0;
|
|
166
|
+
const offsetY = sh.offsetY ?? 0;
|
|
167
|
+
const xPx = Tm.e + offsetX + minX;
|
|
168
|
+
const yPxTop = Tm.f + offsetY + minY;
|
|
169
|
+
const widthPt = this.coordinateTransformer.convertPxToPt(combinedW);
|
|
170
|
+
const heightPt = this.coordinateTransformer.convertPxToPt(combinedH);
|
|
171
|
+
const xPt = this.coordinateTransformer.convertPxToPt(xPx);
|
|
172
|
+
const localYTop = yPxTop - this.coordinateTransformer.pageOffsetPx;
|
|
173
|
+
const yPt = this.coordinateTransformer.pageHeightPt - this.coordinateTransformer.convertPxToPt(localYTop + combinedH);
|
|
174
|
+
|
|
175
|
+
commands.push(
|
|
176
|
+
"q",
|
|
177
|
+
`${formatNumber(widthPt)} 0 0 ${formatNumber(heightPt)} ${formatNumber(xPt)} ${formatNumber(yPt)} cm`,
|
|
178
|
+
`/${resAlias} Do`,
|
|
179
|
+
"Q",
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// If we failed to build any glyph masks (e.g., missing outlines), fall back to vector shadows.
|
|
186
|
+
if (glyphMasks.length === 0) {
|
|
187
|
+
this.appendVectorShadowLayers(commands, run, font, encoded, Tm, fontSizePt, fontName, wordSpacingCmd, resetWordSpacingCmd);
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
if (needsRaster && this.imageRenderer) {
|
|
191
|
+
try {
|
|
192
|
+
for (const sh of run.textShadows) {
|
|
193
|
+
if (!sh || !sh.color) continue;
|
|
194
|
+
const offsetX = sh.offsetX ?? 0;
|
|
195
|
+
const offsetY = sh.offsetY ?? 0;
|
|
196
|
+
const blurPx = Math.max(0, sh.blur ?? 0);
|
|
197
|
+
const baseAlpha = sh.color.a ?? 1;
|
|
198
|
+
|
|
199
|
+
const samples: { dx: number; dy: number; weight: number }[] = [];
|
|
200
|
+
if (blurPx <= 1) {
|
|
201
|
+
samples.push({ dx: 0, dy: 0, weight: 1 });
|
|
202
|
+
} else {
|
|
203
|
+
const centerW = 0.38;
|
|
204
|
+
const orthoW = 0.12;
|
|
205
|
+
const diagW = (1 - (centerW + 4 * orthoW)) / 4;
|
|
206
|
+
const radius = blurPx / 2;
|
|
207
|
+
samples.push({ dx: 0, dy: 0, weight: centerW });
|
|
208
|
+
samples.push({ dx: -radius, dy: 0, weight: orthoW });
|
|
209
|
+
samples.push({ dx: radius, dy: 0, weight: orthoW });
|
|
210
|
+
samples.push({ dx: 0, dy: -radius, weight: orthoW });
|
|
211
|
+
samples.push({ dx: 0, dy: radius, weight: orthoW });
|
|
212
|
+
samples.push({ dx: -radius, dy: -radius, weight: diagW });
|
|
213
|
+
samples.push({ dx: radius, dy: -radius, weight: diagW });
|
|
214
|
+
samples.push({ dx: -radius, dy: radius, weight: diagW });
|
|
215
|
+
samples.push({ dx: radius, dy: radius, weight: diagW });
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
for (const s of samples) {
|
|
219
|
+
const sx = s.dx;
|
|
220
|
+
const sy = s.dy;
|
|
221
|
+
const sampleAlpha = baseAlpha * s.weight;
|
|
222
|
+
const sampleColor = { r: sh.color.r, g: sh.color.g, b: sh.color.b, a: sampleAlpha };
|
|
223
|
+
|
|
224
|
+
const shadowX = this.coordinateTransformer.convertPxToPt(Tm.e + offsetX + sx);
|
|
225
|
+
const shadowLocalBaseline = Tm.f - this.coordinateTransformer.pageOffsetPx + offsetY + sy;
|
|
226
|
+
const shadowYPt = this.coordinateTransformer.pageHeightPt - this.coordinateTransformer.convertPxToPt(shadowLocalBaseline);
|
|
227
|
+
|
|
228
|
+
const shadowSequence: string[] = ["q", fillColorCommand(sampleColor, this.graphicsStateManager), "BT"];
|
|
229
|
+
if (wordSpacingCmd) shadowSequence.push(wordSpacingCmd);
|
|
230
|
+
shadowSequence.push(
|
|
231
|
+
`/${fontName} ${formatNumber(fontSizePt)} Tf`,
|
|
232
|
+
`${formatNumber(Tm.a)} ${formatNumber(Tm.b)} ${formatNumber(Tm.c)} ${formatNumber(Tm.d)} ${formatNumber(shadowX)} ${formatNumber(shadowYPt)} Tm`,
|
|
233
|
+
`(${encoded}) Tj`,
|
|
234
|
+
);
|
|
235
|
+
if (resetWordSpacingCmd) shadowSequence.push(resetWordSpacingCmd);
|
|
236
|
+
shadowSequence.push("ET", "Q");
|
|
237
|
+
commands.push(...shadowSequence);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
} catch {
|
|
241
|
+
this.appendVectorShadowLayers(commands, run, font, encoded, Tm, fontSizePt, fontName, wordSpacingCmd, resetWordSpacingCmd);
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
this.appendVectorShadowLayers(commands, run, font, encoded, Tm, fontSizePt, fontName, wordSpacingCmd, resetWordSpacingCmd);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
this.appendVectorShadowLayers(commands, run, font, encoded, Tm, fontSizePt, fontName, wordSpacingCmd, resetWordSpacingCmd);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return commands;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private appendVectorShadowLayers(
|
|
255
|
+
commands: string[],
|
|
256
|
+
run: Run,
|
|
257
|
+
font: FontResource,
|
|
258
|
+
encoded: string,
|
|
259
|
+
Tm: TextMatrix,
|
|
260
|
+
fontSizePt: number,
|
|
261
|
+
fontName: string,
|
|
262
|
+
wordSpacingCmd?: string,
|
|
263
|
+
resetWordSpacingCmd?: string,
|
|
264
|
+
): void {
|
|
265
|
+
const shadows = run.textShadows ?? [];
|
|
266
|
+
for (const sh of shadows) {
|
|
267
|
+
if (!sh || !sh.color) {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
const shadowX = this.coordinateTransformer.convertPxToPt(Tm.e + (sh.offsetX ?? 0));
|
|
271
|
+
const shadowLocalBaseline = Tm.f - this.coordinateTransformer.pageOffsetPx + (sh.offsetY ?? 0);
|
|
272
|
+
const shadowYPt = this.coordinateTransformer.pageHeightPt - this.coordinateTransformer.convertPxToPt(shadowLocalBaseline);
|
|
273
|
+
|
|
274
|
+
const shadowSequence: string[] = ["q", fillColorCommand(sh.color, this.graphicsStateManager), "BT"];
|
|
275
|
+
if (wordSpacingCmd) shadowSequence.push(wordSpacingCmd);
|
|
276
|
+
shadowSequence.push(
|
|
277
|
+
`/${fontName} ${formatNumber(fontSizePt)} Tf`,
|
|
278
|
+
`${formatNumber(Tm.a)} ${formatNumber(Tm.b)} ${formatNumber(Tm.c)} ${formatNumber(Tm.d)} ${formatNumber(shadowX)} ${formatNumber(shadowYPt)} Tm`,
|
|
279
|
+
`(${encoded}) Tj`,
|
|
280
|
+
);
|
|
281
|
+
if (resetWordSpacingCmd) shadowSequence.push(resetWordSpacingCmd);
|
|
282
|
+
shadowSequence.push("ET", "Q");
|
|
283
|
+
commands.push(...shadowSequence);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Merge UnifiedFont metrics with its outline provider so glyph rasterization can work.
|
|
289
|
+
function mergeMetricsWithOutline(font: UnifiedFont | undefined | null): any | null {
|
|
290
|
+
if (!font?.metrics || !font.program?.getGlyphOutline) {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
metrics: font.metrics.metrics,
|
|
295
|
+
glyphMetrics: font.metrics.glyphMetrics,
|
|
296
|
+
cmap: font.metrics.cmap,
|
|
297
|
+
headBBox: font.metrics.headBBox,
|
|
298
|
+
getGlyphOutline: font.program.getGlyphOutline,
|
|
299
|
+
};
|
|
300
|
+
}
|