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
26 27 28 |
# File 'lib/fontisan/tables/glyf_table.rb', line 26 def head_table @head_table end |
#loca_table ⇒ Object (readonly)
Cache for context tables
26 27 28 |
# File 'lib/fontisan/tables/glyf_table.rb', line 26 def loca_table @loca_table end |
Instance Method Details
#all_glyphs_accessible?(num_glyphs) ⇒ Boolean
Validate all glyphs are accessible
156 157 158 159 160 161 |
# File 'lib/fontisan/tables/glyf_table.rb', line 156 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
137 138 139 140 141 |
# File 'lib/fontisan/tables/glyf_table.rb', line 137 def cache_size return 0 unless parsed parsed.cache_size end |
#clear_cache ⇒ void
This method returns an undefined value.
Clear glyph cache
146 147 148 149 150 |
# File 'lib/fontisan/tables/glyf_table.rb', line 146 def clear_cache return unless parsed parsed.clear_cache end |
#compound_glyph?(glyph_id) ⇒ Boolean
Check if a glyph is compound
86 87 88 89 90 91 |
# File 'lib/fontisan/tables/glyf_table.rb', line 86 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
97 98 99 |
# File 'lib/fontisan/tables/glyf_table.rb', line 97 def empty_glyph?(glyph_id) glyph_for(glyph_id).nil? end |
#glyph_bounding_box(glyph_id) ⇒ Array<Integer>?
Get glyph bounding box
105 106 107 108 109 110 |
# File 'lib/fontisan/tables/glyf_table.rb', line 105 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
116 117 118 119 120 121 |
# File 'lib/fontisan/tables/glyf_table.rb', line 116 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
64 65 66 67 68 69 |
# File 'lib/fontisan/tables/glyf_table.rb', line 64 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
127 128 129 130 131 132 |
# File 'lib/fontisan/tables/glyf_table.rb', line 127 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
55 56 57 |
# File 'lib/fontisan/tables/glyf_table.rb', line 55 def has_context? !@loca_table.nil? && !@head_table.nil? end |
#instructions_sound?(num_glyphs) ⇒ Boolean
Validate glyphs have sound instructions
189 190 191 192 193 194 |
# File 'lib/fontisan/tables/glyf_table.rb', line 189 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
167 168 169 170 171 172 |
# File 'lib/fontisan/tables/glyf_table.rb', line 167 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.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fontisan/tables/glyf_table.rb', line 37 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)
75 76 77 78 79 80 |
# File 'lib/fontisan/tables/glyf_table.rb', line 75 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
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/fontisan/tables/glyf_table.rb', line 200 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
178 179 180 181 182 183 |
# File 'lib/fontisan/tables/glyf_table.rb', line 178 def valid_contour_count?(glyph_id) ensure_context! return false unless parsed parsed.valid_contour_count?(glyph_id, @loca_table, @head_table) end |