fontisan 0.4.49-java
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.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +141 -0
- data/.rubocop_todo.yml +433 -0
- data/BENCHMARKS.md +56 -0
- data/BUG-stitcher-drops-isolated-cps.md +58 -0
- data/BUG-stitcher-drops-plane1-codepoints.md +310 -0
- data/BUG-stitcher-gid-cap-65535.md +110 -0
- data/CHANGELOG.md +293 -0
- data/Cargo.lock +550 -0
- data/Cargo.toml +12 -0
- data/Gemfile +40 -0
- data/LICENSE +28 -0
- data/README.adoc +2811 -0
- data/Rakefile +156 -0
- data/TODO.bug-fixes/01-cff-expert-charsets.md +27 -0
- data/TODO.bug-fixes/02-cff2-subroutine-stubs.md +32 -0
- data/TODO.bug-fixes/03-variation-subsetter-placeholders.md +42 -0
- data/TODO.bug-fixes/04-ufo-image-compile-roundtrip.md +28 -0
- data/TODO.bug-fixes/05-stale-cff-comment.md +18 -0
- data/TODO.bug-fixes/06-instance-woff2-output.md +24 -0
- data/TODO.bug-fixes/07-encapsulation-violations.md +38 -0
- data/TODO.bug-fixes/08-respond-to-violations.md +25 -0
- data/TODO.bug-fixes/09-type1-cff-seac-expansion.md +22 -0
- data/TODO.bug-fixes/10-ttf-type1-composite-glyphs.md +23 -0
- data/TODO.bug-fixes/11-remaining-respond-to.md +25 -0
- data/TODO.bug-fixes/12-type1-generators-duck-typing.md +80 -0
- data/TODO.bug-fixes/13-hint-extractor-duck-typing.md +30 -0
- data/TODO.bug-fixes/14-font-interface-type-checks.md +82 -0
- data/TODO.bug-fixes/15-glyph-type-checks-and-simple-glyph-points-bug.md +49 -0
- data/TODO.bug-fixes/16-variation-table-checks.md +31 -0
- data/TODO.bug-fixes/17-ufo-and-stitcher-cleanup.md +32 -0
- data/TODO.bug-fixes/18-generic-value-and-io-checks.md +56 -0
- data/TODO.bug-fixes/19-serialization-migration.md +52 -0
- data/TODO.bug-fixes/20-variation-validator-type-checks.md +29 -0
- data/TODO.bug-fixes/21-xml-builder-send.md +24 -0
- data/TODO.bug-fixes/22-type1-converter-font-info.md +25 -0
- data/TODO.bug-fixes/23-boundary-type-checks.md +31 -0
- data/TODO.bug-fixes/24-validator-dynamic-field-key.md +25 -0
- data/TODO.bug-fixes/25-serialization-migration.md +49 -0
- data/TODO.bug-fixes/26-variation-preserver-spec-migration.md +25 -0
- data/TODO.bug-fixes/27-table-class-registry.md +50 -0
- data/TODO.bug-fixes/28-spec-doubles-cleanup.md +40 -0
- data/TODO.bug-fixes/29-strategy-registries.md +30 -0
- data/TODO.bug-fixes/30-eliminate-send-in-specs.md +36 -0
- data/TODO.bug-fixes/README.md +52 -0
- data/TODO.improvements/01-cbdt-cblc-gid-stable-propagation.md +73 -0
- data/TODO.improvements/02-collection-outline-priority.md +48 -0
- data/TODO.improvements/03-fontisan-audit-command.md +219 -0
- data/TODO.improvements/04-ufo-composite-glyph-encoding.md +46 -0
- data/TODO.improvements/05-otf-compiler-real-cff.md +63 -0
- data/TODO.improvements/06-cff2-blend-vsindex-operators.md +51 -0
- data/TODO.improvements/07-cpal-v1-header-fields.md +71 -0
- data/TODO.improvements/08-cff-standard-string-table.md +52 -0
- data/TODO.improvements/09-type1-seac-expansion.md +57 -0
- data/TODO.improvements/10-ufo-image-set-feature-writers.md +71 -0
- data/TODO.improvements/11-kern-groups-plist.md +49 -0
- data/TODO.improvements/12-cbdt-fixture-bindata-conversion.md +68 -0
- data/TODO.improvements/13-split-octokit-fetcher.md +45 -0
- data/TODO.improvements/14-rubocop-baseline-chip.md +62 -0
- data/TODO.improvements/15-cff-cff2-subsetter-strategy.md +78 -0
- data/TODO.improvements/README.md +58 -0
- data/benchmark/baseline.json +5 -0
- data/benchmark/ci_gate.rb +217 -0
- data/benchmark/compile_benchmark.rb +78 -0
- data/benchmark/corpus/harness.rb +175 -0
- data/benchmark/corpus/ops.rb +150 -0
- data/benchmark/corpus/run.rb +182 -0
- data/benchmark/corpus/scan_child.rb +8 -0
- data/benchmark/corpus/tiers.rb +176 -0
- data/benchmark/tier_baseline.json +12 -0
- data/benchmark/variation_quick_bench.rb +47 -0
- data/build_mingw32_stub.rb +15 -0
- data/docs/.gitignore +17 -0
- data/docs/.vitepress/config.ts +373 -0
- data/docs/.vitepress/theme/components/ApiMethod.vue +127 -0
- data/docs/.vitepress/theme/components/Badge.vue +51 -0
- data/docs/.vitepress/theme/components/FeatureComparison.vue +87 -0
- data/docs/.vitepress/theme/components/HeroCodeBlock.vue +98 -0
- data/docs/.vitepress/theme/components/WithinHero.vue +30 -0
- data/docs/.vitepress/theme/index.ts +22 -0
- data/docs/.vitepress/theme/style.css +628 -0
- data/docs/AFDKO_MIGRATION.adoc +175 -0
- data/docs/APPLE_LEGACY_FONTS.adoc +173 -0
- data/docs/CFF2_SUPPORT.adoc +184 -0
- data/docs/COLLECTION_VALIDATION.adoc +204 -0
- data/docs/COLOR_FONTS.adoc +127 -0
- data/docs/CONVERSION_GUIDE.adoc +656 -0
- data/docs/EXTRACT_TTC_MIGRATION.md +549 -0
- data/docs/FEATURE_PARITY.adoc +263 -0
- data/docs/FONT_HINTING.adoc +570 -0
- data/docs/STITCHER_GUIDE.adoc +436 -0
- data/docs/SVG_TO_GLYF.adoc +118 -0
- data/docs/TTX.adoc +176 -0
- data/docs/TYPE1_FONTS.adoc +445 -0
- data/docs/UFO_COMPILATION.adoc +397 -0
- data/docs/VALIDATION.adoc +254 -0
- data/docs/VARIABLE_FONT_OPERATIONS.adoc +599 -0
- data/docs/WOFF_WOFF2_FORMATS.adoc +220 -0
- data/docs/api/conversion-options.md +164 -0
- data/docs/api/converters/curve-converter.md +34 -0
- data/docs/api/converters/hint-converter.md +34 -0
- data/docs/api/converters/outline-converter.md +27 -0
- data/docs/api/font-loader.md +117 -0
- data/docs/api/font-writer.md +103 -0
- data/docs/api/index.md +79 -0
- data/docs/api/layer.md +89 -0
- data/docs/api/models/glyph-accessor.md +43 -0
- data/docs/api/models/glyph.md +40 -0
- data/docs/api/models/table-analyzer.md +35 -0
- data/docs/api/sfnt-font.md +53 -0
- data/docs/api/type1-font.md +43 -0
- data/docs/api/validators/font-validator.md +31 -0
- data/docs/api/validators/helper.md +36 -0
- data/docs/api/validators/profile.md +39 -0
- data/docs/cli/convert.md +148 -0
- data/docs/cli/dump-table.md +110 -0
- data/docs/cli/export.md +176 -0
- data/docs/cli/features.md +124 -0
- data/docs/cli/glyphs.md +90 -0
- data/docs/cli/index.md +232 -0
- data/docs/cli/info.md +254 -0
- data/docs/cli/instance.md +122 -0
- data/docs/cli/ls.md +95 -0
- data/docs/cli/optical-size.md +94 -0
- data/docs/cli/pack.md +125 -0
- data/docs/cli/scripts.md +105 -0
- data/docs/cli/subset.md +58 -0
- data/docs/cli/tables.md +84 -0
- data/docs/cli/unicode.md +101 -0
- data/docs/cli/validate-collection.md +95 -0
- data/docs/cli/validate.md +56 -0
- data/docs/cli/variable.md +126 -0
- data/docs/cli/version.md +46 -0
- data/docs/guide/cli/convert.md +108 -0
- data/docs/guide/cli/export.md +138 -0
- data/docs/guide/cli/index.md +99 -0
- data/docs/guide/cli/info.md +144 -0
- data/docs/guide/cli/pack.md +155 -0
- data/docs/guide/cli/subset.md +149 -0
- data/docs/guide/cli/validate.md +139 -0
- data/docs/guide/color-fonts/bitmaps.md +194 -0
- data/docs/guide/color-fonts/colr-cpal.md +175 -0
- data/docs/guide/color-fonts/index.md +140 -0
- data/docs/guide/color-fonts/svg.md +154 -0
- data/docs/guide/color.md +51 -0
- data/docs/guide/comparisons/font-validator.md +222 -0
- data/docs/guide/comparisons/fonttools.md +200 -0
- data/docs/guide/comparisons/index.md +83 -0
- data/docs/guide/comparisons/lcdf-typetools.md +205 -0
- data/docs/guide/contributing.md +279 -0
- data/docs/guide/conversion/collections.md +251 -0
- data/docs/guide/conversion/curves.md +246 -0
- data/docs/guide/conversion/index.md +157 -0
- data/docs/guide/conversion/options.md +280 -0
- data/docs/guide/conversion/ttf-otf.md +184 -0
- data/docs/guide/conversion/type1.md +208 -0
- data/docs/guide/conversion/web.md +299 -0
- data/docs/guide/conversion.md +40 -0
- data/docs/guide/engines.md +117 -0
- data/docs/guide/formats/collections.md +147 -0
- data/docs/guide/formats/dfont.md +99 -0
- data/docs/guide/formats/index.md +65 -0
- data/docs/guide/formats/otf.md +103 -0
- data/docs/guide/formats/svg.md +97 -0
- data/docs/guide/formats/ttf.md +105 -0
- data/docs/guide/formats/type1.md +118 -0
- data/docs/guide/formats/woff.md +139 -0
- data/docs/guide/hinting/autohint.md +141 -0
- data/docs/guide/hinting/conversion.md +161 -0
- data/docs/guide/hinting/index.md +86 -0
- data/docs/guide/hinting/postscript.md +149 -0
- data/docs/guide/hinting/truetype.md +135 -0
- data/docs/guide/hinting.md +44 -0
- data/docs/guide/index.md +152 -0
- data/docs/guide/installation.md +116 -0
- data/docs/guide/migrations/extract-ttc.md +549 -0
- data/docs/guide/migrations/font-validator.md +260 -0
- data/docs/guide/migrations/fonttools.md +208 -0
- data/docs/guide/migrations/index.md +64 -0
- data/docs/guide/migrations/otfinfo.md +197 -0
- data/docs/guide/quick-start.md +204 -0
- data/docs/guide/type1.md +58 -0
- data/docs/guide/universal-outline.md +151 -0
- data/docs/guide/validation/custom.md +195 -0
- data/docs/guide/validation/helpers.md +188 -0
- data/docs/guide/validation/index.md +132 -0
- data/docs/guide/validation/profiles.md +156 -0
- data/docs/guide/validation.md +47 -0
- data/docs/guide/variable-fonts/advanced.md +231 -0
- data/docs/guide/variable-fonts/axes.md +209 -0
- data/docs/guide/variable-fonts/conversion.md +197 -0
- data/docs/guide/variable-fonts/index.md +84 -0
- data/docs/guide/variable-fonts/instances.md +187 -0
- data/docs/guide/variable-fonts/named-instances.md +194 -0
- data/docs/guide/variable-fonts/static.md +168 -0
- data/docs/guide/variable.md +58 -0
- data/docs/guide/woff.md +61 -0
- data/docs/index.md +136 -0
- data/docs/lychee.toml +41 -0
- data/docs/package-lock.json +2560 -0
- data/docs/package.json +15 -0
- data/docs/public/apple-touch-icon.png +0 -0
- data/docs/public/favicon-96x96.png +0 -0
- data/docs/public/favicon.ico +0 -0
- data/docs/public/favicon.svg +1 -0
- data/docs/public/logo-full.svg +1 -0
- data/docs/public/logo.svg +1 -0
- data/docs/public/robots.txt +4 -0
- data/docs/public/site.webmanifest +21 -0
- data/docs/public/web-app-manifest-192x192.png +0 -0
- data/docs/public/web-app-manifest-512x512.png +0 -0
- data/docs/reference-facade.md +130 -0
- data/docs/scripts/post-build.mjs +81 -0
- data/exe/fontisan +7 -0
- data/lib/fontisan/audit/check.rb +47 -0
- data/lib/fontisan/audit/check_registry.rb +77 -0
- data/lib/fontisan/audit/checks/cff_table_check.rb +87 -0
- data/lib/fontisan/audit/checks/cmap_check.rb +256 -0
- data/lib/fontisan/audit/checks/collection_integrity_check.rb +102 -0
- data/lib/fontisan/audit/checks/format_round_trip_check.rb +150 -0
- data/lib/fontisan/audit/checks/glyf_table_check.rb +115 -0
- data/lib/fontisan/audit/checks/glyph_name_check.rb +107 -0
- data/lib/fontisan/audit/checks/head_check.rb +96 -0
- data/lib/fontisan/audit/checks/hhea_check.rb +68 -0
- data/lib/fontisan/audit/checks/hinting_check.rb +163 -0
- data/lib/fontisan/audit/checks/kern_check.rb +47 -0
- data/lib/fontisan/audit/checks/layout_table_check.rb +70 -0
- data/lib/fontisan/audit/checks/maxp_check.rb +85 -0
- data/lib/fontisan/audit/checks/name_table_check.rb +78 -0
- data/lib/fontisan/audit/checks/naming_consistency_check.rb +102 -0
- data/lib/fontisan/audit/checks/opentype_conformance_check.rb +108 -0
- data/lib/fontisan/audit/checks/os2_check.rb +117 -0
- data/lib/fontisan/audit/checks/ots_compatibility_check.rb +191 -0
- data/lib/fontisan/audit/checks/post_check.rb +75 -0
- data/lib/fontisan/audit/checks/table_directory_check.rb +157 -0
- data/lib/fontisan/audit/checks/variable_font_check.rb +151 -0
- data/lib/fontisan/audit/checks/woff2_validation_check.rb +140 -0
- data/lib/fontisan/audit/checks.rb +42 -0
- data/lib/fontisan/audit.rb +20 -0
- data/lib/fontisan/base_collection.rb +312 -0
- data/lib/fontisan/binary/base_record.rb +82 -0
- data/lib/fontisan/binary/structures.rb +82 -0
- data/lib/fontisan/binary.rb +11 -0
- data/lib/fontisan/byte_ops.rb +314 -0
- data/lib/fontisan/cli.rb +1111 -0
- data/lib/fontisan/collection/builder.rb +336 -0
- data/lib/fontisan/collection/dfont_builder.rb +305 -0
- data/lib/fontisan/collection/offset_calculator.rb +229 -0
- data/lib/fontisan/collection/reader/stats.rb +23 -0
- data/lib/fontisan/collection/reader.rb +90 -0
- data/lib/fontisan/collection/shared_logic.rb +52 -0
- data/lib/fontisan/collection/table_analyzer.rb +289 -0
- data/lib/fontisan/collection/table_deduplicator.rb +317 -0
- data/lib/fontisan/collection/writer.rb +289 -0
- data/lib/fontisan/collection.rb +16 -0
- data/lib/fontisan/commands/audit_command.rb +288 -0
- data/lib/fontisan/commands/base_command.rb +88 -0
- data/lib/fontisan/commands/convert_command.rb +506 -0
- data/lib/fontisan/commands/dump_table_command.rb +68 -0
- data/lib/fontisan/commands/export_command.rb +157 -0
- data/lib/fontisan/commands/features_command.rb +90 -0
- data/lib/fontisan/commands/glyphs_command.rb +50 -0
- data/lib/fontisan/commands/info_command.rb +447 -0
- data/lib/fontisan/commands/instance_command.rb +357 -0
- data/lib/fontisan/commands/ls_command.rb +107 -0
- data/lib/fontisan/commands/multi_format_output.rb +64 -0
- data/lib/fontisan/commands/optical_size_command.rb +38 -0
- data/lib/fontisan/commands/pack_command.rb +344 -0
- data/lib/fontisan/commands/scripts_command.rb +56 -0
- data/lib/fontisan/commands/subset_command.rb +285 -0
- data/lib/fontisan/commands/tables_command.rb +52 -0
- data/lib/fontisan/commands/unicode_command.rb +73 -0
- data/lib/fontisan/commands/unpack_command.rb +387 -0
- data/lib/fontisan/commands/validate_collection_command.rb +127 -0
- data/lib/fontisan/commands/validate_command.rb +305 -0
- data/lib/fontisan/commands/variable_command.rb +87 -0
- data/lib/fontisan/commands.rb +30 -0
- data/lib/fontisan/config/collection_settings.yml +56 -0
- data/lib/fontisan/config/conversion_matrix.yml +626 -0
- data/lib/fontisan/config/export_settings.yml +66 -0
- data/lib/fontisan/config/features.yml +143 -0
- data/lib/fontisan/config/scripts.yml +42 -0
- data/lib/fontisan/config/subset_profiles.yml +106 -0
- data/lib/fontisan/config/svg_settings.yml +60 -0
- data/lib/fontisan/config/variable_settings.yml +99 -0
- data/lib/fontisan/config/woff2_settings.yml +77 -0
- data/lib/fontisan/constants.rb +219 -0
- data/lib/fontisan/conversion_options.rb +389 -0
- data/lib/fontisan/converters/cff_table_builder.rb +195 -0
- data/lib/fontisan/converters/collection_converter.rb +520 -0
- data/lib/fontisan/converters/conversion_strategy.rb +211 -0
- data/lib/fontisan/converters/format_converter.rb +536 -0
- data/lib/fontisan/converters/glyf_table_builder.rb +61 -0
- data/lib/fontisan/converters/outline_converter.rb +720 -0
- data/lib/fontisan/converters/outline_extraction.rb +88 -0
- data/lib/fontisan/converters/outline_optimizer.rb +84 -0
- data/lib/fontisan/converters/svg_generator.rb +236 -0
- data/lib/fontisan/converters/table_copier.rb +107 -0
- data/lib/fontisan/converters/type1_converter.rb +1201 -0
- data/lib/fontisan/converters/woff2_encoder.rb +520 -0
- data/lib/fontisan/converters/woff_writer.rb +358 -0
- data/lib/fontisan/converters.rb +21 -0
- data/lib/fontisan/dfont_collection.rb +288 -0
- data/lib/fontisan/engine.rb +393 -0
- data/lib/fontisan/error.rb +281 -0
- data/lib/fontisan/export/exporter.rb +255 -0
- data/lib/fontisan/export/table_serializer.rb +140 -0
- data/lib/fontisan/export/transformers/font_to_ttx.rb +163 -0
- data/lib/fontisan/export/transformers/head_transformer.rb +94 -0
- data/lib/fontisan/export/transformers/hhea_transformer.rb +57 -0
- data/lib/fontisan/export/transformers/maxp_transformer.rb +61 -0
- data/lib/fontisan/export/transformers/name_transformer.rb +61 -0
- data/lib/fontisan/export/transformers/os2_transformer.rb +119 -0
- data/lib/fontisan/export/transformers/post_transformer.rb +49 -0
- data/lib/fontisan/export/transformers.rb +17 -0
- data/lib/fontisan/export/ttx_generator.rb +526 -0
- data/lib/fontisan/export/ttx_parser.rb +300 -0
- data/lib/fontisan/export.rb +13 -0
- data/lib/fontisan/ffi/client.rb +123 -0
- data/lib/fontisan/ffi/darwin-arm64/libfontisan_cdylib.dylib +0 -0
- data/lib/fontisan/ffi/darwin-x86_64/libfontisan_cdylib.dylib +0 -0
- data/lib/fontisan/ffi/linux-x86_64/libfontisan_cdylib.so +0 -0
- data/lib/fontisan/ffi/windows-x86_64/fontisan_cdylib.dll +0 -0
- data/lib/fontisan/ffi.rb +387 -0
- data/lib/fontisan/ffi_platform.rb +24 -0
- data/lib/fontisan/font_loader.rb +315 -0
- data/lib/fontisan/font_writer.rb +309 -0
- data/lib/fontisan/formatters/text_formatter.rb +517 -0
- data/lib/fontisan/formatters.rb +9 -0
- data/lib/fontisan/glyph_accessor.rb +525 -0
- data/lib/fontisan/hints/hint_converter.rb +309 -0
- data/lib/fontisan/hints/hint_validator.rb +287 -0
- data/lib/fontisan/hints/postscript_hint_applier.rb +255 -0
- data/lib/fontisan/hints/postscript_hint_extractor.rb +347 -0
- data/lib/fontisan/hints/truetype_hint_applier.rb +117 -0
- data/lib/fontisan/hints/truetype_hint_extractor.rb +283 -0
- data/lib/fontisan/hints/truetype_instruction_analyzer.rb +268 -0
- data/lib/fontisan/hints/truetype_instruction_generator.rb +266 -0
- data/lib/fontisan/hints.rb +19 -0
- data/lib/fontisan/loading_modes.rb +113 -0
- data/lib/fontisan/metrics_calculator.rb +275 -0
- data/lib/fontisan/models/all_scripts_features_info.rb +20 -0
- data/lib/fontisan/models/audit_report.rb +196 -0
- data/lib/fontisan/models/bitmap_glyph.rb +123 -0
- data/lib/fontisan/models/bitmap_strike.rb +94 -0
- data/lib/fontisan/models/collection_brief_info.rb +36 -0
- data/lib/fontisan/models/collection_font_summary.rb +52 -0
- data/lib/fontisan/models/collection_info.rb +79 -0
- data/lib/fontisan/models/collection_list_info.rb +36 -0
- data/lib/fontisan/models/collection_validation_report.rb +102 -0
- data/lib/fontisan/models/color_glyph.rb +56 -0
- data/lib/fontisan/models/color_layer.rb +53 -0
- data/lib/fontisan/models/color_palette.rb +60 -0
- data/lib/fontisan/models/features_info.rb +42 -0
- data/lib/fontisan/models/font_export.rb +158 -0
- data/lib/fontisan/models/font_info.rb +98 -0
- data/lib/fontisan/models/font_report.rb +23 -0
- data/lib/fontisan/models/font_summary.rb +48 -0
- data/lib/fontisan/models/glyph_info.rb +26 -0
- data/lib/fontisan/models/glyph_outline.rb +343 -0
- data/lib/fontisan/models/hint.rb +404 -0
- data/lib/fontisan/models/optical_size_info.rb +33 -0
- data/lib/fontisan/models/outline.rb +667 -0
- data/lib/fontisan/models/scripts_info.rb +39 -0
- data/lib/fontisan/models/svg_glyph.rb +89 -0
- data/lib/fontisan/models/table_info.rb +55 -0
- data/lib/fontisan/models/table_sharing_info.rb +40 -0
- data/lib/fontisan/models/ttx/glyph_order.rb +31 -0
- data/lib/fontisan/models/ttx/tables/binary_table.rb +67 -0
- data/lib/fontisan/models/ttx/tables/head_table.rb +74 -0
- data/lib/fontisan/models/ttx/tables/hhea_table.rb +74 -0
- data/lib/fontisan/models/ttx/tables/maxp_table.rb +55 -0
- data/lib/fontisan/models/ttx/tables/name_table.rb +45 -0
- data/lib/fontisan/models/ttx/tables/os2_table.rb +157 -0
- data/lib/fontisan/models/ttx/tables/post_table.rb +50 -0
- data/lib/fontisan/models/ttx/tables.rb +21 -0
- data/lib/fontisan/models/ttx/ttfont.rb +41 -0
- data/lib/fontisan/models/ttx.rb +14 -0
- data/lib/fontisan/models/unicode_mappings.rb +42 -0
- data/lib/fontisan/models/validation_report.rb +435 -0
- data/lib/fontisan/models/variable_font_info.rb +82 -0
- data/lib/fontisan/models.rb +49 -0
- data/lib/fontisan/native.rb +235 -0
- data/lib/fontisan/open_type_collection.rb +49 -0
- data/lib/fontisan/open_type_font.rb +161 -0
- data/lib/fontisan/open_type_font_extensions.rb +54 -0
- data/lib/fontisan/optimizers/charstring_rewriter.rb +172 -0
- data/lib/fontisan/optimizers/pattern_analyzer.rb +310 -0
- data/lib/fontisan/optimizers/stack_tracker.rb +246 -0
- data/lib/fontisan/optimizers/subroutine_builder.rb +135 -0
- data/lib/fontisan/optimizers/subroutine_generator.rb +207 -0
- data/lib/fontisan/optimizers/subroutine_optimizer.rb +114 -0
- data/lib/fontisan/optimizers.rb +14 -0
- data/lib/fontisan/outline_extractor.rb +417 -0
- data/lib/fontisan/output_guard.rb +40 -0
- data/lib/fontisan/parsers/dfont_parser.rb +191 -0
- data/lib/fontisan/parsers/tag.rb +77 -0
- data/lib/fontisan/parsers.rb +10 -0
- data/lib/fontisan/pipeline/format_detector.rb +176 -0
- data/lib/fontisan/pipeline/output_writer.rb +161 -0
- data/lib/fontisan/pipeline/strategies/base_strategy.rb +75 -0
- data/lib/fontisan/pipeline/strategies/instance_strategy.rb +89 -0
- data/lib/fontisan/pipeline/strategies/named_strategy.rb +114 -0
- data/lib/fontisan/pipeline/strategies/preserve_strategy.rb +54 -0
- data/lib/fontisan/pipeline/strategies.rb +16 -0
- data/lib/fontisan/pipeline/transformation_pipeline.rb +407 -0
- data/lib/fontisan/pipeline/variation_resolver.rb +158 -0
- data/lib/fontisan/pipeline.rb +14 -0
- data/lib/fontisan/reference/table_digests.rb +251 -0
- data/lib/fontisan/reference.rb +663 -0
- data/lib/fontisan/scan.rb +372 -0
- data/lib/fontisan/sfnt_builder.rb +66 -0
- data/lib/fontisan/sfnt_directory.rb +41 -0
- data/lib/fontisan/sfnt_font.rb +749 -0
- data/lib/fontisan/sfnt_source.rb +28 -0
- data/lib/fontisan/sfnt_table.rb +260 -0
- data/lib/fontisan/stitcher/cbdt_propagator.rb +212 -0
- data/lib/fontisan/stitcher/collection_result.rb +19 -0
- data/lib/fontisan/stitcher/deduplicator.rb +47 -0
- data/lib/fontisan/stitcher/format_metadata.rb +51 -0
- data/lib/fontisan/stitcher/glyph_cloner.rb +41 -0
- data/lib/fontisan/stitcher/glyph_copier.rb +110 -0
- data/lib/fontisan/stitcher/glyph_limit.rb +53 -0
- data/lib/fontisan/stitcher/glyph_signature.rb +51 -0
- data/lib/fontisan/stitcher/partition_strategy/base.rb +52 -0
- data/lib/fontisan/stitcher/partition_strategy/blueprint.rb +24 -0
- data/lib/fontisan/stitcher/partition_strategy/by_block.rb +430 -0
- data/lib/fontisan/stitcher/partition_strategy/by_plane.rb +161 -0
- data/lib/fontisan/stitcher/partition_strategy/by_script.rb +309 -0
- data/lib/fontisan/stitcher/partition_strategy/partition.rb +24 -0
- data/lib/fontisan/stitcher/partition_strategy.rb +24 -0
- data/lib/fontisan/stitcher/selector/codepoints.rb +29 -0
- data/lib/fontisan/stitcher/selector/gid.rb +25 -0
- data/lib/fontisan/stitcher/selector/range.rb +30 -0
- data/lib/fontisan/stitcher/selector.rb +26 -0
- data/lib/fontisan/stitcher/source.rb +459 -0
- data/lib/fontisan/stitcher/unique_glyph_name.rb +46 -0
- data/lib/fontisan/stitcher.rb +185 -0
- data/lib/fontisan/stitcher_cli.rb +69 -0
- data/lib/fontisan/subset/builder.rb +263 -0
- data/lib/fontisan/subset/glyph_mapping.rb +222 -0
- data/lib/fontisan/subset/options.rb +142 -0
- data/lib/fontisan/subset/profile.rb +152 -0
- data/lib/fontisan/subset/shared_state.rb +42 -0
- data/lib/fontisan/subset/subset_context.rb +20 -0
- data/lib/fontisan/subset/table_strategy/cbdt.rb +30 -0
- data/lib/fontisan/subset/table_strategy/cblc.rb +27 -0
- data/lib/fontisan/subset/table_strategy/cff.rb +92 -0
- data/lib/fontisan/subset/table_strategy/cff2.rb +391 -0
- data/lib/fontisan/subset/table_strategy/cmap.rb +146 -0
- data/lib/fontisan/subset/table_strategy/color_bitmap_placement.rb +20 -0
- data/lib/fontisan/subset/table_strategy/color_bitmap_strike_plan.rb +45 -0
- data/lib/fontisan/subset/table_strategy/color_bitmap_subset_plan.rb +62 -0
- data/lib/fontisan/subset/table_strategy/color_bitmap_subsetter.rb +182 -0
- data/lib/fontisan/subset/table_strategy/color_bitmap_subtable_plan.rb +59 -0
- data/lib/fontisan/subset/table_strategy/glyf.rb +29 -0
- data/lib/fontisan/subset/table_strategy/glyf_loca_builder.rb +146 -0
- data/lib/fontisan/subset/table_strategy/head.rb +43 -0
- data/lib/fontisan/subset/table_strategy/hhea.rb +67 -0
- data/lib/fontisan/subset/table_strategy/hmtx.rb +52 -0
- data/lib/fontisan/subset/table_strategy/loca.rb +41 -0
- data/lib/fontisan/subset/table_strategy/maxp.rb +23 -0
- data/lib/fontisan/subset/table_strategy/name.rb +19 -0
- data/lib/fontisan/subset/table_strategy/os2.rb +21 -0
- data/lib/fontisan/subset/table_strategy/pass_through.rb +20 -0
- data/lib/fontisan/subset/table_strategy/post.rb +37 -0
- data/lib/fontisan/subset/table_strategy.rb +79 -0
- data/lib/fontisan/subset/table_subsetter.rb +110 -0
- data/lib/fontisan/subset.rb +16 -0
- data/lib/fontisan/svg/font_face_generator.rb +274 -0
- data/lib/fontisan/svg/font_generator.rb +256 -0
- data/lib/fontisan/svg/glyph_generator.rb +201 -0
- data/lib/fontisan/svg/standalone_glyph.rb +132 -0
- data/lib/fontisan/svg/view_box_calculator.rb +137 -0
- data/lib/fontisan/svg.rb +13 -0
- data/lib/fontisan/svg_to_glyf/assembler.rb +174 -0
- data/lib/fontisan/svg_to_glyf/document.rb +102 -0
- data/lib/fontisan/svg_to_glyf/geometry/affine_transform.rb +112 -0
- data/lib/fontisan/svg_to_glyf/geometry/normalizer.rb +62 -0
- data/lib/fontisan/svg_to_glyf/geometry/transform_parser.rb +98 -0
- data/lib/fontisan/svg_to_glyf/geometry.rb +15 -0
- data/lib/fontisan/svg_to_glyf/path/command.rb +18 -0
- data/lib/fontisan/svg_to_glyf/path/contour_builder.rb +140 -0
- data/lib/fontisan/svg_to_glyf/path/parser.rb +98 -0
- data/lib/fontisan/svg_to_glyf/path/state.rb +79 -0
- data/lib/fontisan/svg_to_glyf/path.rb +14 -0
- data/lib/fontisan/svg_to_glyf.rb +62 -0
- data/lib/fontisan/tables/cbdt.rb +113 -0
- data/lib/fontisan/tables/cblc.rb +172 -0
- data/lib/fontisan/tables/cblc_big_glyph_metrics.rb +28 -0
- data/lib/fontisan/tables/cblc_bitmap_size.rb +67 -0
- data/lib/fontisan/tables/cblc_glyph_bitmap_location.rb +28 -0
- data/lib/fontisan/tables/cblc_index_subtable.rb +104 -0
- data/lib/fontisan/tables/cblc_index_subtable_array_entry.rb +20 -0
- data/lib/fontisan/tables/cblc_index_subtable_format_parser.rb +150 -0
- data/lib/fontisan/tables/cblc_index_subtable_header.rb +18 -0
- data/lib/fontisan/tables/cblc_sbit_line_metrics.rb +28 -0
- data/lib/fontisan/tables/cff/cff2_charstring_builder.rb +225 -0
- data/lib/fontisan/tables/cff/cff_glyph.rb +176 -0
- data/lib/fontisan/tables/cff/charset.rb +276 -0
- data/lib/fontisan/tables/cff/charstring.rb +978 -0
- data/lib/fontisan/tables/cff/charstring_builder.rb +356 -0
- data/lib/fontisan/tables/cff/charstring_parser.rb +249 -0
- data/lib/fontisan/tables/cff/charstring_rebuilder.rb +168 -0
- data/lib/fontisan/tables/cff/charstrings_index.rb +159 -0
- data/lib/fontisan/tables/cff/dict.rb +353 -0
- data/lib/fontisan/tables/cff/dict_builder.rb +260 -0
- data/lib/fontisan/tables/cff/encoding.rb +273 -0
- data/lib/fontisan/tables/cff/expert_charsets.rb +85 -0
- data/lib/fontisan/tables/cff/header.rb +100 -0
- data/lib/fontisan/tables/cff/hint_operation_injector.rb +207 -0
- data/lib/fontisan/tables/cff/index.rb +241 -0
- data/lib/fontisan/tables/cff/index_builder.rb +170 -0
- data/lib/fontisan/tables/cff/offset_recalculator.rb +70 -0
- data/lib/fontisan/tables/cff/private_dict.rb +282 -0
- data/lib/fontisan/tables/cff/private_dict_writer.rb +129 -0
- data/lib/fontisan/tables/cff/standard_strings_data.rb +83 -0
- data/lib/fontisan/tables/cff/table_builder.rb +215 -0
- data/lib/fontisan/tables/cff/top_dict.rb +234 -0
- data/lib/fontisan/tables/cff.rb +497 -0
- data/lib/fontisan/tables/cff2/blend_operator.rb +240 -0
- data/lib/fontisan/tables/cff2/charstring_parser.rb +624 -0
- data/lib/fontisan/tables/cff2/dict_encoder.rb +94 -0
- data/lib/fontisan/tables/cff2/fd_select.rb +142 -0
- data/lib/fontisan/tables/cff2/header.rb +34 -0
- data/lib/fontisan/tables/cff2/index.rb +155 -0
- data/lib/fontisan/tables/cff2/index_builder.rb +80 -0
- data/lib/fontisan/tables/cff2/operand_stack.rb +232 -0
- data/lib/fontisan/tables/cff2/private_dict_blend_handler.rb +247 -0
- data/lib/fontisan/tables/cff2/region_matcher.rb +200 -0
- data/lib/fontisan/tables/cff2/table_builder.rb +567 -0
- data/lib/fontisan/tables/cff2/table_reader.rb +418 -0
- data/lib/fontisan/tables/cff2/variation_data_extractor.rb +212 -0
- data/lib/fontisan/tables/cff2.rb +353 -0
- data/lib/fontisan/tables/cmap.rb +399 -0
- data/lib/fontisan/tables/cmap_table.rb +228 -0
- data/lib/fontisan/tables/colr.rb +290 -0
- data/lib/fontisan/tables/cpal.rb +381 -0
- data/lib/fontisan/tables/cvar.rb +204 -0
- data/lib/fontisan/tables/fvar.rb +159 -0
- data/lib/fontisan/tables/glyf/compound_glyph.rb +482 -0
- data/lib/fontisan/tables/glyf/compound_glyph_resolver.rb +135 -0
- data/lib/fontisan/tables/glyf/curve_converter.rb +349 -0
- data/lib/fontisan/tables/glyf/glyph_builder.rb +468 -0
- data/lib/fontisan/tables/glyf/simple_glyph.rb +391 -0
- data/lib/fontisan/tables/glyf.rb +347 -0
- data/lib/fontisan/tables/glyf_table.rb +252 -0
- data/lib/fontisan/tables/gpos/glyph_filter.rb +87 -0
- data/lib/fontisan/tables/gpos/kerning_pairs.rb +215 -0
- data/lib/fontisan/tables/gpos/pair_position.rb +274 -0
- data/lib/fontisan/tables/gpos.rb +139 -0
- data/lib/fontisan/tables/gsub.rb +116 -0
- data/lib/fontisan/tables/gvar.rb +232 -0
- data/lib/fontisan/tables/head.rb +208 -0
- data/lib/fontisan/tables/head_table.rb +108 -0
- data/lib/fontisan/tables/hhea.rb +199 -0
- data/lib/fontisan/tables/hhea_table.rb +252 -0
- data/lib/fontisan/tables/hmtx.rb +281 -0
- data/lib/fontisan/tables/hmtx_table.rb +188 -0
- data/lib/fontisan/tables/hvar.rb +192 -0
- data/lib/fontisan/tables/layout_common.rb +245 -0
- data/lib/fontisan/tables/loca.rb +323 -0
- data/lib/fontisan/tables/loca_table.rb +209 -0
- data/lib/fontisan/tables/maxp.rb +253 -0
- data/lib/fontisan/tables/maxp_table.rb +255 -0
- data/lib/fontisan/tables/mvar.rb +185 -0
- data/lib/fontisan/tables/name.rb +340 -0
- data/lib/fontisan/tables/name_table.rb +173 -0
- data/lib/fontisan/tables/os2.rb +291 -0
- data/lib/fontisan/tables/os2_table.rb +326 -0
- data/lib/fontisan/tables/post.rb +206 -0
- data/lib/fontisan/tables/post_table.rb +180 -0
- data/lib/fontisan/tables/registry.rb +71 -0
- data/lib/fontisan/tables/sbix.rb +379 -0
- data/lib/fontisan/tables/svg.rb +300 -0
- data/lib/fontisan/tables/variation_common.rb +345 -0
- data/lib/fontisan/tables/vvar.rb +234 -0
- data/lib/fontisan/tables.rb +69 -0
- data/lib/fontisan/true_type_collection.rb +160 -0
- data/lib/fontisan/true_type_font.rb +80 -0
- data/lib/fontisan/true_type_font_extensions.rb +54 -0
- data/lib/fontisan/type1/afm_generator.rb +379 -0
- data/lib/fontisan/type1/afm_parser.rb +299 -0
- data/lib/fontisan/type1/agl.rb +456 -0
- data/lib/fontisan/type1/cff_to_type1_converter.rb +307 -0
- data/lib/fontisan/type1/charstring_converter.rb +238 -0
- data/lib/fontisan/type1/charstrings.rb +441 -0
- data/lib/fontisan/type1/conversion_options.rb +242 -0
- data/lib/fontisan/type1/decryptor.rb +183 -0
- data/lib/fontisan/type1/encodings.rb +695 -0
- data/lib/fontisan/type1/font_dictionary.rb +576 -0
- data/lib/fontisan/type1/generator.rb +217 -0
- data/lib/fontisan/type1/inf_generator.rb +307 -0
- data/lib/fontisan/type1/pfa_generator.rb +376 -0
- data/lib/fontisan/type1/pfa_parser.rb +159 -0
- data/lib/fontisan/type1/pfb_generator.rb +321 -0
- data/lib/fontisan/type1/pfb_parser.rb +166 -0
- data/lib/fontisan/type1/pfm_generator.rb +589 -0
- data/lib/fontisan/type1/pfm_parser.rb +433 -0
- data/lib/fontisan/type1/private_dict.rb +363 -0
- data/lib/fontisan/type1/seac_expander.rb +517 -0
- data/lib/fontisan/type1/ttf_to_type1_converter.rb +389 -0
- data/lib/fontisan/type1/upm_scaler.rb +118 -0
- data/lib/fontisan/type1.rb +48 -0
- data/lib/fontisan/type1_font.rb +347 -0
- data/lib/fontisan/ufo/anchor.rb +17 -0
- data/lib/fontisan/ufo/bounds.rb +91 -0
- data/lib/fontisan/ufo/cli.rb +105 -0
- data/lib/fontisan/ufo/compile/avar.rb +46 -0
- data/lib/fontisan/ufo/compile/base_compiler.rb +162 -0
- data/lib/fontisan/ufo/compile/cbdt_cblc.rb +104 -0
- data/lib/fontisan/ufo/compile/cff.rb +229 -0
- data/lib/fontisan/ufo/compile/cff2.rb +323 -0
- data/lib/fontisan/ufo/compile/cff2_subroutines.rb +39 -0
- data/lib/fontisan/ufo/compile/cmap.rb +143 -0
- data/lib/fontisan/ufo/compile/colr.rb +80 -0
- data/lib/fontisan/ufo/compile/cpal.rb +62 -0
- data/lib/fontisan/ufo/compile/feature_compiler.rb +161 -0
- data/lib/fontisan/ufo/compile/feature_writers/base.rb +56 -0
- data/lib/fontisan/ufo/compile/feature_writers/curs.rb +72 -0
- data/lib/fontisan/ufo/compile/feature_writers/gdef.rb +92 -0
- data/lib/fontisan/ufo/compile/feature_writers/kern.rb +50 -0
- data/lib/fontisan/ufo/compile/feature_writers/kern2.rb +57 -0
- data/lib/fontisan/ufo/compile/feature_writers/mark.rb +45 -0
- data/lib/fontisan/ufo/compile/feature_writers/mark_family_base.rb +124 -0
- data/lib/fontisan/ufo/compile/feature_writers/mkmk.rb +53 -0
- data/lib/fontisan/ufo/compile/feature_writers.rb +38 -0
- data/lib/fontisan/ufo/compile/filters/cubic_to_quadratic.rb +176 -0
- data/lib/fontisan/ufo/compile/filters/decompose_components.rb +33 -0
- data/lib/fontisan/ufo/compile/filters/flatten_components.rb +22 -0
- data/lib/fontisan/ufo/compile/filters/propagate_anchors.rb +102 -0
- data/lib/fontisan/ufo/compile/filters/remove_overlaps.rb +95 -0
- data/lib/fontisan/ufo/compile/filters/reverse_contour_direction.rb +27 -0
- data/lib/fontisan/ufo/compile/filters/sort_contours.rb +69 -0
- data/lib/fontisan/ufo/compile/filters/transformations.rb +113 -0
- data/lib/fontisan/ufo/compile/filters.rb +69 -0
- data/lib/fontisan/ufo/compile/fvar.rb +113 -0
- data/lib/fontisan/ufo/compile/glyf_loca.rb +206 -0
- data/lib/fontisan/ufo/compile/gpos.rb +248 -0
- data/lib/fontisan/ufo/compile/gsub.rb +267 -0
- data/lib/fontisan/ufo/compile/gvar.rb +225 -0
- data/lib/fontisan/ufo/compile/head.rb +97 -0
- data/lib/fontisan/ufo/compile/hhea.rb +57 -0
- data/lib/fontisan/ufo/compile/hmtx.rb +38 -0
- data/lib/fontisan/ufo/compile/hvar.rb +42 -0
- data/lib/fontisan/ufo/compile/item_variation_store.rb +100 -0
- data/lib/fontisan/ufo/compile/math.rb +143 -0
- data/lib/fontisan/ufo/compile/maxp.rb +57 -0
- data/lib/fontisan/ufo/compile/meta.rb +51 -0
- data/lib/fontisan/ufo/compile/mvar.rb +59 -0
- data/lib/fontisan/ufo/compile/name.rb +81 -0
- data/lib/fontisan/ufo/compile/os2.rb +81 -0
- data/lib/fontisan/ufo/compile/otf2_compiler.rb +40 -0
- data/lib/fontisan/ufo/compile/otf_compiler.rb +34 -0
- data/lib/fontisan/ufo/compile/post.rb +32 -0
- data/lib/fontisan/ufo/compile/sbix.rb +100 -0
- data/lib/fontisan/ufo/compile/stat.rb +106 -0
- data/lib/fontisan/ufo/compile/svg_table.rb +60 -0
- data/lib/fontisan/ufo/compile/ttf_compiler.rb +75 -0
- data/lib/fontisan/ufo/compile/variable_otf.rb +84 -0
- data/lib/fontisan/ufo/compile/variable_ttf.rb +161 -0
- data/lib/fontisan/ufo/compile.rb +72 -0
- data/lib/fontisan/ufo/component.rb +18 -0
- data/lib/fontisan/ufo/contour.rb +34 -0
- data/lib/fontisan/ufo/convert/from_bin_data.rb +366 -0
- data/lib/fontisan/ufo/convert/to_dfont.rb +45 -0
- data/lib/fontisan/ufo/convert/to_otc.rb +40 -0
- data/lib/fontisan/ufo/convert/to_otf.rb +18 -0
- data/lib/fontisan/ufo/convert/to_otf2.rb +20 -0
- data/lib/fontisan/ufo/convert/to_postscript.rb +64 -0
- data/lib/fontisan/ufo/convert/to_ttc.rb +35 -0
- data/lib/fontisan/ufo/convert/to_ttf.rb +21 -0
- data/lib/fontisan/ufo/convert/to_woff.rb +61 -0
- data/lib/fontisan/ufo/convert/to_woff2.rb +50 -0
- data/lib/fontisan/ufo/convert.rb +84 -0
- data/lib/fontisan/ufo/data_set.rb +21 -0
- data/lib/fontisan/ufo/features.rb +17 -0
- data/lib/fontisan/ufo/font.rb +63 -0
- data/lib/fontisan/ufo/glyph.rb +445 -0
- data/lib/fontisan/ufo/glyph_exists_error.rb +23 -0
- data/lib/fontisan/ufo/groups.rb +45 -0
- data/lib/fontisan/ufo/guideline.rb +19 -0
- data/lib/fontisan/ufo/image.rb +29 -0
- data/lib/fontisan/ufo/image_set.rb +99 -0
- data/lib/fontisan/ufo/info.rb +133 -0
- data/lib/fontisan/ufo/kerning.rb +32 -0
- data/lib/fontisan/ufo/layer.rb +78 -0
- data/lib/fontisan/ufo/layer_set.rb +37 -0
- data/lib/fontisan/ufo/lib.rb +24 -0
- data/lib/fontisan/ufo/plist.rb +123 -0
- data/lib/fontisan/ufo/point.rb +32 -0
- data/lib/fontisan/ufo/reader.rb +163 -0
- data/lib/fontisan/ufo/transformation.rb +50 -0
- data/lib/fontisan/ufo/writer.rb +123 -0
- data/lib/fontisan/ufo.rb +47 -0
- data/lib/fontisan/unicode/plane.rb +44 -0
- data/lib/fontisan/unicode.rb +17 -0
- data/lib/fontisan/utilities/brotli_wrapper.rb +177 -0
- data/lib/fontisan/utilities/checksum_calculator.rb +104 -0
- data/lib/fontisan/utilities/padding.rb +61 -0
- data/lib/fontisan/utilities.rb +11 -0
- data/lib/fontisan/utils/thread_pool.rb +134 -0
- data/lib/fontisan/utils.rb +10 -0
- data/lib/fontisan/validation/collection_validator.rb +265 -0
- data/lib/fontisan/validation.rb +9 -0
- data/lib/fontisan/validators/basic_validator.rb +73 -0
- data/lib/fontisan/validators/font_book_validator.rb +107 -0
- data/lib/fontisan/validators/opentype_validator.rb +118 -0
- data/lib/fontisan/validators/profile_loader.rb +134 -0
- data/lib/fontisan/validators/validator.rb +494 -0
- data/lib/fontisan/validators/web_font_validator.rb +95 -0
- data/lib/fontisan/validators.rb +14 -0
- data/lib/fontisan/variable/axis_normalizer.rb +215 -0
- data/lib/fontisan/variable/delta_applicator.rb +302 -0
- data/lib/fontisan/variable/glyph_delta_processor.rb +218 -0
- data/lib/fontisan/variable/instancer.rb +172 -0
- data/lib/fontisan/variable/metric_delta_processor.rb +282 -0
- data/lib/fontisan/variable/region_matcher.rb +208 -0
- data/lib/fontisan/variable/static_font_builder.rb +209 -0
- data/lib/fontisan/variable/table_updater.rb +219 -0
- data/lib/fontisan/variable.rb +16 -0
- data/lib/fontisan/variation/blend_applier.rb +197 -0
- data/lib/fontisan/variation/cache.rb +299 -0
- data/lib/fontisan/variation/cache_key_builder.rb +162 -0
- data/lib/fontisan/variation/converter.rb +373 -0
- data/lib/fontisan/variation/data_extractor.rb +84 -0
- data/lib/fontisan/variation/delta_applier.rb +262 -0
- data/lib/fontisan/variation/delta_parser.rb +228 -0
- data/lib/fontisan/variation/inspector.rb +275 -0
- data/lib/fontisan/variation/instance_font_wrapper.rb +41 -0
- data/lib/fontisan/variation/instance_generator.rb +122 -0
- data/lib/fontisan/variation/instance_writer.rb +360 -0
- data/lib/fontisan/variation/instancing/axis_space.rb +136 -0
- data/lib/fontisan/variation/instancing/glyph_outline.rb +204 -0
- data/lib/fontisan/variation/instancing/gvar_reader.rb +146 -0
- data/lib/fontisan/variation/instancing/item_variation_store.rb +92 -0
- data/lib/fontisan/variation/instancing/name_rewriter.rb +90 -0
- data/lib/fontisan/variation/instancing/true_type_instancer.rb +326 -0
- data/lib/fontisan/variation/instancing.rb +20 -0
- data/lib/fontisan/variation/interpolator.rb +231 -0
- data/lib/fontisan/variation/metrics_adjuster.rb +309 -0
- data/lib/fontisan/variation/optimizer.rb +417 -0
- data/lib/fontisan/variation/parallel_generator.rb +147 -0
- data/lib/fontisan/variation/region_matcher.rb +221 -0
- data/lib/fontisan/variation/subsetter.rb +400 -0
- data/lib/fontisan/variation/table_accessor.rb +105 -0
- data/lib/fontisan/variation/tuple_variation_header.rb +49 -0
- data/lib/fontisan/variation/validator.rb +336 -0
- data/lib/fontisan/variation/variable_svg_generator.rb +235 -0
- data/lib/fontisan/variation/variation_context.rb +208 -0
- data/lib/fontisan/variation/variation_preserver.rb +287 -0
- data/lib/fontisan/variation.rb +33 -0
- data/lib/fontisan/version.rb +5 -0
- data/lib/fontisan/version.rb.orig +9 -0
- data/lib/fontisan/woff2/collection_decoder.rb +223 -0
- data/lib/fontisan/woff2/collection_encoder.rb +302 -0
- data/lib/fontisan/woff2/directory.rb +255 -0
- data/lib/fontisan/woff2/encoder_rules.rb +114 -0
- data/lib/fontisan/woff2/glyf_canonicalizer.rb +90 -0
- data/lib/fontisan/woff2/glyf_loca_reconstruct.rb +401 -0
- data/lib/fontisan/woff2/glyf_loca_transform.rb +319 -0
- data/lib/fontisan/woff2/header.rb +101 -0
- data/lib/fontisan/woff2/hmtx_transformer.rb +140 -0
- data/lib/fontisan/woff2/sfnt_checksum.rb +107 -0
- data/lib/fontisan/woff2/table_transformer.rb +575 -0
- data/lib/fontisan/woff2/triplet_codec.rb +181 -0
- data/lib/fontisan/woff2/uint255.rb +101 -0
- data/lib/fontisan/woff2.rb +21 -0
- data/lib/fontisan/woff2_collection.rb +127 -0
- data/lib/fontisan/woff2_font.rb +754 -0
- data/lib/fontisan/woff_container.rb +83 -0
- data/lib/fontisan/woff_font.rb +554 -0
- data/lib/fontisan.rb +299 -0
- data/rakelib/bench.rake +9 -0
- data/rakelib/cdylib.rake +39 -0
- data/rakelib/corpus.rake +272 -0
- data/rakelib/corpus_convert.rake +43 -0
- data/rakelib/corpus_goldens.rake +22 -0
- data/rakelib/corpus_malformed.rake +20 -0
- data/rakelib/corpus_scan.rake +24 -0
- data/rakelib/java.rake +61 -0
- data/rakelib/native.rake +43 -0
- data/scripts/build-woff2.sh +57 -0
- data/scripts/compare_stack_aware.rb +187 -0
- data/scripts/corpus/generate_convert_goldens.rb +478 -0
- data/scripts/corpus/generate_goldens.rb +282 -0
- data/scripts/corpus/generate_malformed_goldens.rb +254 -0
- data/scripts/corpus/generate_scan_goldens.rb +98 -0
- data/scripts/measure_optimization.rb +148 -0
- data/scripts/tier_fallback.rb +228 -0
- data/scripts/tier_smoke.rb +72 -0
- metadata +940 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "stringio"
|
|
4
|
+
require "digest/sha2"
|
|
5
|
+
|
|
6
|
+
module Fontisan
|
|
7
|
+
module Woff2
|
|
8
|
+
# Encodes a TTC/OTC font collection into WOFF2 collection format per
|
|
9
|
+
# spec section 4.2.
|
|
10
|
+
#
|
|
11
|
+
# Output layout:
|
|
12
|
+
# [WOFF2Header (48 bytes, flavor = 'ttcf')]
|
|
13
|
+
# [TableDirectory] # one entry per unique table
|
|
14
|
+
# [CollectionDirectory] # CollectionHeader + N CollectionFontEntry
|
|
15
|
+
# [CompressedFontData] # single brotli stream of all tables
|
|
16
|
+
#
|
|
17
|
+
# Each font references tables via indices in its CollectionFontEntry.
|
|
18
|
+
# Identical tables across fonts share a single directory entry.
|
|
19
|
+
#
|
|
20
|
+
# Per spec section 5.5, glyf/loca pairs from the same font MUST be
|
|
21
|
+
# adjacent (loca immediately follows glyf) in the directory.
|
|
22
|
+
class CollectionEncoder
|
|
23
|
+
TTC_FLAVOR = 0x74746366 # 'ttcf'
|
|
24
|
+
# Largest padded glyf a short (uint16, offset / 2) loca can index.
|
|
25
|
+
SHORT_LOCA_GLYF_MAX = 0x1FFFE
|
|
26
|
+
|
|
27
|
+
# @param brotli_quality [Integer] 0-11
|
|
28
|
+
# @param timestamp [Integer, nil] Unix seconds stamped into every
|
|
29
|
+
# head.modified; nil uses the clock
|
|
30
|
+
def initialize(brotli_quality: 11, timestamp: nil)
|
|
31
|
+
@brotli_quality = brotli_quality
|
|
32
|
+
@timestamp = timestamp
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Encode an array of fonts as a WOFF2 collection.
|
|
36
|
+
#
|
|
37
|
+
# @param fonts [Array<TrueTypeFont, OpenTypeFont>] Source fonts
|
|
38
|
+
# @return [String] WOFF2 collection binary
|
|
39
|
+
def encode_fonts(fonts)
|
|
40
|
+
if fonts.nil? || fonts.empty?
|
|
41
|
+
raise ArgumentError,
|
|
42
|
+
"fonts cannot be empty"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
prepared = fonts.map.with_index { |font, i| prepare_font(font, i) }
|
|
46
|
+
_, font_to_ckeys = deduplicate(prepared)
|
|
47
|
+
layout = build_layout(prepared, font_to_ckeys)
|
|
48
|
+
compressed = compress_stream(layout)
|
|
49
|
+
assemble(fonts:, layout:, font_to_ckeys:, compressed:)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
# Prepare a single font: collect tables, apply encoder rules, run
|
|
55
|
+
# glyf/loca transform. Returns a Hash:
|
|
56
|
+
# {index:, tables: {tag ⇒ bytes}, loca_orig_length: (or nil)}
|
|
57
|
+
def prepare_font(font, index)
|
|
58
|
+
tables = {}
|
|
59
|
+
font.table_names.each do |tag|
|
|
60
|
+
data = font.table_data[tag]
|
|
61
|
+
next unless data && !data.empty?
|
|
62
|
+
|
|
63
|
+
tables[tag] = data
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
EncoderRules.apply!(tables, timestamp: @timestamp)
|
|
67
|
+
loca_orig_length = apply_glyf_loca_transform!(tables, font)
|
|
68
|
+
|
|
69
|
+
{ index:, tables:, loca_orig_length: }
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Apply the glyf/loca transform in place. Removes "loca" from
|
|
73
|
+
# `tables`. Returns the original loca length, or nil if not applied.
|
|
74
|
+
def apply_glyf_loca_transform!(tables, font)
|
|
75
|
+
return nil unless tables.key?("glyf") && tables.key?("loca")
|
|
76
|
+
|
|
77
|
+
maxp = font.table("maxp")
|
|
78
|
+
head = font.table("head")
|
|
79
|
+
return nil unless maxp && head
|
|
80
|
+
|
|
81
|
+
glyf = tables["glyf"]
|
|
82
|
+
loca = tables["loca"]
|
|
83
|
+
index_format = head.index_to_loc_format
|
|
84
|
+
# The WOFF2 decoder pads every glyph to 4 bytes; a short loca
|
|
85
|
+
# (offset / 2 as uint16) wraps once that padded glyf passes
|
|
86
|
+
# SHORT_LOCA_GLYF_MAX, so such a member is re-emitted with a long loca.
|
|
87
|
+
if index_format.zero? &&
|
|
88
|
+
glyf.bytesize + 3 * maxp.num_glyphs > SHORT_LOCA_GLYF_MAX
|
|
89
|
+
canonical = GlyfCanonicalizer.new(
|
|
90
|
+
glyf_data: glyf, loca_data: loca, num_glyphs: maxp.num_glyphs,
|
|
91
|
+
source_format: 0, target_format: 1
|
|
92
|
+
).canonical
|
|
93
|
+
glyf = canonical[:glyf]
|
|
94
|
+
loca = canonical[:loca]
|
|
95
|
+
index_format = 1
|
|
96
|
+
EncoderRules.set_head_index_to_loc_format!(tables, 1)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
loca_orig_length = loca.bytesize
|
|
100
|
+
tables["glyf"] = GlyfLocaTransform.new(
|
|
101
|
+
glyf_data: glyf,
|
|
102
|
+
loca_data: loca,
|
|
103
|
+
num_glyphs: maxp.num_glyphs,
|
|
104
|
+
index_format:,
|
|
105
|
+
).transform
|
|
106
|
+
tables.delete("loca")
|
|
107
|
+
loca_orig_length
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Deduplicate identical tables across fonts. Returns:
|
|
111
|
+
# canonical: ckey → {tag, data}
|
|
112
|
+
# font_to_ckeys: Array (per font) of {tag ⇒ ckey}
|
|
113
|
+
def deduplicate(prepared)
|
|
114
|
+
canonical = {}
|
|
115
|
+
font_to_ckeys = Array.new(prepared.size) { {} }
|
|
116
|
+
seen = {} # "tag:sha256" → ckey
|
|
117
|
+
|
|
118
|
+
prepared.each do |pf|
|
|
119
|
+
pf[:tables].each do |tag, data|
|
|
120
|
+
cache_key = "#{tag}:#{Digest::SHA256.digest(data)}"
|
|
121
|
+
if (existing = seen[cache_key])
|
|
122
|
+
font_to_ckeys[pf[:index]][tag] = existing
|
|
123
|
+
else
|
|
124
|
+
ckey = "#{tag}@#{pf[:index]}"
|
|
125
|
+
canonical[ckey] = { tag:, data: }
|
|
126
|
+
seen[cache_key] = ckey
|
|
127
|
+
font_to_ckeys[pf[:index]][tag] = ckey
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
[canonical, font_to_ckeys]
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Walk fonts in order; for each font, walk tags in spec-mandated
|
|
136
|
+
# order (glyf → loca placeholder → rest alphabetical). Each unique
|
|
137
|
+
# ckey appears once in the layout.
|
|
138
|
+
#
|
|
139
|
+
# Loca placeholders are keyed by the glyf ckey they pair with, so
|
|
140
|
+
# fonts that share a transformed glyf (via deduplication) also
|
|
141
|
+
# share the loca placeholder. Per spec section 5.5, loca MUST
|
|
142
|
+
# immediately follow glyf in the directory.
|
|
143
|
+
def build_layout(prepared, font_to_ckeys)
|
|
144
|
+
seen = {}
|
|
145
|
+
entries = []
|
|
146
|
+
|
|
147
|
+
prepared.each do |pf|
|
|
148
|
+
tags = pf[:tables].keys
|
|
149
|
+
ordered = order_tags_for_font(tags, has_loca: pf[:loca_orig_length])
|
|
150
|
+
|
|
151
|
+
ordered.each do |tag|
|
|
152
|
+
if tag == "loca_placeholder"
|
|
153
|
+
# Handled below as part of the glyf branch.
|
|
154
|
+
next
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
ckey = font_to_ckeys[pf[:index]][tag]
|
|
158
|
+
unless seen[ckey]
|
|
159
|
+
data = pf[:tables][tag]
|
|
160
|
+
seen[ckey] = entries.size
|
|
161
|
+
entries << {
|
|
162
|
+
ckey:, tag:,
|
|
163
|
+
data:,
|
|
164
|
+
orig_length: data.bytesize,
|
|
165
|
+
transform_length: (tag == "glyf" ? data.bytesize : nil)
|
|
166
|
+
}
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# loca placeholder immediately after glyf. Tied to glyf's ckey
|
|
170
|
+
# so fonts that share a glyf also share its loca placeholder.
|
|
171
|
+
if tag == "glyf" && pf[:loca_orig_length]
|
|
172
|
+
placeholder_key = "loca_placeholder_for:#{ckey}"
|
|
173
|
+
unless seen[placeholder_key]
|
|
174
|
+
seen[placeholder_key] = entries.size
|
|
175
|
+
entries << {
|
|
176
|
+
ckey: placeholder_key,
|
|
177
|
+
tag: "loca",
|
|
178
|
+
data: nil,
|
|
179
|
+
orig_length: pf[:loca_orig_length],
|
|
180
|
+
transform_length: 0,
|
|
181
|
+
}
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
entries
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Per-font tag order: glyf first, loca placeholder immediately after,
|
|
191
|
+
# rest alphabetical. Spec section 5.5.
|
|
192
|
+
def order_tags_for_font(tags, has_loca:)
|
|
193
|
+
return tags.sort unless has_loca
|
|
194
|
+
|
|
195
|
+
%w[glyf loca_placeholder] + (tags - ["glyf"]).sort
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# Concatenate unique table data in directory order. Placeholder
|
|
199
|
+
# entries (loca after transform) contribute 0 bytes per spec 5.3.
|
|
200
|
+
def compress_stream(layout)
|
|
201
|
+
combined = String.new(encoding: Encoding::BINARY)
|
|
202
|
+
layout.each do |e|
|
|
203
|
+
combined << e[:data] if e[:data]
|
|
204
|
+
end
|
|
205
|
+
Utilities::BrotliWrapper.compress(combined, quality: @brotli_quality)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def assemble(fonts:, layout:, font_to_ckeys:, compressed:)
|
|
209
|
+
io = StringIO.new
|
|
210
|
+
io.set_encoding(Encoding::BINARY)
|
|
211
|
+
|
|
212
|
+
io.write("\x00" * 48) # reserve header
|
|
213
|
+
layout.each { |e| write_table_directory_entry(io, e) }
|
|
214
|
+
|
|
215
|
+
ckey_to_index = layout.each_with_index.to_h { |e, i| [e[:ckey], i] }
|
|
216
|
+
write_collection_directory(io, fonts, font_to_ckeys, ckey_to_index)
|
|
217
|
+
|
|
218
|
+
io.write(compressed)
|
|
219
|
+
|
|
220
|
+
# Pad to a 4-byte boundary. The W3C reference decoder validates that
|
|
221
|
+
# the file's `length` field matches the actual byte count, and many
|
|
222
|
+
# decoders expect a 4-byte-aligned file length for collections.
|
|
223
|
+
pad = (4 - (io.pos % 4)) % 4
|
|
224
|
+
io.write("\x00" * pad) if pad.positive?
|
|
225
|
+
total_size = io.size
|
|
226
|
+
|
|
227
|
+
io.pos = 0
|
|
228
|
+
write_header(io, num_tables: layout.size,
|
|
229
|
+
total_compressed_size: compressed.bytesize, total_size:)
|
|
230
|
+
io.string
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def write_header(io, num_tables:, total_compressed_size:, total_size:)
|
|
234
|
+
io.write([Woff2::Woff2Header::SIGNATURE].pack("N"))
|
|
235
|
+
io.write([TTC_FLAVOR].pack("N"))
|
|
236
|
+
io.write([total_size].pack("N"))
|
|
237
|
+
io.write([num_tables].pack("n"))
|
|
238
|
+
io.write([0].pack("n"))
|
|
239
|
+
io.write([0].pack("N")) # totalSfntSize (ref only)
|
|
240
|
+
io.write([total_compressed_size].pack("N"))
|
|
241
|
+
io.write([1].pack("n")) # majorVersion
|
|
242
|
+
io.write([0].pack("n")) # minorVersion
|
|
243
|
+
io.write([0].pack("N")) # metaOffset
|
|
244
|
+
io.write([0].pack("N")) # metaLength
|
|
245
|
+
io.write([0].pack("N")) # metaOrigLength
|
|
246
|
+
io.write([0].pack("N")) # privOffset
|
|
247
|
+
io.write([0].pack("N")) # privLength
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def write_table_directory_entry(io, entry)
|
|
251
|
+
dir_entry = Directory::Entry.new
|
|
252
|
+
dir_entry.tag = entry[:tag]
|
|
253
|
+
dir_entry.orig_length = entry[:orig_length]
|
|
254
|
+
dir_entry.transform_length = entry[:transform_length]
|
|
255
|
+
flags = dir_entry.calculate_flags
|
|
256
|
+
io.write([flags].pack("C"))
|
|
257
|
+
io.write(entry[:tag].ljust(4, "\x00")) unless dir_entry.known_tag?
|
|
258
|
+
io.write(Directory.encode_uint_base128(entry[:orig_length]))
|
|
259
|
+
return unless dir_entry.transformed?
|
|
260
|
+
|
|
261
|
+
io.write(Directory.encode_uint_base128(entry[:transform_length] || 0))
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def write_collection_directory(io, fonts, font_to_ckeys, ckey_to_index)
|
|
265
|
+
# CollectionHeader
|
|
266
|
+
io.write([0x00010000].pack("N")) # version 1.0
|
|
267
|
+
io.write(UInt255.encode(fonts.size))
|
|
268
|
+
|
|
269
|
+
# One CollectionFontEntry per font
|
|
270
|
+
fonts.each_with_index do |font, fi|
|
|
271
|
+
font_keys = font_to_ckeys[fi]
|
|
272
|
+
glyf_ckey = font_keys["glyf"]
|
|
273
|
+
placeholder_key = glyf_ckey && "loca_placeholder_for:#{glyf_ckey}"
|
|
274
|
+
has_placeholder = ckey_to_index.key?(placeholder_key)
|
|
275
|
+
# CollectionFontEntry index list is in font's natural alphabetical
|
|
276
|
+
# order (including "loca" if a placeholder exists). The glyf/loca
|
|
277
|
+
# adjacency constraint applies to the table directory, not the
|
|
278
|
+
# entry index list per spec section 5.5.
|
|
279
|
+
ordered = font_keys.keys
|
|
280
|
+
ordered << "loca" if has_placeholder
|
|
281
|
+
ordered = ordered.sort
|
|
282
|
+
|
|
283
|
+
io.write(UInt255.encode(ordered.size))
|
|
284
|
+
io.write([font_flavor(font)].pack("N"))
|
|
285
|
+
ordered.each do |tag|
|
|
286
|
+
ckey = font_keys[tag] || placeholder_key
|
|
287
|
+
index = ckey_to_index.fetch(ckey)
|
|
288
|
+
io.write(UInt255.encode(index))
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
def font_flavor(font)
|
|
294
|
+
if font.has_table?("CFF ") || font.has_table?("CFF2")
|
|
295
|
+
Constants::SFNT_VERSION_OTTO
|
|
296
|
+
else
|
|
297
|
+
Constants::SFNT_VERSION_TRUETYPE
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
end
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Fontisan
|
|
4
|
+
module Woff2
|
|
5
|
+
# WOFF2 Table Directory Entry
|
|
6
|
+
#
|
|
7
|
+
# [`Woff2::Directory`](lib/fontisan/woff2/directory.rb) represents
|
|
8
|
+
# a single table entry in the WOFF2 table directory. Unlike WOFF,
|
|
9
|
+
# WOFF2 uses variable-length encoding for sizes and supports table
|
|
10
|
+
# transformations for better compression.
|
|
11
|
+
#
|
|
12
|
+
# Each entry contains:
|
|
13
|
+
# - flags (1 byte): Contains tag index and transformation version
|
|
14
|
+
# - tag (0 or 4 bytes): Table tag (omitted if using known tag index)
|
|
15
|
+
# - origLength (UIntBase128): Original uncompressed table length
|
|
16
|
+
# - transformLength (UIntBase128, optional): Transformed data length
|
|
17
|
+
#
|
|
18
|
+
# Flags byte structure:
|
|
19
|
+
# - Bits 0-5: Table tag index (0-62 = known tags, 63 = custom tag)
|
|
20
|
+
# - Bits 6-7: Transformation version
|
|
21
|
+
#
|
|
22
|
+
# Reference: https://www.w3.org/TR/WOFF2/#table_dir_format
|
|
23
|
+
#
|
|
24
|
+
# @example Create entry for known table
|
|
25
|
+
# entry = Directory::Entry.new
|
|
26
|
+
# entry.tag = "glyf"
|
|
27
|
+
# entry.orig_length = 12000
|
|
28
|
+
# entry.flags = entry.calculate_flags
|
|
29
|
+
#
|
|
30
|
+
# @example Create entry for custom table
|
|
31
|
+
# entry = Directory::Entry.new
|
|
32
|
+
# entry.tag = "CUST"
|
|
33
|
+
# entry.orig_length = 5000
|
|
34
|
+
# entry.flags = 0x3F # Custom tag indicator
|
|
35
|
+
module Directory
|
|
36
|
+
# Known table tags with assigned indices (0-62)
|
|
37
|
+
# Index 63 (0x3F) indicates a custom tag follows
|
|
38
|
+
KNOWN_TAGS = [
|
|
39
|
+
"cmap", "head", "hhea", "hmtx", "maxp", "name", "OS/2", "post",
|
|
40
|
+
"cvt ", "fpgm", "glyf", "loca", "prep", "CFF ", "VORG", "EBDT",
|
|
41
|
+
"EBLC", "gasp", "hdmx", "kern", "LTSH", "PCLT", "VDMX", "vhea",
|
|
42
|
+
"vmtx", "BASE", "GDEF", "GPOS", "GSUB", "EBSC", "JSTF", "MATH",
|
|
43
|
+
"CBDT", "CBLC", "COLR", "CPAL", "SVG ", "sbix", "acnt", "avar",
|
|
44
|
+
"bdat", "bloc", "bsln", "cvar", "fdsc", "feat", "fmtx", "fvar",
|
|
45
|
+
"gvar", "hsty", "just", "lcar", "mort", "morx", "opbd", "prop",
|
|
46
|
+
"trak", "Zapf", "Silf", "Glat", "Gloc", "Feat", "Sill"
|
|
47
|
+
].freeze
|
|
48
|
+
|
|
49
|
+
# Transformation versions per WOFF2 spec section 5.1, 5.3, 5.4.
|
|
50
|
+
#
|
|
51
|
+
# glyf/loca:
|
|
52
|
+
# - version 0: transformed format (spec section 5.1 / 5.3)
|
|
53
|
+
# - version 3: null transform — original bytes passed to brotli as-is
|
|
54
|
+
# (Chrome's OTS does not accept version 3 for glyf/loca; encoders
|
|
55
|
+
# that want to interoperate with browsers MUST use version 0).
|
|
56
|
+
# hmtx:
|
|
57
|
+
# - version 0: null transform (default)
|
|
58
|
+
# - version 1: transformed format (spec section 5.4)
|
|
59
|
+
# All other tables use version 0 for the null transform.
|
|
60
|
+
TRANSFORM_NULL = 3 # glyf/loca null transform
|
|
61
|
+
TRANSFORM_NONE = TRANSFORM_NULL # deprecated alias kept for older callers
|
|
62
|
+
TRANSFORM_GLYF_LOCA = 0 # glyf/loca transformed format
|
|
63
|
+
TRANSFORM_HMTX = 1 # hmtx transformed format
|
|
64
|
+
TRANSFORM_HMTX_NULL = 0 # hmtx null transform
|
|
65
|
+
|
|
66
|
+
# Custom tag indicator
|
|
67
|
+
CUSTOM_TAG_INDEX = 0x3F
|
|
68
|
+
|
|
69
|
+
# WOFF2 Table Directory Entry
|
|
70
|
+
#
|
|
71
|
+
# Represents a single table in the WOFF2 font with all metadata
|
|
72
|
+
# needed for decompression and reconstruction.
|
|
73
|
+
class Entry
|
|
74
|
+
attr_accessor :tag, :flags, :orig_length, :transform_length, :offset # Calculated during encoding
|
|
75
|
+
|
|
76
|
+
def initialize
|
|
77
|
+
@tag = nil
|
|
78
|
+
@flags = 0
|
|
79
|
+
@orig_length = 0
|
|
80
|
+
@transform_length = nil
|
|
81
|
+
@offset = 0
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Calculate flags byte for this entry
|
|
85
|
+
#
|
|
86
|
+
# @return [Integer] Flags byte (0-255)
|
|
87
|
+
def calculate_flags
|
|
88
|
+
tag_index = KNOWN_TAGS.index(tag) || CUSTOM_TAG_INDEX
|
|
89
|
+
transform_version = determine_transform_version
|
|
90
|
+
|
|
91
|
+
# Combine tag index (bits 0-5) and transform version (bits 6-7)
|
|
92
|
+
(transform_version << 6) | tag_index
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Check if table uses a known tag
|
|
96
|
+
#
|
|
97
|
+
# @return [Boolean] True if known tag
|
|
98
|
+
def known_tag?
|
|
99
|
+
KNOWN_TAGS.include?(tag)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Whether this entry will be serialized with a transformLength field.
|
|
103
|
+
#
|
|
104
|
+
# Per WOFF2 spec section 4.1, transformLength is encoded when the
|
|
105
|
+
# table is in a transformed format. For loca the value is always 0
|
|
106
|
+
# (spec section 5.3), so we cannot use `.positive?` to detect the
|
|
107
|
+
# transformed state — the encoder explicitly sets `transform_length`
|
|
108
|
+
# (even to 0) when emitting a transformed entry, and leaves it nil
|
|
109
|
+
# otherwise.
|
|
110
|
+
#
|
|
111
|
+
# @return [Boolean] True if a transformLength field should be written
|
|
112
|
+
def transformed?
|
|
113
|
+
!transform_length.nil?
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Get transformation version from flags
|
|
117
|
+
#
|
|
118
|
+
# @return [Integer] Transform version (0-3)
|
|
119
|
+
def transform_version
|
|
120
|
+
(flags >> 6) & 0x03
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Get tag index from flags
|
|
124
|
+
#
|
|
125
|
+
# @return [Integer] Tag index (0-63)
|
|
126
|
+
def tag_index
|
|
127
|
+
flags & 0x3F
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Determine the transform version to encode in the flags byte.
|
|
131
|
+
#
|
|
132
|
+
# Per WOFF2 spec section 5.1, glyf/loca use version 0 for the
|
|
133
|
+
# transformed format and version 3 for the null transform; hmtx
|
|
134
|
+
# uses version 1 for transformed and version 0 for null. The
|
|
135
|
+
# encoder sets `transform_length` (or leaves it nil) to indicate
|
|
136
|
+
# which case applies — see `transformed?`.
|
|
137
|
+
#
|
|
138
|
+
# @return [Integer] Transform version (0-3)
|
|
139
|
+
def determine_transform_version
|
|
140
|
+
if ["glyf", "loca"].include?(tag)
|
|
141
|
+
transformed? ? TRANSFORM_GLYF_LOCA : TRANSFORM_NULL
|
|
142
|
+
elsif tag == "hmtx"
|
|
143
|
+
transformed? ? TRANSFORM_HMTX : TRANSFORM_HMTX_NULL
|
|
144
|
+
else
|
|
145
|
+
0
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Check if table can be transformed (glyf, loca, hmtx)
|
|
150
|
+
#
|
|
151
|
+
# @return [Boolean] True if transformable
|
|
152
|
+
def transformable?
|
|
153
|
+
%w[glyf loca hmtx].include?(tag)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Calculate size of this entry when serialized
|
|
157
|
+
#
|
|
158
|
+
# @return [Integer] Size in bytes
|
|
159
|
+
def serialized_size
|
|
160
|
+
size = 1 # flags byte
|
|
161
|
+
size += 4 unless known_tag? # custom tag
|
|
162
|
+
size += uint_base128_size(orig_length)
|
|
163
|
+
size += uint_base128_size(transform_length) if transformed?
|
|
164
|
+
size
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
private
|
|
168
|
+
|
|
169
|
+
# Estimate size of UIntBase128 encoded value
|
|
170
|
+
#
|
|
171
|
+
# @param value [Integer] Value to encode
|
|
172
|
+
# @return [Integer] Size in bytes (1-5)
|
|
173
|
+
def uint_base128_size(value)
|
|
174
|
+
return 1 if value.nil? || value < 128
|
|
175
|
+
|
|
176
|
+
bytes = 0
|
|
177
|
+
v = value
|
|
178
|
+
while v.positive?
|
|
179
|
+
bytes += 1
|
|
180
|
+
v >>= 7
|
|
181
|
+
end
|
|
182
|
+
[bytes, 5].min # Max 5 bytes
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# Encode an integer as UIntBase128
|
|
187
|
+
#
|
|
188
|
+
# Variable-length encoding where:
|
|
189
|
+
# - If value < 128, use 1 byte
|
|
190
|
+
# - Otherwise, use high bit to indicate continuation
|
|
191
|
+
#
|
|
192
|
+
# @param value [Integer] Value to encode
|
|
193
|
+
# @return [String] Binary encoded data
|
|
194
|
+
def self.encode_uint_base128(value)
|
|
195
|
+
return [value].pack("C") if value < 128
|
|
196
|
+
|
|
197
|
+
bytes = []
|
|
198
|
+
v = value
|
|
199
|
+
|
|
200
|
+
# Build bytes from least to most significant
|
|
201
|
+
loop do
|
|
202
|
+
bytes.unshift(v & 0x7F)
|
|
203
|
+
v >>= 7
|
|
204
|
+
break if v.zero?
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
# Set high bit on all but last byte
|
|
208
|
+
(0...bytes.length - 1).each do |i|
|
|
209
|
+
bytes[i] |= 0x80
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
bytes.pack("C*")
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
# Decode UIntBase128 from IO
|
|
216
|
+
#
|
|
217
|
+
# @param io [IO] Input stream
|
|
218
|
+
# @return [Integer] Decoded value
|
|
219
|
+
# @raise [Error] If encoding is invalid
|
|
220
|
+
def self.decode_uint_base128(io)
|
|
221
|
+
result = 0
|
|
222
|
+
5.times do
|
|
223
|
+
byte = io.read(1)&.unpack1("C")
|
|
224
|
+
return nil unless byte
|
|
225
|
+
|
|
226
|
+
# Check if high bit is set (continuation)
|
|
227
|
+
if (byte & 0x80).zero?
|
|
228
|
+
return (result << 7) | byte
|
|
229
|
+
else
|
|
230
|
+
result = (result << 7) | (byte & 0x7F)
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
# If we're here, encoding is invalid (> 5 bytes)
|
|
235
|
+
raise Fontisan::Error, "Invalid UIntBase128 encoding"
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
# Encode 255UInt16. Delegates to {UInt255} (single source of truth).
|
|
239
|
+
#
|
|
240
|
+
# @param value [Integer] Value to encode (0-65535)
|
|
241
|
+
# @return [String] Binary encoded data
|
|
242
|
+
def self.encode_255_uint16(value)
|
|
243
|
+
UInt255.encode(value)
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# Decode 255UInt16 from IO. Delegates to {UInt255}.
|
|
247
|
+
#
|
|
248
|
+
# @param io [IO] Input stream
|
|
249
|
+
# @return [Integer] Decoded value
|
|
250
|
+
def self.decode_255_uint16(io)
|
|
251
|
+
UInt255.decode(io)
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Fontisan
|
|
4
|
+
module Woff2
|
|
5
|
+
# Applies WOFF2 spec "encoder MUST" rules to a table collection before
|
|
6
|
+
# the table directory is built and brotli compression is applied.
|
|
7
|
+
#
|
|
8
|
+
# Each spec-mandated transform lives here so the encoder stays a thin
|
|
9
|
+
# orchestrator and new rules are MECE/discoverable instead of sprinkled
|
|
10
|
+
# as inline conditionals across Woff2Encoder.
|
|
11
|
+
#
|
|
12
|
+
# Reference: W3C WOFF2 spec, section 5 ("Recommended table directory").
|
|
13
|
+
class EncoderRules
|
|
14
|
+
# Tables that MUST NOT appear in WOFF2 output.
|
|
15
|
+
#
|
|
16
|
+
# Per spec section 5: "The compliant WOFF2 encoder MUST remove the
|
|
17
|
+
# DSIG table from an input font data, prior to applying
|
|
18
|
+
# transformations and entropy coding steps." Chrome's OpenType
|
|
19
|
+
# Sanitizer (OTS) rejects WOFF2 files that still contain DSIG.
|
|
20
|
+
EXCLUDED_TABLES = %w[DSIG].freeze
|
|
21
|
+
|
|
22
|
+
# Tables that MUST be transformed (when present) per WOFF2 spec
|
|
23
|
+
# section 5.3: glyf and loca are paired — both are either
|
|
24
|
+
# transformed (version 0) or null-transformed (version 3) together.
|
|
25
|
+
# Browsers (Chrome OTS) only accept the transformed form.
|
|
26
|
+
TRANSFORMED_TABLES = %w[glyf loca].freeze
|
|
27
|
+
|
|
28
|
+
# Apply all WOFF2 encoder rules to `table_data` in place.
|
|
29
|
+
#
|
|
30
|
+
# @param table_data [Hash{String => String}] Map of tag → binary
|
|
31
|
+
# table data. Mutated.
|
|
32
|
+
# @param timestamp [Integer, Time, nil] Fixed value for head.modified
|
|
33
|
+
# (Unix seconds); nil stamps the current wall-clock time.
|
|
34
|
+
# @return [Hash{String => String}] The same hash, for chaining.
|
|
35
|
+
def self.apply!(table_data, timestamp: nil)
|
|
36
|
+
exclude_tables!(table_data)
|
|
37
|
+
mark_lossless_modifying!(table_data)
|
|
38
|
+
touch_head_modified!(table_data, timestamp: timestamp)
|
|
39
|
+
table_data
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Whether `tag` is dropped by WOFF2 spec rules.
|
|
43
|
+
def self.excluded?(tag)
|
|
44
|
+
EXCLUDED_TABLES.include?(tag)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Drop spec-excluded tables from the collection.
|
|
48
|
+
def self.exclude_tables!(table_data)
|
|
49
|
+
EXCLUDED_TABLES.each { |tag| table_data.delete(tag) }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Set head.flags bit 11 to indicate the font was losslessly modified.
|
|
53
|
+
#
|
|
54
|
+
# Per spec section 5: "The WOFF 2.0 encoders MUST also set bit 11 of
|
|
55
|
+
# the 'flags' field of the head table ... to indicate that a recreated
|
|
56
|
+
# font file was subjected to lossless modifying transform."
|
|
57
|
+
#
|
|
58
|
+
# Uses the model-driven Head BinData record so the bits are set via a
|
|
59
|
+
# named attribute on a typed object, not via raw byte slicing.
|
|
60
|
+
def self.mark_lossless_modifying!(table_data)
|
|
61
|
+
return unless table_data.key?("head")
|
|
62
|
+
|
|
63
|
+
head = Tables::Head.read(table_data["head"])
|
|
64
|
+
head.flags |= Tables::Head::FLAG_LOSSLESS_MODIFYING
|
|
65
|
+
table_data["head"] = head.to_binary_s
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Set head.indexToLocFormat to match the chosen output loca format.
|
|
69
|
+
#
|
|
70
|
+
# fontTools' WOFF2 encoder re-picks the loca format (preferring short
|
|
71
|
+
# when glyf fits). The reconstructed SFNT must carry the matching
|
|
72
|
+
# indexToLocFormat in head, or Chrome's OTS rejects the file with
|
|
73
|
+
# "Failed to convert WOFF 2.0 font to SFNT".
|
|
74
|
+
#
|
|
75
|
+
# @param table_data [Hash{String => String}]
|
|
76
|
+
# @param format_code [Integer] 0 (short) or 1 (long)
|
|
77
|
+
def self.set_head_index_to_loc_format!(table_data, format_code)
|
|
78
|
+
return unless table_data.key?("head")
|
|
79
|
+
|
|
80
|
+
head = Tables::Head.read(table_data["head"])
|
|
81
|
+
head.index_to_loc_format = format_code
|
|
82
|
+
table_data["head"] = head.to_binary_s
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Set head.modified to the current time.
|
|
86
|
+
#
|
|
87
|
+
# Chrome's OTS rejects WOFF2 fonts whose head.modified is not
|
|
88
|
+
# meaningfully later than head.created. Source fonts frequently
|
|
89
|
+
# carry modified == created (or modified within seconds of it),
|
|
90
|
+
# which Chrome rejects. Setting modified to the actual current
|
|
91
|
+
# wall-clock time matches fontTools' behaviour (it sets
|
|
92
|
+
# head.modified = timestampNow() on every save) and gives Chrome
|
|
93
|
+
# a delta large enough to accept.
|
|
94
|
+
#
|
|
95
|
+
# Must be called BEFORE checksum recompute so the modified bytes
|
|
96
|
+
# are included in the checksum.
|
|
97
|
+
#
|
|
98
|
+
# @param table_data [Hash{String => String}]
|
|
99
|
+
# @param timestamp [Integer, Time, nil] Unix seconds to stamp instead of
|
|
100
|
+
# the current time (reproducible output); nil keeps the clock.
|
|
101
|
+
def self.touch_head_modified!(table_data, timestamp: nil)
|
|
102
|
+
return unless table_data.key?("head")
|
|
103
|
+
|
|
104
|
+
head = Tables::Head.read(table_data["head"])
|
|
105
|
+
head.modified_raw = if timestamp.nil?
|
|
106
|
+
Tables::Head.now_longdatetime
|
|
107
|
+
else
|
|
108
|
+
Tables::Head.to_longdatetime(timestamp)
|
|
109
|
+
end
|
|
110
|
+
table_data["head"] = head.to_binary_s
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|