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



76
77
78
# File 'lib/fontisan/tables/hhea_table.rb', line 76

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



38
39
40
# File 'lib/fontisan/tables/hhea_table.rb', line 38

def ascent
  parsed&.ascent
end

#caret_angleFloat?

Get caret angle in degrees

Returns:

  • (Float, nil)

    Caret angle in degrees, or nil if not parsed



180
181
182
183
184
185
186
# File 'lib/fontisan/tables/hhea_table.rb', line 180

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



128
129
130
# File 'lib/fontisan/tables/hhea_table.rb', line 128

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



109
110
111
# File 'lib/fontisan/tables/hhea_table.rb', line 109

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



119
120
121
# File 'lib/fontisan/tables/hhea_table.rb', line 119

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



47
48
49
# File 'lib/fontisan/tables/hhea_table.rb', line 47

def descent
  parsed&.descent
end

#horizontal_caret?Boolean

Check if caret is horizontal

Returns:

  • (Boolean)

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



171
172
173
174
175
# File 'lib/fontisan/tables/hhea_table.rb', line 171

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)



162
163
164
165
166
# File 'lib/fontisan/tables/hhea_table.rb', line 162

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



56
57
58
# File 'lib/fontisan/tables/hhea_table.rb', line 56

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



65
66
67
68
69
# File 'lib/fontisan/tables/hhea_table.rb', line 65

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



137
138
139
# File 'lib/fontisan/tables/hhea_table.rb', line 137

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



83
84
85
# File 'lib/fontisan/tables/hhea_table.rb', line 83

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



90
91
92
# File 'lib/fontisan/tables/hhea_table.rb', line 90

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



146
147
148
# File 'lib/fontisan/tables/hhea_table.rb', line 146

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



27
28
29
30
31
# File 'lib/fontisan/tables/hhea_table.rb', line 27

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)



153
154
155
156
157
# File 'lib/fontisan/tables/hhea_table.rb', line 153

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



99
100
101
# File 'lib/fontisan/tables/hhea_table.rb', line 99

def x_max_extent
  parsed&.x_max_extent
end