Class: Ucode::Glyphs::EmbeddedFonts::TraceCorrelator
- Inherits:
-
Object
- Object
- Ucode::Glyphs::EmbeddedFonts::TraceCorrelator
- Defined in:
- lib/ucode/glyphs/embedded_fonts/trace_correlator.rb
Overview
Correlates specimen glyphs (CID font without /ToUnicode) to
their Unicode codepoints via positional matching against hex
codepoint labels on the same chart page.
Adapter for the mutool trace XML format: parses TraceGlyph
arrays, partitions into specimens and labels, auto-detects the
label font by proximity, then delegates matching to
PositionalMatcher.
The label font auto-detection is the only piece of "intelligence" in this adapter — everything else is format translation. The matching algorithm lives in PositionalMatcher and is shared with ContentStreamCorrelator.
Instance Method Summary collapse
-
#correlate(trace_glyphs) ⇒ Hash{Integer=>Integer}
Codepoint => gid.
-
#initialize(specimen_font_name:) ⇒ TraceCorrelator
constructor
A new instance of TraceCorrelator.
Constructor Details
#initialize(specimen_font_name:) ⇒ TraceCorrelator
Returns a new instance of TraceCorrelator.
29 30 31 |
# File 'lib/ucode/glyphs/embedded_fonts/trace_correlator.rb', line 29 def initialize(specimen_font_name:) @specimen_font_name = specimen_font_name end |
Instance Method Details
#correlate(trace_glyphs) ⇒ Hash{Integer=>Integer}
Returns codepoint => gid.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ucode/glyphs/embedded_fonts/trace_correlator.rb', line 35 def correlate(trace_glyphs) specimens = select_specimens(trace_glyphs) return {} if specimens.empty? labels = select_labels(trace_glyphs) return {} if labels.empty? PositionalMatcher.match( specimens.map { |g| to_position(g) }, labels.map { |g| to_position(g) }, ) end |