Class: Fontisan::Pipeline::OutputWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/pipeline/output_writer.rb

Overview

Handles writing font tables to various output formats

This class abstracts the complexity of writing different font formats:

  • SFNT formats (TTF, OTF) via FontWriter
  • WOFF via WoffWriter
  • WOFF2 via Woff2Encoder

Single Responsibility: Coordinate output writing for different formats

Examples:

Write TTF font

writer = OutputWriter.new("output.ttf", :ttf)
writer.write(tables)

Write OTF font

writer = OutputWriter.new("output.otf", :otf)
writer.write(tables)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_path, format, options = {}) ⇒ OutputWriter

Initialize output writer

Parameters:

  • output_path (String)

    Path to write output

  • format (Symbol)

    Target format (:ttf, :otf, :woff, :woff2, :svg)

  • options (Hash) (defaults to: {})

    Writing options. Format-specific compression knobs (zlib_level, brotli_quality, etc.) pass through to the strategy.



37
38
39
40
41
# File 'lib/fontisan/pipeline/output_writer.rb', line 37

def initialize(output_path, format, options = {})
  @output_path = output_path
  @format = format
  @options = options
end

Instance Attribute Details

#formatSymbol (readonly)

Returns Target format.

Returns:

  • (Symbol)

    Target format



26
27
28
# File 'lib/fontisan/pipeline/output_writer.rb', line 26

def format
  @format
end

#optionsHash (readonly)

Returns Writing options.

Returns:

  • (Hash)

    Writing options



29
30
31
# File 'lib/fontisan/pipeline/output_writer.rb', line 29

def options
  @options
end

#output_pathString (readonly)

Returns Output file path.

Returns:

  • (String)

    Output file path



23
24
25
# File 'lib/fontisan/pipeline/output_writer.rb', line 23

def output_path
  @output_path
end

Instance Method Details

#write(tables) ⇒ Integer

Write font tables to output file

Parameters:

  • tables (Hash<String, String>, Hash)

    Font tables (tag => binary data) or special format result

Returns:

  • (Integer)

    Number of bytes written

Raises:

  • (ArgumentError)

    If format is unsupported or options don't apply



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fontisan/pipeline/output_writer.rb', line 48

def write(tables)
  # Catch cross-format misuse before delegating, so the error message
  # is consistent regardless of whether the format goes through
  # FormatConverter (outline conversions) or this writer (packaging
  # changes for WOFF/WOFF2).
  Converters::FormatConverter.validate_options_for_target!(@format,
                                                           @options)

  case @format
  when :ttf, :otf
    write_sfnt(tables)
  when :woff
    write_woff(tables)
  when :woff2
    write_woff2(tables)
  when :svg
    write_svg(tables)
  else
    raise ArgumentError, "Unsupported output format: #{@format}"
  end
end