Class: Fontisan::Binary::OffsetTable

Inherits:
BaseRecord
  • Object
show all
Defined in:
lib/fontisan/binary/structures.rb

Overview

OpenType Offset Table (Font Header)

This structure appears at the beginning of every OpenType font file. It contains metadata about the table directory.

Structure:

  • uint32: sfnt_version (0x00010000 for TrueType, ‘OTTO’ for CFF)

  • uint16: num_tables (number of tables in font)

  • uint16: search_range (maximum power of 2 <= num_tables) * 16

  • uint16: entry_selector (log2 of maximum power of 2 <= num_tables)

  • uint16: range_shift (num_tables * 16 - search_range)

Instance Method Summary collapse

Methods inherited from BaseRecord

#raw_data, read, #valid?

Instance Method Details

#cff?Boolean

Check if this is an OpenType/CFF font (version ‘OTTO’)

Returns:

  • (Boolean)

    True if CFF font



35
36
37
# File 'lib/fontisan/binary/structures.rb', line 35

def cff?
  sfnt_version == 0x4F54544F # 'OTTO'
end

#truetype?Boolean

Check if this is a TrueType font (version 0x00010000 or ‘true’)

Returns:

  • (Boolean)

    True if TrueType font



28
29
30
# File 'lib/fontisan/binary/structures.rb', line 28

def truetype?
  [0x00010000, 0x74727565].include?(sfnt_version) # 'true'
end

#version_tagString

Get sfnt version as a tag string

Returns:

  • (String)

    Version tag (‘OTTO’ or version number)



42
43
44
45
46
47
48
49
50
# File 'lib/fontisan/binary/structures.rb', line 42

def version_tag
  if cff?
    "OTTO"
  elsif truetype?
    "TrueType"
  else
    format("0x%08X", sfnt_version)
  end
end