class TTFunk::Collection

TrueType font collection. Usually a file with ‘.ttc` extension.

def self.open(path)

Returns:
  • (any) - whatever the block returns
  • (any) - whatever the block returns

Other tags:
    Yieldparam: collection -
    Yieldparam: collection -

Parameters:
  • file_path (String, Pathname) -- Path to the font collection file.
  • io (IO) -- IO to read the collection from.

Overloads:
  • open(file_path)
  • open(io)
def self.open(path)
  if path.respond_to?(:read)
    result = yield(new(path))
    path.rewind
    result
  else
    ::File.open(path, 'rb') do |io|
      yield(new(io))
    end
  end
end

def [](index)

Returns:
  • (TTFunk::File) -

Parameters:
  • index (Integer) --
def [](index)
  @cache[index] ||= TTFunk::File.new(@contents, @offsets[index])
end

def count

Returns:
  • (Integer) -
def count
  @offsets.length
end

def each

Returns:
  • (self) -

Other tags:
    Yieldparam: font -
def each
  count.times do |index|
    yield(self[index])
  end
  self
end

def initialize(io)

Raises:
  • (ArgumentError) - if `io` doesn't start with a ttc tag

Parameters:
  • io (IO(#read & #rewind)) --
def initialize(io)
  tag = io.read(4)
  raise ArgumentError, 'not a TTC file' unless tag == 'ttcf'
  _major, _minor = io.read(4).unpack('n*')
  count = io.read(4).unpack1('N')
  @offsets = io.read(count * 4).unpack('N*')
  io.rewind
  @contents = io.read
  @cache = []
end