Class: Ucode::Glyphs::EmbeddedFonts::Catalog
- Inherits:
-
Object
- Object
- Ucode::Glyphs::EmbeddedFonts::Catalog
- Defined in:
- lib/ucode/glyphs/embedded_fonts/catalog.rb
Overview
Walks the Code Charts PDF once and builds a global ‘=> FontEntry` index.
Discovery uses ‘mutool info` for the font list (one line per page-font), then `mutool show -g` to fetch the Type0 font dicts, their descendant CIDFont dicts, and the FontDescriptors — all in a handful of batched subprocess calls rather than one per font.
For each Type0 font we then fetch its ToUnicode CMap stream (one ‘mutool show -b -o <tmpfile>` per font — these can’t be batched because each is a separate stream) and parse it into a ‘=> codepoint` map. With `/CIDToGIDMap /Identity` (the only form we currently support), `gid == cid`, so the per-font map is directly `=> gid`.
When multiple fonts cover the same codepoint (which happens for a handful of codepoints that appear in multiple blocks), the first font discovered wins. The discovery order follows the ‘mutool info` listing, which is page-major, so the earlier block’s font wins — the expected behavior for the Code Charts.
Instance Method Summary collapse
-
#codepoints ⇒ Array<Integer>
Every codepoint this PDF covers.
-
#font_count ⇒ Integer
Number of Type0 fonts discovered.
-
#font_entries ⇒ Array<FontEntry>
Every font entry (one per Type0 font).
-
#index ⇒ Hash{Integer=>FontEntry}
Frozen codepoint → entry map.
-
#initialize(source, correlator_configs: {}) ⇒ Catalog
constructor
A new instance of Catalog.
- #lookup(codepoint) ⇒ FontEntry?
-
#size ⇒ Integer
Number of codepoints covered.
Constructor Details
#initialize(source, correlator_configs: {}) ⇒ Catalog
Returns a new instance of Catalog.
40 41 42 43 44 |
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 40 def initialize(source, correlator_configs: {}) @source = source @correlator_configs = correlator_configs @index = nil end |
Instance Method Details
#codepoints ⇒ Array<Integer>
Returns every codepoint this PDF covers.
58 59 60 |
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 58 def codepoints index.keys end |
#font_count ⇒ Integer
Returns number of Type0 fonts discovered.
68 69 70 |
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 68 def font_count font_entries.size end |
#font_entries ⇒ Array<FontEntry>
Returns every font entry (one per Type0 font).
73 74 75 |
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 73 def font_entries @font_entries ||= build_font_entries end |
#index ⇒ Hash{Integer=>FontEntry}
Returns frozen codepoint → entry map.
47 48 49 |
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 47 def index @index ||= build_index.freeze end |
#lookup(codepoint) ⇒ FontEntry?
53 54 55 |
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 53 def lookup(codepoint) index[codepoint] end |
#size ⇒ Integer
Returns number of codepoints covered.
63 64 65 |
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 63 def size index.size end |