ucode 0.5.1 → 0.5.3
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/config/unicode17_universal_glyph_set.yml +1 -1
- data/lib/ucode/audit/differ.rb +17 -7
- data/lib/ucode/audit/extractors/metrics.rb +19 -19
- data/lib/ucode/audit/library_auditor.rb +2 -2
- data/lib/ucode/cli.rb +2 -2
- data/lib/ucode/coordinator/indices.rb +9 -9
- data/lib/ucode/coordinator.rb +15 -15
- data/lib/ucode/glyphs/embedded_fonts/codepoint_mapper.rb +35 -4
- data/lib/ucode/glyphs/embedded_fonts/page_trace_cache.rb +32 -3
- data/lib/ucode/glyphs/embedded_fonts/trace_correlator.rb +2 -2
- data/lib/ucode/glyphs/embedded_fonts/trace_glyph.rb +35 -1
- data/lib/ucode/models/audit/color_capabilities.rb +2 -2
- data/lib/ucode/models/unihan_entry.rb +18 -5
- data/lib/ucode/parsers/names_list.rb +13 -1
- data/lib/ucode/version.rb +1 -1
- metadata +10 -5
- data/ucode.gemspec +0 -56
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 17cbcd20288991b0c1392fb75f7190f0e4b5eaf56f71806f497eec24444caeaa
|
|
4
|
+
data.tar.gz: 9a901ccc82d0da5e54888fddb9e2af66fc70ab3ed0a4f6904bd98dfe62d17ab5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a896530701e78f713caaa9bfb2408dbc00157dab0aca51ead1c587120aa3c6d1e0fed3a8fa6383b0c9de724cb8a90dc0e7b5f945f051ee66eded449624c5be6d
|
|
7
|
+
data.tar.gz: 060601504647de557b1f1fa6bad4d2154c2687331e46463b27f54d6a9883076684397319f722e678fdbed46d6098002abc621bdab86892f3b75d996c0973a0ff
|
data/lib/ucode/audit/differ.rb
CHANGED
|
@@ -22,10 +22,20 @@ module Ucode
|
|
|
22
22
|
# generated_at / source_sha256 / source_file (per-report identity),
|
|
23
23
|
# codepoints / codepoint_ranges (handled via CodepointSetDiff),
|
|
24
24
|
# and nested models (surfaced via structural add/remove lists).
|
|
25
|
-
COMPARED_FIELDS =
|
|
26
|
-
family_name
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
COMPARED_FIELDS = [
|
|
26
|
+
[:family_name, lambda(&:family_name)],
|
|
27
|
+
[:subfamily_name, lambda(&:subfamily_name)],
|
|
28
|
+
[:full_name, lambda(&:full_name)],
|
|
29
|
+
[:postscript_name, lambda(&:postscript_name)],
|
|
30
|
+
[:version, lambda(&:version)],
|
|
31
|
+
[:font_revision, lambda(&:font_revision)],
|
|
32
|
+
[:weight_class, lambda(&:weight_class)],
|
|
33
|
+
[:width_class, lambda(&:width_class)],
|
|
34
|
+
[:italic, lambda(&:italic)],
|
|
35
|
+
[:bold, lambda(&:bold)],
|
|
36
|
+
[:panose, lambda(&:panose)],
|
|
37
|
+
[:total_codepoints, lambda(&:total_codepoints)],
|
|
38
|
+
[:total_glyphs, lambda(&:total_glyphs)],
|
|
29
39
|
].freeze
|
|
30
40
|
|
|
31
41
|
# @param left_report [Models::Audit::AuditReport]
|
|
@@ -54,9 +64,9 @@ module Ucode
|
|
|
54
64
|
private
|
|
55
65
|
|
|
56
66
|
def field_changes
|
|
57
|
-
COMPARED_FIELDS.filter_map do |field|
|
|
58
|
-
left_val = @left
|
|
59
|
-
right_val = @right
|
|
67
|
+
COMPARED_FIELDS.filter_map do |field, reader|
|
|
68
|
+
left_val = reader.call(@left)
|
|
69
|
+
right_val = reader.call(@right)
|
|
60
70
|
next if left_val == right_val
|
|
61
71
|
|
|
62
72
|
Models::Audit::FieldChange.new(
|
|
@@ -60,25 +60,25 @@ module Ucode
|
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
# OS/2 table fields exposed on Metrics, as
|
|
63
|
-
# `Metrics attribute name` => `OS/2 reader
|
|
63
|
+
# `Metrics attribute name` => `OS/2 reader lambda`.
|
|
64
64
|
OS2_FIELDS = {
|
|
65
|
-
typo_ascender:
|
|
66
|
-
typo_descender:
|
|
67
|
-
typo_line_gap:
|
|
68
|
-
win_ascent:
|
|
69
|
-
win_descent:
|
|
70
|
-
x_height:
|
|
71
|
-
cap_height:
|
|
72
|
-
subscript_x_size:
|
|
73
|
-
subscript_y_size:
|
|
74
|
-
subscript_x_offset:
|
|
75
|
-
subscript_y_offset:
|
|
76
|
-
superscript_x_size:
|
|
77
|
-
superscript_y_size:
|
|
78
|
-
superscript_x_offset:
|
|
79
|
-
superscript_y_offset:
|
|
80
|
-
strikeout_size:
|
|
81
|
-
strikeout_position:
|
|
65
|
+
typo_ascender: lambda(&:s_typo_ascender),
|
|
66
|
+
typo_descender: lambda(&:s_typo_descender),
|
|
67
|
+
typo_line_gap: lambda(&:s_typo_line_gap),
|
|
68
|
+
win_ascent: lambda(&:us_win_ascent),
|
|
69
|
+
win_descent: lambda(&:us_win_descent),
|
|
70
|
+
x_height: lambda(&:sx_height),
|
|
71
|
+
cap_height: lambda(&:s_cap_height),
|
|
72
|
+
subscript_x_size: lambda(&:y_subscript_x_size),
|
|
73
|
+
subscript_y_size: lambda(&:y_subscript_y_size),
|
|
74
|
+
subscript_x_offset: lambda(&:y_subscript_x_offset),
|
|
75
|
+
subscript_y_offset: lambda(&:y_subscript_y_offset),
|
|
76
|
+
superscript_x_size: lambda(&:y_superscript_x_size),
|
|
77
|
+
superscript_y_size: lambda(&:y_superscript_y_size),
|
|
78
|
+
superscript_x_offset: lambda(&:y_superscript_x_offset),
|
|
79
|
+
superscript_y_offset: lambda(&:y_superscript_y_offset),
|
|
80
|
+
strikeout_size: lambda(&:y_strikeout_size),
|
|
81
|
+
strikeout_position: lambda(&:y_strikeout_position),
|
|
82
82
|
}.freeze
|
|
83
83
|
private_constant :OS2_FIELDS
|
|
84
84
|
|
|
@@ -86,7 +86,7 @@ module Ucode
|
|
|
86
86
|
os2 = table(font, "OS/2")
|
|
87
87
|
return {} unless os2
|
|
88
88
|
|
|
89
|
-
OS2_FIELDS.transform_values { |reader|
|
|
89
|
+
OS2_FIELDS.transform_values { |reader| reader.call(os2)&.to_i }
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
def post_fields(font)
|
|
@@ -67,8 +67,8 @@ module Ucode
|
|
|
67
67
|
private
|
|
68
68
|
|
|
69
69
|
def discover_font_paths
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
entries = @recursive ? @root_path.find : @root_path.children
|
|
71
|
+
entries.select do |entry|
|
|
72
72
|
next false unless entry.file?
|
|
73
73
|
next false if entry.symlink?
|
|
74
74
|
|
data/lib/ucode/cli.rb
CHANGED
|
@@ -629,8 +629,8 @@ module Ucode
|
|
|
629
629
|
|
|
630
630
|
desc "compare LEFT RIGHT", "Diff two audits"
|
|
631
631
|
option :unicode_version, type: :string, default: nil
|
|
632
|
-
option :output,
|
|
633
|
-
|
|
632
|
+
option :output, type: :string, default: nil,
|
|
633
|
+
desc: "Write text diff to file (default: stdout)"
|
|
634
634
|
def compare(left, right)
|
|
635
635
|
result = Commands::Audit::CompareCommand.new.call(
|
|
636
636
|
left, right,
|
|
@@ -8,13 +8,13 @@ module Ucode
|
|
|
8
8
|
# `Indices#each_relationship` instead of reaching into the Struct by
|
|
9
9
|
# field name (see Candidate 1 of the 2026-06-29 architecture review).
|
|
10
10
|
RELATIONSHIPS = [
|
|
11
|
-
["special_casing",
|
|
12
|
-
["case_folding",
|
|
13
|
-
["bidi_mirroring",
|
|
14
|
-
["bidi_brackets",
|
|
15
|
-
["cjk_radicals",
|
|
16
|
-
["standardized_variants",
|
|
17
|
-
["name_aliases",
|
|
11
|
+
["special_casing", lambda(&:special_casing)],
|
|
12
|
+
["case_folding", lambda(&:case_folding)],
|
|
13
|
+
["bidi_mirroring", lambda(&:bidi_mirroring)],
|
|
14
|
+
["bidi_brackets", lambda(&:bidi_brackets)],
|
|
15
|
+
["cjk_radicals", lambda(&:cjk_radicals)],
|
|
16
|
+
["standardized_variants", lambda(&:standardized_variants)],
|
|
17
|
+
["name_aliases", lambda(&:name_aliases)],
|
|
18
18
|
].freeze
|
|
19
19
|
private_constant :RELATIONSHIPS
|
|
20
20
|
|
|
@@ -72,8 +72,8 @@ module Ucode
|
|
|
72
72
|
def each_relationship(&)
|
|
73
73
|
return enum_for(:each_relationship) unless block_given?
|
|
74
74
|
|
|
75
|
-
RELATIONSHIPS.each do |slug,
|
|
76
|
-
yield(slug,
|
|
75
|
+
RELATIONSHIPS.each do |slug, reader|
|
|
76
|
+
yield(slug, reader.call(self))
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
end
|
data/lib/ucode/coordinator.rb
CHANGED
|
@@ -99,31 +99,31 @@ module Ucode
|
|
|
99
99
|
blocks: range_index(ucd_dir, "Blocks.txt", Parsers::Blocks),
|
|
100
100
|
scripts: scripts_index(ucd_dir, property_value_aliases),
|
|
101
101
|
property_value_aliases: property_value_aliases,
|
|
102
|
-
derived_age: cp_index(ucd_dir, "DerivedAge.txt", Parsers::DerivedAge,
|
|
102
|
+
derived_age: cp_index(ucd_dir, "DerivedAge.txt", Parsers::DerivedAge, &:cp),
|
|
103
103
|
binary_properties: multi_cp_index(ucd_dir, "DerivedCoreProperties.txt",
|
|
104
104
|
Parsers::DerivedCoreProperties),
|
|
105
105
|
script_extensions: multi_cp_index(ucd_dir, "ScriptExtensions.txt",
|
|
106
|
-
Parsers::ScriptExtensions,
|
|
106
|
+
Parsers::ScriptExtensions, &:cp),
|
|
107
107
|
bidi_mirroring: cp_index(ucd_dir, "BidiMirroring.txt",
|
|
108
|
-
Parsers::BidiMirroring,
|
|
108
|
+
Parsers::BidiMirroring, &:codepoint),
|
|
109
109
|
bidi_brackets: cp_index(ucd_dir, "BidiBrackets.txt",
|
|
110
|
-
Parsers::BidiBrackets,
|
|
110
|
+
Parsers::BidiBrackets, &:codepoint),
|
|
111
111
|
special_casing: multi_cp_index(ucd_dir, "SpecialCasing.txt",
|
|
112
112
|
Parsers::SpecialCasing),
|
|
113
113
|
# CaseFolding: one cp can carry C, F, S, and T statuses; the
|
|
114
114
|
# Coordinator buckets each row into CodePoint::CaseFolding by
|
|
115
115
|
# status, so the index holds an Array per cp.
|
|
116
116
|
case_folding: multi_cp_index(ucd_dir, "CaseFolding.txt",
|
|
117
|
-
Parsers::CaseFolding,
|
|
117
|
+
Parsers::CaseFolding, &:codepoint),
|
|
118
118
|
name_aliases: multi_cp_index(ucd_dir, "NameAliases.txt",
|
|
119
119
|
Parsers::NameAliases),
|
|
120
120
|
# CJKRadicals maps a canonical ideograph (e.g. U+4E00) to its
|
|
121
121
|
# KangXi radical; the lookup key is the ideograph_id ("U+XXXX"),
|
|
122
122
|
# not the radical_number or the cjk_radical_id.
|
|
123
123
|
cjk_radicals: multi_cp_index_by_id(ucd_dir, "CJKRadicals.txt",
|
|
124
|
-
Parsers::CjkRadicals,
|
|
124
|
+
Parsers::CjkRadicals, &:ideograph_id),
|
|
125
125
|
standardized_variants: multi_cp_index_by_id(ucd_dir, "StandardizedVariants.txt",
|
|
126
|
-
Parsers::StandardizedVariants,
|
|
126
|
+
Parsers::StandardizedVariants, &:base_id),
|
|
127
127
|
names_list: names_list_index(ucd_dir),
|
|
128
128
|
unihan: unihan_index(unihan_dir),
|
|
129
129
|
line_break: range_value_index(ucd_dir, "LineBreak.txt"),
|
|
@@ -180,37 +180,37 @@ module Ucode
|
|
|
180
180
|
end.sort_by(&:range_first)
|
|
181
181
|
end
|
|
182
182
|
|
|
183
|
-
# Indexes by
|
|
184
|
-
|
|
185
|
-
def cp_index(ucd_dir, filename, parser, key_method)
|
|
183
|
+
# Indexes by the codepoint the given block extracts from each record.
|
|
184
|
+
def cp_index(ucd_dir, filename, parser, &)
|
|
186
185
|
path = Pathname.new(ucd_dir).join(filename)
|
|
187
186
|
return {} unless path.exist?
|
|
188
187
|
|
|
189
188
|
parser.each_record(path).each_with_object({}) do |record, h|
|
|
190
|
-
h[record
|
|
189
|
+
h[yield(record)] = record
|
|
191
190
|
end
|
|
192
191
|
end
|
|
193
192
|
|
|
194
193
|
# Multi-valued index by integer codepoint. Each cp maps to an array
|
|
195
194
|
# of records (e.g. one cp can have several binary properties, several
|
|
196
195
|
# script extensions, several SpecialCasing rules).
|
|
197
|
-
def multi_cp_index(ucd_dir, filename, parser,
|
|
196
|
+
def multi_cp_index(ucd_dir, filename, parser, &key)
|
|
197
|
+
key ||= lambda(&:codepoint)
|
|
198
198
|
path = Pathname.new(ucd_dir).join(filename)
|
|
199
199
|
return {} unless path.exist?
|
|
200
200
|
|
|
201
201
|
parser.each_record(path).each_with_object(Hash.new { |h, k| h[k] = [] }) do |record, h|
|
|
202
|
-
h[
|
|
202
|
+
h[key.call(record)] << record
|
|
203
203
|
end
|
|
204
204
|
end
|
|
205
205
|
|
|
206
206
|
# Multi-valued index keyed by a "U+XXXX" string id (e.g. standardized
|
|
207
207
|
# variants are keyed by base_id).
|
|
208
|
-
def multi_cp_index_by_id(ucd_dir, filename, parser,
|
|
208
|
+
def multi_cp_index_by_id(ucd_dir, filename, parser, &)
|
|
209
209
|
path = Pathname.new(ucd_dir).join(filename)
|
|
210
210
|
return {} unless path.exist?
|
|
211
211
|
|
|
212
212
|
parser.each_record(path).each_with_object(Hash.new { |h, k| h[k] = [] }) do |record, h|
|
|
213
|
-
h[record
|
|
213
|
+
h[yield(record)] << record
|
|
214
214
|
end
|
|
215
215
|
end
|
|
216
216
|
|
|
@@ -56,11 +56,17 @@ module Ucode
|
|
|
56
56
|
# about block scope).
|
|
57
57
|
# @param force_positional_for_font_ids [Set<Integer>] Type0
|
|
58
58
|
# font object IDs that always trigger positional attribution
|
|
59
|
+
# @param trace_cache [PageTraceCache, nil] consulted by
|
|
60
|
+
# {#needs_positional?} for the partial-ToUnicode-coverage
|
|
61
|
+
# case (the font has glyphs the CMap doesn't list). nil =
|
|
62
|
+
# skip that check (legacy behavior).
|
|
59
63
|
def initialize(strategies:, block_range: nil,
|
|
60
|
-
force_positional_for_font_ids: Set.new
|
|
64
|
+
force_positional_for_font_ids: Set.new,
|
|
65
|
+
trace_cache: nil)
|
|
61
66
|
@strategies = strategies
|
|
62
67
|
@block_range = block_range
|
|
63
68
|
@force_positional_for_font_ids = force_positional_for_font_ids
|
|
69
|
+
@trace_cache = trace_cache
|
|
64
70
|
end
|
|
65
71
|
|
|
66
72
|
# Convenience builder — wires up the default 3-strategy chain
|
|
@@ -71,7 +77,9 @@ module Ucode
|
|
|
71
77
|
# @param trace_cache [PageTraceCache, nil] when provided, the
|
|
72
78
|
# TraceStrategy shares this cache (lets the caller reuse the
|
|
73
79
|
# traced pages for downstream concerns like Catalog's
|
|
74
|
-
# location lookup)
|
|
80
|
+
# location lookup) AND the orchestrator consults it for
|
|
81
|
+
# gap detection (ToUnicode partial-coverage case). nil =
|
|
82
|
+
# construct internally.
|
|
75
83
|
# @return [CodepointMapper]
|
|
76
84
|
def self.build(source:, correlator_configs:, indexer:,
|
|
77
85
|
block_range: nil, force_positional_for_font_ids: Set.new,
|
|
@@ -93,7 +101,8 @@ module Ucode
|
|
|
93
101
|
]
|
|
94
102
|
new(strategies: strategies,
|
|
95
103
|
block_range: block_range,
|
|
96
|
-
force_positional_for_font_ids: force_positional_for_font_ids
|
|
104
|
+
force_positional_for_font_ids: force_positional_for_font_ids,
|
|
105
|
+
trace_cache: trace_cache)
|
|
97
106
|
end
|
|
98
107
|
|
|
99
108
|
# @param descriptor [RawFontDescriptor]
|
|
@@ -136,7 +145,7 @@ module Ucode
|
|
|
136
145
|
{}
|
|
137
146
|
end
|
|
138
147
|
|
|
139
|
-
# Positional strategies are gated behind
|
|
148
|
+
# Positional strategies are gated behind four conditions, any
|
|
140
149
|
# of which triggers them:
|
|
141
150
|
#
|
|
142
151
|
# 1. Caller explicitly listed this font in
|
|
@@ -146,10 +155,17 @@ module Ucode
|
|
|
146
155
|
# 3. The intrinsic result fell entirely outside the
|
|
147
156
|
# caller's block scope — the font's CMap encoded the
|
|
148
157
|
# wrong codepoints (Option 1 auto-detect, e.g. U1F200).
|
|
158
|
+
# 4. The intrinsic result covered fewer glyphs than the
|
|
159
|
+
# trace cache observes on the page — the font's CMap is
|
|
160
|
+
# partial (Unicode Consortium ships orphan glyphs whose
|
|
161
|
+
# CIDs the ToUnicode stream forgot to map, e.g. the
|
|
162
|
+
# last glyph of Mongolian Supplement U+1166C and Myanmar
|
|
163
|
+
# Extended-A U+116DA in the v17.0 charts).
|
|
149
164
|
def needs_positional?(descriptor, intrinsic_result)
|
|
150
165
|
return true if @force_positional_for_font_ids.include?(descriptor.font_obj_id)
|
|
151
166
|
return true if intrinsic_result.empty?
|
|
152
167
|
return true if intrinsic_out_of_scope?(intrinsic_result)
|
|
168
|
+
return true if intrinsic_has_uncovered_gids?(descriptor, intrinsic_result)
|
|
153
169
|
|
|
154
170
|
false
|
|
155
171
|
end
|
|
@@ -162,6 +178,21 @@ module Ucode
|
|
|
162
178
|
intrinsic_result.keys.all? { |cp| !@block_range.include?(cp) }
|
|
163
179
|
end
|
|
164
180
|
|
|
181
|
+
# Detects the partial-ToUnicode-coverage case: the font's
|
|
182
|
+
# CMap names N codepoints, but the page actually renders >N
|
|
183
|
+
# glyphs from this font (orphan glyphs whose CIDs the CMap
|
|
184
|
+
# forgot). Positional attribution via the chart's hex labels
|
|
185
|
+
# is the only way to recover them.
|
|
186
|
+
def intrinsic_has_uncovered_gids?(descriptor, intrinsic_result)
|
|
187
|
+
return false unless @trace_cache
|
|
188
|
+
return false if intrinsic_result.empty?
|
|
189
|
+
|
|
190
|
+
covered_gids = intrinsic_result.values.to_set
|
|
191
|
+
@trace_cache.distinct_gids_for(descriptor.base_font).any? do |gid|
|
|
192
|
+
!covered_gids.include?(gid)
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
165
196
|
# Positional chain: union of all positional strategies' results.
|
|
166
197
|
# Within positional, earlier strategies win on conflict (chain
|
|
167
198
|
# order expresses caller preference — CorrelatorStrategy
|
|
@@ -4,6 +4,7 @@ require "pathname"
|
|
|
4
4
|
|
|
5
5
|
require "ucode/glyphs/embedded_fonts/mutool"
|
|
6
6
|
require "ucode/glyphs/embedded_fonts/trace_parser"
|
|
7
|
+
require "ucode/glyphs/embedded_fonts/trace_glyph"
|
|
7
8
|
|
|
8
9
|
module Ucode
|
|
9
10
|
module Glyphs
|
|
@@ -24,6 +25,15 @@ module Ucode
|
|
|
24
25
|
# Lazy: glyphs are only fetched when a strategy first asks for
|
|
25
26
|
# them. PDFs where every font has /ToUnicode never trigger the
|
|
26
27
|
# trace at all.
|
|
28
|
+
#
|
|
29
|
+
# ## mutool font-name truncation
|
|
30
|
+
#
|
|
31
|
+
# mutool trace emits font names truncated to 31 chars (PDF
|
|
32
|
+
# base-font-name limit). The BaseFont dict may carry the full
|
|
33
|
+
# original name (e.g. `HBBJCP+Uni11660Mongoliansupplement`).
|
|
34
|
+
# All name comparisons in this class go through
|
|
35
|
+
# {TraceGlyph.name_match?} so the truncation doesn't silently
|
|
36
|
+
# break lookups for long-named fonts.
|
|
27
37
|
class PageTraceCache
|
|
28
38
|
# @param pdf [Pathname, String]
|
|
29
39
|
# @param page_count [Integer] total pages in the PDF
|
|
@@ -55,7 +65,7 @@ module Ucode
|
|
|
55
65
|
glyphs_by_page.each_with_index do |glyphs, idx|
|
|
56
66
|
next if idx.zero?
|
|
57
67
|
|
|
58
|
-
present = glyphs.any? { |g| g.font_name
|
|
68
|
+
present = glyphs.any? { |g| TraceGlyph.name_match?(g.font_name, base_font) }
|
|
59
69
|
next unless present
|
|
60
70
|
|
|
61
71
|
present_in_any = true
|
|
@@ -68,8 +78,27 @@ module Ucode
|
|
|
68
78
|
# @return [Boolean] true if any page references this font
|
|
69
79
|
def references_font?(base_font)
|
|
70
80
|
glyphs_by_page.any? do |page_glyphs|
|
|
71
|
-
page_glyphs.any? { |g| g.font_name
|
|
81
|
+
page_glyphs.any? { |g| TraceGlyph.name_match?(g.font_name, base_font) }
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Returns the set of distinct GIDs rendered on any page for
|
|
86
|
+
# the given font. Used by {CodepointMapper#needs_positional?}
|
|
87
|
+
# to detect the partial-ToUnicode-coverage case (font ships
|
|
88
|
+
# more glyphs than its CMap admits).
|
|
89
|
+
#
|
|
90
|
+
# @param base_font [String]
|
|
91
|
+
# @return [Set<Integer>]
|
|
92
|
+
def distinct_gids_for(base_font)
|
|
93
|
+
gids = Set.new
|
|
94
|
+
glyphs_by_page.each do |page_glyphs|
|
|
95
|
+
page_glyphs.each do |g|
|
|
96
|
+
next unless TraceGlyph.name_match?(g.font_name, base_font)
|
|
97
|
+
|
|
98
|
+
gids << g.gid if g.gid
|
|
99
|
+
end
|
|
72
100
|
end
|
|
101
|
+
gids
|
|
73
102
|
end
|
|
74
103
|
|
|
75
104
|
# Locate the first occurrence of a specific (font, gid) pair
|
|
@@ -87,7 +116,7 @@ module Ucode
|
|
|
87
116
|
next if idx.zero?
|
|
88
117
|
|
|
89
118
|
match = page_glyphs.find do |g|
|
|
90
|
-
g.font_name
|
|
119
|
+
TraceGlyph.name_match?(g.font_name, base_font) && g.gid == gid
|
|
91
120
|
end
|
|
92
121
|
return { page: idx, x: match.x, y: match.y } if match
|
|
93
122
|
end
|
|
@@ -48,7 +48,7 @@ module Ucode
|
|
|
48
48
|
private
|
|
49
49
|
|
|
50
50
|
def select_specimens(trace_glyphs)
|
|
51
|
-
trace_glyphs.select { |g| g.font_name
|
|
51
|
+
trace_glyphs.select { |g| TraceGlyph.name_match?(g.font_name, @specimen_font_name) }
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def select_labels(trace_glyphs)
|
|
@@ -93,7 +93,7 @@ module Ucode
|
|
|
93
93
|
|
|
94
94
|
def select_hex_candidates(trace_glyphs)
|
|
95
95
|
trace_glyphs.select do |g|
|
|
96
|
-
g.font_name
|
|
96
|
+
!TraceGlyph.name_match?(g.font_name, @specimen_font_name) &&
|
|
97
97
|
g.unicode&.match?(/\A[0-9A-Fa-f]\z/)
|
|
98
98
|
end
|
|
99
99
|
end
|
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
module Ucode
|
|
4
4
|
module Glyphs
|
|
5
5
|
module EmbeddedFonts
|
|
6
|
+
# mutool trace emits font names truncated to 31 characters
|
|
7
|
+
# (PDF base-font-name limit, see PDF 32000-1 §7.9.6). The
|
|
8
|
+
# BaseFont dict, however, may carry the full original name.
|
|
9
|
+
# `HBBJCP+Uni11660Mongoliansupplement` (34 chars) is emitted
|
|
10
|
+
# by mutool trace as `HBBJCP+Uni11660Mongoliansupplem`. The
|
|
11
|
+
# helpers below let callers compare trace-side names against
|
|
12
|
+
# catalog-side names without tripping on the truncation.
|
|
13
|
+
TRACE_NAME_LIMIT = 31
|
|
14
|
+
private_constant :TRACE_NAME_LIMIT
|
|
15
|
+
|
|
6
16
|
# Value object for one glyph emitted by `mutool trace`.
|
|
7
17
|
#
|
|
8
18
|
# Each `<g>` element in the trace XML maps to one TraceGlyph:
|
|
@@ -21,7 +31,31 @@ module Ucode
|
|
|
21
31
|
:y,
|
|
22
32
|
:unicode,
|
|
23
33
|
keyword_init: true,
|
|
24
|
-
)
|
|
34
|
+
) do
|
|
35
|
+
class << self
|
|
36
|
+
# @param name [String, nil] a BaseFont name from `mutool info`
|
|
37
|
+
# or a trace-emitted font name
|
|
38
|
+
# @return [String, nil] the name truncated to the trace limit
|
|
39
|
+
def normalize_name(name)
|
|
40
|
+
return nil if name.nil?
|
|
41
|
+
|
|
42
|
+
name.length <= TRACE_NAME_LIMIT ? name : name[0, TRACE_NAME_LIMIT]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# True when `a` and `b` resolve to the same normalized
|
|
46
|
+
# name. Treats `nil` as never matching (avoids accidental
|
|
47
|
+
# collision on missing names).
|
|
48
|
+
#
|
|
49
|
+
# @param a [String, nil]
|
|
50
|
+
# @param b [String, nil]
|
|
51
|
+
# @return [Boolean]
|
|
52
|
+
def name_match?(a, b)
|
|
53
|
+
return false if a.nil? || b.nil?
|
|
54
|
+
|
|
55
|
+
normalize_name(a) == normalize_name(b)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
25
59
|
end
|
|
26
60
|
end
|
|
27
61
|
end
|
|
@@ -39,8 +39,8 @@ module Ucode
|
|
|
39
39
|
attribute :svg_document_count, :integer
|
|
40
40
|
|
|
41
41
|
# CBDT/CBLC (color bitmaps — paired tables).
|
|
42
|
-
attribute :has_cbdt,
|
|
43
|
-
attribute :has_cblc,
|
|
42
|
+
attribute :has_cbdt, Lutaml::Model::Type::Boolean
|
|
43
|
+
attribute :has_cblc, Lutaml::Model::Type::Boolean
|
|
44
44
|
# Strike count comes from the paired CBLC locator table.
|
|
45
45
|
attribute :cbdt_strike_count, :integer
|
|
46
46
|
|
|
@@ -58,6 +58,19 @@ module Ucode
|
|
|
58
58
|
attribute :variants, UnihanField, collection: true, default: -> { [] }
|
|
59
59
|
attribute :other_mappings, UnihanField, collection: true, default: -> { [] }
|
|
60
60
|
|
|
61
|
+
# Collection accessors per category, mirroring CATEGORIES. Explicit
|
|
62
|
+
# lambdas instead of dynamic dispatch so the buckets stay greppable.
|
|
63
|
+
BUCKETS = {
|
|
64
|
+
dictionary_indices: lambda(&:dictionary_indices),
|
|
65
|
+
dictionary_like_data: lambda(&:dictionary_like_data),
|
|
66
|
+
irg_sources: lambda(&:irg_sources),
|
|
67
|
+
numeric_values: lambda(&:numeric_values),
|
|
68
|
+
radical_stroke_counts: lambda(&:radical_stroke_counts),
|
|
69
|
+
readings: lambda(&:readings),
|
|
70
|
+
variants: lambda(&:variants),
|
|
71
|
+
other_mappings: lambda(&:other_mappings),
|
|
72
|
+
}.freeze
|
|
73
|
+
|
|
61
74
|
# Pushes a field into the right category bucket. Used by the
|
|
62
75
|
# Coordinator when streaming records from the parser.
|
|
63
76
|
#
|
|
@@ -65,13 +78,13 @@ module Ucode
|
|
|
65
78
|
# @param name [String] e.g. "kMandarin"
|
|
66
79
|
# @param values [Array<String>] space-split values from Unihan
|
|
67
80
|
def add(category, name, values)
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
bucket = BUCKETS.fetch(category) { return }
|
|
82
|
+
bucket.call(self) << UnihanField.new(name: name, values: values)
|
|
70
83
|
end
|
|
71
84
|
|
|
72
85
|
# True if any category has data.
|
|
73
86
|
def any?
|
|
74
|
-
|
|
87
|
+
BUCKETS.each_value.any? { |bucket| !bucket.call(self).empty? }
|
|
75
88
|
end
|
|
76
89
|
|
|
77
90
|
# All fields across every category, flattened to {name => values}.
|
|
@@ -80,8 +93,8 @@ module Ucode
|
|
|
80
93
|
#
|
|
81
94
|
# @return [Hash{String => Array<String>}]
|
|
82
95
|
def all_fields
|
|
83
|
-
|
|
84
|
-
|
|
96
|
+
BUCKETS.each_value.with_object({}) do |bucket, h|
|
|
97
|
+
bucket.call(self).each { |f| h[f.name] = f.values }
|
|
85
98
|
end
|
|
86
99
|
end
|
|
87
100
|
|
|
@@ -240,9 +240,21 @@ module Ucode
|
|
|
240
240
|
end
|
|
241
241
|
end
|
|
242
242
|
|
|
243
|
+
# Container accessor for each annotation kind `parse_annotation`
|
|
244
|
+
# can return. Kept beside the marker dispatch so adding a marker
|
|
245
|
+
# is one case branch plus one entry here.
|
|
246
|
+
ENTRY_CONTAINERS = {
|
|
247
|
+
cross_references: lambda(&:cross_references),
|
|
248
|
+
sample_sequences: lambda(&:sample_sequences),
|
|
249
|
+
compatibility_equivalents: lambda(&:compatibility_equivalents),
|
|
250
|
+
informal_aliases: lambda(&:informal_aliases),
|
|
251
|
+
footnotes: lambda(&:footnotes),
|
|
252
|
+
}.freeze
|
|
253
|
+
private_constant :ENTRY_CONTAINERS
|
|
254
|
+
|
|
243
255
|
def attach_annotation(entry, parsed)
|
|
244
256
|
attr_name, instance = parsed
|
|
245
|
-
|
|
257
|
+
ENTRY_CONTAINERS.fetch(attr_name).call(entry) << instance
|
|
246
258
|
end
|
|
247
259
|
end
|
|
248
260
|
end
|
data/lib/ucode/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ucode
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-12-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -104,16 +104,22 @@ dependencies:
|
|
|
104
104
|
name: rubyzip
|
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
|
106
106
|
requirements:
|
|
107
|
-
- - "
|
|
107
|
+
- - ">="
|
|
108
108
|
- !ruby/object:Gem::Version
|
|
109
109
|
version: '2.3'
|
|
110
|
+
- - "<"
|
|
111
|
+
- !ruby/object:Gem::Version
|
|
112
|
+
version: '4'
|
|
110
113
|
type: :runtime
|
|
111
114
|
prerelease: false
|
|
112
115
|
version_requirements: !ruby/object:Gem::Requirement
|
|
113
116
|
requirements:
|
|
114
|
-
- - "
|
|
117
|
+
- - ">="
|
|
115
118
|
- !ruby/object:Gem::Version
|
|
116
119
|
version: '2.3'
|
|
120
|
+
- - "<"
|
|
121
|
+
- !ruby/object:Gem::Version
|
|
122
|
+
version: '4'
|
|
117
123
|
- !ruby/object:Gem::Dependency
|
|
118
124
|
name: sqlite3
|
|
119
125
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -518,7 +524,6 @@ files:
|
|
|
518
524
|
- lib/ucode/version.rb
|
|
519
525
|
- lib/ucode/version_resolver.rb
|
|
520
526
|
- schema/block-feed.output.schema.yml
|
|
521
|
-
- ucode.gemspec
|
|
522
527
|
homepage: https://github.com/fontist/ucode
|
|
523
528
|
licenses:
|
|
524
529
|
- BSD-2-Clause
|
data/ucode.gemspec
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "lib/ucode/version"
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = "ucode"
|
|
7
|
-
spec.version = Ucode::VERSION
|
|
8
|
-
spec.authors = ["Ribose Inc."]
|
|
9
|
-
spec.email = ["open.source@ribose.com"]
|
|
10
|
-
|
|
11
|
-
spec.summary = "Unicode Character Database toolkit — lookup, dataset, glyphs, site"
|
|
12
|
-
spec.description = <<~DESC
|
|
13
|
-
ucode turns the Unicode Character Database (UCD) text files and the official
|
|
14
|
-
Unicode Code Charts into a structured, browsable dataset. For every assigned
|
|
15
|
-
codepoint it produces a JSON document with full UCD properties, the
|
|
16
|
-
human-curated relationships from NamesList.txt, Unihan readings, and
|
|
17
|
-
machine-computed references; an SVG of the official glyph vector-extracted
|
|
18
|
-
from the Code Charts; and a Vitepress site for browsing Plane, Block,
|
|
19
|
-
and Character.
|
|
20
|
-
DESC
|
|
21
|
-
|
|
22
|
-
spec.homepage = "https://github.com/fontist/ucode"
|
|
23
|
-
spec.license = "BSD-2-Clause"
|
|
24
|
-
spec.required_ruby_version = ">= 3.2.0"
|
|
25
|
-
|
|
26
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
|
27
|
-
spec.metadata["source_code_uri"] = "https://github.com/fontist/ucode"
|
|
28
|
-
spec.metadata["changelog_uri"] = "https://github.com/fontist/ucode/blob/main/CHANGELOG.md"
|
|
29
|
-
spec.metadata["rubygems_mfa_required"] = "true"
|
|
30
|
-
|
|
31
|
-
spec.files = Dir.chdir(__dir__) do
|
|
32
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
|
33
|
-
f == __FILE__ ||
|
|
34
|
-
f.start_with?(".") ||
|
|
35
|
-
f.start_with?("spec/") ||
|
|
36
|
-
f.start_with?("benchmark/") ||
|
|
37
|
-
f.start_with?("TODO.impl/") ||
|
|
38
|
-
f.start_with?("docs/") ||
|
|
39
|
-
f.start_with?("site/")
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
spec.bindir = "exe"
|
|
44
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
45
|
-
spec.require_paths = ["lib"]
|
|
46
|
-
|
|
47
|
-
spec.add_dependency "base64"
|
|
48
|
-
spec.add_dependency "fontisan", "~> 0.4", ">= 0.4.9"
|
|
49
|
-
spec.add_dependency "fontist", "~> 3.0"
|
|
50
|
-
spec.add_dependency "logger"
|
|
51
|
-
spec.add_dependency "lutaml-model", "~> 0.8"
|
|
52
|
-
spec.add_dependency "nokogiri", "~> 1.16"
|
|
53
|
-
spec.add_dependency "rubyzip", "~> 2.3"
|
|
54
|
-
spec.add_dependency "sqlite3", "~> 2.0"
|
|
55
|
-
spec.add_dependency "thor", "~> 1.3"
|
|
56
|
-
end
|