Class: Ucode::Glyphs::EmbeddedFonts::Catalog

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

Overview

Composes PdfIndexer + CodepointMapper to build a global {codepoint => FontEntry} index from a Code Charts PDF.

Responsibilities split cleanly:

* {PdfIndexer} — subprocess + dict parsing → Array<RawFontDescriptor>
* {CodepointMapper} — 3-path codepoint→GID strategy → {cp => gid}
* {Catalog} (this class) — composes both into FontEntry objects
and exposes the public lookup interface

When multiple fonts cover the same codepoint, the first font discovered wins. Discovery order follows mutool info's page-major listing, so earlier blocks' fonts win — the expected behavior.

Instance Method Summary collapse

Constructor Details

#initialize(source, correlator_configs: {}) ⇒ Catalog

Returns a new instance of Catalog.

Parameters:

  • source (PdfLocation)
  • correlator_configs (Hash{Integer=>ContentStreamCorrelator::Config}) (defaults to: {})

    maps a Type0 font's PDF object ID to the pillar-2 config to use when the font has no /ToUnicode CMap. Empty by default.



24
25
26
27
28
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 24

def initialize(source, correlator_configs: {})
  @source = source
  @correlator_configs = correlator_configs
  @index = nil
end

Instance Method Details

#codepointsArray<Integer>

Returns every codepoint this PDF covers.

Returns:

  • (Array<Integer>)

    every codepoint this PDF covers



42
43
44
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 42

def codepoints
  index.keys
end

#font_countInteger

Returns number of Type0 fonts with non-empty maps.

Returns:

  • (Integer)

    number of Type0 fonts with non-empty maps



52
53
54
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 52

def font_count
  font_entries.size
end

#font_entriesArray<FontEntry>

Returns every font entry (one per Type0 font).

Returns:

  • (Array<FontEntry>)

    every font entry (one per Type0 font)



57
58
59
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 57

def font_entries
  @font_entries ||= build_font_entries
end

#indexHash{Integer=>FontEntry}

Returns frozen codepoint → entry map.

Returns:

  • (Hash{Integer=>FontEntry})

    frozen codepoint → entry map



31
32
33
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 31

def index
  @index ||= build_index.freeze
end

#lookup(codepoint) ⇒ FontEntry?

Parameters:

  • codepoint (Integer)

Returns:



37
38
39
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 37

def lookup(codepoint)
  index[codepoint]
end

#sizeInteger

Returns number of codepoints covered.

Returns:

  • (Integer)

    number of codepoints covered



47
48
49
# File 'lib/ucode/glyphs/embedded_fonts/catalog.rb', line 47

def size
  index.size
end