Class: Fontisan::Variation::VariationPreserver
- Inherits:
-
Object
- Object
- Fontisan::Variation::VariationPreserver
- Defined in:
- lib/fontisan/variation/variation_preserver.rb
Overview
Preserves variation data when converting between compatible font formats
VariationPreserver
copies variation tables from source to target font during format
conversion. It handles:
- Common variation tables (fvar, avar, STAT) - shared by all variable fonts
- Format-specific tables (gvar for TTF, CFF2 for OTF)
- Metrics variation tables (HVAR, VVAR, MVAR)
- Table checksum updates
- Validation of table consistency
Use Cases:
- Variable TTF → Variable WOFF: Preserve all gvar-based variation
- Variable OTF → Variable WOFF: Preserve all CFF2-based variation
- Variable TTF → Variable OTF: Copy common tables (fvar, avar, STAT) but variation data conversion handled by Converter
- Variable OTF → Variable TTF: Copy common tables (fvar, avar, STAT) but variation data conversion handled by Converter
Preserved Tables:
Common (all variable fonts):
- fvar (Font Variations)
- avar (Axis Variations, optional)
- STAT (Style Attributes)
TrueType-specific:
- gvar (Glyph Variations)
- cvar (CVT Variations, optional)
CFF2-specific:
- CFF2 (with blend operators)
Metrics (optional):
- HVAR (Horizontal Metrics Variations)
- VVAR (Vertical Metrics Variations)
- MVAR (Metrics Variations)
Constant Summary collapse
- COMMON_TABLES =
Common variation tables present in all variable fonts
%w[fvar avar STAT].freeze
- TRUETYPE_TABLES =
TrueType-specific variation tables
%w[gvar cvar].freeze
- CFF2_TABLES =
CFF2-specific variation tables
%w[CFF2].freeze
- METRICS_TABLES =
Metrics variation tables
%w[HVAR VVAR MVAR].freeze
- ALL_VARIATION_TABLES =
All variation-related tables
(COMMON_TABLES + TRUETYPE_TABLES + CFF2_TABLES + METRICS_TABLES).freeze
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Preservation options.
-
#source_font ⇒ Object
readonly
Source font.
-
#target_tables ⇒ Hash<String, String>
readonly
Target tables.
Class Method Summary collapse
-
.preserve(source_font, target_tables, options = {}) ⇒ Hash<String, String>
Preserve variation data from source to target.
Instance Method Summary collapse
-
#initialize(source_font, target_tables, options = {}) ⇒ VariationPreserver
constructor
Initialize preserver.
-
#preserve ⇒ Hash<String, String>
Preserve variation tables.
-
#variable_font? ⇒ Boolean
Check if source font is a variable font.
-
#variation_type ⇒ Symbol?
Get variation type of source font.
Constructor Details
#initialize(source_font, target_tables, options = {}) ⇒ VariationPreserver
Initialize preserver
99 100 101 102 103 104 105 106 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 99 def initialize(source_font, target_tables, = {}) @source_font = source_font @target_tables = target_tables.dup @options = validate_source! @context = VariationContext.new(source_font) end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns Preservation options.
86 87 88 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 86 def @options end |
#source_font ⇒ Object (readonly)
Returns Source font.
80 81 82 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 80 def source_font @source_font end |
#target_tables ⇒ Hash<String, String> (readonly)
Returns Target tables.
83 84 85 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 83 def target_tables @target_tables end |
Class Method Details
.preserve(source_font, target_tables, options = {}) ⇒ Hash<String, String>
Preserve variation data from source to target
75 76 77 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 75 def self.preserve(source_font, target_tables, = {}) new(source_font, target_tables, ).preserve end |
Instance Method Details
#preserve ⇒ Hash<String, String>
Preserve variation tables
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 111 def preserve # Copy common variation tables (fvar, avar, STAT) copy_common_tables # Copy format-specific variation tables if requested if preserve_format_specific? copy_format_specific_tables end # Copy metrics variation tables if requested copy_metrics_tables if preserve_metrics? # Validate consistency if requested validate_consistency if validate? @target_tables end |
#variable_font? ⇒ Boolean
Check if source font is a variable font
132 133 134 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 132 def variable_font? @context.variable_font? end |
#variation_type ⇒ Symbol?
Get variation type of source font
139 140 141 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 139 def variation_type @context.variation_type end |