Class: Fontisan::Variable::Instancer
- Inherits:
-
Object
- Object
- Fontisan::Variable::Instancer
- Defined in:
- lib/fontisan/variable/instancer.rb
Overview
Main entry point for variable font instancing
This class orchestrates the complete process of generating a static font instance from a variable font at specified coordinates:
- Validates the font is a variable font (has fvar table)
- Normalizes user coordinates using AxisNormalizer
- Calculates region scalars using RegionMatcher
- Applies deltas using DeltaApplicator
- Builds static font using StaticFontBuilder
Instance Attribute Summary collapse
-
#delta_applicator ⇒ DeltaApplicator
readonly
Delta applicator.
-
#font ⇒ Object
readonly
The variable font object.
-
#static_font_builder ⇒ StaticFontBuilder
readonly
Static font builder.
Instance Method Summary collapse
-
#axes ⇒ Hash
Get available axis information.
-
#axis_tags ⇒ Array<String>
Get available axis tags.
-
#initialize(font) ⇒ Instancer
constructor
Initialize the instancer.
-
#instance(user_coords, options = {}) ⇒ String
Generate static font instance at specified coordinates.
-
#instance_named(instance_name, options = {}) ⇒ String
Generate static font instance for a named instance.
-
#instance_named_to_file(output_path, instance_name, options = {}) ⇒ Integer
Generate static font instance for a named instance and write to file.
-
#instance_to_file(output_path, user_coords, options = {}) ⇒ Integer
Generate static font instance and write to file.
-
#named_instances ⇒ Array<Hash>
Get list of available named instances.
-
#variable_font? ⇒ Boolean
Check if font is a variable font.
Constructor Details
#initialize(font) ⇒ Instancer
Initialize the instancer
38 39 40 41 42 43 44 |
# File 'lib/fontisan/variable/instancer.rb', line 38 def initialize(font) @font = font validate_variable_font! @delta_applicator = DeltaApplicator.new(font) @static_font_builder = StaticFontBuilder.new(font) end |
Instance Attribute Details
#delta_applicator ⇒ DeltaApplicator (readonly)
Returns Delta applicator.
29 30 31 |
# File 'lib/fontisan/variable/instancer.rb', line 29 def delta_applicator @delta_applicator end |
#font ⇒ Object (readonly)
Returns The variable font object.
26 27 28 |
# File 'lib/fontisan/variable/instancer.rb', line 26 def font @font end |
#static_font_builder ⇒ StaticFontBuilder (readonly)
Returns Static font builder.
32 33 34 |
# File 'lib/fontisan/variable/instancer.rb', line 32 def static_font_builder @static_font_builder end |
Instance Method Details
#axes ⇒ Hash
Get available axis information
151 152 153 |
# File 'lib/fontisan/variable/instancer.rb', line 151 def axes @delta_applicator.axes end |
#axis_tags ⇒ Array<String>
Get available axis tags
158 159 160 |
# File 'lib/fontisan/variable/instancer.rb', line 158 def @delta_applicator. end |
#instance(user_coords, options = {}) ⇒ String
Generate static font instance at specified coordinates
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fontisan/variable/instancer.rb', line 56 def instance(user_coords, = {}) # Apply deltas to get all varied data delta_result = @delta_applicator.apply(user_coords) # Collect varied metrics for all glyphs varied_metrics = collect_varied_glyph_metrics( delta_result[:normalized_coords], delta_result[:region_scalars], ) # Extract font-level metrics font_metrics = delta_result[:font_metrics] # Build static font @static_font_builder.build(varied_metrics, font_metrics, ) end |
#instance_named(instance_name, options = {}) ⇒ String
Generate static font instance for a named instance
96 97 98 99 |
# File 'lib/fontisan/variable/instancer.rb', line 96 def instance_named(instance_name, = {}) coords = find_named_instance_coords(instance_name) instance(coords, ) end |
#instance_named_to_file(output_path, instance_name, options = {}) ⇒ Integer
Generate static font instance for a named instance and write to file
110 111 112 113 |
# File 'lib/fontisan/variable/instancer.rb', line 110 def instance_named_to_file(output_path, instance_name, = {}) binary = instance_named(instance_name, ) File.binwrite(output_path, binary) end |
#instance_to_file(output_path, user_coords, options = {}) ⇒ Integer
Generate static font instance and write to file
82 83 84 85 |
# File 'lib/fontisan/variable/instancer.rb', line 82 def instance_to_file(output_path, user_coords, = {}) binary = instance(user_coords, ) File.binwrite(output_path, binary) end |
#named_instances ⇒ Array<Hash>
Get list of available named instances
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/fontisan/variable/instancer.rb', line 119 def named_instances fvar = load_fvar_table return [] unless fvar # Get name table for instance names name_table = load_name_table fvar.instances.map do |instance| coords = extract_instance_coords(instance, fvar) name = if name_table get_instance_name(instance[:name_id], name_table) end { name_id: instance[:name_id], name: name || "Instance #{instance[:name_id]}", coordinates: coords, } end end |
#variable_font? ⇒ Boolean
Check if font is a variable font
144 145 146 |
# File 'lib/fontisan/variable/instancer.rb', line 144 def variable_font? @delta_applicator.variable_font? end |