Class: Vectory::Conversion::GhostscriptStrategy

Inherits:
Strategy
  • Object
show all
Defined in:
lib/vectory/conversion/ghostscript_strategy.rb

Overview

Ghostscript-based conversion strategy

Handles PS/EPS → PDF conversions using Ghostscript. Ghostscript is used for its accurate BoundingBox preservation.

Constant Summary collapse

SUPPORTED_CONVERSIONS =

Ghostscript supports PS/EPS → PDF conversions

[
  %i[ps pdf],
  %i[eps pdf],
].freeze

Instance Method Summary collapse

Instance Method Details

#available?Boolean

Check if Ghostscript is available

Returns:

  • (Boolean)

    true if Ghostscript can be found



62
63
64
# File 'lib/vectory/conversion/ghostscript_strategy.rb', line 62

def available?
  GhostscriptWrapper.available?
end

#convert(content, input_format:, output_format:, **options) ⇒ String

Convert PS/EPS content to PDF using Ghostscript

Parameters:

  • content (String)

    the PS/EPS content to convert

  • input_format (Symbol)

    the input format (:ps or :eps)

  • output_format (Symbol)

    the output format (must be :pdf)

  • options (Hash)

    additional options

Options Hash (**options):

  • :eps_crop (Boolean)

    use EPSCrop for better BoundingBox handling

Returns:

  • (String)

    the PDF content

Raises:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vectory/conversion/ghostscript_strategy.rb', line 28

def convert(content, input_format:, output_format:, **options)
  unless output_format == :pdf
    raise ArgumentError,
          "Ghostscript only supports PDF output, got: #{output_format}"
  end

  unless %i[ps eps].include?(input_format)
    raise ArgumentError,
          "Ghostscript only supports PS/EPS input, got: #{input_format}"
  end

  GhostscriptWrapper.convert(content,
                             eps_crop: options[:eps_crop] || false)
end

#supported_conversionsArray<Array<Symbol>>

Get supported conversions

Returns:

  • (Array<Array<Symbol>>)

    array of [input, output] format pairs



55
56
57
# File 'lib/vectory/conversion/ghostscript_strategy.rb', line 55

def supported_conversions
  SUPPORTED_CONVERSIONS
end

#supports?(input_format, output_format) ⇒ Boolean

Check if this conversion is supported

Parameters:

  • input_format (Symbol)

    the input format

  • output_format (Symbol)

    the output format

Returns:

  • (Boolean)

    true if Ghostscript supports this conversion



48
49
50
# File 'lib/vectory/conversion/ghostscript_strategy.rb', line 48

def supports?(input_format, output_format)
  SUPPORTED_CONVERSIONS.include?([input_format, output_format])
end

#tool_nameString

Get the tool name

Returns:

  • (String)

    “ghostscript”



69
70
71
# File 'lib/vectory/conversion/ghostscript_strategy.rb', line 69

def tool_name
  "ghostscript"
end