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



243
244
245
246
247
248
# File 'lib/fontisan/tables/os2_table.rb', line 243

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



118
119
120
# File 'lib/fontisan/tables/os2_table.rb', line 118

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



188
189
190
# File 'lib/fontisan/tables/os2_table.rb', line 188

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



223
224
225
226
227
228
# File 'lib/fontisan/tables/os2_table.rb', line 223

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)



195
196
197
198
199
200
201
# File 'lib/fontisan/tables/os2_table.rb', line 195

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



206
207
208
# File 'lib/fontisan/tables/os2_table.rb', line 206

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



260
261
262
# File 'lib/fontisan/tables/os2_table.rb', line 260

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



111
112
113
# File 'lib/fontisan/tables/os2_table.rb', line 111

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



267
268
269
# File 'lib/fontisan/tables/os2_table.rb', line 267

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



139
140
141
# File 'lib/fontisan/tables/os2_table.rb', line 139

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



253
254
255
# File 'lib/fontisan/tables/os2_table.rb', line 253

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



213
214
215
216
217
218
# File 'lib/fontisan/tables/os2_table.rb', line 213

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



125
126
127
# File 'lib/fontisan/tables/os2_table.rb', line 125

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)



233
234
235
236
237
238
# File 'lib/fontisan/tables/os2_table.rb', line 233

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



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

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



153
154
155
# File 'lib/fontisan/tables/os2_table.rb', line 153

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



160
161
162
# File 'lib/fontisan/tables/os2_table.rb', line 160

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



132
133
134
# File 'lib/fontisan/tables/os2_table.rb', line 132

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



104
105
106
# File 'lib/fontisan/tables/os2_table.rb', line 104

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



65
66
67
# File 'lib/fontisan/tables/os2_table.rb', line 65

def version
  parsed&.version
end

#weight_classInteger?

Get weight class

Returns:

  • (Integer, nil)

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



72
73
74
# File 'lib/fontisan/tables/os2_table.rb', line 72

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



79
80
81
82
83
# File 'lib/fontisan/tables/os2_table.rb', line 79

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



88
89
90
# File 'lib/fontisan/tables/os2_table.rb', line 88

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



95
96
97
98
99
# File 'lib/fontisan/tables/os2_table.rb', line 95

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



167
168
169
# File 'lib/fontisan/tables/os2_table.rb', line 167

def win_ascent
  parsed&.us_win_ascent
end

#win_descentInteger?

Get Windows descent

Returns:

  • (Integer, nil)

    Windows descender, or nil if not parsed



174
175
176
# File 'lib/fontisan/tables/os2_table.rb', line 174

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



181
182
183
# File 'lib/fontisan/tables/os2_table.rb', line 181

def x_height
  parsed&.sx_height
end