Class: Fontisan::Variation::InstanceFontWrapper

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/fontisan/variation/instance_font_wrapper.rb

Overview

Wraps a variable font to substitute specific table tags with instance-generated equivalents while forwarding everything else to the original font. Used by VariableSvgGenerator to feed the SVG generator an instance-shaped font without rewriting it.

Delegation uses SimpleDelegator so the wrapper is transparent: the original font's interface is preserved verbatim. Only #has_table? is overridden to also report instance-supplied tags.

NOTE: #table currently delegates to the original font for any tag not in the instance map. The previous implementation always delegated regardless of @table_data contents, which SvgGenerator depended on (it expects parsed BinData records, not raw bytes). Until SvgGenerator can consume raw instance bytes, this wrapper preserves that behavior. The @table_data map is still exposed so downstream code that wants the raw bytes can read them.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_font, instance_tables) ⇒ InstanceFontWrapper

Returns a new instance of InstanceFontWrapper.

Parameters:

  • original_font (TrueTypeFont, OpenTypeFont)

    the variable font

  • instance_tables (Hash<String, String>)

    instance-generated bytes



29
30
31
32
# File 'lib/fontisan/variation/instance_font_wrapper.rb', line 29

def initialize(original_font, instance_tables)
  super(original_font)
  @table_data = instance_tables
end

Instance Attribute Details

#table_dataHash<String, String> (readonly)

Returns instance-generated table bytes by tag.

Returns:

  • (Hash<String, String>)

    instance-generated table bytes by tag



25
26
27
# File 'lib/fontisan/variation/instance_font_wrapper.rb', line 25

def table_data
  @table_data
end

Instance Method Details

#has_table?(tag) ⇒ Boolean

Parameters:

  • tag (String)

    table tag

Returns:

  • (Boolean)


36
37
38
# File 'lib/fontisan/variation/instance_font_wrapper.rb', line 36

def has_table?(tag)
  @table_data.key?(tag) || __getobj__.has_table?(tag)
end