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



54
55
56
57
58
# File 'lib/fontisan/tables/maxp_table.rb', line 54

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



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

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



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

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



171
172
173
174
175
# File 'lib/fontisan/tables/maxp_table.rb', line 171

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



162
163
164
165
166
# File 'lib/fontisan/tables/maxp_table.rb', line 162

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



90
91
92
93
94
# File 'lib/fontisan/tables/maxp_table.rb', line 90

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



81
82
83
84
85
# File 'lib/fontisan/tables/maxp_table.rb', line 81

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



72
73
74
75
76
# File 'lib/fontisan/tables/maxp_table.rb', line 72

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



126
127
128
129
130
# File 'lib/fontisan/tables/maxp_table.rb', line 126

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



135
136
137
138
139
# File 'lib/fontisan/tables/maxp_table.rb', line 135

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



63
64
65
66
67
# File 'lib/fontisan/tables/maxp_table.rb', line 63

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



153
154
155
156
157
# File 'lib/fontisan/tables/maxp_table.rb', line 153

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



144
145
146
147
148
# File 'lib/fontisan/tables/maxp_table.rb', line 144

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



117
118
119
120
121
# File 'lib/fontisan/tables/maxp_table.rb', line 117

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



108
109
110
111
112
# File 'lib/fontisan/tables/maxp_table.rb', line 108

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



99
100
101
102
103
# File 'lib/fontisan/tables/maxp_table.rb', line 99

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



38
39
40
# File 'lib/fontisan/tables/maxp_table.rb', line 38

def num_glyphs
  parsed&.num_glyphs
end

#statisticsHash

Get complexity statistics

Returns:

  • (Hash)

    Statistics about font complexity



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

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



45
46
47
48
49
# File 'lib/fontisan/tables/maxp_table.rb', line 45

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



29
30
31
32
33
# File 'lib/fontisan/tables/maxp_table.rb', line 29

def version
  return nil unless parsed

  parsed.version
end