Class: Fontisan::Pipeline::TransformationPipeline

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

Overview

Orchestrates universal font transformation pipeline

This is the main entry point for font conversion operations. It coordinates:

  1. Format detection (via FormatDetector)

  2. Font loading (via FontLoader)

  3. Variation resolution (via VariationResolver)

  4. Format conversion (via FormatConverter)

  5. Output writing (via OutputWriter)

  6. Validation (optional, via Validation::Validator)

The pipeline follows a clear MECE architecture where each phase has a single responsibility and produces well-defined outputs.

Examples:

Basic TTF to OTF conversion

pipeline = TransformationPipeline.new("input.ttf", "output.otf")
result = pipeline.transform
puts result[:success] # => true

Variable font instance generation

pipeline = TransformationPipeline.new(
  "variable.ttf",
  "bold.ttf",
  coordinates: { "wght" => 700.0 }
)
result = pipeline.transform

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_path, output_path, options = {}) ⇒ TransformationPipeline

Initialize transformation pipeline

Parameters:

  • input_path (String)

    Path to input font

  • output_path (String)

    Path to output font

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

    Transformation options

Options Hash (options):

  • :target_format (Symbol)

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

  • :coordinates (Hash)

    Instance coordinates (for variable fonts)

  • :instance_index (Integer)

    Named instance index

  • :preserve_variation (Boolean)

    Preserve variation data (default: auto)

  • :validate (Boolean)

    Validate output (default: true)

  • :verbose (Boolean)

    Verbose output (default: false)



58
59
60
61
62
63
64
65
# File 'lib/fontisan/pipeline/transformation_pipeline.rb', line 58

def initialize(input_path, output_path, options = {})
  @input_path = input_path
  @output_path = output_path
  @options = default_options.merge(options)
  @variation_strategy = nil

  validate_paths!
end

Instance Attribute Details

#input_pathString (readonly)

Returns Input file path.

Returns:

  • (String)

    Input file path



39
40
41
# File 'lib/fontisan/pipeline/transformation_pipeline.rb', line 39

def input_path
  @input_path
end

#optionsHash (readonly)

Returns Transformation options.

Returns:

  • (Hash)

    Transformation options



45
46
47
# File 'lib/fontisan/pipeline/transformation_pipeline.rb', line 45

def options
  @options
end

#output_pathString (readonly)

Returns Output file path.

Returns:

  • (String)

    Output file path



42
43
44
# File 'lib/fontisan/pipeline/transformation_pipeline.rb', line 42

def output_path
  @output_path
end

Instance Method Details

#transformHash

Execute transformation pipeline

This is the main entry point. It orchestrates:

  1. Format detection

  2. Font loading

  3. Variation resolution

  4. Format conversion

  5. Output writing

  6. Validation (optional)

Returns:

  • (Hash)

    Transformation result with :success, :output_path, :details

Raises:

  • (Error)

    If transformation fails



79
80
81
82
83
84
85
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
112
113
# File 'lib/fontisan/pipeline/transformation_pipeline.rb', line 79

def transform
  log "Starting transformation: #{@input_path}#{@output_path}"

  # Phase 1: Detect input format
  detection = detect_input_format
  log "Detected: #{detection[:format]} (#{detection[:variation_type]})"

  # Phase 2: Load font
  font = load_font(detection)
  log "Loaded: #{font.class.name}"

  # Phase 3: Resolve variation
  tables = resolve_variation(font, detection)
  log "Resolved variation using #{@variation_strategy} strategy"

  # Phase 4: Convert format
  tables = convert_format(tables, detection)
  log "Converted to #{target_format}"

  # Phase 5: Write output
  write_output(tables, detection)
  log "Written to #{@output_path}"

  # Phase 6: Validate (optional)
  validate_output if @options[:validate] && !same_format_conversion? && !export_only_format?
  log "Validation passed" if @options[:validate] && !export_only_format?

  {
    success: true,
    output_path: @output_path,
    details: build_details(detection),
  }
rescue StandardError => e
  handle_error(e)
end