Module: Fontisan::Ufo::Compile::Cpal
- Defined in:
- lib/fontisan/ufo/compile/cpal.rb
Overview
Builds the OpenType CPAL (Color Palette) table.
CPAL stores one or more palettes of BGRA color records, referenced by COLR layers and other color-glyph mechanisms.
Defined Under Namespace
Classes: Color
Constant Summary collapse
- VERSION =
0- HEADER_SIZE =
12- COLOR_RECORD_SIZE =
BGRA
4
Class Method Summary collapse
-
.build(palettes:) ⇒ String?
CPAL table bytes, or nil if no palettes.
Class Method Details
.build(palettes:) ⇒ String?
Returns CPAL table bytes, or nil if no palettes.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fontisan/ufo/compile/cpal.rb', line 28 def self.build(palettes:) return nil if palettes.nil? || palettes.empty? num_entries = palettes.first.size num_palettes = palettes.size num_records = num_entries * num_palettes indices = Array.new(num_palettes) { |i| i * num_entries } records = palettes.flatten offset = HEADER_SIZE + (num_palettes * 2) # header + indices io = +"" io << [VERSION, num_entries, num_palettes, num_records, offset].pack("nnnnN") indices.each { |idx| io << [idx].pack("n") } records.each { |c| io << color_bytes(c) } io end |