Module: Fontisan::Variation::TableAccessor

Included in:
Converter, DeltaApplier, InstanceGenerator, MetricsAdjuster, Subsetter
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.

Examples:

Using TableAccessor in a variation class

class MyVariationClass
  include TableAccessor

  def initialize(font)
    @font = font
    @variation_tables = {}
  end

  def process
    gvar = variation_table("gvar")
    fvar = require_variation_table("fvar")
  end
end

Instance Method Summary collapse

Instance Method Details

#clear_variation_cachevoid

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

Parameters:

  • tag (String)

    Table tag to clear



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

Examples:

Check table presence

if has_variation_table?("gvar")
  # Process gvar
end

Parameters:

  • tag (String)

    Table tag

Returns:

  • (Boolean)

    True if 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.

Examples:

Require table

fvar = require_variation_table("fvar")
# Guaranteed to have fvar or error raised

Parameters:

  • tag (String)

    Table tag

Returns:

  • (Object)

    Parsed table object

Raises:



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.

Examples:

Get optional table

gvar = variation_table("gvar")
return unless gvar

Parameters:

  • tag (String)

    Table tag (e.g., “gvar”, “fvar”)

  • lazy (Boolean) (defaults to: true)

    Enable lazy loading (default: true)

Returns:

  • (Object, nil)

    Parsed table object or nil



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