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)

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

    Writing options



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

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



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

def format
  @format
end

#optionsHash (readonly)

Returns Writing options.

Returns:

  • (Hash)

    Writing options



31
32
33
# File 'lib/fontisan/pipeline/output_writer.rb', line 31

def options
  @options
end

#output_pathString (readonly)

Returns Output file path.

Returns:

  • (String)

    Output file path



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

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fontisan/pipeline/output_writer.rb', line 49

def write(tables)
  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