Class: Fontisan::Variation::InstanceWriter
- Inherits:
-
Object
- Object
- Fontisan::Variation::InstanceWriter
- Defined in:
- lib/fontisan/variation/instance_writer.rb
Overview
Writes generated static font instances to files in various formats
InstanceWriter takes
instance tables generated by
InstanceGenerator and
writes them to files in the desired output format. It handles:
- Format detection from file extension
- Format conversion when needed (e.g., glyf → CFF for OTF)
- SFNT version selection based on output format
- Integration with FontWriter for binary output
- Integration with OutlineConverter for format conversion
- Integration with WoffWriter for WOFF packaging
Supported Output Formats:
- TTF (TrueType with glyf outlines)
- OTF (OpenType with CFF outlines)
- WOFF (Web Open Font Format)
- WOFF2 (Web Open Font Format 2.0, future)
Constant Summary collapse
- SUPPORTED_FORMATS =
Supported output formats
%i[ttf otf woff woff2].freeze
- SFNT_VERSION_TRUETYPE =
SFNT version constants
0x00010000- SFNT_VERSION_CFF =
TrueType with glyf
0x4F54544F
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Writer options.
-
#tables ⇒ Hash<String, String>
readonly
Instance tables.
Class Method Summary collapse
-
.write(tables, output_path, options = {}) ⇒ Integer
Write instance tables to file.
Instance Method Summary collapse
-
#initialize(tables, options = {}) ⇒ InstanceWriter
constructor
Initialize writer with instance tables.
-
#write(output_path) ⇒ Integer
Write instance to file.
Constructor Details
#initialize(tables, options = {}) ⇒ InstanceWriter
Initialize writer with instance tables
76 77 78 79 80 |
# File 'lib/fontisan/variation/instance_writer.rb', line 76 def initialize(tables, = {}) @tables = tables @options = validate_tables! end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns Writer options.
67 68 69 |
# File 'lib/fontisan/variation/instance_writer.rb', line 67 def @options end |
#tables ⇒ Hash<String, String> (readonly)
Returns Instance tables.
64 65 66 |
# File 'lib/fontisan/variation/instance_writer.rb', line 64 def tables @tables end |
Class Method Details
.write(tables, output_path, options = {}) ⇒ Integer
Write instance tables to file
59 60 61 |
# File 'lib/fontisan/variation/instance_writer.rb', line 59 def self.write(tables, output_path, = {}) new(tables, ).write(output_path) end |
Instance Method Details
#write(output_path) ⇒ Integer
Write instance to file
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fontisan/variation/instance_writer.rb', line 86 def write(output_path) # Detect output format format = detect_output_format(output_path) validate_format!(format) # Detect source format from tables source_format = detect_source_format(@tables) # Convert format if needed output_tables = if format_conversion_needed?(source_format, format) convert_format(source_format, format) else @tables end # Write to file based on format case format when :ttf, :otf write_sfnt(output_tables, output_path, format) when :woff write_woff(output_tables, output_path, source_format) when :woff2 raise Fontisan::Error, "WOFF2 output not yet implemented (planned for Phase 6)" end end |