Class: Ucode::Glyphs::EmbeddedFonts::Writer
- Inherits:
-
Object
- Object
- Ucode::Glyphs::EmbeddedFonts::Writer
- Includes:
- Repo::AtomicWrites
- Defined in:
- lib/ucode/glyphs/embedded_fonts/writer.rb
Overview
Writes one glyph.svg per codepoint in codepoints, sourcing
the outline from the Code Charts PDF's embedded font program.
The Catalog and Renderer are shared across the loop so the
expensive PDF walk + ToUnicode parse + fontisan load happen
once per process. Each FontEntry memoizes its own fontisan
accessor; in long CJK runs you may want to call
entry.reset_accessor! periodically (the Writer doesn't).
Idempotent and atomic via Repo::AtomicWrites — same protocol
as the LastResort and v0.1 cell-extractor writers.
Instance Method Summary collapse
-
#initialize(output_root:, catalog:) ⇒ Writer
constructor
A new instance of Writer.
-
#write_many(codepoints = nil, block_lookup:) ⇒ Hash
Write
glyph.svgfor every codepoint covered by the PDF.
Methods included from Repo::AtomicWrites
#same_content?, #to_pretty_json, #write_atomic
Constructor Details
Instance Method Details
#write_many(codepoints = nil, block_lookup:) ⇒ Hash
Write glyph.svg for every codepoint covered by the PDF.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ucode/glyphs/embedded_fonts/writer.rb', line 43 def write_many(codepoints = nil, block_lookup:) cps = codepoints || @catalog.codepoints tally = { written: 0, skipped: 0, missing: 0, total: 0 } cps.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 |