Class: Fontisan::Tables::Hhea
- Inherits:
-
Binary::BaseRecord
- Object
- BinData::Record
- Binary::BaseRecord
- Fontisan::Tables::Hhea
- Extended by:
- Registered
- 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 https://docs.microsoft.com/en-us/typography/opentype/spec/hhea
Constant Summary collapse
- TABLE_SIZE =
Table size in bytes (fixed size)
36
Instance Attribute Summary
Attributes inherited from Binary::BaseRecord
Instance Method Summary collapse
-
#valid? ⇒ Boolean
Check if the table is valid.
-
#valid_advance_width_max? ⇒ Boolean
Validation helper: Check if advance width max is positive.
-
#valid_ascent_descent? ⇒ Boolean
Validation helper: Check if ascent/descent values are reasonable.
-
#valid_caret_slope? ⇒ Boolean
Validation helper: Check if caret slope is valid.
-
#valid_line_gap? ⇒ Boolean
Validation helper: Check if line gap is non-negative.
-
#valid_metric_data_format? ⇒ Boolean
Validation helper: Check if metric data format is valid.
-
#valid_number_of_h_metrics? ⇒ Boolean
Validation helper: Check if number of h metrics is valid.
-
#valid_version? ⇒ Boolean
Validation helper: Check if version is valid.
-
#valid_x_max_extent? ⇒ Boolean
Validation helper: Check if extent is reasonable.
-
#validate! ⇒ Object
Validate the table and raise error if invalid.
-
#version ⇒ Float
Convert version from fixed-point to float.
Methods included from Registered
Methods inherited from Binary::BaseRecord
Instance Method Details
#valid? ⇒ Boolean
Check if the table is valid
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/fontisan/tables/hhea.rb', line 88 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 |
#valid_advance_width_max? ⇒ Boolean
Validation helper: Check if advance width max is positive
Maximum advance width should be > 0
151 152 153 |
# File 'lib/fontisan/tables/hhea.rb', line 151 def valid_advance_width_max? advance_width_max&.positive? end |
#valid_ascent_descent? ⇒ Boolean
Validation helper: Check if ascent/descent values are reasonable
Ascent should be positive, descent should be negative
133 134 135 |
# File 'lib/fontisan/tables/hhea.rb', line 133 def valid_ascent_descent? ascent.positive? && descent.negative? end |
#valid_caret_slope? ⇒ Boolean
Validation helper: Check if caret slope is valid
For vertical text: rise=1, run=0 For horizontal italic: both should be non-zero
161 162 163 164 |
# File 'lib/fontisan/tables/hhea.rb', line 161 def valid_caret_slope? # At least one should be non-zero caret_slope_rise != 0 || caret_slope_run != 0 end |
#valid_line_gap? ⇒ Boolean
Validation helper: Check if line gap is non-negative
Line gap should be >= 0
142 143 144 |
# File 'lib/fontisan/tables/hhea.rb', line 142 def valid_line_gap? line_gap >= 0 end |
#valid_metric_data_format? ⇒ Boolean
Validation helper: Check if metric data format is valid
Must be 0 for current format
115 116 117 |
# File 'lib/fontisan/tables/hhea.rb', line 115 def valid_metric_data_format? metric_data_format.zero? end |
#valid_number_of_h_metrics? ⇒ Boolean
Validation helper: Check if number of h metrics is valid
Must be at least 1
124 125 126 |
# File 'lib/fontisan/tables/hhea.rb', line 124 def valid_number_of_h_metrics? number_of_h_metrics && number_of_h_metrics >= 1 end |
#valid_version? ⇒ Boolean
Validation helper: Check if version is valid
OpenType spec requires version to be 1.0
106 107 108 |
# File 'lib/fontisan/tables/hhea.rb', line 106 def valid_version? version_raw == 0x00010000 end |
#valid_x_max_extent? ⇒ Boolean
Validation helper: Check if extent is reasonable
x_max_extent should be positive
171 172 173 |
# File 'lib/fontisan/tables/hhea.rb', line 171 def valid_x_max_extent? x_max_extent.positive? end |
#validate! ⇒ Object
Validate the table and raise error if invalid
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/fontisan/tables/hhea.rb', line 178 def validate! unless version_raw == 0x00010000 = "Invalid hhea version: expected 0x00010000 (1.0), " \ "got 0x#{version_raw.to_i.to_s(16).upcase}" raise Fontisan::CorruptedTableError, end unless metric_data_format.zero? = "Invalid metric data format: expected 0, " \ "got #{metric_data_format.to_i}" raise Fontisan::CorruptedTableError, end unless number_of_h_metrics >= 1 = "Invalid number of h metrics: must be >= 1, " \ "got #{number_of_h_metrics.to_i}" raise Fontisan::CorruptedTableError, end end |
#version ⇒ Float
Convert version from fixed-point to float
81 82 83 |
# File 'lib/fontisan/tables/hhea.rb', line 81 def version fixed_to_float(version_raw) end |