Class: TTFunk::Table::Kern::Format0
- Inherits:
-
Object
- Object
- TTFunk::Table::Kern::Format0
- Includes:
- Reader
- Defined in:
- lib/ttfunk/table/kern/format0.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#pairs ⇒ Object
readonly
Returns the value of attribute pairs.
Instance Method Summary collapse
- #cross_stream? ⇒ Boolean
- #horizontal? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Format0
constructor
A new instance of Format0.
- #recode(mapping) ⇒ Object
- #vertical? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Format0
Returns a new instance of Format0.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ttfunk/table/kern/format0.rb', line 12 def initialize(attributes={}) @attributes = attributes num_pairs, *pairs = attributes.delete(:data).unpack("nx6n*") @pairs = {} num_pairs.times do |i| break if i*3+2 > pairs.length # sanity check, in case there's a bad length somewhere 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 ⇒ Object (readonly)
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/ttfunk/table/kern/format0.rb', line 9 def attributes @attributes end |
#pairs ⇒ Object (readonly)
Returns the value of attribute pairs.
10 11 12 |
# File 'lib/ttfunk/table/kern/format0.rb', line 10 def pairs @pairs end |
Instance Method Details
#cross_stream? ⇒ Boolean
35 36 37 |
# File 'lib/ttfunk/table/kern/format0.rb', line 35 def cross_stream? @attributes[:cross] end |
#horizontal? ⇒ Boolean
31 32 33 |
# File 'lib/ttfunk/table/kern/format0.rb', line 31 def horizontal? !vertical? end |
#recode(mapping) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ttfunk/table/kern/format0.rb', line 39 def recode(mapping) subset = [] pairs.each do |(left, right), value| if mapping[left] && mapping[right] subset << [mapping[left], mapping[right], value] end end return nil if subset.empty? num_pairs = subset.length search_range = 2 * 2 ** (Math.log(num_pairs) / Math.log(2)).to_i entry_selector = (Math.log(search_range / 2) / Math.log(2)).to_i 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
27 28 29 |
# File 'lib/ttfunk/table/kern/format0.rb', line 27 def vertical? @attributes[:vertical] end |