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)



51
52
53
54
55
56
57
58
# File 'lib/fontisan/pipeline/transformation_pipeline.rb', line 51

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



32
33
34
# File 'lib/fontisan/pipeline/transformation_pipeline.rb', line 32

def input_path
  @input_path
end

#optionsHash (readonly)

Returns Transformation options.

Returns:

  • (Hash)

    Transformation options



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

def options
  @options
end

#output_pathString (readonly)

Returns Output file path.

Returns:

  • (String)

    Output file path



35
36
37
# File 'lib/fontisan/pipeline/transformation_pipeline.rb', line 35

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



72
73
74
75
76
77
78
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
# File 'lib/fontisan/pipeline/transformation_pipeline.rb', line 72

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