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