Class: Fontisan::Tables::Os2Table
- Defined in:
- lib/fontisan/tables/os2_table.rb
Overview
OOP representation of the 'OS/2' (OS/2 and Windows Metrics) table
The OS/2 table contains OS/2 and Windows-specific metrics required by Windows and OS/2, including font metrics, character ranges, vendor information, and embedding permissions.
This class extends SfntTable to provide OS/2-specific validation and convenience methods for accessing common OS/2 table fields.
Constant Summary collapse
- WEIGHT_NAMES =
Weight class names (from OpenType spec)
{ 100 => "Thin", 200 => "Extra-light (Ultra-light)", 300 => "Light", 400 => "Normal (Regular)", 500 => "Medium", 600 => "Semi-bold (Demi-bold)", 700 => "Bold", 800 => "Extra-bold (Ultra-bold)", 900 => "Black (Heavy)", }.freeze
- WIDTH_NAMES =
Width class names (from OpenType spec)
{ 1 => "Ultra-condensed", 2 => "Extra-condensed", 3 => "Condensed", 4 => "Semi-condensed", 5 => "Medium (Normal)", 6 => "Semi-expanded", 7 => "Expanded", 8 => "Extra-expanded", 9 => "Ultra-expanded", }.freeze
- FS_ITALIC =
Selection flags (bit field)
1 << 0
- FS_UNDERSCORE =
1 << 1
- FS_NEGATIVE =
1 << 2
- FS_OUTLINED =
1 << 3
- FS_STRIKEOUT =
1 << 4
- FS_BOLD =
1 << 5
- FS_REGULAR =
1 << 6
- FS_USE_TYPO_METRICS =
1 << 7
- FS_WWS =
1 << 8
- FS_OBLIQUE =
1 << 9
Instance Attribute Summary
Attributes inherited from SfntTable
Instance Method Summary collapse
-
#bitmap_embedding_only? ⇒ Boolean
Check if bitmap embedding only is allowed.
-
#bold? ⇒ Boolean
Check if font is bold.
-
#cap_height ⇒ Integer?
Get cap height (version 2+).
-
#editable_allowed? ⇒ Boolean
Check if editable embedding is allowed.
-
#embedding_allowed? ⇒ Boolean
Check if embedding is allowed.
-
#embedding_restricted? ⇒ Boolean
Check if embedding is restricted.
-
#first_char_index ⇒ Integer?
Get first character index.
-
#italic? ⇒ Boolean
Check if font is italic.
-
#last_char_index ⇒ Integer?
Get last character index.
-
#oblique? ⇒ Boolean
Check if font is oblique.
-
#panose ⇒ Array<Integer>?
Get PANOSE classification.
-
#preview_print_allowed? ⇒ Boolean
Check if preview/print embedding is allowed.
-
#regular? ⇒ Boolean
Check if font uses regular style.
-
#subsetting_allowed? ⇒ Boolean
Check if subsetting is allowed.
-
#typo_ascender ⇒ Integer?
Get typographic ascent.
-
#typo_descender ⇒ Integer?
Get typographic descent.
-
#typo_line_gap ⇒ Integer?
Get typographic line gap.
-
#use_typo_metrics? ⇒ Boolean
Check if font uses typographic metrics.
-
#vendor_id ⇒ String?
Get vendor ID.
-
#version ⇒ Integer?
Get OS/2 table version.
-
#weight_class ⇒ Integer?
Get weight class.
-
#weight_class_name ⇒ String?
Get weight class name.
-
#width_class ⇒ Integer?
Get width class.
-
#width_class_name ⇒ String?
Get width class name.
-
#win_ascent ⇒ Integer?
Get Windows ascent.
-
#win_descent ⇒ Integer?
Get Windows descent.
-
#x_height ⇒ Integer?
Get x-height (version 2+).
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
#bitmap_embedding_only? ⇒ Boolean
Check if bitmap embedding only is allowed
240 241 242 243 244 245 |
# File 'lib/fontisan/tables/os2_table.rb', line 240 def return false unless parsed # fs_type bit 9 (0x200) = Bitmap embedding only (parsed.fs_type & 0x200) != 0 end |
#bold? ⇒ Boolean
Check if font is bold
115 116 117 |
# File 'lib/fontisan/tables/os2_table.rb', line 115 def bold? parsed && (parsed.fs_selection & FS_BOLD) != 0 end |
#cap_height ⇒ Integer?
Get cap height (version 2+)
185 186 187 |
# File 'lib/fontisan/tables/os2_table.rb', line 185 def cap_height parsed&.s_cap_height end |
#editable_allowed? ⇒ Boolean
Check if editable embedding is allowed
220 221 222 223 224 225 |
# File 'lib/fontisan/tables/os2_table.rb', line 220 def editable_allowed? return false unless parsed # fs_type bit 2 (0x4) = Editable embedding allowed (parsed.fs_type & 0x4) != 0 end |
#embedding_allowed? ⇒ Boolean
Check if embedding is allowed
192 193 194 195 196 197 198 |
# File 'lib/fontisan/tables/os2_table.rb', line 192 def return false unless parsed # fs_type bit 3 (0x8) = Embedding must not be allowed # If bit 3 is NOT set, embedding is allowed (parsed.fs_type & 0x8).zero? end |
#embedding_restricted? ⇒ Boolean
Check if embedding is restricted
203 204 205 |
# File 'lib/fontisan/tables/os2_table.rb', line 203 def ! end |
#first_char_index ⇒ Integer?
Get first character index
257 258 259 |
# File 'lib/fontisan/tables/os2_table.rb', line 257 def first_char_index parsed&.us_first_char_index end |
#italic? ⇒ Boolean
Check if font is italic
108 109 110 |
# File 'lib/fontisan/tables/os2_table.rb', line 108 def italic? parsed && (parsed.fs_selection & FS_ITALIC) != 0 end |
#last_char_index ⇒ Integer?
Get last character index
264 265 266 |
# File 'lib/fontisan/tables/os2_table.rb', line 264 def last_char_index parsed&.us_last_char_index end |
#oblique? ⇒ Boolean
Check if font is oblique
136 137 138 |
# File 'lib/fontisan/tables/os2_table.rb', line 136 def oblique? parsed && (parsed.fs_selection & FS_OBLIQUE) != 0 end |
#panose ⇒ Array<Integer>?
Get PANOSE classification
250 251 252 |
# File 'lib/fontisan/tables/os2_table.rb', line 250 def panose parsed&.panose&.to_a end |
#preview_print_allowed? ⇒ Boolean
Check if preview/print embedding is allowed
210 211 212 213 214 215 |
# File 'lib/fontisan/tables/os2_table.rb', line 210 def preview_print_allowed? return false unless parsed # fs_type bit 1 (0x2) = Preview & Print embedding allowed (parsed.fs_type & 0x2) != 0 end |
#regular? ⇒ Boolean
Check if font uses regular style
122 123 124 |
# File 'lib/fontisan/tables/os2_table.rb', line 122 def regular? parsed && (parsed.fs_selection & FS_REGULAR) != 0 end |
#subsetting_allowed? ⇒ Boolean
Check if subsetting is allowed
230 231 232 233 234 235 |
# File 'lib/fontisan/tables/os2_table.rb', line 230 def subsetting_allowed? return false unless parsed # fs_type bit 8 (0x100) = No subsetting (parsed.fs_type & 0x100).zero? end |
#typo_ascender ⇒ Integer?
Get typographic ascent
143 144 145 |
# File 'lib/fontisan/tables/os2_table.rb', line 143 def typo_ascender parsed&.s_typo_ascender end |
#typo_descender ⇒ Integer?
Get typographic descent
150 151 152 |
# File 'lib/fontisan/tables/os2_table.rb', line 150 def typo_descender parsed&.s_typo_descender end |
#typo_line_gap ⇒ Integer?
Get typographic line gap
157 158 159 |
# File 'lib/fontisan/tables/os2_table.rb', line 157 def typo_line_gap parsed&.s_typo_line_gap end |
#use_typo_metrics? ⇒ Boolean
Check if font uses typographic metrics
129 130 131 |
# File 'lib/fontisan/tables/os2_table.rb', line 129 def use_typo_metrics? parsed && (parsed.fs_selection & FS_USE_TYPO_METRICS) != 0 end |
#vendor_id ⇒ String?
Get vendor ID
101 102 103 |
# File 'lib/fontisan/tables/os2_table.rb', line 101 def vendor_id parsed&.vendor_id end |
#version ⇒ Integer?
Get OS/2 table version
62 63 64 |
# File 'lib/fontisan/tables/os2_table.rb', line 62 def version parsed&.version end |
#weight_class ⇒ Integer?
Get weight class
69 70 71 |
# File 'lib/fontisan/tables/os2_table.rb', line 69 def weight_class parsed&.us_weight_class end |
#weight_class_name ⇒ String?
Get weight class name
76 77 78 79 80 |
# File 'lib/fontisan/tables/os2_table.rb', line 76 def weight_class_name return nil unless parsed WEIGHT_NAMES[parsed.us_weight_class] || "Unknown" end |
#width_class ⇒ Integer?
Get width class
85 86 87 |
# File 'lib/fontisan/tables/os2_table.rb', line 85 def width_class parsed&.us_width_class end |
#width_class_name ⇒ String?
Get width class name
92 93 94 95 96 |
# File 'lib/fontisan/tables/os2_table.rb', line 92 def width_class_name return nil unless parsed WIDTH_NAMES[parsed.us_width_class] || "Unknown" end |
#win_ascent ⇒ Integer?
Get Windows ascent
164 165 166 |
# File 'lib/fontisan/tables/os2_table.rb', line 164 def win_ascent parsed&.us_win_ascent end |
#win_descent ⇒ Integer?
Get Windows descent
171 172 173 |
# File 'lib/fontisan/tables/os2_table.rb', line 171 def win_descent parsed&.us_win_descent end |
#x_height ⇒ Integer?
Get x-height (version 2+)
178 179 180 |
# File 'lib/fontisan/tables/os2_table.rb', line 178 def x_height parsed&.sx_height end |