Class: Ucode::Glyphs::EmbeddedFonts::CodepointMapper::ToUnicodeStrategy
- Inherits:
-
Strategy
- Object
- Strategy
- Ucode::Glyphs::EmbeddedFonts::CodepointMapper::ToUnicodeStrategy
- Defined in:
- lib/ucode/glyphs/embedded_fonts/codepoint_mapper/tounicode_strategy.rb
Overview
Strategy 1 — read the Type0 font's /ToUnicode CMap stream
and parse it into a {codepoint => gid} map. Highest
fidelity when present; usually missing for subsetted CID
fonts (the case the trace fallback exists for).
Instance Method Summary collapse
-
#initialize(source:, mutool_show:) ⇒ ToUnicodeStrategy
constructor
A new instance of ToUnicodeStrategy.
- #map(descriptor) ⇒ Object
- #supports?(descriptor) ⇒ Boolean
Methods inherited from Strategy
Constructor Details
#initialize(source:, mutool_show:) ⇒ ToUnicodeStrategy
Returns a new instance of ToUnicodeStrategy.
18 19 20 21 22 |
# File 'lib/ucode/glyphs/embedded_fonts/codepoint_mapper/tounicode_strategy.rb', line 18 def initialize(source:, mutool_show:) super() @source = source @mutool_show = mutool_show end |
Instance Method Details
#map(descriptor) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/ucode/glyphs/embedded_fonts/codepoint_mapper/tounicode_strategy.rb', line 29 def map(descriptor) cmap_text = @mutool_show.stream(@source.pdf_to_s, descriptor.tounicode_ref) cid_to_cp = ToUnicode.parse(cmap_text) cid_to_cp.each_with_object({}) do |(cid, cp), h| h[cp] = cid end end |
#supports?(descriptor) ⇒ Boolean
24 25 26 27 |
# File 'lib/ucode/glyphs/embedded_fonts/codepoint_mapper/tounicode_strategy.rb', line 24 def supports?(descriptor) descriptor.cid_map_kind == :identity && !descriptor.tounicode_ref.nil? end |