Class: Skrift::Color::CBDT

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

Overview

Parses CBLC/CBDT colour-bitmap tables and extracts a glyph’s embedded PNG. Handles the common Noto Color Emoji shape: index format 1 (uint32 offset array) and image format 17 (small metrics + PNG). Returns nil for fonts or glyphs it can’t handle, so callers can fall back.

Defined Under Namespace

Classes: Strike, SubTable

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(font, cblc, cbdt) ⇒ CBDT

Returns a new instance of CBDT.



20
21
22
23
24
# File 'lib/skrift/color/cbdt.rb', line 20

def initialize(font, cblc, cbdt)
  @font = font
  @cbdt = cbdt
  @strikes = parse_strikes(cblc)
end

Class Method Details

.parse(font) ⇒ Object



13
14
15
16
17
18
# File 'lib/skrift/color/cbdt.rb', line 13

def self.parse(font)
  cblc = font.tables["CBLC"]
  cbdt = font.tables["CBDT"]
  return nil unless cblc && cbdt
  new(font, cblc, cbdt)
end

Instance Method Details

#glyph(gid) ⇒ Object

png_bytes, ppem_y

for a glyph id, or nil if it has no colour bitmap.



27
28
29
30
31
32
33
34
35
36
# File 'lib/skrift/color/cbdt.rb', line 27

def glyph(gid)
  @strikes.each do |st|
    next unless gid.between?(st.start_gid, st.end_gid)
    sub = st.subtables.find { |s| gid.between?(s.first, s.last) }
    next unless sub
    png = extract(sub, gid)
    return [png, st.ppem_y] if png
  end
  nil
end