Class: Fontisan::Tables::MaxpTable

Inherits:
SfntTable
  • Object
show all
Defined in:
lib/fontisan/tables/maxp_table.rb

Overview

OOP representation of the ‘maxp’ (Maximum Profile) table

The maxp table contains memory and complexity limits for the font, providing the number of glyphs and various maximum values needed for font rendering and processing.

This class extends SfntTable to provide maxp-specific validation and convenience methods for accessing font complexity metrics.

Examples:

Accessing maxp table data

maxp = font.sfnt_table("maxp")
maxp.num_glyphs        # => 512
maxp.version           # => 1.0 or 0.5
maxp.truetype?         # => true or false

Constant Summary collapse

VERSION_0_5 =

Version 0.5 constant (CFF fonts)

0x00005000
VERSION_1_0 =

Version 1.0 constant (TrueType fonts)

0x00010000

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

#cff?Boolean

Check if this is a CFF font (version 0.5)

Returns:

  • (Boolean)

    true if version 0.5



57
58
59
60
61
# File 'lib/fontisan/tables/maxp_table.rb', line 57

def cff?
  return false unless parsed

  parsed.cff?
end

#has_composite_glyphs?Boolean

Check if font uses composite glyphs

Returns:

  • (Boolean)

    true if max_component_elements > 0



183
184
185
186
# File 'lib/fontisan/tables/maxp_table.rb', line 183

def has_composite_glyphs?
  max_comp = max_component_elements
  !max_comp.nil? && max_comp.positive?
end

#has_twilight_zone?Boolean

Check if font uses twilight zone

Returns:

  • (Boolean)

    true if max_zones == 2



191
192
193
# File 'lib/fontisan/tables/maxp_table.rb', line 191

def has_twilight_zone?
  max_zones == 2
end

#max_component_depthInteger?

Get maximum levels of recursion in composite glyphs (version 1.0)

Returns:

  • (Integer, nil)

    Maximum component depth, or nil if not available



174
175
176
177
178
# File 'lib/fontisan/tables/maxp_table.rb', line 174

def max_component_depth
  return nil unless parsed&.version_1_0?

  parsed.max_component_depth
end

#max_component_elementsInteger?

Get maximum component elements in composite glyph (version 1.0)

Returns:

  • (Integer, nil)

    Maximum component elements, or nil if not available



165
166
167
168
169
# File 'lib/fontisan/tables/maxp_table.rb', line 165

def max_component_elements
  return nil unless parsed&.version_1_0?

  parsed.max_component_elements
end

#max_composite_contoursInteger?

Get maximum contours in a composite glyph (version 1.0)

Returns:

  • (Integer, nil)

    Maximum composite contours, or nil if not available



93
94
95
96
97
# File 'lib/fontisan/tables/maxp_table.rb', line 93

def max_composite_contours
  return nil unless parsed&.version_1_0?

  parsed.max_composite_contours
end

#max_composite_pointsInteger?

Get maximum points in a composite glyph (version 1.0)

Returns:

  • (Integer, nil)

    Maximum composite points, or nil if not available



84
85
86
87
88
# File 'lib/fontisan/tables/maxp_table.rb', line 84

def max_composite_points
  return nil unless parsed&.version_1_0?

  parsed.max_composite_points
end

#max_contoursInteger?

Get maximum contours in a non-composite glyph (version 1.0)

Returns:

  • (Integer, nil)

    Maximum contours, or nil if not available



75
76
77
78
79
# File 'lib/fontisan/tables/maxp_table.rb', line 75

def max_contours
  return nil unless parsed&.version_1_0?

  parsed.max_contours
end

#max_function_defsInteger?

Get maximum function definitions (version 1.0)

Returns:

  • (Integer, nil)

    Maximum function defs, or nil if not available



129
130
131
132
133
# File 'lib/fontisan/tables/maxp_table.rb', line 129

def max_function_defs
  return nil unless parsed&.version_1_0?

  parsed.max_function_defs
end

#max_instruction_defsInteger?

Get maximum instruction definitions (version 1.0)

