module HexaPDF::Font::TrueType::Table::CmapSubtable::Format4

Cmap format 4

Public Class Methods

parse(io, length) → code_map click to toggle source

Parses the format 4 cmap subtable from the given IO at the current position and returns the contained code map.

It is assumed that the first six bytes of the subtable have already been consumed.

# File lib/hexapdf/font/true_type/table/cmap_subtable.rb, line 266
def self.parse(io, length)
  seg_count_x2 = io.read(8).unpack1('n')
  end_codes = io.read(seg_count_x2).unpack('n*')
  io.pos += 2
  start_codes = io.read(seg_count_x2).unpack('n*')
  id_deltas = io.read(seg_count_x2).unpack('n*')
  id_range_offsets = io.read(seg_count_x2).unpack('n*').map!.with_index do |offset, idx|
    # Change offsets to indexes, starting from the id_range_offsets array
    offset == 0 ? offset : offset / 2 + idx
  end
  glyph_indexes = io.read(length - 16 - seg_count_x2 * 4).unpack('n*')
  mapper(end_codes, start_codes, id_deltas, id_range_offsets, glyph_indexes)
end