Class: Fontisan::Commands::VariableCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Fontisan::Commands::VariableCommand
- Defined in:
- lib/fontisan/commands/variable_command.rb
Overview
Command to extract variable font information.
This command extracts variation axes and named instances from variable fonts using the fvar (Font Variations) table.
Instance Method Summary collapse
-
#run ⇒ Models::VariableFontInfo
Extract variable font information from the fvar table.
Methods inherited from BaseCommand
Constructor Details
This class inherits a constructor from Fontisan::Commands::BaseCommand
Instance Method Details
#run ⇒ Models::VariableFontInfo
Extract variable font information from the fvar table.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fontisan/commands/variable_command.rb', line 18 def run result = Models::VariableFontInfo.new # Check if font has fvar table unless font.has_table?(Constants::FVAR_TAG) result.is_variable = false result.axis_count = 0 result.instance_count = 0 result.axes = [] result.instances = [] return result end fvar_table = font.table(Constants::FVAR_TAG) name_table = font.table(Constants::NAME_TAG) if font.has_table?(Constants::NAME_TAG) result.is_variable = true result.axis_count = fvar_table.axis_count result.instance_count = fvar_table.instance_count # Extract axes information result.axes = fvar_table.axes.map do |axis| Models::AxisInfo.new( tag: axis.axis_tag, name: name_table&.english_name(axis.axis_name_id), min_value: axis.min_value, default_value: axis.default_value, max_value: axis.max_value, ) end # Extract instances information result.instances = fvar_table.instances.map do |instance| Models::InstanceInfo.new( name: name_table&.english_name(instance[:name_id]), coordinates: instance[:coordinates], ) end result end |