Class: Fontisan::Tables::GlyfTable
- Defined in:
- lib/fontisan/tables/glyf_table.rb
Overview
OOP representation of the ‘glyf’ (Glyph Data) table
The glyf table contains TrueType glyph outline data. Each glyph is described by either a simple glyph (with contours and points) or a compound glyph (composed of other glyphs with transformations).
This class extends SfntTable to provide glyf-specific convenience methods for accessing glyph data. The glyf table requires context from the loca and head tables to function properly.
Instance Attribute Summary collapse
-
#head_table ⇒ Object
readonly
Cache for context tables.
-
#loca_table ⇒ Object
readonly
Cache for context tables.
Attributes inherited from SfntTable
Instance Method Summary collapse
-
#all_glyphs_accessible?(num_glyphs) ⇒ Boolean
Validate all glyphs are accessible.
-
#cache_size ⇒ Integer
Get glyph cache size.
-
#clear_cache ⇒ void
Clear glyph cache.
-
#compound_glyph?(glyph_id) ⇒ Boolean
Check if a glyph is compound.
-
#empty_glyph?(glyph_id) ⇒ Boolean
Check if a glyph is empty.
-
#glyph_bounding_box(glyph_id) ⇒ Array<Integer>?
Get glyph bounding box.
-
#glyph_contour_count(glyph_id) ⇒ Integer?
Get number of contours for a glyph.
-
#glyph_for(glyph_id) ⇒ SimpleGlyph, ...
Get a glyph by ID.
-
#glyph_point_count(glyph_id) ⇒ Integer?
Get number of points for a simple glyph.
-
#has_context? ⇒ Boolean
Check if table has been parsed with context.
-
#instructions_sound?(num_glyphs) ⇒ Boolean
Validate glyphs have sound instructions.
-
#no_clipped_glyphs?(num_glyphs) ⇒ Boolean
Validate no glyphs are clipped.
-
#parse_with_context(loca, head) ⇒ self
Parse the glyf table with required context.
-
#simple_glyph?(glyph_id) ⇒ Boolean
Check if a glyph is simple (has contours).
-
#statistics(num_glyphs) ⇒ Hash
Get glyph statistics.
-
#valid_contour_count?(glyph_id) ⇒ Boolean
Validate all glyphs have valid contour counts.
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 Attribute Details
#head_table ⇒ Object (readonly)
Cache for context tables
29 30 31 |
# File 'lib/fontisan/tables/glyf_table.rb', line 29 def head_table @head_table end |
#loca_table ⇒ Object (readonly)
Cache for context tables
29 30 31 |
# File 'lib/fontisan/tables/glyf_table.rb', line 29 def loca_table @loca_table end |
Instance Method Details
#all_glyphs_accessible?(num_glyphs) ⇒ Boolean
Validate all glyphs are accessible
159 160 161 162 163 164 |
# File 'lib/fontisan/tables/glyf_table.rb', line 159 def all_glyphs_accessible?(num_glyphs) ensure_context! return false unless parsed parsed.all_glyphs_accessible?(@loca_table, @head_table, num_glyphs) end |
#cache_size ⇒ Integer
Get glyph cache size
140 141 142 143 144 |
# File 'lib/fontisan/tables/glyf_table.rb', line 140 def cache_size return 0 unless parsed parsed.cache_size end |
#clear_cache ⇒ void
This method returns an undefined value.
Clear glyph cache
149 150 151 152 153 |
# File 'lib/fontisan/tables/glyf_table.rb', line 149 def clear_cache return unless parsed parsed.clear_cache end |
#compound_glyph?(glyph_id) ⇒ Boolean
Check if a glyph is compound
89 90 91 92 93 94 |
# File 'lib/fontisan/tables/glyf_table.rb', line 89 def compound_glyph?(glyph_id) glyph = glyph_for(glyph_id) return false if glyph.nil? glyph.respond_to?(:num_contours) && glyph.num_contours == -1 end |
#empty_glyph?(glyph_id) ⇒ Boolean
Check if a glyph is empty
100 101 102 |
# File 'lib/fontisan/tables/glyf_table.rb', line 100 def empty_glyph?(glyph_id) glyph_for(glyph_id).nil? end |
#glyph_bounding_box(glyph_id) ⇒ Array<Integer>?
Get glyph bounding box
108 109 110 111 112 113 |
# File 'lib/fontisan/tables/glyf_table.rb', line 108 def glyph_bounding_box(glyph_id) glyph = glyph_for(glyph_id) return nil if glyph.nil? [glyph.x_min, glyph.y_min, glyph.x_max, glyph.y_max] end |
#glyph_contour_count(glyph_id) ⇒ Integer?
Get number of contours for a glyph
119 120 121 122 123 124 |
# File 'lib/fontisan/tables/glyf_table.rb', line 119 def glyph_contour_count(glyph_id) glyph = glyph_for(glyph_id) return nil if glyph.nil? glyph.num_contours if glyph.respond_to?(:num_contours) end |
#glyph_for(glyph_id) ⇒ SimpleGlyph, ...
Get a glyph by ID
67 68 69 70 71 72 |
# File 'lib/fontisan/tables/glyf_table.rb', line 67 def glyph_for(glyph_id) ensure_context! return nil unless parsed parsed.glyph_for(glyph_id, @loca_table, @head_table) end |
#glyph_point_count(glyph_id) ⇒ Integer?
Get number of points for a simple glyph
130 131 132 133 134 135 |
# File 'lib/fontisan/tables/glyf_table.rb', line 130 def glyph_point_count(glyph_id) glyph = glyph_for(glyph_id) return nil if glyph.nil? || !glyph.respond_to?(:num_points) glyph.num_points end |
#has_context? ⇒ Boolean
Check if table has been parsed with context
58 59 60 |
# File 'lib/fontisan/tables/glyf_table.rb', line 58 def has_context? !@loca_table.nil? && !@head_table.nil? end |
#instructions_sound?(num_glyphs) ⇒ Boolean
Validate glyphs have sound instructions
192 193 194 195 196 197 |
# File 'lib/fontisan/tables/glyf_table.rb', line 192 def instructions_sound?(num_glyphs) ensure_context! return false unless parsed parsed.instructions_sound?(@loca_table, @head_table, num_glyphs) end |
#no_clipped_glyphs?(num_glyphs) ⇒ Boolean
Validate no glyphs are clipped
170 171 172 173 174 175 |
# File 'lib/fontisan/tables/glyf_table.rb', line 170 def no_clipped_glyphs?(num_glyphs) ensure_context! return false unless parsed parsed.no_clipped_glyphs?(@loca_table, @head_table, num_glyphs) end |
#parse_with_context(loca, head) ⇒ self
Parse the glyf table with required context
The glyf table cannot be used without context from loca and head tables. This method must be called before accessing glyph data.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fontisan/tables/glyf_table.rb', line 40 def parse_with_context(loca, head) unless loca && head raise ArgumentError, "glyf table requires both loca and head tables as context" end @loca_table = loca @head_table = head # Ensure parsed data is loaded parse self end |
#simple_glyph?(glyph_id) ⇒ Boolean
Check if a glyph is simple (has contours)
78 79 80 81 82 83 |
# File 'lib/fontisan/tables/glyf_table.rb', line 78 def simple_glyph?(glyph_id) glyph = glyph_for(glyph_id) return false if glyph.nil? glyph.respond_to?(:num_contours) && glyph.num_contours >= 0 end |
#statistics(num_glyphs) ⇒ Hash
Get glyph statistics
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/fontisan/tables/glyf_table.rb', line 203 def statistics(num_glyphs) ensure_context! return {} unless parsed simple_count = 0 compound_count = 0 empty_count = 0 (0...num_glyphs).each do |gid| if empty_glyph?(gid) empty_count += 1 elsif simple_glyph?(gid) simple_count += 1 elsif compound_glyph?(gid) compound_count += 1 end end { total_glyphs: num_glyphs, simple_glyphs: simple_count, compound_glyphs: compound_count, empty_glyphs: empty_count, cached_glyphs: cache_size, } end |
#valid_contour_count?(glyph_id) ⇒ Boolean
Validate all glyphs have valid contour counts
181 182 183 184 185 186 |
# File 'lib/fontisan/tables/glyf_table.rb', line 181 def valid_contour_count?(glyph_id) ensure_context! return false unless parsed parsed.valid_contour_count?(glyph_id, @loca_table, @head_table) end |