Class: Fontisan::OpenTypeCollection

Inherits:
BaseCollection show all
Defined in:
lib/fontisan/open_type_collection.rb

Overview

OpenType Collection domain object

Represents a complete OpenType Collection file (OTC). Inherits all shared functionality from BaseCollection and implements OTC-specific behavior.

Examples:

Reading and extracting fonts

File.open("fonts.otc", "rb") do |io|
  otc = OpenTypeCollection.read(io)
  puts otc.num_fonts  # => 4
  fonts = otc.extract_fonts(io)  # => [OpenTypeFont, OpenTypeFont, ...]
end

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCollection

#collection_info, #font, #font_count, from_file, #list_fonts, #valid?, #version, #version_string

Class Method Details

.collection_formatString

Get the collection format identifier

Returns:

  • (String)

    “OTC” for OpenType Collection



29
30
31
# File 'lib/fontisan/open_type_collection.rb', line 29

def self.collection_format
  "OTC"
end

.font_classClass

Get the font class for OpenType collections

Returns:

  • (Class)

    OpenTypeFont class



21
22
23
24
# File 'lib/fontisan/open_type_collection.rb', line 21

def self.font_class
  require_relative "open_type_font"
  OpenTypeFont
end

Instance Method Details

#extract_fonts(io) ⇒ Array<OpenTypeFont>

Extract fonts as OpenTypeFont objects

Reads each font from the OTC file and returns them as OpenTypeFont objects. This method uses the from_collection method.

Parameters:

  • io (IO)

    Open file handle to read fonts from

Returns:



40
41
42
43
44
45
46
# File 'lib/fontisan/open_type_collection.rb', line 40

def extract_fonts(io)
  require_relative "open_type_font"

  font_offsets.map do |offset|
    OpenTypeFont.from_collection(io, offset)
  end
end