Class: Fontisan::Tables::Os2Table

Inherits:
SfntTable
  • Object
show all
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.

Examples:

Accessing OS/2 table data

os2 = font.sfnt_table("OS/2")
os2.weight_class      # => 400 (Normal)
os2.width_class       # => 5 (Medium)
os2.vendor_id         # => "APPL"
os2.embedding_allowed? # => true

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

#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

#bitmap_embedding_only?Boolean

Check if bitmap embedding only is allowed

Returns:

  • (Boolean)

    true if only bitmaps can be embedded



240
241
242
243
244
245
# File 'lib/fontisan/tables/os2_table.rb', line 240

def bitmap_embedding_only?
  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

Returns:

  • (Boolean)

    true if bold flag is set



115
116
117
# File 'lib/fontisan/tables/os2_table.rb', line 115

def bold?
  parsed && (parsed.fs_selection & FS_BOLD) != 0
end

#cap_heightInteger?

Get cap height (version 2+)

Returns:

  • (Integer, nil)

    Cap height value, or nil if not available



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

Returns:

  • (Boolean)

    true if editable embedding is permitted



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

Returns:

  • (Boolean)

    true if embedding is permitted (fs_type & 0x8 == 0)



192
193
194
195
196
197
198
# File 'lib/fontisan/tables/os2_table.rb', line 192

def embedding_allowed?
  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

Returns:

  • (Boolean)

    true if embedding is restricted



203
204
205
# File 'lib/fontisan/tables/os2_table.rb', line 203

def embedding_restricted?
  !embedding_allowed?
end

#first_char_indexInteger?

Get first character index

Returns:

  • (Integer, nil)

    First character Unicode value, or nil if not parsed



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

Returns:

  • (Boolean)

    true if italic flag is set



108
109
110
# File 'lib/fontisan/tables/os2_table.rb', line 108

def italic?
  parsed && (parsed.fs_selection & FS_ITALIC) != 0
end

#last_char_indexInteger?

Get last character index

Returns:

  • (Integer, nil)

    Last character Unicode value, or nil if not parsed



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

Returns:

  • (Boolean)

    true if oblique flag is set



136
137
138
# File 'lib/fontisan/tables/os2_table.rb', line 136

def oblique?
  parsed && (parsed.fs_selection & FS_OBLIQUE) != 0
end

#panoseArray<Integer>?

Get PANOSE classification

Returns:

  • (Array<Integer>, nil)

    Array of 10 PANOSE bytes, or nil if not parsed



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

Returns:

  • (Boolean)

    true if preview and print embedding is permitted



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

Returns:

  • (Boolean)

    true if regular flag is set



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

Returns:

  • (Boolean)

    true if subsetting is permitted (fs_type bit 8 is NOT set)



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_ascenderInteger?

Get typographic ascent

Returns:

  • (Integer, nil)

    Typographic ascender, or nil if not parsed



143
144
145
# File 'lib/fontisan/tables/os2_table.rb', line 143

def typo_ascender
  parsed&.s_typo_ascender
end

#typo_descenderInteger?

Get typographic descent

Returns:

  • (Integer, nil)

    Typographic descender (negative value), or nil if not parsed



150
151
152
# File 'lib/fontisan/tables/os2_table.rb', line 150

def typo_descender
  parsed&.s_typo_descender
end

#typo_line_gapInteger?

Get typographic line gap

Returns:

  • (Integer, nil)

    Line gap, or nil if not parsed



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

Returns:

  • (Boolean)

    true if use typo metrics flag is set



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_idString?

Get vendor ID

Returns:

  • (String, nil)

    4-character vendor identifier, or nil if not parsed



101
102
103
# File 'lib/fontisan/tables/os2_table.rb', line 101

def vendor_id
  parsed&.vendor_id
end

#versionInteger?

Get OS/2 table version

Returns:

  • (Integer, nil)

    Version number (0-5), or nil if not parsed



62
63
64
# File 'lib/fontisan/tables/os2_table.rb', line 62

def version
  parsed&.version
end

#weight_classInteger?

Get weight class

Returns:

  • (Integer, nil)

    Weight class (100-900), or nil if not parsed



69
70
71
# File 'lib/fontisan/tables/os2_table.rb', line 69

def weight_class
  parsed&.us_weight_class
end

#weight_class_nameString?

Get weight class name

Returns:

  • (String, nil)

    Human-readable weight name, or nil if not parsed



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_classInteger?

Get width class

Returns:

  • (Integer, nil)

    Width class (1-9), or nil if not parsed



85
86
87
# File 'lib/fontisan/tables/os2_table.rb', line 85

def width_class
  parsed&.us_width_class
end

#width_class_nameString?

Get width class name

Returns:

  • (String, nil)

    Human-readable width name, or nil if not parsed



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_ascentInteger?

Get Windows ascent

Returns:

  • (Integer, nil)

    Windows ascender, or nil if not parsed



164
165
166
# File 'lib/fontisan/tables/os2_table.rb', line 164

def win_ascent
  parsed&.us_win_ascent
end

#win_descentInteger?

Get Windows descent

Returns:

  • (Integer, nil)

    Windows descender, or nil if not parsed



171
172
173
# File 'lib/fontisan/tables/os2_table.rb', line 171

def win_descent
  parsed&.us_win_descent
end

#x_heightInteger?

Get x-height (version 2+)

Returns:

  • (Integer, nil)

    x-height value, or nil if not available



178
179
180
# File 'lib/fontisan/tables/os2_table.rb', line 178

def x_height
  parsed&.sx_height
end