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. It also provides detailed inspection capabilities through the Inspector class.
Instance Method Summary collapse
-
#inspect(options = {}) ⇒ String
Inspect variable font structure.
-
#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
#inspect(options = {}) ⇒ String
Inspect variable font structure
Provides detailed analysis of variable font structure including axes, instances, regions, and statistics.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fontisan/commands/variable_command.rb', line 73 def inspect( = {}) inspector = Variation::Inspector.new(font) format = [:format] || "json" case format.downcase when "yaml" inspector.export_yaml else inspector.export_json end end |
#run ⇒ Models::VariableFontInfo
Extract variable font information from the fvar table.
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 59 60 61 62 63 |
# File 'lib/fontisan/commands/variable_command.rb', line 23 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 |