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, assigned_only: false, codepoints: 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.

  • assigned_only (Boolean) (defaults to: false)

    when true, iterate only assigned codepoints (via BlockIndex). Default false: iterate the full block range, matching the legacy behavior (Pillar 3 fills unassigned slots when injected; otherwise the Resolver returns nil for them and they're silently skipped).

  • codepoints (Array<Integer>, nil) (defaults to: nil)

    explicit codepoint list — overrides BlockIndex iteration. Used by BatchRunner to extract only the gap set. nil = use BlockIndex.



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ucode/code_chart/extractor.rb', line 81

def initialize(block:, pdf_path:, cache_dir: nil,
               tier1_sources: nil, pillar3_source: nil,
               assigned_only: false, codepoints: 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
  @assigned_only = assigned_only
  @codepoints = codepoints
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).



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ucode/code_chart/extractor.rb', line 96

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,
      base_font: resolver_result.base_font,
      gid: resolver_result.gid,
      source_page: resolver_result.source_page,
      source_cell: resolver_result.source_cell,
      extractor_version: Ucode::VERSION,
    )
  end
  results
end