Class: Skrift::Color::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/skrift/color/renderer.rb

Overview

Renders colour glyphs to an RGBA Skrift::Color::Image. Two formats are supported: COLR/CPAL v0 (layered vector glyphs, composited with skrift’s monochrome rasteriser) and CBDT/CBLC (embedded PNG bitmaps, e.g. Noto Color Emoji), scaled to the requested size.

Instance Method Summary collapse

Constructor Details

#initialize(font, x_scale:, y_scale:) ⇒ Renderer

Returns a new instance of Renderer.



14
15
16
17
18
19
20
21
22
23
# File 'lib/skrift/color/renderer.rb', line 14

def initialize(font, x_scale:, y_scale:)
  @font = font
  @y_scale = y_scale
  @sft  = Skrift::Renderer.new(font)
  @sft.x_scale = x_scale
  @sft.y_scale = y_scale
  @colr = COLR.parse(font)
  @cpal = CPAL.parse(font)
  @cbdt = CBDT.parse(font)
end

Instance Method Details

#color?Boolean

True if the font carries any supported colour data (COLR+CPAL or CBDT).

Returns:

  • (Boolean)


26
# File 'lib/skrift/color/renderer.rb', line 26

def color? = (!@colr.nil? && !@cpal.nil?) || !@cbdt.nil?

#render(codepoint) ⇒ Object

A Skrift::Color::Image (RGBA) for codepoint, or nil if it has no colour glyph — in which case the caller should fall back to ordinary monochrome rendering. Tries vector (COLR) then bitmap (CBDT).



31
32
33
# File 'lib/skrift/color/renderer.rb', line 31

def render(codepoint)
  render_colr(codepoint) || render_cbdt(codepoint)
end