Class: Ucode::Glyphs::LastResort::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/glyphs/last_resort/renderer.rb

Overview

Chains the four lookup stages needed to render one codepoint’s Last Resort glyph: cmap (cp → name) → contents (name → file) → glif (file → outline) → svg (outline → SVG document).

The CmapIndex and Contents are lazily built and memoized per Renderer instance, so rendering many codepoints shares the parsed cmap (1,114,112 entries) and plist (380 entries).

Pure-ish: reads from disk via the Source paths; produces a Result struct. Never raises on missing codepoints — returns ‘nil` so callers can decide whether to log or fall back to a generic placeholder.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Renderer

Returns a new instance of Renderer.

Parameters:



33
34
35
# File 'lib/ucode/glyphs/last_resort/renderer.rb', line 33

def initialize(source)
  @source = source
end

Instance Method Details

#cmapCmapIndex

Returns:



56
57
58
# File 'lib/ucode/glyphs/last_resort/renderer.rb', line 56

def cmap
  @cmap ||= CmapIndex.new(@source.cmap_path)
end

#contentsContents

Returns:



61
62
63
# File 'lib/ucode/glyphs/last_resort/renderer.rb', line 61

def contents
  @contents ||= Contents.new(@source.contents_path)
end

#render(codepoint) ⇒ Result?

Returns nil when the codepoint isn’t in the cmap or the named glyph is missing from disk.

Parameters:

  • codepoint (Integer)

Returns:

  • (Result, nil)

    nil when the codepoint isn’t in the cmap or the named glyph is missing from disk



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ucode/glyphs/last_resort/renderer.rb', line 40

def render(codepoint)
  glyph_name = cmap[codepoint]
  return nil unless glyph_name

  basename = contents[glyph_name]
  return nil unless basename

  path = @source.glif_path(basename)
  return nil unless path.exist?

  outline = Glif.read(path)
  svg = Svg.new(outline, codepoint: codepoint).to_s
  Result.new(codepoint: codepoint, glyph_name: glyph_name, svg: svg)
end