Class: Fontisan::Tables::HheaTable

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

Overview

OOP representation of the ‘hhea’ (Horizontal Header) table

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

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

Examples:

Accessing hhea table data

hhea = font.sfnt_table("hhea")
hhea.ascent            # => 2048
hhea.descent           # => -512
hhea.line_gap          # => 0
hhea.line_height       # => 2560

Constant Summary collapse

VERSION_1_0 =

Fixed value 0x00010000 for version 1.0

0x00010000

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

#advance_width_maxInteger?

Get maximum advance width

Maximum advance width value in hmtx table

Returns:

  • (Integer, nil)

    Maximum advance width, or nil if not parsed



79
80
81
# File 'lib/fontisan/tables/hhea_table.rb', line 79

def advance_width_max
  parsed&.advance_width_max
end

#ascentInteger?

Get typographic ascent

Distance from baseline to highest ascender (positive value)

Returns:

  • (Integer, nil)

    Ascent in FUnits, or nil if not parsed



41
42
43
# File 'lib/fontisan/tables/hhea_table.rb', line 41

def ascent
  parsed&.ascent
end

#caret_angleFloat?

Get caret angle in degrees

Returns:

  • (Float, nil)

    Caret angle in degrees, or nil if not parsed



183
184
185
186
187
188
189
# File 'lib/fontisan/tables/hhea_table.rb', line 183

def caret_angle
  return nil unless parsed

  return 0.0 if caret_slope_run.zero?

  Math.atan2(caret_slope_rise, caret_slope_run) * (180.0 / Math::PI)
end

#caret_offsetInteger?

Get caret offset

Amount by which slanted highlight should be shifted

Returns:

  • (Integer, nil)

    Caret offset, or nil if not parsed



131
132
133
# File 'lib/fontisan/tables/hhea_table.rb', line 131

def caret_offset
  parsed&.caret_offset
end

#caret_slope_riseInteger?

Get caret slope rise

Used to calculate slope of cursor (rise/run) For vertical text: rise = 1, run = 0

Returns:

  • (Integer, nil)

    Caret slope rise, or nil if not parsed



112
113
114
# File 'lib/fontisan/tables/hhea_table.rb', line 112

def caret_slope_rise
  parsed&.caret_slope_rise
end

#caret_slope_runInteger?

Get caret slope run

Used to calculate slope of cursor (rise/run) For vertical text: run = 0

Returns:

  • (Integer, nil)

    Caret slope run, or nil if not parsed



122
123
124
# File 'lib/fontisan/tables/hhea_table.rb', line 122

def caret_slope_run
  parsed&.caret_slope_run
end

#descentInteger?

Get typographic descent

Distance from baseline to lowest descender (negative value)

Returns:

  • (Integer, nil)

    Descent in FUnits, or nil if not parsed



50
51
52
# File 'lib/fontisan/tables/hhea_table.rb', line 50

def descent
  parsed&.descent
end

#horizontal_caret?Boolean

Check if caret is horizontal

Returns:

  • (Boolean)

    true if caret is horizontal (rise == 0, run != 0)



174
175
176
177
178
# File 'lib/fontisan/tables/hhea_table.rb', line 174

def horizontal_caret?
  return false unless parsed

  caret_slope_rise.zero? && caret_slope_run != 0
end

#italic_caret?Boolean

Check if caret is italic

Returns:

  • (Boolean)

    true if caret is slanted (both rise and run non-zero)



165
166
167
168
169
# File 'lib/fontisan/tables/hhea_table.rb', line 165

def italic_caret?
  return false unless parsed

  caret_slope_rise != 0 && caret_slope_run != 0
end

#line_gapInteger?

Get typographic line gap

Additional space between lines (non-negative value)

Returns:

  • (Integer, nil)

    Line gap in FUnits, or nil if not parsed



59
60
61
# File 'lib/fontisan/tables/hhea_table.rb', line 59

def line_gap
  parsed&.line_gap
end

#line_heightInteger?

Get total line height

Calculated as ascent - descent + line_gap

Returns:

  • (Integer, nil)

    Line height in FUnits, or nil if not parsed



68
69
70
71
72
# File 'lib/fontisan/tables/hhea_table.rb', line 68

def line_height
  return nil unless parsed

  ascent - descent + line_gap
end

#metric_data_formatInteger?

Get metric data format

Format of metric data (0 for current format)

Returns:

  • (Integer, nil)

    Metric data format, or nil if not parsed



140
141
142
# File 'lib/fontisan/tables/hhea_table.rb', line 140

def metric_data_format
  parsed&.metric_data_format
end

#min_left_side_bearingInteger?

Get minimum left sidebearing

Returns:

  • (Integer, nil)

    Minimum lsb value, or nil if not parsed



86
87
88
# File 'lib/fontisan/tables/hhea_table.rb', line 86

def min_left_side_bearing
  parsed&.min_left_side_bearing
end

#min_right_side_bearingInteger?

Get minimum right sidebearing

Returns:

  • (Integer, nil)

    Minimum rsb value, or nil if not parsed



93
94
95
# File 'lib/fontisan/tables/hhea_table.rb', line 93

def min_right_side_bearing
  parsed&.min_right_side_bearing
end

#number_of_h_metricsInteger?

Get number of hmetrics

Number of hMetric entries in hmtx table

Returns:

  • (Integer, nil)

    Number of metrics (must be >= 1), or nil if not parsed



149
150
151
# File 'lib/fontisan/tables/hhea_table.rb', line 149

def number_of_h_metrics
  parsed&.number_of_h_metrics
end

#versionFloat?

Get hhea table version

Returns:

  • (Float, nil)

    Version number (typically 1.0), or nil if not parsed



30
31
32
33
34
# File 'lib/fontisan/tables/hhea_table.rb', line 30

def version
  return nil unless parsed

  parsed.version
end

#vertical_caret?Boolean

Check if caret is vertical

Returns:

  • (Boolean)

    true if caret is vertical (rise != 0, run == 0)



156
157
158
159
160
# File 'lib/fontisan/tables/hhea_table.rb', line 156

def vertical_caret?
  return false unless parsed

  caret_slope_rise != 0 && caret_slope_run.zero?
end

#x_max_extentInteger?

Get maximum x extent

Maximum of lsb + (xMax - xMin) for all glyphs

Returns:

  • (Integer, nil)

    Maximum extent, or nil if not parsed



102
103
104
# File 'lib/fontisan/tables/hhea_table.rb', line 102

def x_max_extent
  parsed&.x_max_extent
end