Class: Fontisan::Tables::Hhea

Inherits:
Binary::BaseRecord show all
Defined in:
lib/fontisan/tables/hhea.rb

Overview

BinData structure for the ‘hhea’ (Horizontal Header) table

The hhea table contains horizontal layout metrics for the entire font. It defines font-wide horizontal metrics such as ascent, descent, line gap, and the number of horizontal metrics in the hmtx table.

Reference: OpenType specification, hhea table docs.microsoft.com/en-us/typography/opentype/spec/hhea

Examples:

Reading an hhea table

data = File.binread("font.ttf", 36, hhea_offset)
hhea = Fontisan::Tables::Hhea.read(data)
puts hhea.ascent           # => 2048
puts hhea.descent          # => -512
puts hhea.version_number   # => 1.0

Constant Summary collapse

TABLE_SIZE =

Table size in bytes (fixed size)

36

Instance Method Summary collapse

Methods inherited from Binary::BaseRecord

#raw_data, read

Instance Method Details

#valid?Boolean

Check if the table is valid

Returns:

  • (Boolean)

    True if valid, false otherwise



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fontisan/tables/hhea.rb', line 87

def valid?
  # Version should be 1.0 (0x00010000)
  return false unless version_raw == 0x00010000

  # Metric data format must be 0
  return false unless metric_data_format.zero?

  # Number of metrics must be at least 1
  return false unless number_of_h_metrics >= 1

  true
end

#validate!Object

Validate the table and raise error if invalid

Raises:



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/fontisan/tables/hhea.rb', line 103

def validate!
  unless version_raw == 0x00010000
    message = "Invalid hhea version: expected 0x00010000 (1.0), " \
              "got 0x#{version_raw.to_i.to_s(16).upcase}"
    raise Fontisan::CorruptedTableError, message
  end

  unless metric_data_format.zero?
    message = "Invalid metric data format: expected 0, " \
              "got #{metric_data_format.to_i}"
    raise Fontisan::CorruptedTableError, message
  end

  unless number_of_h_metrics >= 1
    message = "Invalid number of h metrics: must be >= 1, " \
              "got #{number_of_h_metrics.to_i}"
    raise Fontisan::CorruptedTableError, message
  end
end

#versionFloat

Convert version from fixed-point to float

Returns:

  • (Float)

    Version number (typically 1.0)



80
81
82
# File 'lib/fontisan/tables/hhea.rb', line 80

def version
  fixed_to_float(version_raw)
end