Class: TTFunk::Table::Glyf::Compound

### Home Classes Methods

### In Files

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

### Parent

Object

### Methods

- ::new
- #compound?
- #recode

### 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::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::Format25
- TTFunk::Table::Post::Format30
- TTFunk::Table::Post::Format40
- TTFunk::Table::Simple

No matching classes.

# TTFunk::Table::Glyf::Compound

### Constants

ARG_1_AND_2_ARE_WORDS
Component
MORE_COMPONENTS
WE_HAVE_AN_X_AND_Y_SCALE
WE_HAVE_A_SCALE
WE_HAVE_A_TWO_BY_TWO
WE_HAVE_INSTRUCTIONS

### Attributes

glyph_ids[R]
raw[R]
x_max[R]
x_min[R]
y_max[R]
y_min[R]

### Public Class Methods

new(raw, x_min, y_min, x_max, y_max) click to toggle source

    # File lib/ttfunk/table/glyf/compound.rb, line 22
    def initialize(raw, x_min, y_min, x_max, y_max)
      @raw = raw
      @x_min, @y_min, @x_max, @y_max = x_min, y_min, x_max, y_max

      # Because TTFunk only cares about glyphs insofar as they (1) provide
      # a bounding box for each glyph, and (2) can be rewritten into a
      # font subset, we don't really care about the rest of the glyph data
      # except as a whole. Thus, we don't actually decompose the glyph
      # into it's parts--all we really care about are the locations within
      # the raw string where the component glyph ids are stored, so that
      # when we rewrite this glyph into a subset we can rewrite the
      # component glyph-ids so they are correct for the subset.

      @glyph_ids = []
      @glyph_id_offsets = []
      offset = 10 # 2 bytes for each of num-contours, min x/y, max x/y

      loop do
        flags, glyph_id = @raw[offset, 4].unpack("n*")
        @glyph_ids << glyph_id
        @glyph_id_offsets << offset + 2

        break unless flags & MORE_COMPONENTS != 0
        offset += 4

        if flags & ARG_1_AND_2_ARE_WORDS != 0
          offset += 4
        else
          offset += 2
        end

        if flags & WE_HAVE_A_TWO_BY_TWO != 0
          offset += 8
        elsif flags & WE_HAVE_AN_X_AND_Y_SCALE != 0
          offset += 4
        elsif flags & WE_HAVE_A_SCALE != 0
          offset += 2
        end
      end
    end

### Public Instance Methods

compound?() click to toggle source

    # File lib/ttfunk/table/glyf/compound.rb, line 63
    def compound?
      true
    end

recode(mapping) click to toggle source

    # File lib/ttfunk/table/glyf/compound.rb, line 67
    def recode(mapping)
      result = @raw.dup
      new_ids = glyph_ids.map { |id| mapping[id] }

      new_ids.zip(@glyph_id_offsets).each do |new_id, offset|
        result[offset, 2] = [new_id].pack("n")
      end

      return result
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.