Class: Pdfrb::Font::TrueType::Cmap
- Inherits:
-
Object
- Object
- Pdfrb::Font::TrueType::Cmap
- 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
-
#encoding_id ⇒ Object
readonly
Returns the value of attribute encoding_id.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#platform_id ⇒ Object
readonly
Returns the value of attribute platform_id.
-
#subtable_offset ⇒ Object
readonly
Returns the value of attribute subtable_offset.
Instance Method Summary collapse
-
#glyph_id_for(unicode) ⇒ Object
Unicode codepoint → glyph ID.
-
#initialize(data) ⇒ Cmap
constructor
A new instance of Cmap.
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_id ⇒ Object (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 |
#format ⇒ Object (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_id ⇒ Object (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_offset ⇒ Object (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 |