fontisan 0.2.22 → 0.3.0
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.yml +6 -0
- data/.rubocop_todo.yml +93 -17
- data/CHANGELOG.md +12 -2
- data/README.adoc +6 -210
- data/fontisan.gemspec +48 -0
- data/lib/fontisan/cldr/unicode_set_parser.rb +23 -6
- data/lib/fontisan/cldr/version_resolver.rb +1 -1
- data/lib/fontisan/cli.rb +4 -168
- data/lib/fontisan/commands.rb +0 -3
- data/lib/fontisan/formatters/text_formatter.rb +0 -6
- data/lib/fontisan/formatters.rb +0 -3
- data/lib/fontisan/hints.rb +6 -3
- data/lib/fontisan/models.rb +4 -4
- data/lib/fontisan/pipeline/strategies.rb +4 -2
- data/lib/fontisan/pipeline.rb +2 -1
- 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 +97 -0
- data/lib/fontisan/stitcher.rb +182 -0
- data/lib/fontisan/stitcher_cli.rb +69 -0
- data/lib/fontisan/tables/cff.rb +2 -1
- data/lib/fontisan/tables.rb +2 -1
- data/lib/fontisan/ufo/anchor.rb +17 -0
- data/lib/fontisan/ufo/cli.rb +85 -0
- data/lib/fontisan/ufo/compile/base_compiler.rb +81 -0
- data/lib/fontisan/ufo/compile/cff.rb +224 -0
- data/lib/fontisan/ufo/compile/cmap.rb +129 -0
- data/lib/fontisan/ufo/compile/filters/cubic_to_quadratic.rb +174 -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/reverse_contour_direction.rb +27 -0
- data/lib/fontisan/ufo/compile/filters.rb +57 -0
- data/lib/fontisan/ufo/compile/glyf_loca.rb +145 -0
- data/lib/fontisan/ufo/compile/head.rb +98 -0
- data/lib/fontisan/ufo/compile/hhea.rb +36 -0
- data/lib/fontisan/ufo/compile/hmtx.rb +27 -0
- data/lib/fontisan/ufo/compile/maxp.rb +57 -0
- data/lib/fontisan/ufo/compile/name.rb +79 -0
- data/lib/fontisan/ufo/compile/os2.rb +81 -0
- data/lib/fontisan/ufo/compile/otf_compiler.rb +43 -0
- data/lib/fontisan/ufo/compile/post.rb +32 -0
- data/lib/fontisan/ufo/compile/ttf_compiler.rb +69 -0
- data/lib/fontisan/ufo/compile.rb +48 -0
- data/lib/fontisan/ufo/component.rb +18 -0
- data/lib/fontisan/ufo/contour.rb +29 -0
- data/lib/fontisan/ufo/convert/from_bin_data.rb +246 -0
- data/lib/fontisan/ufo/convert.rb +18 -0
- data/lib/fontisan/ufo/data_set.rb +21 -0
- data/lib/fontisan/ufo/features.rb +17 -0
- data/lib/fontisan/ufo/font.rb +61 -0
- data/lib/fontisan/ufo/glyph.rb +421 -0
- data/lib/fontisan/ufo/guideline.rb +19 -0
- data/lib/fontisan/ufo/image.rb +16 -0
- data/lib/fontisan/ufo/image_set.rb +19 -0
- data/lib/fontisan/ufo/info.rb +79 -0
- data/lib/fontisan/ufo/kerning.rb +32 -0
- data/lib/fontisan/ufo/layer.rb +38 -0
- data/lib/fontisan/ufo/layer_set.rb +37 -0
- data/lib/fontisan/ufo/lib.rb +24 -0
- data/lib/fontisan/ufo/plist.rb +118 -0
- data/lib/fontisan/ufo/point.rb +38 -0
- data/lib/fontisan/ufo/reader.rb +144 -0
- data/lib/fontisan/ufo/transformation.rb +39 -0
- data/lib/fontisan/ufo/writer.rb +115 -0
- data/lib/fontisan/ufo.rb +44 -0
- data/lib/fontisan/version.rb +1 -1
- data/lib/fontisan.rb +3 -3
- metadata +57 -70
- data/lib/fontisan/audit/codepoint_range_coalescer.rb +0 -41
- data/lib/fontisan/audit/context.rb +0 -122
- data/lib/fontisan/audit/differ.rb +0 -124
- data/lib/fontisan/audit/extractors/aggregations.rb +0 -54
- data/lib/fontisan/audit/extractors/base.rb +0 -26
- data/lib/fontisan/audit/extractors/color_capabilities.rb +0 -141
- data/lib/fontisan/audit/extractors/coverage.rb +0 -48
- data/lib/fontisan/audit/extractors/hinting.rb +0 -197
- data/lib/fontisan/audit/extractors/identity.rb +0 -52
- data/lib/fontisan/audit/extractors/language_coverage.rb +0 -37
- data/lib/fontisan/audit/extractors/licensing.rb +0 -79
- data/lib/fontisan/audit/extractors/metrics.rb +0 -103
- data/lib/fontisan/audit/extractors/opentype_layout.rb +0 -69
- data/lib/fontisan/audit/extractors/provenance.rb +0 -29
- data/lib/fontisan/audit/extractors/style.rb +0 -32
- data/lib/fontisan/audit/extractors/variation_detail.rb +0 -99
- data/lib/fontisan/audit/extractors.rb +0 -27
- data/lib/fontisan/audit/library_aggregator.rb +0 -83
- data/lib/fontisan/audit/library_auditor.rb +0 -90
- data/lib/fontisan/audit/registry.rb +0 -60
- data/lib/fontisan/audit/style_extractor.rb +0 -80
- data/lib/fontisan/audit.rb +0 -20
- data/lib/fontisan/cli/ucd_cli.rb +0 -97
- data/lib/fontisan/commands/audit_command.rb +0 -123
- data/lib/fontisan/commands/audit_compare_command.rb +0 -66
- data/lib/fontisan/commands/audit_library_command.rb +0 -46
- data/lib/fontisan/config/ucd.yml +0 -23
- data/lib/fontisan/formatters/audit_diff_text_renderer.rb +0 -122
- data/lib/fontisan/formatters/audit_text_renderer.rb +0 -324
- data/lib/fontisan/formatters/library_summary_text_renderer.rb +0 -99
- data/lib/fontisan/models/audit/audit_axis.rb +0 -30
- data/lib/fontisan/models/audit/audit_block.rb +0 -32
- data/lib/fontisan/models/audit/audit_diff.rb +0 -77
- data/lib/fontisan/models/audit/audit_report.rb +0 -153
- data/lib/fontisan/models/audit/codepoint_range.rb +0 -40
- data/lib/fontisan/models/audit/codepoint_set_diff.rb +0 -34
- data/lib/fontisan/models/audit/color_capabilities.rb +0 -93
- data/lib/fontisan/models/audit/duplicate_group.rb +0 -23
- data/lib/fontisan/models/audit/embedding_type.rb +0 -76
- data/lib/fontisan/models/audit/field_change.rb +0 -28
- data/lib/fontisan/models/audit/fs_selection_flags.rb +0 -61
- data/lib/fontisan/models/audit/gasp_range.rb +0 -63
- data/lib/fontisan/models/audit/hinting.rb +0 -93
- data/lib/fontisan/models/audit/library_summary.rb +0 -40
- data/lib/fontisan/models/audit/licensing.rb +0 -48
- data/lib/fontisan/models/audit/metrics.rb +0 -111
- data/lib/fontisan/models/audit/named_instance.rb +0 -41
- data/lib/fontisan/models/audit/opentype_layout.rb +0 -40
- data/lib/fontisan/models/audit/script_coverage_row.rb +0 -26
- data/lib/fontisan/models/audit/script_features.rb +0 -28
- data/lib/fontisan/models/audit/variation_detail.rb +0 -44
- data/lib/fontisan/models/audit.rb +0 -33
- data/lib/fontisan/models/ucd/ucd.rb +0 -38
- data/lib/fontisan/models/ucd/ucd_char.rb +0 -67
- data/lib/fontisan/models/ucd.rb +0 -19
- data/lib/fontisan/ucd/aggregator.rb +0 -73
- data/lib/fontisan/ucd/cache_manager.rb +0 -111
- data/lib/fontisan/ucd/config.rb +0 -59
- data/lib/fontisan/ucd/download_error.rb +0 -9
- data/lib/fontisan/ucd/downloader.rb +0 -88
- data/lib/fontisan/ucd/error.rb +0 -8
- data/lib/fontisan/ucd/index.rb +0 -103
- data/lib/fontisan/ucd/index_builder.rb +0 -107
- data/lib/fontisan/ucd/range_entry.rb +0 -56
- data/lib/fontisan/ucd/unknown_version_error.rb +0 -9
- data/lib/fontisan/ucd/version_resolver.rb +0 -79
- data/lib/fontisan/ucd.rb +0 -23
|
@@ -1,141 +0,0 @@
|
|
|
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
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "stringio"
|
|
4
|
-
|
|
5
|
-
module Fontisan
|
|
6
|
-
module Audit
|
|
7
|
-
module Extractors
|
|
8
|
-
# Hinting summary: TrueType bytecode counts + gasp policy + CFF stem
|
|
9
|
-
# count, with derived `is_unhinted` and `hinting_format` fields.
|
|
10
|
-
#
|
|
11
|
-
# Returned fields:
|
|
12
|
-
# hinting: Models::Audit::Hinting instance, or nil for Type 1
|
|
13
|
-
#
|
|
14
|
-
# The fpgm/prep/cvt/gasp tables have no BinData classes yet — they
|
|
15
|
-
# are read as raw bytes from `font.table_data`. Bytecode is one byte
|
|
16
|
-
# per instruction; cvt is an array of FWord (int16), so the entry
|
|
17
|
-
# count is bytesize / 2.
|
|
18
|
-
class Hinting < Base
|
|
19
|
-
# Raw CFF2 / CFF2 charstring operator bytes that declare stem hints.
|
|
20
|
-
HSTEM = 1
|
|
21
|
-
VSTEM = 3
|
|
22
|
-
HSTEMHM = 18
|
|
23
|
-
VSTEMHM = 23
|
|
24
|
-
HINTMASK = 19
|
|
25
|
-
CNTRMASK = 20
|
|
26
|
-
|
|
27
|
-
def extract(context)
|
|
28
|
-
font = context.font
|
|
29
|
-
return { hinting: nil } unless sfnt?(font)
|
|
30
|
-
|
|
31
|
-
{ hinting: Models::Audit::Hinting.new(**gather(font)) }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
protected
|
|
35
|
-
|
|
36
|
-
def sfnt?(font)
|
|
37
|
-
font.is_a?(SfntFont)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
private
|
|
41
|
-
|
|
42
|
-
def gather(font)
|
|
43
|
-
tt = truetype_fields(font)
|
|
44
|
-
cff = cff_fields(font)
|
|
45
|
-
gasp = parse_gasp(font)
|
|
46
|
-
|
|
47
|
-
derived = Models::Audit::Hinting.derive_flags(
|
|
48
|
-
has_tt: tt[:has_fpgm] || tt[:has_prep] || tt[:has_cvt],
|
|
49
|
-
has_cff: cff[:cff_has_private_dict],
|
|
50
|
-
has_gasp: !gasp.empty?,
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
tt.merge(cff).merge(gasp_ranges: gasp).merge(derived)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def truetype_fields(font)
|
|
57
|
-
{
|
|
58
|
-
has_fpgm: font.has_table?(Constants::FPGM_TAG),
|
|
59
|
-
fpgm_instruction_count: byte_count(font, Constants::FPGM_TAG),
|
|
60
|
-
has_prep: font.has_table?(Constants::PREP_TAG),
|
|
61
|
-
prep_instruction_count: byte_count(font, Constants::PREP_TAG),
|
|
62
|
-
has_cvt: font.has_table?(Constants::CVT_TAG),
|
|
63
|
-
cvt_entry_count: cvt_entry_count(font),
|
|
64
|
-
has_cvar: font.has_table?(Constants::CVAR_TAG),
|
|
65
|
-
}
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def cff_fields(font)
|
|
69
|
-
has_cff1 = font.has_table?(Constants::CFF_TAG)
|
|
70
|
-
has_cff2 = font.has_table?(Constants::CFF2_TAG)
|
|
71
|
-
has_private = has_cff1 || has_cff2
|
|
72
|
-
|
|
73
|
-
{
|
|
74
|
-
cff_has_private_dict: has_private,
|
|
75
|
-
cff_hint_count: has_cff1 ? count_cff_stems(font) : nil,
|
|
76
|
-
}
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def byte_count(font, tag)
|
|
80
|
-
return nil unless font.has_table?(tag)
|
|
81
|
-
|
|
82
|
-
font.table_data[tag]&.bytesize
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def cvt_entry_count(font)
|
|
86
|
-
return nil unless font.has_table?(Constants::CVT_TAG)
|
|
87
|
-
|
|
88
|
-
bytes = font.table_data[Constants::CVT_TAG]
|
|
89
|
-
return nil unless bytes
|
|
90
|
-
|
|
91
|
-
bytes.bytesize / 2
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# Parse the gasp table from raw bytes. Format: uint16 version,
|
|
95
|
-
# uint16 numRanges, then numRanges × (uint16 rangeMaxPPEM,
|
|
96
|
-
# uint16 rangeFlags). Returns [] if gasp is absent or truncated.
|
|
97
|
-
def parse_gasp(font)
|
|
98
|
-
return [] unless font.has_table?(Constants::GASP_TAG)
|
|
99
|
-
|
|
100
|
-
data = font.table_data[Constants::GASP_TAG]
|
|
101
|
-
return [] unless data && data.bytesize >= 4
|
|
102
|
-
|
|
103
|
-
_version, num_ranges = data.unpack("nn")
|
|
104
|
-
ranges = []
|
|
105
|
-
offset = 4
|
|
106
|
-
num_ranges.times do
|
|
107
|
-
break if offset + 4 > data.bytesize
|
|
108
|
-
|
|
109
|
-
max_ppem, flags = data[offset, 4].unpack("nn")
|
|
110
|
-
ranges << Models::Audit::GaspRange.from_flags(max_ppem, flags)
|
|
111
|
-
offset += 4
|
|
112
|
-
end
|
|
113
|
-
ranges
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def count_cff_stems(font)
|
|
117
|
-
return nil unless font.has_table?(Constants::CFF_TAG)
|
|
118
|
-
|
|
119
|
-
cff = font.table(Constants::CFF_TAG)
|
|
120
|
-
return nil unless cff
|
|
121
|
-
|
|
122
|
-
index = cff.charstrings_index(0)
|
|
123
|
-
return nil unless index
|
|
124
|
-
|
|
125
|
-
total = 0
|
|
126
|
-
index.count.times do |glyph_index|
|
|
127
|
-
data = index[glyph_index]
|
|
128
|
-
next unless data
|
|
129
|
-
|
|
130
|
-
total += count_stems_in_charstring(data)
|
|
131
|
-
end
|
|
132
|
-
total
|
|
133
|
-
rescue CorruptedTableError
|
|
134
|
-
nil
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
# Lightweight Type-2 CharString scanner that counts stem hints
|
|
138
|
-
# without instantiating a full CharString (which needs a Private
|
|
139
|
-
# DICT, global/local subrs, etc.). Operates purely on bytes.
|
|
140
|
-
def count_stems_in_charstring(data)
|
|
141
|
-
io = StringIO.new(data)
|
|
142
|
-
stack = 0
|
|
143
|
-
stems = 0
|
|
144
|
-
|
|
145
|
-
until io.eof?
|
|
146
|
-
byte = io.getbyte
|
|
147
|
-
next if byte.nil?
|
|
148
|
-
|
|
149
|
-
stack, stems = process_byte(io, byte, stack, stems)
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
stems
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
def process_byte(io, byte, stack, stems)
|
|
156
|
-
if operator_byte?(byte)
|
|
157
|
-
apply_operator(io, byte, stack, stems)
|
|
158
|
-
else
|
|
159
|
-
[consume_operand(io, byte, stack), stems]
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
def operator_byte?(byte)
|
|
164
|
-
byte <= 31 && byte != 28
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
def apply_operator(io, byte, stack, stems)
|
|
168
|
-
case byte
|
|
169
|
-
when 12
|
|
170
|
-
io.getbyte
|
|
171
|
-
[0, stems]
|
|
172
|
-
when HSTEM, VSTEM, HSTEMHM, VSTEMHM
|
|
173
|
-
[0, stems + stack / 2]
|
|
174
|
-
when HINTMASK, CNTRMASK
|
|
175
|
-
new_stems = stems + stack / 2
|
|
176
|
-
io.read((new_stems + 7) / 8)
|
|
177
|
-
[0, new_stems]
|
|
178
|
-
else
|
|
179
|
-
[0, stems]
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
def consume_operand(io, byte, stack)
|
|
184
|
-
case byte
|
|
185
|
-
when 28
|
|
186
|
-
io.read(2)
|
|
187
|
-
when 255
|
|
188
|
-
io.read(4)
|
|
189
|
-
when 247..254
|
|
190
|
-
io.getbyte
|
|
191
|
-
end
|
|
192
|
-
stack + 1
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
end
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fontisan
|
|
4
|
-
module Audit
|
|
5
|
-
module Extractors
|
|
6
|
-
# Identity fields: the human-readable names a font uses to describe
|
|
7
|
-
# itself, drawn from the `name` table (SFNT) or font dictionary
|
|
8
|
-
# (Type 1).
|
|
9
|
-
#
|
|
10
|
-
# Returned fields:
|
|
11
|
-
# family_name, subfamily_name, full_name, postscript_name,
|
|
12
|
-
# version, font_revision
|
|
13
|
-
class Identity < Base
|
|
14
|
-
def extract(context)
|
|
15
|
-
if context.font.is_a?(Type1Font)
|
|
16
|
-
type1_identity(context.font)
|
|
17
|
-
else
|
|
18
|
-
sfnt_identity(context.font)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
def sfnt_identity(font)
|
|
25
|
-
name_table = font.table(Constants::NAME_TAG) if font.has_table?(Constants::NAME_TAG)
|
|
26
|
-
head_table = font.table(Constants::HEAD_TAG) if font.has_table?(Constants::HEAD_TAG)
|
|
27
|
-
|
|
28
|
-
{
|
|
29
|
-
family_name: name_table&.english_name(Tables::Name::FAMILY),
|
|
30
|
-
subfamily_name: name_table&.english_name(Tables::Name::SUBFAMILY),
|
|
31
|
-
full_name: name_table&.english_name(Tables::Name::FULL_NAME),
|
|
32
|
-
postscript_name: name_table&.english_name(Tables::Name::POSTSCRIPT_NAME),
|
|
33
|
-
version: name_table&.english_name(Tables::Name::VERSION),
|
|
34
|
-
font_revision: head_table&.font_revision,
|
|
35
|
-
}
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def type1_identity(font)
|
|
39
|
-
font_info = font.font_dictionary&.font_info
|
|
40
|
-
{
|
|
41
|
-
family_name: font_info&.family_name,
|
|
42
|
-
subfamily_name: nil,
|
|
43
|
-
full_name: font_info&.full_name,
|
|
44
|
-
postscript_name: font.font_name,
|
|
45
|
-
version: font_info&.version,
|
|
46
|
-
font_revision: nil,
|
|
47
|
-
}
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fontisan
|
|
4
|
-
module Audit
|
|
5
|
-
module Extractors
|
|
6
|
-
# Per-language CLDR coverage for one face.
|
|
7
|
-
#
|
|
8
|
-
# Returned fields:
|
|
9
|
-
# language_coverage, cldr_version
|
|
10
|
-
#
|
|
11
|
-
# Opt-in only — `--with-language-coverage`. When off, Context#cldr
|
|
12
|
-
# returns nil and this extractor emits an empty array + nil version.
|
|
13
|
-
# MECE: this extractor is CLDR-driven; UCD block/script coverage
|
|
14
|
-
# lives in {Extractors::Aggregations}.
|
|
15
|
-
class LanguageCoverage < Base
|
|
16
|
-
def extract(context)
|
|
17
|
-
cldr = context.cldr
|
|
18
|
-
return empty(nil) if cldr.nil?
|
|
19
|
-
|
|
20
|
-
return empty(cldr[:version]) if cldr[:index].nil?
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
language_coverage: Cldr::Aggregator.aggregate(context.codepoints,
|
|
24
|
-
cldr[:index]),
|
|
25
|
-
cldr_version: cldr[:version],
|
|
26
|
-
}
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
private
|
|
30
|
-
|
|
31
|
-
def empty(version)
|
|
32
|
-
{ language_coverage: [], cldr_version: version }
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fontisan
|
|
4
|
-
module Audit
|
|
5
|
-
module Extractors
|
|
6
|
-
# Licensing + embedding permissions + vendor provenance.
|
|
7
|
-
#
|
|
8
|
-
# Returned fields:
|
|
9
|
-
# licensing: Models::Audit::Licensing instance, or nil for Type 1
|
|
10
|
-
#
|
|
11
|
-
# Type 1 fonts have no OS/2 table; their licensing is nil. WOFF/
|
|
12
|
-
# WOFF2 carry the same OS/2 + name tables as TTF/OTF and need no
|
|
13
|
-
# special handling.
|
|
14
|
-
class Licensing < Base
|
|
15
|
-
# nameID → AuditReport field name, per OpenType name table spec.
|
|
16
|
-
NAME_IDS = {
|
|
17
|
-
copyright: 0,
|
|
18
|
-
trademark: 7,
|
|
19
|
-
manufacturer: 8,
|
|
20
|
-
designer: 9,
|
|
21
|
-
description: 10,
|
|
22
|
-
vendor_url: 11,
|
|
23
|
-
designer_url: 12,
|
|
24
|
-
license_description: 13,
|
|
25
|
-
license_url: 14,
|
|
26
|
-
}.freeze
|
|
27
|
-
private_constant :NAME_IDS
|
|
28
|
-
|
|
29
|
-
def extract(context)
|
|
30
|
-
font = context.font
|
|
31
|
-
return { licensing: nil } unless sfnt?(font)
|
|
32
|
-
|
|
33
|
-
os2 = os2_for(font)
|
|
34
|
-
name = name_table_for(font)
|
|
35
|
-
|
|
36
|
-
{
|
|
37
|
-
licensing: Models::Audit::Licensing.new(
|
|
38
|
-
**name_fields(name),
|
|
39
|
-
vendor_id: sanitized_vendor_id(os2),
|
|
40
|
-
embedding_type: Models::Audit::EmbeddingType.decode(os2&.fs_type&.to_i),
|
|
41
|
-
fs_selection_flags: Models::Audit::FsSelectionFlags.decode(os2&.fs_selection&.to_i),
|
|
42
|
-
),
|
|
43
|
-
}
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
private
|
|
47
|
-
|
|
48
|
-
def sfnt?(font)
|
|
49
|
-
font.is_a?(SfntFont)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def os2_for(font)
|
|
53
|
-
return nil unless font.has_table?(Constants::OS2_TAG)
|
|
54
|
-
|
|
55
|
-
font.table(Constants::OS2_TAG)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def name_table_for(font)
|
|
59
|
-
return nil unless font.has_table?(Constants::NAME_TAG)
|
|
60
|
-
|
|
61
|
-
font.table(Constants::NAME_TAG)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def name_fields(name)
|
|
65
|
-
return {} unless name
|
|
66
|
-
|
|
67
|
-
NAME_IDS.transform_values { |id| name.english_name(id) }
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def sanitized_vendor_id(os2)
|
|
71
|
-
raw = os2&.ach_vend_id
|
|
72
|
-
return nil if raw.nil?
|
|
73
|
-
|
|
74
|
-
raw.gsub(/[\x00\s]+$/, "")
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fontisan
|
|
4
|
-
module Audit
|
|
5
|
-
module Extractors
|
|
6
|
-
# Layout-critical metrics consolidated from head, hhea, OS/2, post.
|
|
7
|
-
#
|
|
8
|
-
# Returned fields:
|
|
9
|
-
# metrics: Models::Audit::Metrics instance, or nil for Type 1
|
|
10
|
-
#
|
|
11
|
-
# All table reads are nil-safe; tables may be absent in stripped
|
|
12
|
-
# WOFF builds or legacy formats.
|
|
13
|
-
class Metrics < Base
|
|
14
|
-
def extract(context)
|
|
15
|
-
font = context.font
|
|
16
|
-
return { metrics: nil } unless sfnt?(font)
|
|
17
|
-
|
|
18
|
-
{ metrics: Models::Audit::Metrics.new(**gather(font)) }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
private
|
|
22
|
-
|
|
23
|
-
def sfnt?(font)
|
|
24
|
-
font.is_a?(SfntFont)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def gather(font)
|
|
28
|
-
{}.tap do |h|
|
|
29
|
-
h.merge!(head_fields(font))
|
|
30
|
-
h.merge!(hhea_fields(font))
|
|
31
|
-
h.merge!(os2_fields(font))
|
|
32
|
-
h.merge!(post_fields(font))
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def head_fields(font)
|
|
37
|
-
head = table(font, Constants::HEAD_TAG)
|
|
38
|
-
return {} unless head
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
units_per_em: head.units_per_em&.to_i,
|
|
42
|
-
bbox_x_min: head.x_min&.to_i,
|
|
43
|
-
bbox_y_min: head.y_min&.to_i,
|
|
44
|
-
bbox_x_max: head.x_max&.to_i,
|
|
45
|
-
bbox_y_max: head.y_max&.to_i,
|
|
46
|
-
}
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def hhea_fields(font)
|
|
50
|
-
hhea = table(font, Constants::HHEA_TAG)
|
|
51
|
-
return {} unless hhea
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
hhea_ascent: hhea.ascent&.to_i,
|
|
55
|
-
hhea_descent: hhea.descent&.to_i,
|
|
56
|
-
hhea_line_gap: hhea.line_gap&.to_i,
|
|
57
|
-
}
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def os2_fields(font)
|
|
61
|
-
os2 = table(font, Constants::OS2_TAG)
|
|
62
|
-
return {} unless os2
|
|
63
|
-
|
|
64
|
-
{
|
|
65
|
-
typo_ascender: os2.s_typo_ascender&.to_i,
|
|
66
|
-
typo_descender: os2.s_typo_descender&.to_i,
|
|
67
|
-
typo_line_gap: os2.s_typo_line_gap&.to_i,
|
|
68
|
-
win_ascent: os2.us_win_ascent&.to_i,
|
|
69
|
-
win_descent: os2.us_win_descent&.to_i,
|
|
70
|
-
x_height: os2.sx_height&.to_i,
|
|
71
|
-
cap_height: os2.s_cap_height&.to_i,
|
|
72
|
-
subscript_x_size: os2.y_subscript_x_size&.to_i,
|
|
73
|
-
subscript_y_size: os2.y_subscript_y_size&.to_i,
|
|
74
|
-
subscript_x_offset: os2.y_subscript_x_offset&.to_i,
|
|
75
|
-
subscript_y_offset: os2.y_subscript_y_offset&.to_i,
|
|
76
|
-
superscript_x_size: os2.y_superscript_x_size&.to_i,
|
|
77
|
-
superscript_y_size: os2.y_superscript_y_size&.to_i,
|
|
78
|
-
superscript_x_offset: os2.y_superscript_x_offset&.to_i,
|
|
79
|
-
superscript_y_offset: os2.y_superscript_y_offset&.to_i,
|
|
80
|
-
strikeout_size: os2.y_strikeout_size&.to_i,
|
|
81
|
-
strikeout_position: os2.y_strikeout_position&.to_i,
|
|
82
|
-
}
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def post_fields(font)
|
|
86
|
-
post = table(font, Constants::POST_TAG)
|
|
87
|
-
return {} unless post
|
|
88
|
-
|
|
89
|
-
{
|
|
90
|
-
underline_position: post.underline_position&.to_f,
|
|
91
|
-
underline_thickness: post.underline_thickness&.to_f,
|
|
92
|
-
}
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def table(font, tag)
|
|
96
|
-
return nil unless font.has_table?(tag)
|
|
97
|
-
|
|
98
|
-
font.table(tag)
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|