Class: Fontisan::Tables::CblcIndexSubTable

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

Overview

Parsed IndexSubTable from a CBLC table.

The IndexSubTable is the format-specific directory describing how to locate each glyph's bitmap inside CBDT. Five formats are defined by the OpenType spec:

1 — variable metrics, variable size (uint32 offset array)
2 — constant metrics, constant size (single imageSize for the range)
3 — variable metrics, variable size, 4-byte-aligned (uint16 offsets × 4)
4 — variable metrics, variable size, bit-packed offsets (rare)
5 — constant metrics, constant size, with explicit uint32 offsetArray

Each parsed IndexSubTable exposes one [CblcGlyphBitmapLocation] per glyph in its range, plus the raw bytes so a subsetter can preserve unchanged subtables verbatim if needed.

Format-specific parsing is delegated to [CblcIndexSubTableFormatParser]; this class only owns the data model.

Reference: OpenType CBLC spec, IndexSubTable formats 1–5.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index_format:, image_format:, image_data_offset:, first_glyph_index:, last_glyph_index:, locations:, raw_bytes:) ⇒ CblcIndexSubTable

Returns a new instance of CblcIndexSubTable.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fontisan/tables/cblc_index_subtable.rb', line 47

def initialize(index_format:, image_format:, image_data_offset:,
               first_glyph_index:, last_glyph_index:, locations:,
               raw_bytes:)
  @index_format = index_format
  @image_format = image_format
  @image_data_offset = image_data_offset
  @first_glyph_index = first_glyph_index
  @last_glyph_index = last_glyph_index
  @locations = locations
  @raw_bytes = raw_bytes
end

Instance Attribute Details

#first_glyph_indexInteger (readonly)

Returns first glyph ID covered by this subtable.

Returns:

  • (Integer)

    first glyph ID covered by this subtable



36
37
38
# File 'lib/fontisan/tables/cblc_index_subtable.rb', line 36

def first_glyph_index
  @first_glyph_index
end

#image_data_offsetInteger (readonly)

Returns absolute imageDataOffset from start of CBDT.

Returns:

  • (Integer)

    absolute imageDataOffset from start of CBDT



33
34
35
# File 'lib/fontisan/tables/cblc_index_subtable.rb', line 33

def image_data_offset
  @image_data_offset
end

#image_formatInteger (readonly)

Returns imageFormat field (e.g. 17 = small metrics + PNG).

Returns:

  • (Integer)

    imageFormat field (e.g. 17 = small metrics + PNG)



30
31
32
# File 'lib/fontisan/tables/cblc_index_subtable.rb', line 30

def image_format
  @image_format
end

#index_formatInteger (readonly)

Returns indexFormat field (1, 2, 3, or 5).

Returns:

  • (Integer)

    indexFormat field (1, 2, 3, or 5)



27
28
29
# File 'lib/fontisan/tables/cblc_index_subtable.rb', line 27

def index_format
  @index_format
end

#last_glyph_indexInteger (readonly)

Returns last glyph ID covered by this subtable.

Returns:

  • (Integer)

    last glyph ID covered by this subtable



39
40
41
# File 'lib/fontisan/tables/cblc_index_subtable.rb', line 39

def last_glyph_index
  @last_glyph_index
end

#locationsArray<CblcGlyphBitmapLocation> (readonly)

Returns one per glyph in range.

Returns:



42
43
44
# File 'lib/fontisan/tables/cblc_index_subtable.rb', line 42

def locations
  @locations
end

#raw_bytesString (readonly)

Returns raw bytes of this IndexSubTable in the source CBLC.

Returns:

  • (String)

    raw bytes of this IndexSubTable in the source CBLC



45
46
47
# File 'lib/fontisan/tables/cblc_index_subtable.rb', line 45

def raw_bytes
  @raw_bytes
end

Class Method Details

.parse(cblc_bytes, index_subtable_offset:, first_glyph_index:, last_glyph_index:) ⇒ CblcIndexSubTable

Parse an IndexSubTable from a CBLC binary blob.

Parameters:

  • cblc_bytes (String)

    the full CBLC table bytes

  • index_subtable_offset (Integer)

    absolute byte offset within cblc_bytes where this IndexSubTable begins

  • first_glyph_index (Integer)

    first glyph ID covered

  • last_glyph_index (Integer)

    last glyph ID covered

Returns:



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fontisan/tables/cblc_index_subtable.rb', line 67

def self.parse(cblc_bytes, index_subtable_offset:, first_glyph_index:,
               last_glyph_index:)
  header = CblcIndexSubTableHeader.read(
    cblc_bytes[index_subtable_offset, 8],
  )

  new(
    index_format: header.index_format,
    image_format: header.image_format,
    image_data_offset: header.image_data_offset,
    first_glyph_index: first_glyph_index,
    last_glyph_index: last_glyph_index,
    locations: CblcIndexSubTableFormatParser.locations(
      header: header,
      bytes: cblc_bytes,
      base: index_subtable_offset,
      first: first_glyph_index,
      last: last_glyph_index,
    ),
    raw_bytes: CblcIndexSubTableFormatParser.raw_bytes(
      header: header,
      bytes: cblc_bytes,
      base: index_subtable_offset,
      first: first_glyph_index,
      last: last_glyph_index,
    ),
  )
end

Instance Method Details

#glyph_countInteger

Number of glyphs covered by this subtable.

Returns:

  • (Integer)


99
100
101
# File 'lib/fontisan/tables/cblc_index_subtable.rb', line 99

def glyph_count
  last_glyph_index - first_glyph_index + 1
end