Returns:

  • (Integer, nil)

    Maximum instruction defs, or nil if not available



138
139
140
141
142
# File 'lib/fontisan/tables/maxp_table.rb', line 138

def max_instruction_defs
  return nil unless parsed&.version_1_0?

  parsed.max_instruction_defs
end

#max_pointsInteger?

Get maximum points in a non-composite glyph (version 1.0)

Returns:

  • (Integer, nil)

    Maximum points, or nil if not available



66
67
68
69
70
# File 'lib/fontisan/tables/maxp_table.rb', line 66

def max_points
  return nil unless parsed&.version_1_0?

  parsed.max_points
end

#max_size_of_instructionsInteger?

Get maximum byte count for glyph instructions (version 1.0)

Returns:

  • (Integer, nil)

    Maximum instruction size, or nil if not available



156
157
158
159
160
# File 'lib/fontisan/tables/maxp_table.rb', line 156

def max_size_of_instructions
  return nil unless parsed&.version_1_0?

  parsed.max_size_of_instructions
end

#max_stack_elementsInteger?

Get maximum stack depth (version 1.0)

Returns:

  • (Integer, nil)

    Maximum stack elements, or nil if not available



147
148
149
150
151
# File 'lib/fontisan/tables/maxp_table.rb', line 147

def max_stack_elements
  return nil unless parsed&.version_1_0?

  parsed.max_stack_elements
end

#max_storageInteger?

Get maximum storage area locations (version 1.0)

Returns:

  • (Integer, nil)

    Maximum storage, or nil if not available



120
121
122
123
124
# File 'lib/fontisan/tables/maxp_table.rb', line 120

def max_storage
  return nil unless parsed&.version_1_0?

  parsed.max_storage
end

#max_twilight_pointsInteger?

Get maximum twilight zone points (version 1.0)

Returns:

  • (Integer, nil)

    Maximum twilight points, or nil if not available



111
112
113
114
115
# File 'lib/fontisan/tables/maxp_table.rb', line 111

def max_twilight_points
  return nil unless parsed&.version_1_0?

  parsed.max_twilight_points
end

#max_zonesInteger?

Get maximum zones (version 1.0)

Returns:

  • (Integer, nil)

    Maximum zones (1 or 2), or nil if not available



102
103
104
105
106
# File 'lib/fontisan/tables/maxp_table.rb', line 102

def max_zones
  return nil unless parsed&.version_1_0?

  parsed.max_zones
end

#num_glyphsInteger?

Get number of glyphs

Returns:

  • (Integer, nil)

    Total number of glyphs, or nil if not parsed



41
42
43
# File 'lib/fontisan/tables/maxp_table.rb', line 41

def num_glyphs
  parsed&.num_glyphs
end

#statisticsHash

Get complexity statistics

Returns:

  • (Hash)

    Statistics about font complexity



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/fontisan/tables/maxp_table.rb', line 198

def statistics
  stats = {
    num_glyphs: num_glyphs,
    version: version,
    truetype: truetype?,
    cff: cff?,
  }

  if truetype?
    stats[:max_points] = max_points
    stats[:max_contours] = max_contours
    stats[:max_composite_points] = max_composite_points
    stats[:max_composite_contours] = max_composite_contours
    stats[:max_component_elements] = max_component_elements
    stats[:max_component_depth] = max_component_depth
    stats[:has_composite_glyphs] = has_composite_glyphs?
    stats[:has_twilight_zone] = has_twilight_zone?
  end

  stats
end

#truetype?Boolean

Check if this is a TrueType font (version 1.0)

Returns:

  • (Boolean)

    true if version 1.0



48
49
50
51
52
# File 'lib/fontisan/tables/maxp_table.rb', line 48

def truetype?
  return false unless parsed

  parsed.truetype?
end

#versionFloat?

Get maxp table version

Returns:

  • (Float, nil)

    Version number (0.5 or 1.0), or nil if not parsed



32
33
34
35
36
# File 'lib/fontisan/tables/maxp_table.rb', line 32

def version
  return nil unless parsed

  parsed.version
end