Class: Ucode::Glyphs::EmbeddedFonts::CodepointMapper
- Inherits:
-
Object
- Object
- Ucode::Glyphs::EmbeddedFonts::CodepointMapper
- Defined in:
- lib/ucode/glyphs/embedded_fonts/codepoint_mapper.rb
Overview
Resolves codepoint → GID for one Type0 font via a 3-path strategy:
- ToUnicode CMap — the font's
/ToUnicodestream (Tier 1 for pillar 1). Parsed by ToUnicode. - Caller-supplied correlator config (pillar 2) — render the font's pages to SVG and run ContentStreamCorrelator.
- 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
-
#initialize(source:, correlator_configs:, indexer:) ⇒ CodepointMapper
constructor
A new instance of CodepointMapper.
-
#map(descriptor) ⇒ Hash{Integer=>Integer}
Codepoint => gid; empty when no strategy produces a map.
Constructor Details
#initialize(source:, correlator_configs:, indexer:) ⇒ CodepointMapper
Returns a new instance of CodepointMapper.
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.
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 |