Class: Ucode::Glyphs::EmbeddedFonts::TraceCorrelator

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(specimen_font_name:) ⇒ TraceCorrelator

Returns a new instance of TraceCorrelator.

Parameters:

  • specimen_font_name (String)

    the BaseFont name of the CID font whose glyphs need correlation



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.

Parameters:

Returns:

  • (Hash{Integer=>Integer})

    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