Class: Ucode::CodeChart::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/code_chart/extractor.rb

Overview

Walks every assigned codepoint in a block and returns one Result per codepoint that any tier produced a glyph for.

This is not a new extraction pipeline — it composes the existing Glyphs::Resolver with per-block inputs (the block's Code Charts PDF + optionally Tier 1 and Pillar 3 sources). The Resolver owns tier selection; the Extractor owns inputs.

The REQ (R2) describes extraction via "locate the grid cell whose margin label matches the codepoint" — that was the v0.1 retired approach (cell-border compositing). The current path is the embedded-font walk (Pillar 1, via EmbeddedFonts::Catalog) with Pillar 2 (positional correlation) and Pillar 3 (Last Resort placeholders) as fallbacks.

Tier selection

Pillar 1 is always configured (the embedded font walk over the block's PDF). Tier 1 (real-font cmap) and Pillar 3 (Last Resort) are optional — the caller injects pre-built sources. This avoids forcing the Extractor to construct Last Resort eagerly, which would fail in environments where the UFO is not checked out.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(block:, pdf_path:, cache_dir: nil, tier1_sources: nil, pillar3_source: nil) ⇒ Extractor

Returns a new instance of Extractor.

Parameters:

  • block (Ucode::Models::Block)

    block whose assigned codepoints will be extracted

  • pdf_path (Pathname, String)

    path to the per-block Code Charts PDF (downloaded by the caller; the Extractor doesn't fetch)

  • cache_dir (Pathname, String, nil) (defaults to: nil)

    directory for cached extracted font streams. nil = default (data/pdf-fonts/ relative to the gem root).

  • tier1_sources (Array<Ucode::Glyphs::Source>, nil) (defaults to: nil)

    optional Tier 1 sources (real-font cmap). nil = no Tier 1

  • pillar3_source (Ucode::Glyphs::Source, nil) (defaults to: nil)

    optional Pillar 3 (Last Resort) source. nil = no Pillar 3 fallback. Callers that want Last Resort placeholders inject the pre-built source here.



57
58
59
60
61
62
63
64
# File 'lib/ucode/code_chart/extractor.rb', line 57

def initialize(block:, pdf_path:, cache_dir: nil,
               tier1_sources: nil, pillar3_source: nil)
  @block = block
  @pdf_path = Pathname.new(pdf_path)
  @cache_dir = cache_dir && Pathname.new(cache_dir)
  @tier1_sources = tier1_sources || []
  @pillar3_source = pillar3_source
end

Instance Method Details

#extractArray<Result>

Returns one Result per codepoint that any tier produced a glyph for. Codepoints no tier can serve are silently skipped (no Result yielded).

Returns:

  • (Array<Result>)

    one Result per codepoint that any tier produced a glyph for. Codepoints no tier can serve are silently skipped (no Result yielded).



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ucode/code_chart/extractor.rb', line 69

def extract
  resolver = build_resolver
  results = []
  each_codepoint do |cp|
    resolver_result = resolver.resolve(cp)
    next unless resolver_result&.svg

    results << Result.new(
      codepoint: cp,
      svg: resolver_result.svg,
      tier: resolver_result.tier,
      provenance: resolver_result.provenance,
    )
  end
  results
end