Class: TTFunk::Table::Kern::Format0

### Home Classes Methods

### In Files

- lib/ttfunk/table/kern/format0.rb

### Parent

Object

### Methods

- ::new
- #cross_stream?
- #horizontal?
- #recode
- #vertical?

### Included Modules

- TTFunk::Reader

### Class/Module Index

Quicksearch

- TTFunk
- TTFunk::Directory
- TTFunk::Encoding
- TTFunk::Encoding::MacRoman
- TTFunk::Encoding::Windows1252
- TTFunk::File
- TTFunk::Reader
- TTFunk::ResourceFile
- TTFunk::Subset
- TTFunk::Subset::Base
- TTFunk::Subset::MacRoman
- TTFunk::Subset::Unicode
- TTFunk::Subset::Unicode8Bit
- TTFunk::Subset::Windows1252
- TTFunk::SubsetCollection
- TTFunk::Table
- TTFunk::Table::Cmap
- TTFunk::Table::Cmap::Format00
- TTFunk::Table::Cmap::Format04
- TTFunk::Table::Cmap::Format06
- TTFunk::Table::Cmap::Format10
- TTFunk::Table::Cmap::Format12
- TTFunk::Table::Cmap::Subtable
- TTFunk::Table::Glyf
- TTFunk::Table::Glyf::Compound
- TTFunk::Table::Glyf::Simple
- TTFunk::Table::Head
- TTFunk::Table::Hhea
- TTFunk::Table::Hmtx
- TTFunk::Table::Kern
- TTFunk::Table::Kern::Format0
- TTFunk::Table::Loca
- TTFunk::Table::Maxp
- TTFunk::Table::Name
- TTFunk::Table::Name::String
- TTFunk::Table::OS2
- TTFunk::Table::Post
- TTFunk::Table::Post::Format10
- TTFunk::Table::Post::Format20
- TTFunk::Table::Post::Format30
- TTFunk::Table::Post::Format40
- TTFunk::Table::Sbix
- TTFunk::Table::Simple

No matching classes.

# TTFunk::Table::Kern::Format0

### Attributes

attributes[R]
pairs[R]

### Public Class Methods

new(attributes={}) click to toggle source

    # 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

### Public Instance Methods

cross_stream?() click to toggle source

    # File lib/ttfunk/table/kern/format0.rb, line 35
    def cross_stream?
      @attributes[:cross]
    end

horizontal?() click to toggle source

    # File lib/ttfunk/table/kern/format0.rb, line 31
    def horizontal?
      !vertical?
    end

recode(mapping) click to toggle source

    # 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?() click to toggle source

    # File lib/ttfunk/table/kern/format0.rb, line 27
    def vertical?
      @attributes[:vertical]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.