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,233 @@
|
|
|
1
|
+
import type { Radius, Rect, RGBA, ImageRef } from "../types.js";
|
|
2
|
+
|
|
3
|
+
function clampUnit(value: number): number {
|
|
4
|
+
if (!Number.isFinite(value)) return 0;
|
|
5
|
+
if (value <= 0) return 0;
|
|
6
|
+
if (value >= 1) return 1;
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function ceilPositive(value: number): number {
|
|
11
|
+
if (!Number.isFinite(value) || value <= 0) return 0;
|
|
12
|
+
return Math.ceil(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function inflateRect(rect: Rect, amount: number): Rect {
|
|
16
|
+
const width = rect.width + amount * 2;
|
|
17
|
+
const height = rect.height + amount * 2;
|
|
18
|
+
if (width <= 0 || height <= 0) {
|
|
19
|
+
return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2, width: 0, height: 0 };
|
|
20
|
+
}
|
|
21
|
+
return { x: rect.x - amount, y: rect.y - amount, width, height };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function max2(a: number, b: number): number { return a > b ? a : b; }
|
|
25
|
+
|
|
26
|
+
function pointInRoundedRect(px: number, py: number, rect: Rect, radius: Radius): boolean {
|
|
27
|
+
if (px < rect.x || py < rect.y || px > rect.x + rect.width || py > rect.y + rect.height) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const leftMargin = max2(radius.topLeft.x, radius.bottomLeft.x);
|
|
32
|
+
const rightMargin = max2(radius.topRight.x, radius.bottomRight.x);
|
|
33
|
+
const topMargin = max2(radius.topLeft.y, radius.topRight.y);
|
|
34
|
+
const bottomMargin = max2(radius.bottomLeft.y, radius.bottomRight.y);
|
|
35
|
+
|
|
36
|
+
// Horizontal and vertical straight strips
|
|
37
|
+
if (px >= rect.x + leftMargin && px <= rect.x + rect.width - rightMargin) return true;
|
|
38
|
+
if (py >= rect.y + topMargin && py <= rect.y + rect.height - bottomMargin) return true;
|
|
39
|
+
|
|
40
|
+
// Corner tests (elliptical)
|
|
41
|
+
// Top-left
|
|
42
|
+
if (px < rect.x + radius.topLeft.x && py < rect.y + radius.topLeft.y && radius.topLeft.x > 0 && radius.topLeft.y > 0) {
|
|
43
|
+
const cx = rect.x + radius.topLeft.x;
|
|
44
|
+
const cy = rect.y + radius.topLeft.y;
|
|
45
|
+
const dx = (px - cx) / radius.topLeft.x;
|
|
46
|
+
const dy = (py - cy) / radius.topLeft.y;
|
|
47
|
+
return dx * dx + dy * dy <= 1;
|
|
48
|
+
}
|
|
49
|
+
// Top-right
|
|
50
|
+
if (px > rect.x + rect.width - radius.topRight.x && py < rect.y + radius.topRight.y && radius.topRight.x > 0 && radius.topRight.y > 0) {
|
|
51
|
+
const cx = rect.x + rect.width - radius.topRight.x;
|
|
52
|
+
const cy = rect.y + radius.topRight.y;
|
|
53
|
+
const dx = (px - cx) / radius.topRight.x;
|
|
54
|
+
const dy = (py - cy) / radius.topRight.y;
|
|
55
|
+
return dx * dx + dy * dy <= 1;
|
|
56
|
+
}
|
|
57
|
+
// Bottom-right
|
|
58
|
+
if (px > rect.x + rect.width - radius.bottomRight.x && py > rect.y + rect.height - radius.bottomRight.y && radius.bottomRight.x > 0 && radius.bottomRight.y > 0) {
|
|
59
|
+
const cx = rect.x + rect.width - radius.bottomRight.x;
|
|
60
|
+
const cy = rect.y + rect.height - radius.bottomRight.y;
|
|
61
|
+
const dx = (px - cx) / radius.bottomRight.x;
|
|
62
|
+
const dy = (py - cy) / radius.bottomRight.y;
|
|
63
|
+
return dx * dx + dy * dy <= 1;
|
|
64
|
+
}
|
|
65
|
+
// Bottom-left
|
|
66
|
+
if (px < rect.x + radius.bottomLeft.x && py > rect.y + rect.height - radius.bottomLeft.y && radius.bottomLeft.x > 0 && radius.bottomLeft.y > 0) {
|
|
67
|
+
const cx = rect.x + radius.bottomLeft.x;
|
|
68
|
+
const cy = rect.y + rect.height - radius.bottomLeft.y;
|
|
69
|
+
const dx = (px - cx) / radius.bottomLeft.x;
|
|
70
|
+
const dy = (py - cy) / radius.bottomLeft.y;
|
|
71
|
+
return dx * dx + dy * dy <= 1;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function buildGaussianKernel(sigma: number): { kernel: Float32Array; radius: number; sum: number } {
|
|
77
|
+
const s = sigma > 0 ? sigma : 0.0001;
|
|
78
|
+
const radius = Math.max(1, Math.ceil(s * 3));
|
|
79
|
+
const size = radius * 2 + 1;
|
|
80
|
+
const kernel = new Float32Array(size);
|
|
81
|
+
const coeff = 1 / (Math.sqrt(2 * Math.PI) * s);
|
|
82
|
+
const twoSigmaSq = 2 * s * s;
|
|
83
|
+
let sum = 0;
|
|
84
|
+
for (let i = -radius; i <= radius; i++) {
|
|
85
|
+
const w = coeff * Math.exp(-(i * i) / twoSigmaSq);
|
|
86
|
+
kernel[i + radius] = w;
|
|
87
|
+
sum += w;
|
|
88
|
+
}
|
|
89
|
+
return { kernel, radius, sum };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function blurAlpha(alpha: Uint8Array, width: number, height: number, sigma: number): Uint8Array {
|
|
93
|
+
if (sigma <= 0) return alpha;
|
|
94
|
+
const { kernel, radius, sum } = buildGaussianKernel(sigma);
|
|
95
|
+
const tmp = new Float32Array(width * height);
|
|
96
|
+
// Horizontal pass
|
|
97
|
+
for (let y = 0; y < height; y++) {
|
|
98
|
+
const rowOffset = y * width;
|
|
99
|
+
for (let x = 0; x < width; x++) {
|
|
100
|
+
let acc = 0;
|
|
101
|
+
let wsum = 0;
|
|
102
|
+
for (let k = -radius; k <= radius; k++) {
|
|
103
|
+
const xi = Math.min(width - 1, Math.max(0, x + k));
|
|
104
|
+
const w = kernel[k + radius];
|
|
105
|
+
acc += alpha[rowOffset + xi] * w;
|
|
106
|
+
wsum += w;
|
|
107
|
+
}
|
|
108
|
+
tmp[rowOffset + x] = acc / (wsum || sum);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Vertical pass
|
|
112
|
+
const out = new Uint8Array(width * height);
|
|
113
|
+
for (let x = 0; x < width; x++) {
|
|
114
|
+
for (let y = 0; y < height; y++) {
|
|
115
|
+
let acc = 0;
|
|
116
|
+
let wsum = 0;
|
|
117
|
+
for (let k = -radius; k <= radius; k++) {
|
|
118
|
+
const yi = Math.min(height - 1, Math.max(0, y + k));
|
|
119
|
+
const w = kernel[k + radius];
|
|
120
|
+
acc += tmp[yi * width + x] * w;
|
|
121
|
+
wsum += w;
|
|
122
|
+
}
|
|
123
|
+
const v = acc / (wsum || sum);
|
|
124
|
+
out[y * width + x] = v < 0 ? 0 : v > 255 ? 255 : v;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface ShadowRasterResult {
|
|
131
|
+
readonly image: ImageRef;
|
|
132
|
+
readonly drawRect: Rect; // where to place the image in page coordinates (px)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function rasterizeDropShadowForRect(
|
|
136
|
+
baseRect: Rect,
|
|
137
|
+
baseRadius: Radius,
|
|
138
|
+
color: RGBA,
|
|
139
|
+
blur: number,
|
|
140
|
+
spread: number,
|
|
141
|
+
): ShadowRasterResult | null {
|
|
142
|
+
const blurPx = Math.max(0, blur);
|
|
143
|
+
const shapeRect: Rect = inflateRect(baseRect, spread);
|
|
144
|
+
const shapeRadius: Radius = adjustRadius(baseRadius, spread);
|
|
145
|
+
const outRect: Rect = inflateRect(shapeRect, blurPx);
|
|
146
|
+
const width = ceilPositive(outRect.width);
|
|
147
|
+
const height = ceilPositive(outRect.height);
|
|
148
|
+
if (width === 0 || height === 0) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Build alpha mask for the unblurred rounded rectangle (shapeRect within outRect)
|
|
153
|
+
const alpha = new Uint8Array(width * height);
|
|
154
|
+
const shapeLocal: Rect = { x: shapeRect.x - outRect.x, y: shapeRect.y - outRect.y, width: shapeRect.width, height: shapeRect.height };
|
|
155
|
+
|
|
156
|
+
for (let y = 0; y < height; y++) {
|
|
157
|
+
const py = y + 0.5; // pixel center
|
|
158
|
+
for (let x = 0; x < width; x++) {
|
|
159
|
+
const px = x + 0.5;
|
|
160
|
+
const inside = pointInRoundedRect(px, py, shapeLocal, shapeRadius);
|
|
161
|
+
alpha[y * width + x] = inside ? 255 : 0;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const sigma = blurPx > 0 ? Math.max(0.5, blurPx / 2) : 0;
|
|
166
|
+
const blurred = blurAlpha(alpha, width, height, sigma);
|
|
167
|
+
|
|
168
|
+
// Compose RGBA data with straight alpha (non-premultiplied RGB)
|
|
169
|
+
// sRGB compensation: push base color slightly towards display sRGB to better match browser compositing
|
|
170
|
+
const [r, g, b] = compensateSrgbColor(color.r, color.g, color.b);
|
|
171
|
+
const aMul = clampUnit(color.a ?? 1);
|
|
172
|
+
const data = new Uint8Array(width * height * 4);
|
|
173
|
+
let di = 0;
|
|
174
|
+
for (let i = 0; i < blurred.length; i++) {
|
|
175
|
+
data[di++] = r;
|
|
176
|
+
data[di++] = g;
|
|
177
|
+
data[di++] = b;
|
|
178
|
+
const a = Math.round(blurred[i] * aMul);
|
|
179
|
+
data[di++] = a < 0 ? 0 : a > 255 ? 255 : a;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const image: ImageRef = {
|
|
183
|
+
src: `internal:shadow:${Math.random().toString(36).slice(2)}`,
|
|
184
|
+
width,
|
|
185
|
+
height,
|
|
186
|
+
format: "png",
|
|
187
|
+
channels: 4,
|
|
188
|
+
bitsPerComponent: 8,
|
|
189
|
+
data: data.buffer,
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
return { image, drawRect: outRect };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function adjustRadius(radius: Radius, delta: number): Radius {
|
|
196
|
+
const clampNN = (v: number) => (Number.isFinite(v) && v > 0 ? v : 0);
|
|
197
|
+
return {
|
|
198
|
+
topLeft: { x: clampNN(radius.topLeft.x + delta), y: clampNN(radius.topLeft.y + delta) },
|
|
199
|
+
topRight: { x: clampNN(radius.topRight.x + delta), y: clampNN(radius.topRight.y + delta) },
|
|
200
|
+
bottomRight: { x: clampNN(radius.bottomRight.x + delta), y: clampNN(radius.bottomRight.y + delta) },
|
|
201
|
+
bottomLeft: { x: clampNN(radius.bottomLeft.x + delta), y: clampNN(radius.bottomLeft.y + delta) },
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function srgbToLinearByte(c: number): number {
|
|
206
|
+
const cs = Math.min(1, Math.max(0, c > 1 ? c / 255 : c));
|
|
207
|
+
const lin = cs <= 0.04045 ? cs / 12.92 : Math.pow((cs + 0.055) / 1.055, 2.4);
|
|
208
|
+
return lin * 255;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function linearToSrgbByte(c: number): number {
|
|
212
|
+
const cl = Math.min(1, Math.max(0, c > 1 ? c / 255 : c));
|
|
213
|
+
const srgb = cl <= 0.0031308 ? 12.92 * cl : 1.055 * Math.pow(cl, 1 / 2.4) - 0.055;
|
|
214
|
+
return Math.round(Math.min(255, Math.max(0, srgb * 255)));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Simple compensation to reduce perceived desaturation in some PDF viewers
|
|
218
|
+
function compensateSrgbColor(rIn: number, gIn: number, bIn: number): [number, number, number] {
|
|
219
|
+
// Convert to linear, nudge saturation, convert back to sRGB
|
|
220
|
+
const rl = srgbToLinearByte(rIn) / 255;
|
|
221
|
+
const gl = srgbToLinearByte(gIn) / 255;
|
|
222
|
+
const bl = srgbToLinearByte(bIn) / 255;
|
|
223
|
+
const max = Math.max(rl, gl, bl);
|
|
224
|
+
const min = Math.min(rl, gl, bl);
|
|
225
|
+
const mid = (rl + gl + bl) / 3;
|
|
226
|
+
const sat = max - min;
|
|
227
|
+
const boosted = Math.min(1, sat * 1.08); // small boost only
|
|
228
|
+
const scale = sat > 0 ? boosted / sat : 1;
|
|
229
|
+
const r = mid + (rl - mid) * scale;
|
|
230
|
+
const g = mid + (gl - mid) * scale;
|
|
231
|
+
const b = mid + (bl - mid) * scale;
|
|
232
|
+
return [linearToSrgbByte(r), linearToSrgbByte(g), linearToSrgbByte(b)];
|
|
233
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { log } from "../../logging/debug.js";
|
|
2
|
+
|
|
3
|
+
const WIN_ANSI_UNICODE = (() => {
|
|
4
|
+
const table: number[] = new Array(256);
|
|
5
|
+
for (let code = 0; code <= 0xff; code++) {
|
|
6
|
+
table[code] = code;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const overrides: Record<number, number> = {
|
|
10
|
+
0x80: 0x20ac,
|
|
11
|
+
0x82: 0x201a,
|
|
12
|
+
0x83: 0x0192,
|
|
13
|
+
0x84: 0x201e,
|
|
14
|
+
0x85: 0x2026,
|
|
15
|
+
0x86: 0x2020,
|
|
16
|
+
0x87: 0x2021,
|
|
17
|
+
0x88: 0x02c6,
|
|
18
|
+
0x89: 0x2030,
|
|
19
|
+
0x8a: 0x0160,
|
|
20
|
+
0x8b: 0x2039,
|
|
21
|
+
0x8c: 0x0152,
|
|
22
|
+
0x8e: 0x017d,
|
|
23
|
+
0x91: 0x2018,
|
|
24
|
+
0x92: 0x2019,
|
|
25
|
+
0x93: 0x201c,
|
|
26
|
+
0x94: 0x201d,
|
|
27
|
+
0x95: 0x2022,
|
|
28
|
+
0x96: 0x2013,
|
|
29
|
+
0x97: 0x2014,
|
|
30
|
+
0x98: 0x02dc,
|
|
31
|
+
0x99: 0x2122,
|
|
32
|
+
0x9a: 0x0161,
|
|
33
|
+
0x9b: 0x203a,
|
|
34
|
+
0x9c: 0x0153,
|
|
35
|
+
0x9e: 0x017e,
|
|
36
|
+
0x9f: 0x0178,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
for (const [codePoint, unicode] of Object.entries(overrides)) {
|
|
40
|
+
const code = Number(codePoint);
|
|
41
|
+
table[code] = unicode;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return table;
|
|
45
|
+
})();
|
|
46
|
+
|
|
47
|
+
const UNICODE_TO_WIN_ANSI = (() => {
|
|
48
|
+
const map = new Map<number, number>();
|
|
49
|
+
for (let code = 0; code <= 0xff; code++) {
|
|
50
|
+
const unicode = WIN_ANSI_UNICODE[code];
|
|
51
|
+
if (!map.has(unicode)) {
|
|
52
|
+
map.set(unicode, code);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return map;
|
|
56
|
+
})();
|
|
57
|
+
|
|
58
|
+
export { UNICODE_TO_WIN_ANSI };
|
|
59
|
+
|
|
60
|
+
export type PdfEncodingScheme = "WinAnsi" | "Identity-H";
|
|
61
|
+
|
|
62
|
+
export function encodeToWinAnsi(text: string): string {
|
|
63
|
+
let result = "",
|
|
64
|
+
misses = 0,
|
|
65
|
+
details: number[] = [];
|
|
66
|
+
for (const char of text) {
|
|
67
|
+
const codePoint = char.codePointAt(0);
|
|
68
|
+
if (codePoint === undefined) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const byte = UNICODE_TO_WIN_ANSI.get(codePoint);
|
|
72
|
+
if (byte === undefined) {
|
|
73
|
+
misses++;
|
|
74
|
+
details.push(codePoint);
|
|
75
|
+
result += "?";
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
result += String.fromCharCode(byte);
|
|
79
|
+
}
|
|
80
|
+
if (misses) {
|
|
81
|
+
log("encoding", "debug", "WinAnsi misses", {
|
|
82
|
+
misses,
|
|
83
|
+
codepoints: details.slice(0, 20),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function escapePdfLiteral(text: string): string {
|
|
90
|
+
return text.replace(/([()\\])/g, "\\$1");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function encodeAndEscapePdfText(text: string, scheme: PdfEncodingScheme = "WinAnsi"): string {
|
|
94
|
+
const before = text;
|
|
95
|
+
const payload = scheme === "WinAnsi" ? encodeToWinAnsi(text) : text;
|
|
96
|
+
log("encoding", "trace", "PdfText transformation", { scheme, before, after: payload });
|
|
97
|
+
return escapePdfLiteral(payload);
|
|
98
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { globalGlyphAtlas } from "../font/glyph-atlas.js";
|
|
2
|
+
import type { ImageRenderer } from "../renderers/image-renderer.js";
|
|
3
|
+
|
|
4
|
+
export function registerGlyphAtlasPages(imageRenderer: ImageRenderer): void {
|
|
5
|
+
try {
|
|
6
|
+
const pages = globalGlyphAtlas.getPages();
|
|
7
|
+
if (pages && pages.length > 0) {
|
|
8
|
+
imageRenderer.registerAtlasPages(pages);
|
|
9
|
+
}
|
|
10
|
+
} catch {
|
|
11
|
+
// ignore atlas registration errors - fall back to per-glyph images
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { GlyphRun } from "../../layout/text-run.js";
|
|
2
|
+
import type { PdfFontSubset } from "../font/font-subset.js";
|
|
3
|
+
import type { GraphicsStateManager } from "../renderers/graphics-state-manager.js";
|
|
4
|
+
import { fillColorCommand, formatNumber } from "../renderers/text-renderer-utils.js";
|
|
5
|
+
import type { RGBA } from "../types.js";
|
|
6
|
+
|
|
7
|
+
export interface DrawGlyphRunOptions {
|
|
8
|
+
skipColor?: boolean;
|
|
9
|
+
textRenderingMode?: number;
|
|
10
|
+
afterTextCommands?: string[];
|
|
11
|
+
/** Optional text matrix (Tm) to apply instead of simple translation. Values must be in PDF user space (points). */
|
|
12
|
+
tm?: { a: number; b: number; c: number; d: number; e: number; f: number };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Draws a GlyphRun using a PdfFontSubset.
|
|
17
|
+
* Returns PDF content stream commands.
|
|
18
|
+
*/
|
|
19
|
+
export function drawGlyphRun(
|
|
20
|
+
run: GlyphRun,
|
|
21
|
+
subset: PdfFontSubset,
|
|
22
|
+
xPt: number,
|
|
23
|
+
yPt: number,
|
|
24
|
+
fontSizePt: number,
|
|
25
|
+
color: RGBA,
|
|
26
|
+
graphicsStateManager?: GraphicsStateManager,
|
|
27
|
+
wordSpacingPt = 0,
|
|
28
|
+
options?: DrawGlyphRunOptions,
|
|
29
|
+
): string[] {
|
|
30
|
+
const commands: string[] = [];
|
|
31
|
+
if (!options?.skipColor) {
|
|
32
|
+
commands.push(fillColorCommand(color, graphicsStateManager));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Begin text
|
|
36
|
+
commands.push("BT");
|
|
37
|
+
commands.push(`${subset.name} ${formatNumber(fontSizePt)} Tf`);
|
|
38
|
+
if (options?.tm) {
|
|
39
|
+
const { a, b, c, d, e, f } = options.tm;
|
|
40
|
+
commands.push(
|
|
41
|
+
`${formatNumber(a)} ${formatNumber(b)} ${formatNumber(c)} ${formatNumber(d)} ${formatNumber(e)} ${formatNumber(f)} Tm`,
|
|
42
|
+
);
|
|
43
|
+
} else {
|
|
44
|
+
commands.push(`${formatNumber(xPt)} ${formatNumber(yPt)} Td`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const appliedWordSpacing = wordSpacingPt !== 0;
|
|
48
|
+
if (appliedWordSpacing) {
|
|
49
|
+
commands.push(`${formatNumber(wordSpacingPt)} Tw`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (options?.textRenderingMode !== undefined) {
|
|
53
|
+
commands.push(`${options.textRenderingMode} Tr`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Build TJ array with per-glyph kerning/letter-spacing adjustments and optional word spacing.
|
|
57
|
+
// Positions are provided in layout px units; scale to PDF points.
|
|
58
|
+
const ptPerPx = fontSizePt / run.fontSize;
|
|
59
|
+
const unitsPerEm = run.font.metrics.metrics.unitsPerEm;
|
|
60
|
+
const glyphWidths = run.font.metrics.glyphMetrics;
|
|
61
|
+
const encodeGlyphId = (gid: number): string => {
|
|
62
|
+
const charCode = subset.encodeGlyph(gid);
|
|
63
|
+
const hex = charCode.toString(16).toUpperCase();
|
|
64
|
+
// PDF expects an even number of hex digits; use at least 2 bytes for Identity-H
|
|
65
|
+
const evenHex = hex.length % 2 === 0 ? hex : `0${hex}`;
|
|
66
|
+
return evenHex.length < 4 ? evenHex.padStart(4, "0") : evenHex;
|
|
67
|
+
};
|
|
68
|
+
const elements: (string | number)[] = [];
|
|
69
|
+
let hasAdjustments = false;
|
|
70
|
+
|
|
71
|
+
for (let i = 0; i < run.glyphIds.length; i++) {
|
|
72
|
+
const gid = run.glyphIds[i];
|
|
73
|
+
const hexCode = encodeGlyphId(gid);
|
|
74
|
+
elements.push(`<${hexCode}>`);
|
|
75
|
+
|
|
76
|
+
if (i < run.glyphIds.length - 1) {
|
|
77
|
+
const currentPos = run.positions[i]?.x ?? 0;
|
|
78
|
+
const nextPos = run.positions[i + 1]?.x ?? currentPos;
|
|
79
|
+
let desiredAdvancePx = nextPos - currentPos;
|
|
80
|
+
if (appliedWordSpacing) {
|
|
81
|
+
const nextChar = run.text[i + 1] ?? "";
|
|
82
|
+
if (nextChar === " ") {
|
|
83
|
+
// Word spacing is added on spaces; add to desired advance.
|
|
84
|
+
desiredAdvancePx += wordSpacingPt / ptPerPx;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const gm = glyphWidths.get(gid);
|
|
89
|
+
const defaultAdvancePx = ((gm?.advanceWidth ?? 0) / unitsPerEm) * run.fontSize;
|
|
90
|
+
|
|
91
|
+
const deltaPx = desiredAdvancePx - defaultAdvancePx;
|
|
92
|
+
if (Math.abs(deltaPx) > 1e-6) {
|
|
93
|
+
const deltaPt = deltaPx * ptPerPx;
|
|
94
|
+
// TJ numbers are in thousandths of text space; positive numbers tighten spacing.
|
|
95
|
+
const adjustment = -deltaPt / fontSizePt * 1000;
|
|
96
|
+
if (Math.abs(adjustment) > 1e-6) {
|
|
97
|
+
hasAdjustments = true;
|
|
98
|
+
elements.push(adjustment);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!hasAdjustments) {
|
|
105
|
+
// Use a single hex string when there are no per-glyph adjustments; simpler and more compatible.
|
|
106
|
+
const hex = run.glyphIds.map((gid) => encodeGlyphId(gid)).join("");
|
|
107
|
+
commands.push(`<${hex}> Tj`);
|
|
108
|
+
} else {
|
|
109
|
+
const tjContent = elements
|
|
110
|
+
.map((el) => (typeof el === "number" ? formatPdfNumber(el) : el))
|
|
111
|
+
.join(" ");
|
|
112
|
+
commands.push(`[${tjContent}] TJ`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// End text
|
|
116
|
+
commands.push("ET");
|
|
117
|
+
if (options?.afterTextCommands && options.afterTextCommands.length > 0) {
|
|
118
|
+
commands.push(...options.afterTextCommands);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return commands;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Format a number for PDF (up to 6 decimal places, trailing zeros removed).
|
|
126
|
+
*/
|
|
127
|
+
export function formatPdfNumber(n: number): string {
|
|
128
|
+
return n.toFixed(6).replace(/\.?0+$/, "");
|
|
129
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface PartitionedCommands {
|
|
2
|
+
readonly preShadow: string[];
|
|
3
|
+
readonly post: string[];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function partitionImageCommands(commands: string[], shadowAliases: Set<string>): PartitionedCommands {
|
|
7
|
+
const preShadowImageCmds: string[] = [];
|
|
8
|
+
const postImageCmds: string[] = [];
|
|
9
|
+
|
|
10
|
+
for (let i = 0; i < commands.length; ) {
|
|
11
|
+
if (commands[i] === "q" && i + 3 < commands.length && commands[i + 3] === "Q") {
|
|
12
|
+
const doLine = commands[i + 2] ?? "";
|
|
13
|
+
const match = doLine.match(/^\/(\w+)\s+Do$/);
|
|
14
|
+
const block = [commands[i], commands[i + 1] ?? "", commands[i + 2] ?? "", commands[i + 3] ?? ""];
|
|
15
|
+
i += 4;
|
|
16
|
+
if (match && shadowAliases.has(match[1])) {
|
|
17
|
+
preShadowImageCmds.push(...block);
|
|
18
|
+
} else {
|
|
19
|
+
postImageCmds.push(...block);
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
postImageCmds.push(commands[i]);
|
|
23
|
+
i += 1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return { preShadow: preShadowImageCmds, post: postImageCmds };
|
|
28
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Rect } from "../types.js";
|
|
2
|
+
import { CoordinateTransformer } from "./coordinate-transformer.js";
|
|
3
|
+
|
|
4
|
+
export class ImageMatrixBuilder {
|
|
5
|
+
constructor(private readonly coordinateTransformer: CoordinateTransformer) {}
|
|
6
|
+
|
|
7
|
+
buildImageMatrix(rect: Rect): string | null {
|
|
8
|
+
if (!rect || rect.width <= 0 || rect.height <= 0) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const widthPt = this.coordinateTransformer.convertPxToPt(rect.width);
|
|
12
|
+
const heightPt = this.coordinateTransformer.convertPxToPt(rect.height);
|
|
13
|
+
if (!Number.isFinite(widthPt) || !Number.isFinite(heightPt) || widthPt === 0 || heightPt === 0) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const xPt = this.coordinateTransformer.convertPxToPt(rect.x);
|
|
17
|
+
const localY = rect.y - this.coordinateTransformer.pageOffsetPx;
|
|
18
|
+
const yPt = this.coordinateTransformer.pageHeightPt - this.coordinateTransformer.convertPxToPt(localY + rect.height);
|
|
19
|
+
if (!Number.isFinite(xPt) || !Number.isFinite(yPt)) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return `${formatNumber(widthPt)} 0 0 ${formatNumber(heightPt)} ${formatNumber(xPt)} ${formatNumber(yPt)} cm`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function formatNumber(value: number): string {
|
|
27
|
+
if (!Number.isFinite(value)) {
|
|
28
|
+
return "0";
|
|
29
|
+
}
|
|
30
|
+
return Number.isInteger(value) ? value.toString() : value.toFixed(4).replace(/0+$/, "").replace(/\.$/, "");
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LayoutNode } from "../../dom/node.js";
|
|
2
|
+
import type { ImageRef } from "../types.js";
|
|
3
|
+
import type { ImageInfo } from "../../image/types.js";
|
|
4
|
+
|
|
5
|
+
export function extractImageRef(node: LayoutNode): ImageRef | undefined {
|
|
6
|
+
if (node.tagName !== "img") {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const payload = node.customData?.image as
|
|
10
|
+
| { originalSrc?: string; resolvedSrc?: string; info?: ImageInfo }
|
|
11
|
+
| undefined;
|
|
12
|
+
if (!payload?.info) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const info = payload.info;
|
|
16
|
+
const src = payload.resolvedSrc ?? payload.originalSrc ?? "";
|
|
17
|
+
return {
|
|
18
|
+
src,
|
|
19
|
+
width: info.width,
|
|
20
|
+
height: info.height,
|
|
21
|
+
format: info.format,
|
|
22
|
+
channels: info.channels,
|
|
23
|
+
bitsPerComponent: info.bitsPerChannel,
|
|
24
|
+
data: info.data,
|
|
25
|
+
};
|
|
26
|
+
}
|