Class: Fontisan::Tables::Cff::IndexBuilder
- Inherits:
-
Object
- Object
- Fontisan::Tables::Cff::IndexBuilder
- Defined in:
- lib/fontisan/tables/cff/index_builder.rb
Overview
CFF INDEX structure builder
IndexBuilder constructs
binary INDEX structures from arrays of data items. INDEX is a fundamental
CFF data structure used for storing arrays of variable-length data.
The builder calculates optimal offset sizes, constructs the offset array, and produces compact binary output.
Structure produced:
- count (Card16): Number of items
- offSize (OffSize): Size of offset values (1-4 bytes)
- offset (Offset): Array of offsets to data
- data: Concatenated data bytes
Offsets are 1-based (first offset is always 1). The last offset points one byte past the end of the data.
Reference: CFF specification section 5 "INDEX Data" https://adobe-type-tools.github.io/font-tech-notes/pdfs/5176.CFF.pdf
Class Method Summary collapse
-
.build(items) ⇒ String
Build INDEX structure from array of binary strings.
Class Method Details
.build(items) ⇒ String
Build INDEX structure from array of binary strings
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fontisan/tables/cff/index_builder.rb', line 38 def self.build(items) validate_items!(items) return build_empty_index if items.empty? # Calculate total data size data_size = items.sum(&:bytesize) # Calculate optimal offset size (1-4 bytes) # Last offset will be data_size + 1 (1-based) off_size = calculate_off_size(data_size + 1) # Build offset array (count + 1 offsets) offsets = build_offsets(items, off_size) # Concatenate all data data = items.join # Assemble INDEX structure output = StringIO.new("".b) # Write count (Card16) output.write([items.length].pack("n")) # Write offSize (OffSize) output.putc(off_size) # Write offset array offsets.each do |offset| write_offset(output, offset, off_size) end # Write data output.write(data) output.string end |