Class: Fontisan::OpenTypeFont

Inherits:
SfntFont
  • Object
show all
Extended by:
OpenTypeFontExtensions
Defined in:
lib/fontisan/open_type_font.rb

Overview

OpenType Font domain object

Represents an OpenType Font file (CFF outlines). Inherits all shared SFNT functionality from SfntFont and adds OpenType-specific behavior including page-aligned lazy loading for optimal performance.

Examples:

Reading and analyzing a font

otf = OpenTypeFont.from_file("font.otf")
puts otf.header.num_tables  # => 12
name_table = otf.table("name")
puts name_table.english_name(Tables::Name::FAMILY)

Loading with metadata mode

otf = OpenTypeFont.from_file("font.otf", mode: :metadata)
puts otf.loading_mode  # => :metadata
otf.table_available?("GSUB")  # => false

Writing a font

otf.to_file("output.otf")

Reading from TTC collection

otf = OpenTypeFont.from_collection(io, offset)

Constant Summary collapse

PAGE_SIZE =

Page size for lazy loading alignment (typical filesystem page size)

4096

Constants inherited from SfntFont

SfntFont::PADDING_BYTES, SfntFont::SFNT_TABLE_CLASS_MAP, SfntFont::TABLE_CLASS_MAP

Instance Attribute Summary collapse

Attributes inherited from SfntFont

#io_source, #lazy_load_enabled, #loading_mode, #parsed_tables, #sfnt_tables, #table_data, #table_entry_cache

Instance Method Summary collapse

Methods included from OpenTypeFontExtensions

from_tables

Methods inherited from SfntFont

#all_sfnt_tables, #close, #collection?, #family_name, finalize, #find_table_entry, from_collection, from_file, #full_name, #has_table?, #head_table, #outline_type, #post_script_name, #preferred_family_name, #preferred_subfamily_name, #read_metadata_tables_batched, #read_table_data, #setup_finalizer, #sfnt_table, #subfamily_name, #table, #table_available?, #table_names, #to_file, #units_per_em, #update_checksum_adjustment_in_file, #update_checksum_adjustment_in_io, #variation_type

Instance Attribute Details

#page_cacheObject

Page cache for lazy loading (maps page_start_offset => page_data)



36
37
38
# File 'lib/fontisan/open_type_font.rb', line 36

def page_cache
  @page_cache
end

Instance Method Details

#cff?Boolean

Check if font is CFF flavored

Returns:

  • (Boolean)

    true for OpenType fonts



73
74
75
# File 'lib/fontisan/open_type_font.rb', line 73

def cff?
  true
end

#formatSymbol

High-level pipeline format identifier. Owned by the font class so the conversion pipeline can dispatch without case statements (OCP).

Returns:

  • (Symbol)

    :otf



33
# File 'lib/fontisan/open_type_font.rb', line 33

def format = :otf

#initialize_storagevoid

This method returns an undefined value.

Initialize storage hashes

Extends base class to add page_cache for lazy loading.



46
47
48
49
# File 'lib/fontisan/open_type_font.rb', line 46

def initialize_storage
  super
  @page_cache = {}
end

#truetype?Boolean

Check if font is TrueType flavored

Returns:

  • (Boolean)

    false for OpenType fonts



66
67
68
# File 'lib/fontisan/open_type_font.rb', line 66

def truetype?
  false
end

#valid?Boolean

Validate format correctness

Extends base class to check for CFF table (OpenType-specific).

Returns:

  • (Boolean)

    true if the OTF format is valid, false otherwise



56
57
58
59
60
61
# File 'lib/fontisan/open_type_font.rb', line 56

def valid?
  return false unless super
  return false unless has_table?(Constants::CFF_TAG)

  true
end