Module: TTFunk::Table::Cmap::Format12
- Defined in:
- lib/ttfunk/table/cmap/format12.rb
Overview
Format 12: Segmented coverage.
This module conditionally extends Subtable.
Instance Attribute Summary collapse
-
#code_map ⇒ Hash{Integer => Integer}
readonly
Code map.
-
#language ⇒ Integer
readonly
Language.
Class Method Summary collapse
-
.encode(charmap) ⇒ Hash
Encode the encoding record to format 12.
Instance Method Summary collapse
-
#[](code) ⇒ Integer
Get glyph ID for character code.
-
#supported? ⇒ true
Is this encoding record format supported?.
Instance Attribute Details
#code_map ⇒ Hash{Integer => Integer} (readonly)
Code map.
Source Code
lib/ttfunk/table/cmap/format12.rb, line 16
16 | def code_map |
17 | @code_map
|
18 | end
|
#language ⇒ Integer (readonly)
Language.
Source Code
lib/ttfunk/table/cmap/format12.rb, line 12
12 | def language |
13 | @language
|
14 | end
|
Class Method Details
.encode(charmap) ⇒ Hash
Encode the encoding record to format 12.
Source Code
lib/ttfunk/table/cmap/format12.rb, line 30
30 | def self.encode(charmap) |
31 | next_id = 0 |
32 | glyph_map = { 0 => 0 } |
33 | range_firstglyphs = [] |
34 | range_firstcodes = [] |
35 | range_lengths = [] |
36 | last_glyph = last_code = -999 |
37 | |
38 | new_map = |
39 | charmap.keys.sort.each_with_object({}) do |code, map| |
40 | glyph_map[charmap[code]] ||= next_id += 1 |
41 | map[code] = { old: charmap[code], new: glyph_map[charmap[code]] } |
42 | |
43 | if code > last_code + 1 || glyph_map[charmap[code]] > last_glyph + 1 |
44 | range_firstcodes << code |
45 | range_firstglyphs << glyph_map[charmap[code]] |
46 | range_lengths << 1 |
47 | else
|
48 | range_lengths.push(range_lengths.pop) + 1 |
49 | end
|
50 | last_code = code |
51 | last_glyph = glyph_map[charmap[code]] |
52 | end
|
53 | |
54 | subtable = [ |
55 | 12, 0, 16 + (12 * range_lengths.size), 0, range_lengths.size, |
56 | ].pack('nnNNN') |
57 | range_lengths.each_with_index do |length, i| |
58 | firstglyph = range_firstglyphs[i] |
59 | firstcode = range_firstcodes[i] |
60 | subtable << [ |
61 | firstcode, firstcode + length - 1, firstglyph, |
62 | ].pack('NNN') |
63 | end
|
64 | |
65 | { charmap: new_map, subtable: subtable, max_glyph_id: next_id + 1 } |
66 | end
|
Instance Method Details
#[](code) ⇒ Integer
Get glyph ID for character code.
Source Code
lib/ttfunk/table/cmap/format12.rb, line 72
72 | def [](code) |
73 | @code_map[code] || 0 |
74 | end
|
#supported? ⇒ true
Is this encoding record format supported?
Source Code
lib/ttfunk/table/cmap/format12.rb, line 79
79 | def supported? |
80 | true
|
81 | end
|