Class: TTFunk::Table::Kern::Format0
- Inherits:
-
Object
- Object
- TTFunk::Table::Kern::Format0
- Includes:
- Reader
- Defined in:
- lib/ttfunk/table/kern/format0.rb
Overview
Format 0 kerning subtable.
Instance Attribute Summary collapse
-
#attributes ⇒ Hash{Symbol => any}
readonly
Subtable attributes.
-
#pairs ⇒ Hash{Array(Integer, Integer) => Integer}
readonly
Kerning pairs.
Instance Method Summary collapse
-
#cross_stream? ⇒ Boolean
Is this cross-stream kerning?.
-
#horizontal? ⇒ Boolean
Is this horizontal kerning?.
-
#initialize(attributes = {}) ⇒ Format0
constructor
A new instance of Format0.
-
#recode(mapping) ⇒ String
Recode this subtable using the specified mapping.
-
#vertical? ⇒ Boolean
Is this vertical kerning?.
Constructor Details
#initialize(attributes = {}) ⇒ Format0
Returns a new instance of Format0.
Source Code
lib/ttfunk/table/kern/format0.rb, line 21
21 | def initialize(attributes = {}) |
22 | @attributes = attributes |
23 | |
24 | num_pairs, *pairs = attributes.delete(:data).unpack('nx6n*') |
25 | |
26 | @pairs = {} |
27 | num_pairs.times do |i| |
28 | # sanity check, in case there's a bad length somewhere
|
29 | break if (i * 3) + 2 > pairs.length |
30 | |
31 | left = pairs[i * 3] |
32 | right = pairs[(i * 3) + 1] |
33 | value = to_signed(pairs[(i * 3) + 2]) |
34 | @pairs[[left, right]] = value |
35 | end
|
36 | end
|
Instance Attribute Details
#attributes ⇒ Hash{Symbol => any} (readonly)
Subtable attributes.
Source Code
lib/ttfunk/table/kern/format0.rb, line 14
14 | def attributes |
15 | @attributes
|
16 | end
|
#pairs ⇒ Hash{Array(Integer, Integer) => Integer} (readonly)
Kerning pairs.
Source Code
lib/ttfunk/table/kern/format0.rb, line 18
18 | def pairs |
19 | @pairs
|
20 | end
|
Instance Method Details
#cross_stream? ⇒ Boolean
Is this cross-stream kerning?
Source Code
lib/ttfunk/table/kern/format0.rb, line 52
52 | def cross_stream? |
53 | @attributes[:cross] |
54 | end
|
#horizontal? ⇒ Boolean
Is this horizontal kerning?
Source Code
lib/ttfunk/table/kern/format0.rb, line 46
46 | def horizontal? |
47 | !vertical? |
48 | end
|
#recode(mapping) ⇒ String
Recode this subtable using the specified mapping.
Source Code
lib/ttfunk/table/kern/format0.rb, line 61
61 | def recode(mapping) |
62 | subset = [] |
63 | pairs.each do |(left, right), value| |
64 | if mapping[left] && mapping[right] |
65 | subset << [mapping[left], mapping[right], value] |
66 | end
|
67 | end
|
68 | |
69 | return if subset.empty? |
70 | |
71 | num_pairs = subset.length |
72 | search_range = 2 * (2**Integer(Math.log(num_pairs) / Math.log(2))) |
73 | entry_selector = Integer(Math.log(search_range / 2) / Math.log(2)) |
74 | range_shift = (2 * num_pairs) - search_range |
75 | |
76 | [
|
77 | attributes[:version], |
78 | (num_pairs * 6) + 14, |
79 | attributes[:coverage], |
80 | num_pairs, |
81 | search_range, |
82 | entry_selector, |
83 | range_shift, |
84 | subset, |
85 | ].flatten.pack('n*') |
86 | end
|
#vertical? ⇒ Boolean
Is this vertical kerning?
Source Code
lib/ttfunk/table/kern/format0.rb, line 40
40 | def vertical? |
41 | @attributes[:vertical] |
42 | end
|