Class: Ucode::Glyphs::LastResort::Writer
- Inherits:
-
Object
- Object
- Ucode::Glyphs::LastResort::Writer
- 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
-
#initialize(output_root:, source:) ⇒ Writer
constructor
A new instance of Writer.
-
#write_many(codepoints, block_lookup:) ⇒ Hash
Write
glyph.svgfor every codepoint incodepointswhose block is known, using the Last Resort outline.
Methods included from Repo::AtomicWrites
#same_content?, #to_pretty_json, #write_atomic
Constructor Details
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.
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 |