Module: HexaPDF::Font::TrueType::Table::CmapSubtable::Format12

Defined in:
lib/hexapdf/font/true_type/table/cmap_subtable.rb

Overview

Cmap format 12

Class Method Summary collapse

Class Method Details

.mapper(groups) ⇒ Object

The parameter groups is an array containing [start_code, end_code, start_glyph_id] arrays.



374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/hexapdf/font/true_type/table/cmap_subtable.rb', line 374

def self.mapper(groups) #:nodoc:
  code_map = Hash.new do |h, code|
    group = groups.bsearch {|g| g[1] >= code }
    h[code] = group[2] + (code - group[0]) if group && group[0] <= code
  end
  groups_by_gid = groups.sort_by {|g| g[2] }
  gid_map = Hash.new do |h, gid|
    group = groups_by_gid.bsearch {|g| g[2] + g[1] - g[0] >= gid }
    h[gid] = group[0] + (gid - group[2]) if group && group[2] <= gid
  end
  [code_map, gid_map]
end

.parse(io, _length) ⇒ Object

:call-seq:

Format12.parse(io, length)    -> code_map

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

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



368
369
370
# File 'lib/hexapdf/font/true_type/table/cmap_subtable.rb', line 368

def self.parse(io, _length)
  mapper(Array.new(io.read(4).unpack1('N')) { io.read(12).unpack('N3') })
end