Class: Fontisan::Tables::Maxp
- Inherits:
-
Binary::BaseRecord
- Object
- BinData::Record
- Binary::BaseRecord
- Fontisan::Tables::Maxp
- Defined in:
- lib/fontisan/tables/maxp.rb
Overview
BinData structure for the ‘maxp’ (Maximum Profile) table
The maxp table contains memory and complexity limits for the font. It provides the number of glyphs and various maximum values needed for font rendering and processing.
The table has two versions:
-
Version 0.5 (0x00005000): CFF fonts - only version and numGlyphs
-
Version 1.0 (0x00010000): TrueType fonts - includes additional fields
Version 1.0 fields provide information about:
-
Glyph outline complexity (points, contours)
-
Composite glyph structure
-
TrueType instruction limitations
Reference: OpenType specification, maxp table docs.microsoft.com/en-us/typography/opentype/spec/maxp
Constant Summary collapse
- VERSION_0_5 =
Version 0.5 constant (CFF fonts)
0x00005000- VERSION_1_0 =
Version 1.0 constant (TrueType fonts)
0x00010000- TABLE_SIZE_V0_5 =
Minimum table size for version 0.5 (4 + 2 = 6 bytes)
6- TABLE_SIZE_V1_0 =
Full table size for version 1.0 (4 + 2 + 13×2 = 32 bytes)
32
Instance Method Summary collapse
-
#cff? ⇒ Boolean
Check if this is a CFF font (alias for version_0_5?).
-
#expected_size ⇒ Integer
Get the expected table size based on version.
-
#truetype? ⇒ Boolean
Check if this is a TrueType font (alias for version_1_0?).
-
#valid? ⇒ Boolean
Check if the table is valid.
-
#validate_structure! ⇒ Object
(also: #validate!)
Validate the table and raise error if invalid.
-
#version ⇒ Float
Convert version from fixed-point to float.
-
#version_0_5? ⇒ Boolean
Check if this is version 0.5 (CFF).
-
#version_1_0? ⇒ Boolean
Check if this is version 1.0 (TrueType).
Methods inherited from Binary::BaseRecord
Instance Method Details
#cff? ⇒ Boolean
Check if this is a CFF font (alias for version_0_5?)
138 139 140 |
# File 'lib/fontisan/tables/maxp.rb', line 138 def cff? version_0_5? end |
#expected_size ⇒ Integer
Get the expected table size based on version
187 188 189 |
# File 'lib/fontisan/tables/maxp.rb', line 187 def expected_size version_1_0? ? TABLE_SIZE_V1_0 : TABLE_SIZE_V0_5 end |
#truetype? ⇒ Boolean
Check if this is a TrueType font (alias for version_1_0?)
131 132 133 |
# File 'lib/fontisan/tables/maxp.rb', line 131 def truetype? version_1_0? end |
#valid? ⇒ Boolean
Check if the table is valid
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/fontisan/tables/maxp.rb', line 145 def valid? # Version must be either 0.5 or 1.0 return false unless version_0_5? || version_1_0? # Number of glyphs must be at least 1 return false unless num_glyphs >= 1 # For version 1.0, maxZones must be 1 or 2 if version_1_0? && max_zones && !(max_zones >= 1 && max_zones <= 2) return false end true end |
#validate_structure! ⇒ Object Also known as: validate!
Validate the table and raise error if invalid
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/fontisan/tables/maxp.rb', line 163 def validate_structure! unless version_0_5? || version_1_0? raise Fontisan::CorruptedTableError, "Invalid maxp version: expected 0x00005000 (0.5) or " \ "0x00010000 (1.0), got 0x#{version_raw.to_s(16).upcase}" end unless num_glyphs >= 1 raise Fontisan::CorruptedTableError, "Invalid number of glyphs: must be >= 1, got #{num_glyphs}" end if version_1_0? && max_zones && (max_zones < 1 || max_zones > 2) raise Fontisan::CorruptedTableError, "Invalid maxZones: must be 1 or 2, got #{max_zones}" end end |
#version ⇒ Float
Convert version from fixed-point to float
Version 0.5 (0x00005000) is a special case, not standard 16.16 fixed-point
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/fontisan/tables/maxp.rb', line 103 def version case version_raw when VERSION_0_5 0.5 when VERSION_1_0 1.0 else fixed_to_float(version_raw) end end |
#version_0_5? ⇒ Boolean
Check if this is version 0.5 (CFF)
124 125 126 |
# File 'lib/fontisan/tables/maxp.rb', line 124 def version_0_5? version_raw == VERSION_0_5 end |
#version_1_0? ⇒ Boolean
Check if this is version 1.0 (TrueType)
117 118 119 |
# File 'lib/fontisan/tables/maxp.rb', line 117 def version_1_0? version_raw == VERSION_1_0 end |