Class: Ucode::Glyphs::EmbeddedFonts::CodepointMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/glyphs/embedded_fonts/codepoint_mapper.rb

Overview

Resolves codepoint → GID for one Type0 font via a 3-path strategy:

  1. ToUnicode CMap — the font's /ToUnicode stream (Tier 1 for pillar 1). Parsed by ToUnicode.
  2. Caller-supplied correlator config (pillar 2) — render the font's pages to SVG and run ContentStreamCorrelator.
  3. Auto-detect via mutool trace (pillar 2b) — trace every page and run TraceCorrelator positionally.

Each path returns a {codepoint => gid} map. First non-empty result wins; the strategy stops there.

Pure strategy orchestration — does NOT parse the PDF object graph (that's PdfIndexer's job). Takes a RawFontDescriptor + the shared PdfIndexer (for page_count + font_appears? queries used by the trace fallback).

Instance Method Summary collapse

Constructor Details

#initialize(source:, correlator_configs:, indexer:) ⇒ CodepointMapper

Returns a new instance of CodepointMapper.

Parameters:



31
32
33
34
35
# File 'lib/ucode/glyphs/embedded_fonts/codepoint_mapper.rb', line 31

def initialize(source:, correlator_configs:, indexer:)
  @source = source
  @correlator_configs = correlator_configs
  @indexer = indexer
end

Instance Method Details

#map(descriptor) ⇒ Hash{Integer=>Integer}

Returns codepoint => gid; empty when no strategy produces a map.

Parameters:

Returns:

  • (Hash{Integer=>Integer})

    codepoint => gid; empty when no strategy produces a map



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ucode/glyphs/embedded_fonts/codepoint_mapper.rb', line 40

def map(descriptor)
  return {} unless descriptor.cid_map_kind == :identity

  from_tounicode = map_from_tounicode(descriptor.tounicode_ref)
  return from_tounicode unless from_tounicode.empty?

  from_correlator = map_from_correlator(descriptor.font_obj_id)
  return from_correlator unless from_correlator.empty?

  map_from_trace(descriptor.base_font)
end