Class: Fontisan::Tables::Os2
- Inherits:
-
Binary::BaseRecord
- Object
- BinData::Record
- Binary::BaseRecord
- Fontisan::Tables::Os2
- Extended by:
- Registered
- Defined in:
- lib/fontisan/tables/os2.rb
Overview
Parser for the 'OS/2' (OS/2 and Windows Metrics) table
The OS/2 table contains OS/2 and Windows-specific metrics that are required by Windows and OS/2. This includes font metrics, character ranges, vendor information, and embedding permissions.
The table has evolved through multiple versions (0-5), with newer versions adding additional fields while maintaining backward compatibility.
Reference: OpenType specification, OS/2 table
Instance Attribute Summary
Attributes inherited from Binary::BaseRecord
Instance Method Summary collapse
-
#has_embedding_permissions? ⇒ Boolean
Validation helper: Check if embedding permissions are set.
-
#has_optical_point_size? ⇒ Boolean
Check if optical point size information is available.
-
#has_panose? ⇒ Boolean
Validation helper: Check if PANOSE data is present.
-
#has_unicode_ranges? ⇒ Boolean
Validation helper: Check if Unicode ranges are set.
-
#has_vendor_id? ⇒ Boolean
Validation helper: Check if vendor ID is present.
-
#has_x_height_cap_height? ⇒ Boolean
Validation helper: Check if x_height and cap_height are present (v2+).
-
#lower_optical_point_size ⇒ Float?
Get the lower optical point size.
- #s_cap_height ⇒ Object
- #sx_height ⇒ Object
-
#type_flags ⇒ Integer
Get the embedding type flags.
-
#ul_code_page_range1 ⇒ Object
Override conditional field accessors to return nil when not present BinData's onlyif fields return default values even when not read, so we need to check the version before accessing them.
- #ul_code_page_range2 ⇒ Object
-
#upper_optical_point_size ⇒ Float?
Get the upper optical point size.
- #us_break_char ⇒ Object
- #us_default_char ⇒ Object
- #us_lower_optical_point_size ⇒ Object
- #us_max_context ⇒ Object
- #us_upper_optical_point_size ⇒ Object
-
#valid_char_range? ⇒ Boolean
Validation helper: Check if first/last char indices are reasonable.
-
#valid_selection_flags? ⇒ Boolean
Validation helper: Check if selection flags are valid.
-
#valid_typo_metrics? ⇒ Boolean
Validation helper: Check if typo metrics are reasonable.
-
#valid_version? ⇒ Boolean
Validation helper: Check if version is valid.
-
#valid_weight_class? ⇒ Boolean
Validation helper: Check if weight class is valid.
-
#valid_width_class? ⇒ Boolean
Validation helper: Check if width class is valid.
-
#valid_win_metrics? ⇒ Boolean
Validation helper: Check if Win metrics are valid.
-
#vendor_id ⇒ String
Get the vendor ID as a trimmed string.
Methods included from Registered
Methods inherited from Binary::BaseRecord
Instance Method Details
#has_embedding_permissions? ⇒ Boolean
Validation helper: Check if embedding permissions are set
fs_type indicates embedding and subsetting permissions
254 255 256 |
# File 'lib/fontisan/tables/os2.rb', line 254 def !fs_type.nil? end |
#has_optical_point_size? ⇒ Boolean
Check if optical point size information is available
153 154 155 |
# File 'lib/fontisan/tables/os2.rb', line 153 def has_optical_point_size? version >= 5 end |
#has_panose? ⇒ Boolean
Validation helper: Check if PANOSE data is present
All PANOSE values should not be zero
245 246 247 |
# File 'lib/fontisan/tables/os2.rb', line 245 def has_panose? panose&.any? { |val| val != 0 } end |
#has_unicode_ranges? ⇒ Boolean
Validation helper: Check if Unicode ranges are set
At least one Unicode range bit should be set
236 237 238 |
# File 'lib/fontisan/tables/os2.rb', line 236 def has_unicode_ranges? (ul_unicode_range1 | ul_unicode_range2 | ul_unicode_range3 | ul_unicode_range4) != 0 end |
#has_vendor_id? ⇒ Boolean
Validation helper: Check if vendor ID is present
Vendor ID should be a 4-character code
209 210 211 |
# File 'lib/fontisan/tables/os2.rb', line 209 def has_vendor_id? !vendor_id.empty? end |
#has_x_height_cap_height? ⇒ Boolean
Validation helper: Check if x_height and cap_height are present (v2+)
For version 2+, these should be set
275 276 277 278 279 |
# File 'lib/fontisan/tables/os2.rb', line 275 def has_x_height_cap_height? return true if version < 2 # Not required for v0-1 !sx_height.nil? && !s_cap_height.nil? && sx_height.positive? && s_cap_height.positive? end |
#lower_optical_point_size ⇒ Float?
Get the lower optical point size
161 162 163 164 165 |
# File 'lib/fontisan/tables/os2.rb', line 161 def lower_optical_point_size return nil unless has_optical_point_size? us_lower_optical_point_size / 20.0 end |
#s_cap_height ⇒ Object
98 99 100 101 102 |
# File 'lib/fontisan/tables/os2.rb', line 98 def s_cap_height return nil unless version >= 2 super end |
#sx_height ⇒ Object
92 93 94 95 96 |
# File 'lib/fontisan/tables/os2.rb', line 92 def sx_height return nil unless version >= 2 super end |
#type_flags ⇒ Integer
Get the embedding type flags
146 147 148 |
# File 'lib/fontisan/tables/os2.rb', line 146 def type_flags fs_type end |
#ul_code_page_range1 ⇒ Object
Override conditional field accessors to return nil when not present BinData's onlyif fields return default values even when not read, so we need to check the version before accessing them
80 81 82 83 84 |
# File 'lib/fontisan/tables/os2.rb', line 80 def ul_code_page_range1 return nil unless version >= 1 super end |
#ul_code_page_range2 ⇒ Object
86 87 88 89 90 |
# File 'lib/fontisan/tables/os2.rb', line 86 def ul_code_page_range2 return nil unless version >= 1 super end |
#upper_optical_point_size ⇒ Float?
Get the upper optical point size
171 172 173 174 175 |
# File 'lib/fontisan/tables/os2.rb', line 171 def upper_optical_point_size return nil unless has_optical_point_size? us_upper_optical_point_size / 20.0 end |
#us_break_char ⇒ Object
110 111 112 113 114 |
# File 'lib/fontisan/tables/os2.rb', line 110 def us_break_char return nil unless version >= 2 super end |
#us_default_char ⇒ Object
104 105 106 107 108 |
# File 'lib/fontisan/tables/os2.rb', line 104 def us_default_char return nil unless version >= 2 super end |
#us_lower_optical_point_size ⇒ Object
122 123 124 125 126 |
# File 'lib/fontisan/tables/os2.rb', line 122 def us_lower_optical_point_size return nil unless version >= 5 super end |
#us_max_context ⇒ Object
116 117 118 119 120 |
# File 'lib/fontisan/tables/os2.rb', line 116 def us_max_context return nil unless version >= 2 super end |
#us_upper_optical_point_size ⇒ Object
128 129 130 131 132 |
# File 'lib/fontisan/tables/os2.rb', line 128 def us_upper_optical_point_size return nil unless version >= 5 super end |
#valid_char_range? ⇒ Boolean
Validation helper: Check if first/last char indices are reasonable
first should be <= last
286 287 288 |
# File 'lib/fontisan/tables/os2.rb', line 286 def valid_char_range? us_first_char_index <= us_last_char_index end |
#valid_selection_flags? ⇒ Boolean
Validation helper: Check if selection flags are valid
Checks for valid combinations of selection flags
263 264 265 266 267 268 |
# File 'lib/fontisan/tables/os2.rb', line 263 def valid_selection_flags? return false if fs_selection.nil? # Bits 0-9 are defined, others should be zero (fs_selection & 0xFC00).zero? end |
#valid_typo_metrics? ⇒ Boolean
Validation helper: Check if typo metrics are reasonable
Ascent should be positive, descender negative, line gap non-negative
218 219 220 |
# File 'lib/fontisan/tables/os2.rb', line 218 def valid_typo_metrics? s_typo_ascender.positive? && s_typo_descender.negative? && s_typo_line_gap >= 0 end |
#valid_version? ⇒ Boolean
Validation helper: Check if version is valid
Valid versions are 0 through 5
182 183 184 |
# File 'lib/fontisan/tables/os2.rb', line 182 def valid_version? version&.between?(0, 5) end |
#valid_weight_class? ⇒ Boolean
Validation helper: Check if weight class is valid
Valid values are 1-1000, common values are multiples of 100
191 192 193 |
# File 'lib/fontisan/tables/os2.rb', line 191 def valid_weight_class? us_weight_class&.between?(1, 1000) end |
#valid_width_class? ⇒ Boolean
Validation helper: Check if width class is valid
Valid values are 1-9
200 201 202 |
# File 'lib/fontisan/tables/os2.rb', line 200 def valid_width_class? us_width_class&.between?(1, 9) end |
#valid_win_metrics? ⇒ Boolean
Validation helper: Check if Win metrics are valid
Both should be positive (unsigned in spec)
227 228 229 |
# File 'lib/fontisan/tables/os2.rb', line 227 def valid_win_metrics? us_win_ascent.positive? && us_win_descent.positive? end |
#vendor_id ⇒ String
Get the vendor ID as a trimmed string
137 138 139 140 141 |
# File 'lib/fontisan/tables/os2.rb', line 137 def vendor_id return "" unless ach_vend_id ach_vend_id.gsub(/[\x00\s]+$/, "") end |