Class: Ucode::Glyphs::EmbeddedFonts::Renderer

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

Overview

Renders one codepoint's glyph by chaining the Catalog index lookup → FontEntry accessor → Svg wrapper.

Mirrors LastResort::Renderer: a Result struct is returned on success, nil on miss. The caller (Writer or CLI) decides how to handle misses — typically by falling back to the LastResort renderer.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(catalog) ⇒ Renderer

Returns a new instance of Renderer.

Parameters:



31
32
33
# File 'lib/ucode/glyphs/embedded_fonts/renderer.rb', line 31

def initialize(catalog)
  @catalog = catalog
end

Instance Method Details

#render(codepoint) ⇒ Result?

Returns nil when no font in the PDF covers this codepoint, or when the GID's outline is empty.

Parameters:

  • codepoint (Integer)

Returns:

  • (Result, nil)

    nil when no font in the PDF covers this codepoint, or when the GID's outline is empty



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ucode/glyphs/embedded_fonts/renderer.rb', line 38

def render(codepoint)
  entry = @catalog.lookup(codepoint)
  return nil unless entry

  gid = entry.gid_for(codepoint)
  return nil unless gid

  outline = entry.accessor.outline_for_id(gid)
  return nil if outline.nil? || outline.empty?

  svg = Svg.new(outline, codepoint: codepoint, base_font: entry.base_font).to_s
  location = @catalog.location_for(codepoint)
  Result.new(
    codepoint: codepoint,
    base_font: entry.base_font,
    gid: gid,
    svg: svg,
    source_page: location&.fetch(:page),
    source_cell: location && { x: location[:x], y: location[:y] },
  )
end