Module: Fontisan::Variation::TableAccessor
- Included in:
- DeltaApplier, InstanceGenerator, MetricsAdjuster, Subsetter, VariationConverter
- Defined in:
- lib/fontisan/variation/table_accessor.rb
Overview
Provides unified table access for variation classes
This module centralizes table loading logic with optional caching and consistent error handling. It should be included in variation classes that need to access font tables.
Instance Method Summary collapse
-
#clear_variation_cache ⇒ void
Clear variation table cache.
-
#clear_variation_table(tag) ⇒ void
Clear specific cached table.
-
#has_variation_table?(tag) ⇒ Boolean
Check if variation table exists.
-
#require_variation_table(tag) ⇒ Object
Get a required variation table.
-
#variation_table(tag, lazy: true) ⇒ Object?
Get a variation table with optional caching.
Instance Method Details
#clear_variation_cache ⇒ void
This method returns an undefined value.
Clear variation table cache
Useful when font tables are modified and need to be reloaded.
92 93 94 |
# File 'lib/fontisan/variation/table_accessor.rb', line 92 def clear_variation_cache @variation_tables&.clear end |
#clear_variation_table(tag) ⇒ void
This method returns an undefined value.
Clear specific cached table
100 101 102 |
# File 'lib/fontisan/variation/table_accessor.rb', line 100 def clear_variation_table(tag) @variation_tables&.delete(tag) end |
#has_variation_table?(tag) ⇒ Boolean
Check if variation table exists
83 84 85 |
# File 'lib/fontisan/variation/table_accessor.rb', line 83 def has_variation_table?(tag) @font.has_table?(tag) end |
#require_variation_table(tag) ⇒ Object
Get a required variation table
Loads a table that must exist. Raises error if table is missing. Use when table presence is required for operation.
64 65 66 67 68 69 70 71 72 |
# File 'lib/fontisan/variation/table_accessor.rb', line 64 def require_variation_table(tag) table = variation_table(tag) return table if table raise MissingVariationTableError.new( table: tag, message: "Required variation table '#{tag}' not found in font", ) end |
#variation_table(tag, lazy: true) ⇒ Object?
Get a variation table with optional caching
Loads and optionally caches a font table. Returns nil if table doesn’t exist. Use when table presence is optional.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fontisan/variation/table_accessor.rb', line 38 def variation_table(tag, lazy: true) # Return cached table if available return @variation_tables[tag] if @variation_tables&.key?(tag) # Check table exists return nil unless @font.has_table?(tag) # Initialize cache if needed @variation_tables ||= {} # Load and cache table @variation_tables[tag] = @font.table(tag) end |