Class: TTFunk::Table::Glyf

### Home Classes Methods

### In Files

- lib/ttfunk/table/glyf.rb
- lib/ttfunk/table/glyf/compound.rb
- lib/ttfunk/table/glyf/simple.rb

### Parent

TTFunk::Table

### Namespace

- CLASS TTFunk::Table::Glyf::Compound
- CLASS TTFunk::Table::Glyf::Simple

### Methods

- ::encode
- #for

### 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::Glyf

### Public Class Methods

encode(glyphs, new2old, old2new) click to toggle source

Accepts a hash mapping (old) glyph-ids to glyph objects, and a hash mapping old glyph-ids to new glyph-ids.

Returns a hash containing:

- :table - a string representing the encoded 'glyf' table containing the given glyphs.

- :offsets - an array of offsets for each glyph

    # File lib/ttfunk/table/glyf.rb, line 14
    def self.encode(glyphs, new2old, old2new)
      result = { :table => "", :offsets => [] }

      new2old.keys.sort.each do |new_id|
        glyph = glyphs[new2old[new_id]]
        result[:offsets] << result[:table].length
        result[:table] << glyph.recode(old2new) if glyph
      end

      # include an offset at the end of the table, for use in computing the
      # size of the last glyph
      result[:offsets] << result[:table].length
      return result
    end

### Public Instance Methods

for(glyph_id) click to toggle source

    # File lib/ttfunk/table/glyf.rb, line 29
    def for(glyph_id)
      return @cache[glyph_id] if @cache.key?(glyph_id)

      index = file.glyph_locations.index_of(glyph_id)
      size  = file.glyph_locations.size_of(glyph_id)

      if size.zero? # blank glyph, e.g. space character
        @cache[glyph_id] = nil
        return nil
      end

      parse_from(offset + index) do
        raw = io.read(size)
        number_of_contours, x_min, y_min, x_max, y_max = raw.unpack("n5").map { |i| to_signed(i) }

        @cache[glyph_id] = if number_of_contours == -1
            Compound.new(raw, x_min, y_min, x_max, y_max)
          else
            Simple.new(raw, number_of_contours, x_min, y_min, x_max, y_max)
          end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.