Class: Ucode::Glyphs::EmbeddedFonts::CodepointMapper::TraceStrategy
- Inherits:
-
Strategy
- Object
- Strategy
- Ucode::Glyphs::EmbeddedFonts::CodepointMapper::TraceStrategy
- Defined in:
- lib/ucode/glyphs/embedded_fonts/codepoint_mapper/trace_strategy.rb
Overview
Strategy 3 — auto-detect via mutool trace. Last-resort
fallback for CID fonts without /ToUnicode and without a
caller-supplied correlator config.
Consumes a PageTraceCache that traces each PDF page exactly once across all CID fonts. The pre-cache path was O(F × P) subprocess invocations; this is O(P).
Correlates per page (Y positions are page-local — clustering across page boundaries would produce false matches).
Instance Method Summary collapse
-
#initialize(cache:, indexer:) ⇒ TraceStrategy
constructor
A new instance of TraceStrategy.
- #map(descriptor) ⇒ Object
- #positional? ⇒ Boolean
- #supports?(descriptor) ⇒ Boolean
Constructor Details
#initialize(cache:, indexer:) ⇒ TraceStrategy
Returns a new instance of TraceStrategy.
27 28 29 30 31 |
# File 'lib/ucode/glyphs/embedded_fonts/codepoint_mapper/trace_strategy.rb', line 27 def initialize(cache:, indexer:) super() @cache = cache @indexer = indexer end |
Instance Method Details
#map(descriptor) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ucode/glyphs/embedded_fonts/codepoint_mapper/trace_strategy.rb', line 45 def map(descriptor) return {} unless @cache correlator = TraceCorrelator.new( specimen_font_name: descriptor.base_font, ) mapping = {} @cache.each_page_for(descriptor.base_font) do |_page, glyphs| page_mapping = correlator.correlate(glyphs) page_mapping.each do |cp, gid| mapping[cp] ||= gid end end mapping end |
#positional? ⇒ Boolean
41 42 43 |
# File 'lib/ucode/glyphs/embedded_fonts/codepoint_mapper/trace_strategy.rb', line 41 def positional? true end |
#supports?(descriptor) ⇒ Boolean
33 34 35 36 37 38 |
# File 'lib/ucode/glyphs/embedded_fonts/codepoint_mapper/trace_strategy.rb', line 33 def supports?(descriptor) return false unless @cache return false unless descriptor.cid_map_kind == :identity @indexer.font_appears?(descriptor.base_font) end |