Class: Pdfrb::Font::TrueType::Cmap

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/font/true_type/cmap.rb

Overview

cmap table parser. Resolves Unicode codepoints to glyph IDs by picking the best available subtable and applying its format-specific decoding.

Supported subtable formats:

* 0  — byte encoding (256 entries)
* 4  — segment mapping (BMP)
* 6  — trimmed table (range)
* 12 — sparse coverage (full Unicode)

Subtable selection prefers Unicode platforms:

(3,10) Windows Unicode full > (0,* ) Unicode > (3,1) Windows BMP

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Cmap

Returns a new instance of Cmap.



33
34
35
36
37
38
39
# File 'lib/pdfrb/font/true_type/cmap.rb', line 33

def initialize(data)
  @data = data
  @glyph_cache = {}
  return unless data && data.bytesize >= 4

  choose_subtable
end

Instance Attribute Details

#encoding_idObject (readonly)

Returns the value of attribute encoding_id.



19
20
21
# File 'lib/pdfrb/font/true_type/cmap.rb', line 19

def encoding_id
  @encoding_id
end

#formatObject (readonly)

Returns the value of attribute format.



19
20
21
# File 'lib/pdfrb/font/true_type/cmap.rb', line 19

def format
  @format
end

#platform_idObject (readonly)

Returns the value of attribute platform_id.



19
20
21
# File 'lib/pdfrb/font/true_type/cmap.rb', line 19

def platform_id
  @platform_id
end

#subtable_offsetObject (readonly)

Returns the value of attribute subtable_offset.



19
20
21
# File 'lib/pdfrb/font/true_type/cmap.rb', line 19

def subtable_offset
  @subtable_offset
end

Instance Method Details

#glyph_id_for(unicode) ⇒ Object

Unicode codepoint → glyph ID. Returns 0 (.notdef) if no mapping exists.



43
44
45
46
47
# File 'lib/pdfrb/font/true_type/cmap.rb', line 43

def glyph_id_for(unicode)
  return 0 if @format.nil?

  @glyph_cache[unicode] ||= lookup(unicode)
end