Class: Ucode::Glyphs::LastResort::Writer

Inherits:
Object
  • Object
show all
Includes:
Repo::AtomicWrites
Defined in:
lib/ucode/glyphs/last_resort/writer.rb

Overview

Writes one glyph.svg per codepoint in codepoints, sourcing the outline from the Last Resort UFO.

Single Renderer instance shared across the loop, so the parsed cmap and contents.plist are paid for once.

Idempotent: re-runs are no-ops via Repo::AtomicWrites (byte comparison; same content is skipped). Safe to re-run on the whole output tree.

Atomic: writes go through <path>.tmp + rename. A crash mid-write leaves either the old file or no file.

Block membership is the caller's responsibility — the Writer doesn't gate codepoints by assigned/unassigned. Last Resort placeholders exist for every codepoint in the cmap, including assigned ones, but the v0.2 pipeline only writes Last Resort SVGs for codepoints whose chart cell shows a placeholder box (see README "two pillars").

Instance Method Summary collapse

Methods included from Repo::AtomicWrites

#same_content?, #to_pretty_json, #write_atomic

Constructor Details

#initialize(output_root:, source:) ⇒ Writer

Returns a new instance of Writer.

Parameters:

  • output_root (String, Pathname)
  • source (Source)


37
38
39
40
41
# File 'lib/ucode/glyphs/last_resort/writer.rb', line 37

def initialize(output_root:, source:)
  @output_root = Pathname.new(output_root)
  @source = source
  @renderer = Renderer.new(source)
end

Instance Method Details

#write_many(codepoints, block_lookup:) ⇒ Hash

Write glyph.svg for every codepoint in codepoints whose block is known, using the Last Resort outline.

Parameters:

  • codepoints (Array<Integer>, Enumerable<Integer>)
  • block_lookup (Proc, #call)

    codepoint → block id string (e.g. "Basic_Latin"). Returns nil for codepoints without a block; those are skipped.

Returns:

  • (Hash)

    tally { written:, skipped:, missing:, total: }



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ucode/glyphs/last_resort/writer.rb', line 51

def write_many(codepoints, block_lookup:)
  tally = { written: 0, skipped: 0, missing: 0, total: 0 }
  codepoints.each do |cp|
    tally[:total] += 1
    block_id = block_lookup.call(cp)
    if block_id.nil?
      tally[:missing] += 1
      next
    end

    result = @renderer.render(cp)
    if result.nil? || !result.ok?
      tally[:missing] += 1
      next
    end

    written = write_glyph(block_id, cp, result.svg)
    tally[written ? :written : :skipped] += 1
  end
  tally
end