Class: Fontisan::Tables::HeadTable

Inherits:
SfntTable
  • Object
show all
Defined in:
lib/fontisan/tables/head_table.rb

Overview

OOP representation of the ‘head’ (Font Header) table

The head table contains global information about the font, including metadata about the font file, bounding box, and indexing information.

This class extends SfntTable to provide head-specific validation and convenience methods for accessing common head table fields.

Examples:

Accessing head table data

head = font.table("head")  # Returns SfntTable instance
head.magic_number_valid?  # => true
head.units_per_em  # => 2048
head.bounding_box  # => {x_min: -123, y_min: -456, ...}

Instance Attribute Summary

Attributes inherited from SfntTable

#data, #entry, #font, #parsed

Instance Method Summary collapse

Methods inherited from SfntTable

#available?, #calculate_checksum, #checksum, #data_loaded?, #human_name, #initialize, #inspect, #length, #load_data!, #offset, #parse, #parsed?, #required?, #tag, #to_s, #validate!

Constructor Details

This class inherits a constructor from Fontisan::SfntTable

Instance Method Details

#bounding_boxHash?

Get font bounding box

Returns:

  • (Hash, nil)

    Bounding box hash, or nil if not parsed



39
40
41
42
43
44
45
46
47
48
# File 'lib/fontisan/tables/head_table.rb', line 39

def bounding_box
  return nil unless parsed

  {
    x_min: parsed.x_min,
    y_min: parsed.y_min,
    x_max: parsed.x_max,
    y_max: parsed.y_max,
  }
end

#font_revisionFloat?

Get font revision

Returns:

  • (Float, nil)

    Font revision as Fixed-point number



74
75
76
# File 'lib/fontisan/tables/head_table.rb', line 74

def font_revision
  parsed&.font_revision
end

#index_to_loc_formatInteger?

Get index to loc format

Returns:

  • (Integer, nil)

    IndexToLocFormat value, or nil if not parsed



53
54
55
# File 'lib/fontisan/tables/head_table.rb', line 53

def index_to_loc_format
  parsed&.index_to_loc_format
end

#long_loca_format?Boolean

Check if using long loca format

Returns:

  • (Boolean)

    true if using 32-bit loca offsets



60
61
62
# File 'lib/fontisan/tables/head_table.rb', line 60

def long_loca_format?
  index_to_loc_format == 1
end

#magic_number_valid?Boolean

Check if magic number is valid

Returns:

  • (Boolean)

    true if magic number is 0x5F0F3CF5



25
26
27
# File 'lib/fontisan/tables/head_table.rb', line 25

def magic_number_valid?
  parsed && parsed.magic_number == Tables::Head::MAGIC_NUMBER
end

#units_per_emInteger?

Get units per em

Returns:

  • (Integer, nil)

    Units per em value, or nil if not parsed



32
33
34
# File 'lib/fontisan/tables/head_table.rb', line 32

def units_per_em
  parsed&.units_per_em
end

#versionFloat?

Get font version

Returns:

  • (Float, nil)

    Font version as Fixed-point number



67
68
69
# File 'lib/fontisan/tables/head_table.rb', line 67

def version
  parsed&.version
end