Class: Fontisan::Tables::Cbdt
- Inherits:
-
Binary::BaseRecord
- Object
- BinData::Record
- Binary::BaseRecord
- Fontisan::Tables::Cbdt
- Defined in:
- lib/fontisan/tables/cbdt.rb
Overview
CBDT (Color Bitmap Data) table.
CBDT stores the raw bitmap data blocks for color glyphs. CBLC indexes
into CBDT via imageDataOffset and per-glyph offset arrays. CBDT
itself is essentially a blob: the 4-byte header (majorVersion +
minorVersion) followed by an opaque sequence of bitmap blocks.
This model exposes the header fields via BinData and preserves the
original bytes for subsetting and direct slicing. A Cbdt constructed
via Cbdt.new (no read) has no captured bytes — raw_data is nil
and data_size returns 0.
Reference: OpenType CBDT specification. https://learn.microsoft.com/en-us/typography/opentype/spec/cbdt
Constant Summary collapse
- TAG =
"CBDT"- VERSION_2_0 =
CBDT v2.0 — original release
0x00020000- VERSION_3_0 =
CBDT v3.0 — adds PNG image format support
0x00030000
Instance Method Summary collapse
-
#bitmap_data_at(offset, length) ⇒ String?
Slice
lengthbytes starting atoffsetfrom the CBDT blob. -
#data_size ⇒ Integer
Total byte size of the captured CBDT bytes, or 0 if none.
-
#has_raw_data? ⇒ Boolean
Whether this instance was populated from real table bytes.
-
#raw_data ⇒ String?
Raw bytes captured at read time, or nil for a fresh instance.
-
#to_binary_s ⇒ String
Serialize the captured bytes back to binary.
-
#valid? ⇒ Boolean
Whether the header declares a CBDT version fontisan understands (v2.0 or v3.0) and any raw bytes were captured.
-
#valid_offset?(offset) ⇒ Boolean
Whether
offsetfalls within the captured CBDT byte range. -
#version ⇒ Integer
Combined version number (e.g. 0x00030000 for v3.0).
Methods inherited from Binary::BaseRecord
Instance Method Details
#bitmap_data_at(offset, length) ⇒ String?
Slice length bytes starting at offset from the CBDT blob.
Returns nil for out-of-range offsets/lengths so callers can use a
nil check instead of rescuing IndexError.
81 82 83 84 85 86 87 |
# File 'lib/fontisan/tables/cbdt.rb', line 81 def bitmap_data_at(offset, length) return nil if offset.nil? || length.nil? return nil if offset.negative? || length.negative? return nil if offset + length > data_size raw_data[offset, length] end |
#data_size ⇒ Integer
Total byte size of the captured CBDT bytes, or 0 if none.
60 61 62 |
# File 'lib/fontisan/tables/cbdt.rb', line 60 def data_size raw_data&.bytesize || 0 end |
#has_raw_data? ⇒ Boolean
Whether this instance was populated from real table bytes.
37 38 39 |
# File 'lib/fontisan/tables/cbdt.rb', line 37 def has_raw_data? defined?(@raw_data) && !@raw_data.nil? ? true : false end |
#raw_data ⇒ String?
Raw bytes captured at read time, or nil for a fresh instance.
44 45 46 47 48 |
# File 'lib/fontisan/tables/cbdt.rb', line 44 def raw_data return @raw_data if defined?(@raw_data) nil end |
#to_binary_s ⇒ String
Serialize the captured bytes back to binary. Falls back to BinData's default serialization (4-byte header) if no bytes were captured, so consumers can construct a CBDT from scratch.
94 95 96 97 98 |
# File 'lib/fontisan/tables/cbdt.rb', line 94 def to_binary_s return raw_data if has_raw_data? super end |
#valid? ⇒ Boolean
Whether the header declares a CBDT version fontisan understands (v2.0 or v3.0) and any raw bytes were captured.
104 105 106 107 108 109 110 |
# File 'lib/fontisan/tables/cbdt.rb', line 104 def valid? return false unless [2, 3].include?(major_version) return false unless minor_version.zero? return false unless has_raw_data? true end |
#valid_offset?(offset) ⇒ Boolean
Whether offset falls within the captured CBDT byte range.
68 69 70 71 72 |
# File 'lib/fontisan/tables/cbdt.rb', line 68 def valid_offset?(offset) return false if offset.nil? || offset.negative? offset < data_size end |
#version ⇒ Integer
Combined version number (e.g. 0x00030000 for v3.0).
53 54 55 |
# File 'lib/fontisan/tables/cbdt.rb', line 53 def version (major_version << 16) | minor_version end |