Class: Vectory::Conversion::InkscapeStrategy

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

Overview

Inkscape-based conversion strategy

Handles conversions using Inkscape, including:

  • SVG ↔ EPS

  • SVG ↔ PS

  • SVG ↔ EMF

  • SVG ↔ PDF

  • EPS/PS → PDF

Constant Summary collapse

SUPPORTED_CONVERSIONS =

Inkscape supports bidirectional conversion with SVG as source/target

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

Instance Method Summary collapse

Instance Method Details

#available?Boolean

Check if Inkscape is available

Returns:

  • (Boolean)

    true if Inkscape can be found in PATH



73
74
75
76
77
78
# File 'lib/vectory/conversion/inkscape_strategy.rb', line 73

def available?
  InkscapeWrapper.instance.send(:inkscape_path)
  true
rescue Vectory::InkscapeNotFoundError
  false
end

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

Convert content using Inkscape

Parameters:

  • content (String)

    the input content to convert

  • input_format (Symbol)

    the input format

  • output_format (Symbol)

    the output format

  • options (Hash)

    additional options

Options Hash (**options):

  • :plain (Boolean)

    export plain SVG (for SVG output)

  • :output_class (Class)

    the class to instantiate with result

Returns:

Raises:



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vectory/conversion/inkscape_strategy.rb', line 40

def convert(content, input_format:, output_format:, **options)
  output_class = options.fetch(:output_class) do
    format_class(output_format)
  end

  InkscapeWrapper.convert(
    content: content,
    input_format: input_format,
    output_format: output_format,
    output_class: output_class,
    plain: options[:plain] || false,
  )
end

#height(content, format) ⇒ Integer

Query the height of content

Parameters:

  • content (String)

    the vector content

  • format (Symbol)

    the format of the content

Returns:

  • (Integer)

    the height in pixels



101
102
103
# File 'lib/vectory/conversion/inkscape_strategy.rb', line 101

def height(content, format)
  InkscapeWrapper.instance.height(content, format)
end

#supported_conversionsArray<Array<Symbol>>

Get supported conversions

Returns:

  • (Array<Array<Symbol>>)

    array of [input, output] format pairs



66
67
68
# File 'lib/vectory/conversion/inkscape_strategy.rb', line 66

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 Inkscape supports this conversion



59
60
61
# File 'lib/vectory/conversion/inkscape_strategy.rb', line 59

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

#tool_nameString

Get the tool name

Returns:

  • (String)

    “inkscape”



83
84
85
# File 'lib/vectory/conversion/inkscape_strategy.rb', line 83

def tool_name
  "inkscape"
end

#width(content, format) ⇒ Integer

Query the width of content

Parameters:

  • content (String)

    the vector content

  • format (Symbol)

    the format of the content

Returns:

  • (Integer)

    the width in pixels



92
93
94
# File 'lib/vectory/conversion/inkscape_strategy.rb', line 92

def width(content, format)
  InkscapeWrapper.instance.width(content, format)
end