Class: Fontisan::Tables::Os2

Inherits:
Binary::BaseRecord show all
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 Method Summary collapse

Methods inherited from Binary::BaseRecord

#raw_data, read, #valid?

Instance Method Details

#has_optical_point_size?Boolean

Check if optical point size information is available

Returns:

  • (Boolean)

    True if version >= 5



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

def has_optical_point_size?
  version >= 5
end

#lower_optical_point_sizeFloat?

Get the lower optical point size

Returns:

  • (Float, nil)

    The lower optical point size in points, or nil if not available



158
159
160
161
162
# File 'lib/fontisan/tables/os2.rb', line 158

def lower_optical_point_size
  return nil unless has_optical_point_size?

  us_lower_optical_point_size / 20.0
end

#s_cap_heightObject



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

def s_cap_height
  return nil unless version >= 2

  super
end

#sx_heightObject



89
90
91
92
93
# File 'lib/fontisan/tables/os2.rb', line 89

def sx_height
  return nil unless version >= 2

  super
end

#type_flagsInteger

Get the embedding type flags

Returns:

  • (Integer)

    The fs_type value (embedding permissions)



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

def type_flags
  fs_type
end

#ul_code_page_range1Object

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



77
78
79
80
81
# File 'lib/fontisan/tables/os2.rb', line 77

def ul_code_page_range1
  return nil unless version >= 1

  super
end

#ul_code_page_range2Object



83
84
85
86
87
# File 'lib/fontisan/tables/os2.rb', line 83

def ul_code_page_range2
  return nil unless version >= 1

  super
end

#upper_optical_point_sizeFloat?

Get the upper optical point size

Returns:

  • (Float, nil)

    The upper optical point size in points, or nil if not available



168
169
170
171
172
# File 'lib/fontisan/tables/os2.rb', line 168

def upper_optical_point_size
  return nil unless has_optical_point_size?

  us_upper_optical_point_size / 20.0
end

#us_break_charObject



107
108
109
110
111
# File 'lib/fontisan/tables/os2.rb', line 107

def us_break_char
  return nil unless version >= 2

  super
end

#us_default_charObject



101
102
103
104
105
# File 'lib/fontisan/tables/os2.rb', line 101

def us_default_char
  return nil unless version >= 2

  super
end

#us_lower_optical_point_sizeObject



119
120
121
122
123
# File 'lib/fontisan/tables/os2.rb', line 119

def us_lower_optical_point_size
  return nil unless version >= 5

  super
end

#us_max_contextObject



113
114
115
116
117
# File 'lib/fontisan/tables/os2.rb', line 113

def us_max_context
  return nil unless version >= 2

  super
end

#us_upper_optical_point_sizeObject



125
126
127
128
129
# File 'lib/fontisan/tables/os2.rb', line 125

def us_upper_optical_point_size
  return nil unless version >= 5

  super
end

#vendor_idString

Get the vendor ID as a trimmed string

Returns:

  • (String)

    The vendor ID with trailing spaces and nulls removed



134
135
136
137
138
# File 'lib/fontisan/tables/os2.rb', line 134

def vendor_id
  return "" unless ach_vend_id

  ach_vend_id.gsub(/[\x00\s]+$/, "")
end