Sha256: fb0293c77a33d701bc506d589714eed4481169ef71244e0d3f4f74286d8b0b6e

Contents?: true

Size: 1.6 KB

Versions: 34

Compression:

Stored size: 1.6 KB

Contents

require 'ttfunk/reader'

module TTFunk
  class Table
    class Kern
      class Format0
        include Reader

        attr_reader :attributes
        attr_reader :pairs

        def initialize(attributes={})
          @attributes = attributes

          num_pairs, search_range, entry_selector, range_shift, *pairs =
            attributes.delete(:data).unpack("n*")

          @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

        def vertical?
          @attributes[:vertical]
        end

        def horizontal?
          !vertical?
        end

        def cross_stream?
          @attributes[:cross]
        end

        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
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 10 rubygems

Version Path
ttfunk-1.2.2 lib/ttfunk/table/kern/format0.rb
ttfunk-1.2.1 lib/ttfunk/table/kern/format0.rb
ttfunk-1.2.0 lib/ttfunk/table/kern/format0.rb
ttfunk-1.1.1 lib/ttfunk/table/kern/format0.rb
ttfunk-1.1.0 lib/ttfunk/table/kern/format0.rb
ttfunk-1.0.3 lib/ttfunk/table/kern/format0.rb
ttfunk-1.0.2 lib/ttfunk/table/kern/format0.rb
ttfunk-1.0.1 lib/ttfunk/table/kern/format0.rb
davebenvenuti-prawn-0.11.1.pre vendor/ttfunk/lib/ttfunk/table/kern/format0.rb
piglop-prawn-0.10.2.3 vendor/ttfunk/lib/ttfunk/table/kern/format0.rb
piglop-prawn-0.10.2.2 vendor/ttfunk/lib/ttfunk/table/kern/format0.rb
piglop-prawn-0.10.2.1 vendor/ttfunk/lib/ttfunk/table/kern/format0.rb
glyph_imager-0.1.1 vendor/ttfunk/lib/ttfunk/table/kern/format0.rb
prawn-0.11.1.pre vendor/ttfunk/lib/ttfunk/table/kern/format0.rb
goodwill-prawn-edge-0.10.0 vendor/ttfunk/lib/ttfunk/table/kern/format0.rb
alphasights-prawn-0.10.4 vendor/ttfunk/lib/ttfunk/table/kern/format0.rb
alphasights-prawn-0.10.3 vendor/ttfunk/lib/ttfunk/table/kern/format0.rb
alphasights-prawn-0.10.2 vendor/ttfunk/lib/ttfunk/table/kern/format0.rb
alphasights-prawn-0.10.1 vendor/ttfunk/lib/ttfunk/table/kern/format0.rb
glyph_imager-0.1.0 vendor/ttfunk/lib/ttfunk/table/kern/format0.rb