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`](lib/fontisan/variation/variation_preserver.rb) 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
102 103 104 105 106 107 108 109 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 102 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.
89 90 91 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 89 def @options end |
#source_font ⇒ Object (readonly)
Returns Source font.
83 84 85 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 83 def source_font @source_font end |
#target_tables ⇒ Hash<String, String> (readonly)
Returns Target tables.
86 87 88 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 86 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
78 79 80 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 78 def self.preserve(source_font, target_tables, = {}) new(source_font, target_tables, ).preserve end |
Instance Method Details
#preserve ⇒ Hash<String, String>
Preserve variation tables
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 114 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
135 136 137 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 135 def variable_font? @context.variable_font? end |
#variation_type ⇒ Symbol?
Get variation type of source font
142 143 144 |
# File 'lib/fontisan/variation/variation_preserver.rb', line 142 def variation_type @context.variation_type end |