fontisan 0.2.16 → 0.2.22
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 +4 -4
- data/.rubocop_todo.yml +14 -90
- data/Gemfile +6 -3
- data/README.adoc +257 -1
- data/docs/.vitepress/config.ts +68 -8
- data/docs/.vitepress/theme/style.css +570 -272
- data/docs/CONVERSION_GUIDE.adoc +31 -8
- data/docs/EXTRACT_TTC_MIGRATION.md +1 -1
- data/docs/WOFF_WOFF2_FORMATS.adoc +53 -0
- data/docs/api/conversion-options.md +37 -14
- data/docs/api/font-loader.md +21 -15
- data/docs/cli/audit.md +337 -0
- data/docs/cli/convert.md +20 -1
- data/docs/cli/index.md +31 -0
- data/docs/guide/color.md +1 -1
- data/docs/guide/conversion/options.md +32 -3
- data/docs/guide/conversion/ttf-otf.md +1 -1
- data/docs/guide/conversion/type1.md +1 -1
- data/docs/guide/conversion/web.md +91 -32
- data/docs/guide/conversion.md +6 -5
- data/docs/guide/formats/woff.md +35 -11
- data/docs/guide/index.md +2 -2
- data/docs/guide/migrations/extract-ttc.md +1 -1
- data/docs/guide/quick-start.md +4 -4
- data/docs/guide/type1.md +4 -4
- data/docs/guide/woff.md +19 -17
- data/docs/index.md +2 -0
- data/docs/lychee.toml +5 -1
- data/docs/package.json +1 -1
- data/docs/public/robots.txt +4 -0
- data/docs/scripts/post-build.mjs +81 -0
- data/lib/fontisan/audit/codepoint_range_coalescer.rb +41 -0
- data/lib/fontisan/audit/context.rb +122 -0
- data/lib/fontisan/audit/differ.rb +124 -0
- data/lib/fontisan/audit/extractors/aggregations.rb +54 -0
- data/lib/fontisan/audit/extractors/base.rb +26 -0
- data/lib/fontisan/audit/extractors/color_capabilities.rb +141 -0
- data/lib/fontisan/audit/extractors/coverage.rb +48 -0
- data/lib/fontisan/audit/extractors/hinting.rb +197 -0
- data/lib/fontisan/audit/extractors/identity.rb +52 -0
- data/lib/fontisan/audit/extractors/language_coverage.rb +37 -0
- data/lib/fontisan/audit/extractors/licensing.rb +79 -0
- data/lib/fontisan/audit/extractors/metrics.rb +103 -0
- data/lib/fontisan/audit/extractors/opentype_layout.rb +69 -0
- data/lib/fontisan/audit/extractors/provenance.rb +29 -0
- data/lib/fontisan/audit/extractors/style.rb +32 -0
- data/lib/fontisan/audit/extractors/variation_detail.rb +99 -0
- data/lib/fontisan/audit/extractors.rb +27 -0
- data/lib/fontisan/audit/library_aggregator.rb +83 -0
- data/lib/fontisan/audit/library_auditor.rb +90 -0
- data/lib/fontisan/audit/registry.rb +60 -0
- data/lib/fontisan/audit/style_extractor.rb +80 -0
- data/lib/fontisan/audit.rb +20 -0
- data/lib/fontisan/base_collection.rb +23 -9
- data/lib/fontisan/binary/structures.rb +0 -2
- data/lib/fontisan/binary.rb +11 -0
- data/lib/fontisan/cldr/aggregator.rb +33 -0
- data/lib/fontisan/cldr/cache_manager.rb +110 -0
- data/lib/fontisan/cldr/config.rb +59 -0
- data/lib/fontisan/cldr/download_error.rb +9 -0
- data/lib/fontisan/cldr/downloader.rb +79 -0
- data/lib/fontisan/cldr/error.rb +8 -0
- data/lib/fontisan/cldr/index.rb +64 -0
- data/lib/fontisan/cldr/index_builder.rb +72 -0
- data/lib/fontisan/cldr/unicode_set_parser.rb +172 -0
- data/lib/fontisan/cldr/unknown_version_error.rb +9 -0
- data/lib/fontisan/cldr/version_resolver.rb +91 -0
- data/lib/fontisan/cldr.rb +23 -0
- data/lib/fontisan/cli/cldr_cli.rb +85 -0
- data/lib/fontisan/cli/ucd_cli.rb +97 -0
- data/lib/fontisan/cli.rb +201 -2
- data/lib/fontisan/collection/builder.rb +0 -4
- data/lib/fontisan/collection/dfont_builder.rb +0 -4
- data/lib/fontisan/collection/shared_logic.rb +0 -2
- data/lib/fontisan/collection/writer.rb +0 -3
- data/lib/fontisan/collection.rb +15 -0
- data/lib/fontisan/commands/audit_command.rb +123 -0
- data/lib/fontisan/commands/audit_compare_command.rb +66 -0
- data/lib/fontisan/commands/audit_library_command.rb +46 -0
- data/lib/fontisan/commands/base_command.rb +0 -3
- data/lib/fontisan/commands/convert_command.rb +25 -20
- data/lib/fontisan/commands/dump_table_command.rb +0 -3
- data/lib/fontisan/commands/export_command.rb +0 -4
- data/lib/fontisan/commands/features_command.rb +0 -3
- data/lib/fontisan/commands/instance_command.rb +0 -5
- data/lib/fontisan/commands/ls_command.rb +0 -6
- data/lib/fontisan/commands/optical_size_command.rb +0 -3
- data/lib/fontisan/commands/pack_command.rb +0 -5
- data/lib/fontisan/commands/scripts_command.rb +0 -2
- data/lib/fontisan/commands/subset_command.rb +0 -3
- data/lib/fontisan/commands/unicode_command.rb +0 -3
- data/lib/fontisan/commands/unpack_command.rb +0 -7
- data/lib/fontisan/commands/validate_command.rb +0 -8
- data/lib/fontisan/commands/variable_command.rb +0 -3
- data/lib/fontisan/commands.rb +29 -0
- data/lib/fontisan/config/cldr.yml +22 -0
- data/lib/fontisan/config/conversion_matrix.yml +38 -0
- data/lib/fontisan/config/ucd.yml +23 -0
- data/lib/fontisan/constants.rb +48 -6
- data/lib/fontisan/conversion_options.rb +30 -19
- data/lib/fontisan/converters/cff_table_builder.rb +0 -3
- data/lib/fontisan/converters/collection_converter.rb +0 -8
- data/lib/fontisan/converters/conversion_strategy.rb +161 -46
- data/lib/fontisan/converters/format_converter.rb +143 -32
- data/lib/fontisan/converters/glyf_table_builder.rb +0 -2
- data/lib/fontisan/converters/outline_converter.rb +0 -19
- data/lib/fontisan/converters/outline_extraction.rb +0 -5
- data/lib/fontisan/converters/outline_optimizer.rb +0 -5
- data/lib/fontisan/converters/svg_generator.rb +0 -4
- data/lib/fontisan/converters/table_copier.rb +0 -2
- data/lib/fontisan/converters/type1_converter.rb +0 -11
- data/lib/fontisan/converters/woff2_encoder.rb +49 -20
- data/lib/fontisan/converters/woff_writer.rb +211 -282
- data/lib/fontisan/converters.rb +21 -0
- data/lib/fontisan/dfont_collection.rb +29 -10
- data/lib/fontisan/export/exporter.rb +0 -6
- data/lib/fontisan/export/transformers/font_to_ttx.rb +0 -9
- data/lib/fontisan/export/transformers/head_transformer.rb +0 -2
- data/lib/fontisan/export/transformers/hhea_transformer.rb +0 -2
- data/lib/fontisan/export/transformers/maxp_transformer.rb +0 -2
- data/lib/fontisan/export/transformers/name_transformer.rb +0 -2
- data/lib/fontisan/export/transformers/os2_transformer.rb +0 -2
- data/lib/fontisan/export/transformers/post_transformer.rb +0 -2
- data/lib/fontisan/export/transformers.rb +17 -0
- data/lib/fontisan/export.rb +13 -0
- data/lib/fontisan/font_loader.rb +189 -328
- data/lib/fontisan/font_writer.rb +0 -1
- data/lib/fontisan/formatters/audit_diff_text_renderer.rb +122 -0
- data/lib/fontisan/formatters/audit_text_renderer.rb +324 -0
- data/lib/fontisan/formatters/library_summary_text_renderer.rb +99 -0
- data/lib/fontisan/formatters/text_formatter.rb +6 -0
- data/lib/fontisan/formatters.rb +12 -0
- data/lib/fontisan/hints/hint_converter.rb +0 -1
- data/lib/fontisan/hints/postscript_hint_applier.rb +0 -9
- data/lib/fontisan/hints/postscript_hint_extractor.rb +0 -2
- data/lib/fontisan/hints/truetype_hint_extractor.rb +0 -2
- data/lib/fontisan/hints.rb +16 -0
- data/lib/fontisan/metrics_calculator.rb +0 -2
- data/lib/fontisan/models/all_scripts_features_info.rb +0 -1
- data/lib/fontisan/models/audit/audit_axis.rb +30 -0
- data/lib/fontisan/models/audit/audit_block.rb +32 -0
- data/lib/fontisan/models/audit/audit_diff.rb +77 -0
- data/lib/fontisan/models/audit/audit_report.rb +153 -0
- data/lib/fontisan/models/audit/codepoint_range.rb +40 -0
- data/lib/fontisan/models/audit/codepoint_set_diff.rb +34 -0
- data/lib/fontisan/models/audit/color_capabilities.rb +93 -0
- data/lib/fontisan/models/audit/duplicate_group.rb +23 -0
- data/lib/fontisan/models/audit/embedding_type.rb +76 -0
- data/lib/fontisan/models/audit/field_change.rb +28 -0
- data/lib/fontisan/models/audit/fs_selection_flags.rb +61 -0
- data/lib/fontisan/models/audit/gasp_range.rb +63 -0
- data/lib/fontisan/models/audit/hinting.rb +93 -0
- data/lib/fontisan/models/audit/library_summary.rb +40 -0
- data/lib/fontisan/models/audit/licensing.rb +48 -0
- data/lib/fontisan/models/audit/metrics.rb +111 -0
- data/lib/fontisan/models/audit/named_instance.rb +41 -0
- data/lib/fontisan/models/audit/opentype_layout.rb +40 -0
- data/lib/fontisan/models/audit/script_coverage_row.rb +26 -0
- data/lib/fontisan/models/audit/script_features.rb +28 -0
- data/lib/fontisan/models/audit/variation_detail.rb +44 -0
- data/lib/fontisan/models/audit.rb +33 -0
- data/lib/fontisan/models/cldr/language_coverage.rb +31 -0
- data/lib/fontisan/models/cldr.rb +12 -0
- data/lib/fontisan/models/collection_brief_info.rb +0 -1
- data/lib/fontisan/models/collection_info.rb +0 -2
- data/lib/fontisan/models/collection_list_info.rb +0 -1
- data/lib/fontisan/models/collection_validation_report.rb +0 -2
- data/lib/fontisan/models/color_glyph.rb +0 -1
- data/lib/fontisan/models/font_report.rb +0 -1
- data/lib/fontisan/models/ttx/tables.rb +21 -0
- data/lib/fontisan/models/ttx/ttfont.rb +0 -8
- data/lib/fontisan/models/ttx.rb +14 -0
- data/lib/fontisan/models/ucd/ucd.rb +38 -0
- data/lib/fontisan/models/ucd/ucd_char.rb +67 -0
- data/lib/fontisan/models/ucd.rb +19 -0
- data/lib/fontisan/models.rb +47 -0
- data/lib/fontisan/open_type_collection.rb +6 -5
- data/lib/fontisan/open_type_font.rb +8 -2
- data/lib/fontisan/open_type_font_extensions.rb +9 -9
- data/lib/fontisan/optimizers/pattern_analyzer.rb +0 -1
- data/lib/fontisan/optimizers.rb +14 -0
- data/lib/fontisan/outline_extractor.rb +0 -2
- data/lib/fontisan/parsers/dfont_parser.rb +0 -1
- data/lib/fontisan/parsers.rb +10 -0
- data/lib/fontisan/pipeline/format_detector.rb +29 -102
- data/lib/fontisan/pipeline/output_writer.rb +11 -9
- data/lib/fontisan/pipeline/strategies/instance_strategy.rb +0 -4
- data/lib/fontisan/pipeline/strategies/named_strategy.rb +0 -4
- data/lib/fontisan/pipeline/strategies/preserve_strategy.rb +0 -2
- data/lib/fontisan/pipeline/strategies.rb +14 -0
- data/lib/fontisan/pipeline/transformation_pipeline.rb +0 -7
- data/lib/fontisan/pipeline/variation_resolver.rb +0 -7
- data/lib/fontisan/pipeline.rb +13 -0
- data/lib/fontisan/sfnt_font.rb +29 -14
- data/lib/fontisan/sfnt_table.rb +0 -4
- data/lib/fontisan/subset/builder.rb +0 -6
- data/lib/fontisan/subset.rb +13 -0
- data/lib/fontisan/svg/font_generator.rb +0 -4
- data/lib/fontisan/svg/glyph_generator.rb +0 -2
- data/lib/fontisan/svg.rb +12 -0
- data/lib/fontisan/tables/cbdt.rb +0 -1
- data/lib/fontisan/tables/cblc.rb +0 -1
- data/lib/fontisan/tables/cff/charset.rb +0 -1
- data/lib/fontisan/tables/cff/charstring.rb +0 -1
- data/lib/fontisan/tables/cff/charstring_rebuilder.rb +0 -4
- data/lib/fontisan/tables/cff/charstrings_index.rb +0 -3
- data/lib/fontisan/tables/cff/dict.rb +0 -1
- data/lib/fontisan/tables/cff/encoding.rb +0 -1
- data/lib/fontisan/tables/cff/header.rb +0 -2
- data/lib/fontisan/tables/cff/hint_operation_injector.rb +0 -2
- data/lib/fontisan/tables/cff/index.rb +0 -1
- data/lib/fontisan/tables/cff/private_dict.rb +0 -2
- data/lib/fontisan/tables/cff/private_dict_writer.rb +0 -2
- data/lib/fontisan/tables/cff/table_builder.rb +0 -6
- data/lib/fontisan/tables/cff/top_dict.rb +0 -2
- data/lib/fontisan/tables/cff.rb +22 -15
- data/lib/fontisan/tables/cff2/charstring_parser.rb +0 -2
- data/lib/fontisan/tables/cff2/table_builder.rb +0 -11
- data/lib/fontisan/tables/cff2/table_reader.rb +0 -2
- data/lib/fontisan/tables/cff2.rb +13 -14
- data/lib/fontisan/tables/cmap.rb +24 -2
- data/lib/fontisan/tables/cmap_table.rb +0 -3
- data/lib/fontisan/tables/colr.rb +0 -1
- data/lib/fontisan/tables/cpal.rb +0 -1
- data/lib/fontisan/tables/cvar.rb +0 -2
- data/lib/fontisan/tables/fvar.rb +0 -1
- data/lib/fontisan/tables/glyf/compound_glyph_resolver.rb +0 -2
- data/lib/fontisan/tables/glyf/glyph_builder.rb +0 -3
- data/lib/fontisan/tables/glyf.rb +0 -6
- data/lib/fontisan/tables/glyf_table.rb +0 -3
- data/lib/fontisan/tables/gpos.rb +0 -2
- data/lib/fontisan/tables/gsub.rb +0 -2
- data/lib/fontisan/tables/gvar.rb +0 -2
- data/lib/fontisan/tables/head.rb +0 -2
- data/lib/fontisan/tables/head_table.rb +0 -3
- data/lib/fontisan/tables/hhea.rb +0 -2
- data/lib/fontisan/tables/hhea_table.rb +0 -3
- data/lib/fontisan/tables/hmtx.rb +0 -2
- data/lib/fontisan/tables/hmtx_table.rb +0 -3
- data/lib/fontisan/tables/hvar.rb +0 -3
- data/lib/fontisan/tables/loca.rb +0 -2
- data/lib/fontisan/tables/loca_table.rb +0 -3
- data/lib/fontisan/tables/maxp.rb +0 -2
- data/lib/fontisan/tables/maxp_table.rb +0 -3
- data/lib/fontisan/tables/mvar.rb +0 -3
- data/lib/fontisan/tables/name.rb +0 -2
- data/lib/fontisan/tables/name_table.rb +0 -3
- data/lib/fontisan/tables/os2_table.rb +0 -3
- data/lib/fontisan/tables/post_table.rb +0 -3
- data/lib/fontisan/tables/sbix.rb +0 -1
- data/lib/fontisan/tables/svg.rb +0 -1
- data/lib/fontisan/tables/variation_common.rb +0 -1
- data/lib/fontisan/tables/vvar.rb +0 -3
- data/lib/fontisan/tables.rb +54 -0
- data/lib/fontisan/true_type_collection.rb +6 -14
- data/lib/fontisan/true_type_font.rb +8 -2
- data/lib/fontisan/true_type_font_extensions.rb +9 -9
- data/lib/fontisan/type1/afm_generator.rb +0 -4
- data/lib/fontisan/type1/conversion_options.rb +0 -2
- data/lib/fontisan/type1/encodings.rb +0 -2
- data/lib/fontisan/type1/generator.rb +0 -8
- data/lib/fontisan/type1/pfa_generator.rb +0 -3
- data/lib/fontisan/type1/pfb_generator.rb +0 -5
- data/lib/fontisan/type1/pfm_generator.rb +0 -4
- data/lib/fontisan/type1.rb +42 -69
- data/lib/fontisan/type1_font.rb +40 -11
- data/lib/fontisan/ucd/aggregator.rb +73 -0
- data/lib/fontisan/ucd/cache_manager.rb +111 -0
- data/lib/fontisan/ucd/config.rb +59 -0
- data/lib/fontisan/ucd/download_error.rb +9 -0
- data/lib/fontisan/ucd/downloader.rb +88 -0
- data/lib/fontisan/ucd/error.rb +8 -0
- data/lib/fontisan/ucd/index.rb +103 -0
- data/lib/fontisan/ucd/index_builder.rb +107 -0
- data/lib/fontisan/ucd/range_entry.rb +56 -0
- data/lib/fontisan/ucd/unknown_version_error.rb +9 -0
- data/lib/fontisan/ucd/version_resolver.rb +79 -0
- data/lib/fontisan/ucd.rb +23 -0
- data/lib/fontisan/utilities/checksum_calculator.rb +0 -1
- data/lib/fontisan/utilities.rb +10 -0
- data/lib/fontisan/utils.rb +10 -0
- data/lib/fontisan/validation/collection_validator.rb +0 -2
- data/lib/fontisan/validation.rb +9 -0
- data/lib/fontisan/validators/basic_validator.rb +0 -2
- data/lib/fontisan/validators/font_book_validator.rb +0 -2
- data/lib/fontisan/validators/opentype_validator.rb +0 -2
- data/lib/fontisan/validators/profile_loader.rb +0 -5
- data/lib/fontisan/validators/validator.rb +0 -2
- data/lib/fontisan/validators/web_font_validator.rb +0 -2
- data/lib/fontisan/validators.rb +14 -0
- data/lib/fontisan/variable/delta_applicator.rb +0 -4
- data/lib/fontisan/variable/instancer.rb +0 -3
- data/lib/fontisan/variable/static_font_builder.rb +0 -3
- data/lib/fontisan/variable.rb +16 -0
- data/lib/fontisan/variation/blend_applier.rb +0 -2
- data/lib/fontisan/variation/cache.rb +0 -2
- data/lib/fontisan/variation/converter.rb +0 -3
- data/lib/fontisan/variation/data_extractor.rb +0 -2
- data/lib/fontisan/variation/delta_applier.rb +0 -5
- data/lib/fontisan/variation/inspector.rb +0 -1
- data/lib/fontisan/variation/instance_generator.rb +0 -6
- data/lib/fontisan/variation/instance_writer.rb +0 -5
- data/lib/fontisan/variation/metrics_adjuster.rb +0 -4
- data/lib/fontisan/variation/optimizer.rb +0 -3
- data/lib/fontisan/variation/parallel_generator.rb +0 -3
- data/lib/fontisan/variation/subsetter.rb +0 -4
- data/lib/fontisan/variation/tuple_variation_header.rb +0 -2
- data/lib/fontisan/variation/variable_svg_generator.rb +0 -3
- data/lib/fontisan/variation/variation_context.rb +0 -3
- data/lib/fontisan/variation/variation_preserver.rb +0 -3
- data/lib/fontisan/variation.rb +31 -0
- data/lib/fontisan/version.rb +1 -1
- data/lib/fontisan/woff2.rb +13 -0
- data/lib/fontisan/woff2_font.rb +31 -9
- data/lib/fontisan/woff_font.rb +31 -2
- data/lib/fontisan.rb +124 -196
- metadata +128 -7
- data/fontisan.gemspec +0 -47
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Post-build fixes for GitHub Pages subpath deployment.
|
|
3
|
+
//
|
|
4
|
+
// 1. Dirify: convert VitePress file-style output (foo.html) to directory-style
|
|
5
|
+
// (foo/index.html) so GitHub Pages resolves BOTH /foo and /foo/. Without
|
|
6
|
+
// this, /foo/ 404s because foo.html is a file, not a directory.
|
|
7
|
+
//
|
|
8
|
+
// 2. Sitemap base: insert the deployment base path into sitemap.xml URLs.
|
|
9
|
+
// VitePress omits `base` from sitemap route paths (and ignores the path
|
|
10
|
+
// portion of `sitemap.hostname`), so the generated URLs point at the origin
|
|
11
|
+
// root instead of the subsite. We rewrite each <loc> to include the base.
|
|
12
|
+
//
|
|
13
|
+
// Idempotent. Kept at the dist root: index.html (site root), 404.html (GHP 404 page).
|
|
14
|
+
import {
|
|
15
|
+
existsSync,
|
|
16
|
+
mkdirSync,
|
|
17
|
+
readdirSync,
|
|
18
|
+
readFileSync,
|
|
19
|
+
renameSync,
|
|
20
|
+
statSync,
|
|
21
|
+
writeFileSync,
|
|
22
|
+
} from "node:fs";
|
|
23
|
+
import { join } from "node:path";
|
|
24
|
+
|
|
25
|
+
const DIST = ".vitepress/dist";
|
|
26
|
+
const HTML = ".html";
|
|
27
|
+
const KEEP_AT_ROOT = new Set(["index.html", "404.html"]);
|
|
28
|
+
// Subsite identity — must match config.ts base and the real deployment URL.
|
|
29
|
+
const ORIGIN = "https://www.fontist.org";
|
|
30
|
+
const BASE = "fontisan"; // path segment under ORIGIN (no slashes)
|
|
31
|
+
|
|
32
|
+
let moved = 0;
|
|
33
|
+
let skipped = 0;
|
|
34
|
+
|
|
35
|
+
function dirify(dir) {
|
|
36
|
+
for (const entry of readdirSync(dir)) {
|
|
37
|
+
const full = join(dir, entry);
|
|
38
|
+
if (statSync(full).isDirectory()) {
|
|
39
|
+
dirify(full);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (!entry.endsWith(HTML)) continue;
|
|
43
|
+
if (entry === "index.html") continue; // already directory-style
|
|
44
|
+
if (dir === DIST && KEEP_AT_ROOT.has(entry)) {
|
|
45
|
+
skipped++; // root index.html / 404.html stay put
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const name = entry.slice(0, -HTML.length);
|
|
49
|
+
const targetDir = join(dir, name);
|
|
50
|
+
const targetIndex = join(targetDir, "index.html");
|
|
51
|
+
if (existsSync(targetIndex)) {
|
|
52
|
+
console.warn(`[post-build] skip ${full.replace(DIST + "/", "")}: target exists`);
|
|
53
|
+
skipped++;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
mkdirSync(targetDir, { recursive: true });
|
|
57
|
+
renameSync(full, targetIndex);
|
|
58
|
+
moved++;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function fixSitemapBase() {
|
|
63
|
+
const sitemap = `${DIST}/sitemap.xml`;
|
|
64
|
+
if (!existsSync(sitemap)) return false;
|
|
65
|
+
let xml = readFileSync(sitemap, "utf8");
|
|
66
|
+
// Insert BASE after the origin unless the path already starts with BASE
|
|
67
|
+
// (VitePress emits the homepage route as "/<base>"; other routes omit it).
|
|
68
|
+
const originPattern = new RegExp(
|
|
69
|
+
`(<loc>${ORIGIN.replaceAll("/", "\\/")}\\/)(?!${BASE}(\\/|$))`,
|
|
70
|
+
"g",
|
|
71
|
+
);
|
|
72
|
+
xml = xml.replace(originPattern, `$1${BASE}/`);
|
|
73
|
+
writeFileSync(sitemap, xml);
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
dirify(DIST);
|
|
78
|
+
const sitemapFixed = fixSitemapBase();
|
|
79
|
+
console.log(
|
|
80
|
+
`[post-build] dirified ${moved} route(s), kept ${skipped} at root; sitemap ${sitemapFixed ? "rewritten with /" + BASE + "/" : "absent (skipped)"}`,
|
|
81
|
+
);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Fontisan
|
|
4
|
+
module Audit
|
|
5
|
+
# Coalesces a flat codepoint list into contiguous {Models::Audit::CodepointRange}s.
|
|
6
|
+
#
|
|
7
|
+
# Single static call site, deterministic output. Used by the Coverage
|
|
8
|
+
# extractor to produce the compact range view that is the default
|
|
9
|
+
# AuditReport shape.
|
|
10
|
+
module CodepointRangeCoalescer
|
|
11
|
+
module_function
|
|
12
|
+
|
|
13
|
+
# @param codepoints [Enumerable<Integer>] any enumeration of integers
|
|
14
|
+
# @return [Array<Models::Audit::CodepointRange>] contiguous, sorted
|
|
15
|
+
def call(codepoints)
|
|
16
|
+
return [] if codepoints.nil? || codepoints.empty?
|
|
17
|
+
|
|
18
|
+
sorted = codepoints.sort.uniq
|
|
19
|
+
ranges = []
|
|
20
|
+
range_start = sorted[0]
|
|
21
|
+
prev = sorted[0]
|
|
22
|
+
|
|
23
|
+
sorted[1..].each do |cp|
|
|
24
|
+
next if cp == prev # defensive: .uniq already handles this
|
|
25
|
+
|
|
26
|
+
if cp == prev + 1
|
|
27
|
+
prev = cp
|
|
28
|
+
else
|
|
29
|
+
ranges << Models::Audit::CodepointRange.new(first_cp: range_start,
|
|
30
|
+
last_cp: prev)
|
|
31
|
+
range_start = cp
|
|
32
|
+
prev = cp
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
ranges << Models::Audit::CodepointRange.new(first_cp: range_start,
|
|
36
|
+
last_cp: prev)
|
|
37
|
+
ranges
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Fontisan
|
|
4
|
+
module Audit
|
|
5
|
+
# Value object carrying everything an extractor needs to do its job.
|
|
6
|
+
#
|
|
7
|
+
# Extractors never reach back into AuditCommand state — they read
|
|
8
|
+
# exclusively from the Context. Shared derived data (codepoints,
|
|
9
|
+
# UCD indices, source format) is memoized here so multiple
|
|
10
|
+
# extractors don't recompute it.
|
|
11
|
+
class Context
|
|
12
|
+
attr_reader :font, :font_path, :font_index, :num_fonts_in_source,
|
|
13
|
+
:options
|
|
14
|
+
|
|
15
|
+
def initialize(font:, font_path:, font_index:, num_fonts_in_source:,
|
|
16
|
+
options:)
|
|
17
|
+
@font = font
|
|
18
|
+
@font_path = font_path
|
|
19
|
+
@font_index = font_index
|
|
20
|
+
@num_fonts_in_source = num_fonts_in_source
|
|
21
|
+
@options = options
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def codepoints
|
|
25
|
+
@codepoints ||= extract_codepoints
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def ucd
|
|
29
|
+
@ucd ||= resolve_ucd
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def cldr
|
|
33
|
+
return nil unless @options[:with_language_coverage]
|
|
34
|
+
|
|
35
|
+
@cldr ||= resolve_cldr
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def source_format
|
|
39
|
+
@source_format ||= FontLoader.detect_format(@font_path)&.to_s
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def all_codepoints?
|
|
43
|
+
@options[:all_codepoints] == true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def extract_codepoints
|
|
49
|
+
return [] unless @font.has_table?(Constants::CMAP_TAG)
|
|
50
|
+
|
|
51
|
+
@font.table(Constants::CMAP_TAG).unicode_mappings.keys
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def resolve_ucd
|
|
55
|
+
version = Ucd::VersionResolver.resolve(@options[:ucd_version])
|
|
56
|
+
|
|
57
|
+
with_local_indices(version) do |blocks_path, scripts_path|
|
|
58
|
+
{
|
|
59
|
+
version: version,
|
|
60
|
+
blocks_index: Ucd::Index.load(blocks_path),
|
|
61
|
+
scripts_index: Ucd::Index.load(scripts_path),
|
|
62
|
+
warning: nil,
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
rescue Ucd::UnknownVersionError => e
|
|
66
|
+
{ version: nil, blocks_index: nil, scripts_index: nil,
|
|
67
|
+
warning: "UCD version rejected: #{e.message}" }
|
|
68
|
+
rescue StandardError => e
|
|
69
|
+
version_ref = @ucd&.fetch(:version, nil)
|
|
70
|
+
{
|
|
71
|
+
version: version_ref,
|
|
72
|
+
blocks_index: nil,
|
|
73
|
+
scripts_index: nil,
|
|
74
|
+
warning: "UCD unavailable for version #{version_ref}: #{e.message}",
|
|
75
|
+
}
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def with_local_indices(version)
|
|
79
|
+
unless Ucd::CacheManager.cached?(version)
|
|
80
|
+
Ucd::Downloader.download(version)
|
|
81
|
+
end
|
|
82
|
+
unless Ucd::CacheManager.blocks_index_path(version).exist?
|
|
83
|
+
Ucd::IndexBuilder.build(version)
|
|
84
|
+
end
|
|
85
|
+
yield Ucd::CacheManager.blocks_index_path(version),
|
|
86
|
+
Ucd::CacheManager.scripts_index_path(version)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def resolve_cldr
|
|
90
|
+
version = Cldr::VersionResolver.resolve(@options[:cldr_version])
|
|
91
|
+
|
|
92
|
+
with_local_languages_index(version) do |index_path|
|
|
93
|
+
{
|
|
94
|
+
version: version,
|
|
95
|
+
index: Cldr::Index.load(index_path),
|
|
96
|
+
warning: nil,
|
|
97
|
+
}
|
|
98
|
+
end
|
|
99
|
+
rescue Cldr::UnknownVersionError => e
|
|
100
|
+
{ version: nil, index: nil,
|
|
101
|
+
warning: "CLDR version rejected: #{e.message}" }
|
|
102
|
+
rescue StandardError => e
|
|
103
|
+
version_ref = @cldr&.fetch(:version, nil)
|
|
104
|
+
{
|
|
105
|
+
version: version_ref,
|
|
106
|
+
index: nil,
|
|
107
|
+
warning: "CLDR unavailable for version #{version_ref}: #{e.message}",
|
|
108
|
+
}
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def with_local_languages_index(version)
|
|
112
|
+
unless Cldr::CacheManager.cached?(version)
|
|
113
|
+
Cldr::Downloader.download(version)
|
|
114
|
+
end
|
|
115
|
+
unless Cldr::CacheManager.languages_index_path(version).exist?
|
|
116
|
+
Cldr::IndexBuilder.build(version)
|
|
117
|
+
end
|
|
118
|
+
yield Cldr::CacheManager.languages_index_path(version)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Fontisan
|
|
4
|
+
module Audit
|
|
5
|
+
# Computes an {Models::Audit::AuditDiff} between two AuditReports.
|
|
6
|
+
#
|
|
7
|
+
# Pure: no I/O, no font parsing. Both reports must already be built
|
|
8
|
+
# (Commands::AuditCompareCommand handles loading reports from disk
|
|
9
|
+
# or auditing fresh fonts before invoking the differ).
|
|
10
|
+
#
|
|
11
|
+
# Comparison shape:
|
|
12
|
+
# - Scalar fields: one FieldChange per differing field.
|
|
13
|
+
# - Codepoint coverage: CodepointSetDiff built from the cmap range
|
|
14
|
+
# lists (expanded to integer sets for set arithmetic, then
|
|
15
|
+
# re-coalesced to ranges for output).
|
|
16
|
+
# - Structural inventories (features, scripts, blocks, languages):
|
|
17
|
+
# simple array set-diffs.
|
|
18
|
+
class Differ
|
|
19
|
+
# Scalar AuditReport fields compared field-by-field. Excludes
|
|
20
|
+
# generated_at / source_sha256 / source_file (per-report identity),
|
|
21
|
+
# codepoints / codepoint_ranges (handled via CodepointSetDiff),
|
|
22
|
+
# and nested models (surfaced via structural add/remove lists).
|
|
23
|
+
COMPARED_FIELDS = %i[
|
|
24
|
+
family_name subfamily_name full_name postscript_name version
|
|
25
|
+
font_revision weight_class width_class italic bold panose
|
|
26
|
+
total_codepoints total_glyphs ucd_version cldr_version
|
|
27
|
+
].freeze
|
|
28
|
+
|
|
29
|
+
def initialize(left_report, right_report)
|
|
30
|
+
@left = left_report
|
|
31
|
+
@right = right_report
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @return [Models::Audit::AuditDiff]
|
|
35
|
+
def diff
|
|
36
|
+
Models::Audit::AuditDiff.new(
|
|
37
|
+
left_source: @left.source_file,
|
|
38
|
+
right_source: @right.source_file,
|
|
39
|
+
field_changes: field_changes,
|
|
40
|
+
codepoints: codepoint_diff,
|
|
41
|
+
added_features: set_diff(features(@right), features(@left)),
|
|
42
|
+
removed_features: set_diff(features(@left), features(@right)),
|
|
43
|
+
added_scripts: set_diff(scripts(@right), scripts(@left)),
|
|
44
|
+
removed_scripts: set_diff(scripts(@left), scripts(@right)),
|
|
45
|
+
added_blocks: set_diff(blocks(@right), blocks(@left)),
|
|
46
|
+
removed_blocks: set_diff(blocks(@left), blocks(@right)),
|
|
47
|
+
added_languages: set_diff(languages(@right), languages(@left)),
|
|
48
|
+
removed_languages: set_diff(languages(@left), languages(@right)),
|
|
49
|
+
)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def field_changes
|
|
55
|
+
COMPARED_FIELDS.filter_map do |field|
|
|
56
|
+
left_val = @left.public_send(field)
|
|
57
|
+
right_val = @right.public_send(field)
|
|
58
|
+
next if left_val == right_val
|
|
59
|
+
|
|
60
|
+
Models::Audit::FieldChange.new(
|
|
61
|
+
field: field.to_s,
|
|
62
|
+
left: serialize_value(left_val),
|
|
63
|
+
right: serialize_value(right_val),
|
|
64
|
+
)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def codepoint_diff
|
|
69
|
+
left_set = codepoints_from_ranges(@left)
|
|
70
|
+
right_set = codepoints_from_ranges(@right)
|
|
71
|
+
added = right_set - left_set
|
|
72
|
+
removed = left_set - right_set
|
|
73
|
+
unchanged = left_set & right_set
|
|
74
|
+
|
|
75
|
+
Models::Audit::CodepointSetDiff.new(
|
|
76
|
+
added: CodepointRangeCoalescer.call(added.to_a),
|
|
77
|
+
removed: CodepointRangeCoalescer.call(removed.to_a),
|
|
78
|
+
added_count: added.size,
|
|
79
|
+
removed_count: removed.size,
|
|
80
|
+
unchanged_count: unchanged.size,
|
|
81
|
+
)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Expand a report's compact codepoint range list into a Set<Integer>.
|
|
85
|
+
# Works for both default reports (range list populated) and
|
|
86
|
+
# --all-codepoints reports (range list is also populated).
|
|
87
|
+
def codepoints_from_ranges(report)
|
|
88
|
+
ranges = report.codepoint_ranges || []
|
|
89
|
+
ranges.each_with_object(Set.new) do |range, set|
|
|
90
|
+
(range.first_cp..range.last_cp).each { |cp| set << cp }
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def features(report)
|
|
95
|
+
report.opentype_layout&.features || []
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def scripts(report)
|
|
99
|
+
report.opentype_layout&.scripts || []
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def blocks(report)
|
|
103
|
+
(report.blocks || []).map(&:name)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def languages(report)
|
|
107
|
+
(report.language_coverage || []).map(&:language)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def set_diff(minuend, subtrahend)
|
|
111
|
+
(Array(minuend) - Array(subtrahend)).sort
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def serialize_value(value)
|
|
115
|
+
case value
|
|
116
|
+
when nil then ""
|
|
117
|
+
when String, Integer, Float then value.to_s
|
|
118
|
+
when true, false then value.to_s
|
|
119
|
+
else value.to_yaml
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Fontisan
|
|
4
|
+
module Audit
|
|
5
|
+
module Extractors
|
|
6
|
+
# Aggregation fields: UCD block/script coverage.
|
|
7
|
+
#
|
|
8
|
+
# Returned fields:
|
|
9
|
+
# ucd_version, blocks, unicode_scripts
|
|
10
|
+
#
|
|
11
|
+
# OpenType script/feature inventory lives in {Extractors::OpenTypeLayout}
|
|
12
|
+
# (MECE: this extractor is UCD-driven, that one is SFNT-table-driven).
|
|
13
|
+
class Aggregations < Base
|
|
14
|
+
def extract(context)
|
|
15
|
+
ucd = context.ucd
|
|
16
|
+
ucd_aggregations(context.codepoints, ucd)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def ucd_aggregations(codepoints, ucd)
|
|
22
|
+
return empty_aggregation(ucd) if ucd[:blocks_index].nil?
|
|
23
|
+
|
|
24
|
+
blocks_hashes = Ucd::Aggregator.aggregate_blocks(codepoints,
|
|
25
|
+
ucd[:blocks_index])
|
|
26
|
+
{
|
|
27
|
+
ucd_version: ucd[:version],
|
|
28
|
+
blocks: blocks_hashes.map { |h| build_audit_block(h) },
|
|
29
|
+
unicode_scripts: Ucd::Aggregator.aggregate_scripts(codepoints,
|
|
30
|
+
ucd[:scripts_index]),
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def empty_aggregation(ucd)
|
|
35
|
+
{ ucd_version: ucd[:version], blocks: [], unicode_scripts: [] }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def build_audit_block(block_hash)
|
|
39
|
+
Models::Audit::AuditBlock.new(
|
|
40
|
+
name: block_hash[:name],
|
|
41
|
+
first_cp: block_hash[:first_cp],
|
|
42
|
+
last_cp: block_hash[:last_cp],
|
|
43
|
+
range: format("U+%<first>04X-U+%<last>04X",
|
|
44
|
+
first: block_hash[:first_cp], last: block_hash[:last_cp]),
|
|
45
|
+
total: block_hash[:total],
|
|
46
|
+
covered: block_hash[:covered],
|
|
47
|
+
fill_ratio: block_hash[:fill_ratio],
|
|
48
|
+
complete: block_hash[:complete],
|
|
49
|
+
)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Fontisan
|
|
4
|
+
module Audit
|
|
5
|
+
module Extractors
|
|
6
|
+
# Abstract extractor interface. Subclasses implement `#extract`.
|
|
7
|
+
#
|
|
8
|
+
# An extractor reads from a Context and returns a hash of fields
|
|
9
|
+
# suitable for `Models::Audit::AuditReport.new(**fields)`.
|
|
10
|
+
# Returning an empty hash is valid (no-op).
|
|
11
|
+
class Base
|
|
12
|
+
def extract(context)
|
|
13
|
+
raise NotImplementedError,
|
|
14
|
+
"#{self.class} must implement #extract"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
|
|
19
|
+
# Convenience accessor used by most extractors.
|
|
20
|
+
def font(context)
|
|
21
|
+
context.font
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Fontisan
|
|
4
|
+
module Audit
|
|
5
|
+
module Extractors
|
|
6
|
+
# Color-font capability summary: which color formats a face carries
|
|
7
|
+
# (COLR v0/v1, CPAL, SVG, CBDT/CBLC, sbix) plus lightweight counts
|
|
8
|
+
# from each table's header.
|
|
9
|
+
#
|
|
10
|
+
# Returned fields:
|
|
11
|
+
# color_capabilities: Models::Audit::ColorCapabilities, or nil
|
|
12
|
+
# for Type 1
|
|
13
|
+
#
|
|
14
|
+
# Counts are best-effort — any table that fails to parse yields nil
|
|
15
|
+
# for its corresponding count fields rather than crashing the audit.
|
|
16
|
+
class ColorCapabilities < Base
|
|
17
|
+
def extract(context)
|
|
18
|
+
font = context.font
|
|
19
|
+
return { color_capabilities: nil } unless sfnt?(font)
|
|
20
|
+
|
|
21
|
+
{ color_capabilities: Models::Audit::ColorCapabilities.new(**gather(font)) }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
protected
|
|
25
|
+
|
|
26
|
+
def sfnt?(font)
|
|
27
|
+
font.is_a?(SfntFont)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def gather(font)
|
|
33
|
+
colr = colr_fields(font)
|
|
34
|
+
cpal = cpal_fields(font)
|
|
35
|
+
svg = svg_fields(font)
|
|
36
|
+
cbdt = cbdt_fields(font)
|
|
37
|
+
sbix = sbix_fields(font)
|
|
38
|
+
|
|
39
|
+
formats = Models::Audit::ColorCapabilities.derive_formats(
|
|
40
|
+
has_colr: colr[:has_colr], colr_version: colr[:colr_version],
|
|
41
|
+
has_cpal: cpal[:has_cpal], has_svg: svg[:has_svg],
|
|
42
|
+
has_cbdt: cbdt[:has_cbdt], has_sbix: sbix[:has_sbix]
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
colr.merge(cpal).merge(svg).merge(cbdt).merge(sbix)
|
|
46
|
+
.merge(color_formats: formats)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def colr_fields(font)
|
|
50
|
+
return empty_colr unless font.has_table?(Constants::COLR_TAG)
|
|
51
|
+
|
|
52
|
+
colr = font.table(Constants::COLR_TAG)
|
|
53
|
+
return empty_colr unless colr
|
|
54
|
+
|
|
55
|
+
{
|
|
56
|
+
has_colr: true,
|
|
57
|
+
colr_version: colr.version&.to_i,
|
|
58
|
+
colr_base_glyph_count: colr.num_base_glyph_records&.to_i,
|
|
59
|
+
colr_layer_count: colr.num_layer_records&.to_i,
|
|
60
|
+
}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def empty_colr
|
|
64
|
+
{ has_colr: false, colr_version: nil,
|
|
65
|
+
colr_base_glyph_count: nil, colr_layer_count: nil }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def cpal_fields(font)
|
|
69
|
+
return empty_cpal unless font.has_table?(Constants::CPAL_TAG)
|
|
70
|
+
|
|
71
|
+
cpal = font.table(Constants::CPAL_TAG)
|
|
72
|
+
return empty_cpal unless cpal
|
|
73
|
+
|
|
74
|
+
{
|
|
75
|
+
has_cpal: true,
|
|
76
|
+
cpal_palette_count: cpal.num_palettes&.to_i,
|
|
77
|
+
cpal_color_count: cpal.num_color_records&.to_i,
|
|
78
|
+
}
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def empty_cpal
|
|
82
|
+
{ has_cpal: false, cpal_palette_count: nil, cpal_color_count: nil }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def svg_fields(font)
|
|
86
|
+
return empty_svg unless font.has_table?(Constants::SVG_TAG)
|
|
87
|
+
|
|
88
|
+
svg = font.table(Constants::SVG_TAG)
|
|
89
|
+
return empty_svg unless svg
|
|
90
|
+
|
|
91
|
+
{
|
|
92
|
+
has_svg: true,
|
|
93
|
+
svg_document_count: svg.num_svg_documents&.to_i,
|
|
94
|
+
}
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def empty_svg
|
|
98
|
+
{ has_svg: false, svg_document_count: nil }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# CBDT/CBLC are paired tables: CBLC holds the strike index,
|
|
102
|
+
# CBDT holds the bitmap data. has_cbdt vs has_cblc disagreement
|
|
103
|
+
# is reported as-is — audit consumers can spot the inconsistency.
|
|
104
|
+
def cbdt_fields(font)
|
|
105
|
+
has_cbdt = font.has_table?(Constants::CBDT_TAG)
|
|
106
|
+
has_cblc = font.has_table?(Constants::CBLC_TAG)
|
|
107
|
+
strike_count = cblc_strike_count(font) if has_cblc
|
|
108
|
+
|
|
109
|
+
{
|
|
110
|
+
has_cbdt: has_cbdt,
|
|
111
|
+
has_cblc: has_cblc,
|
|
112
|
+
cbdt_strike_count: strike_count,
|
|
113
|
+
}
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def cblc_strike_count(font)
|
|
117
|
+
cblc = font.table(Constants::CBLC_TAG)
|
|
118
|
+
return nil unless cblc
|
|
119
|
+
|
|
120
|
+
cblc.num_sizes&.to_i
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def sbix_fields(font)
|
|
124
|
+
return empty_sbix unless font.has_table?(Constants::SBIX_TAG)
|
|
125
|
+
|
|
126
|
+
sbix = font.table(Constants::SBIX_TAG)
|
|
127
|
+
return empty_sbix unless sbix
|
|
128
|
+
|
|
129
|
+
{
|
|
130
|
+
has_sbix: true,
|
|
131
|
+
sbix_strike_count: sbix.num_strikes&.to_i,
|
|
132
|
+
}
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def empty_sbix
|
|
136
|
+
{ has_sbix: false, sbix_strike_count: nil }
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Fontisan
|
|
4
|
+
module Audit
|
|
5
|
+
module Extractors
|
|
6
|
+
# Coverage fields: how many codepoints and glyphs the font ships,
|
|
7
|
+
# the compact codepoint-range view (default), and the optional flat
|
|
8
|
+
# per-codepoint list (only when `--all-codepoints` is on).
|
|
9
|
+
#
|
|
10
|
+
# Returned fields:
|
|
11
|
+
# total_codepoints, total_glyphs, cmap_subtables,
|
|
12
|
+
# codepoint_ranges, codepoints
|
|
13
|
+
class Coverage < Base
|
|
14
|
+
def extract(context)
|
|
15
|
+
font = context.font
|
|
16
|
+
codepoints = context.codepoints
|
|
17
|
+
{
|
|
18
|
+
total_codepoints: codepoints.length,
|
|
19
|
+
total_glyphs: total_glyphs(font),
|
|
20
|
+
cmap_subtables: cmap_subtable_formats(font),
|
|
21
|
+
codepoint_ranges: CodepointRangeCoalescer.call(codepoints),
|
|
22
|
+
codepoints: codepoints_for_report(context, codepoints),
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def total_glyphs(font)
|
|
29
|
+
return nil unless font.has_table?(Constants::MAXP_TAG)
|
|
30
|
+
|
|
31
|
+
font.table(Constants::MAXP_TAG).num_glyphs
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def cmap_subtable_formats(font)
|
|
35
|
+
return [] unless font.has_table?(Constants::CMAP_TAG)
|
|
36
|
+
|
|
37
|
+
font.table(Constants::CMAP_TAG).subtable_formats
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def codepoints_for_report(context, codepoints)
|
|
41
|
+
return [] unless context.all_codepoints?
|
|
42
|
+
|
|
43
|
+
codepoints.map { |cp| format("U+%<cp>04X", cp: cp) }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|