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
41 42 43 44 45 46 47 |
# File 'lib/fontisan/variable/instancer.rb', line 41 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.
32 33 34 |
# File 'lib/fontisan/variable/instancer.rb', line 32 def delta_applicator @delta_applicator end |
#font ⇒ Object (readonly)
Returns The variable font object.
29 30 31 |
# File 'lib/fontisan/variable/instancer.rb', line 29 def font @font end |
#static_font_builder ⇒ StaticFontBuilder (readonly)
Returns Static font builder.
35 36 37 |
# File 'lib/fontisan/variable/instancer.rb', line 35 def static_font_builder @static_font_builder end |
Instance Method Details
#axes ⇒ Hash
Get available axis information
154 155 156 |
# File 'lib/fontisan/variable/instancer.rb', line 154 def axes @delta_applicator.axes end |
#axis_tags ⇒ Array<String>
Get available axis tags
161 162 163 |
# File 'lib/fontisan/variable/instancer.rb', line 161 def @delta_applicator. end |
#instance(user_coords, options = {}) ⇒ String
Generate static font instance at specified coordinates
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fontisan/variable/instancer.rb', line 59 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
99 100 101 102 |
# File 'lib/fontisan/variable/instancer.rb', line 99 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
113 114 115 116 |
# File 'lib/fontisan/variable/instancer.rb', line 113 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
85 86 87 88 |
# File 'lib/fontisan/variable/instancer.rb', line 85 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
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/fontisan/variable/instancer.rb', line 122 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
147 148 149 |
# File 'lib/fontisan/variable/instancer.rb', line 147 def variable_font? @delta_applicator.variable_font? end |