Class: Fontisan::Tables::Cff2::IndexBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/tables/cff2/index_builder.rb

Overview

Builds CFF2 INDEX structures.

A CFF2 INDEX is identical to a CFF1 INDEX except the count field is uint32 (vs card16 in CFF1). This allows > 65,535 entries — though the CharStrings INDEX is still capped at 65,535 by maxp.numGlyphs.

Structure:

count      (uint32)  number of objects
offSize    (uint8)   1, 2, 3, or 4
offsets    (offSize × (count + 1))  1-based, relative to
                                 the byte before data
data       (variable)  concatenated object bytes

An empty INDEX is just a 4-byte count field of 0.

Constant Summary collapse

EMPTY_INDEX_BYTESIZE =
4

Class Method Summary collapse

Class Method Details

.build(items) ⇒ String

Returns binary INDEX.

Parameters:

  • items (Array<String>)

    binary data items

Returns:

  • (String)

    binary INDEX



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fontisan/tables/cff2/index_builder.rb', line 26

def self.build(items)
  return [0].pack("N") if items.empty?

  data = items.join.b
  off_size = off_size_for(data.bytesize + 1)
  offsets = build_offsets(items, off_size)

  io = +""
  io << [items.size].pack("N")     # count (uint32)
  io << [off_size].pack("C")       # offSize (uint8)
  io << offsets
  io << data
  io
end