Class: Postsvg::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/postsvg/converter.rb

Overview

Converts PostScript/EPS to SVG by interpreting PostScript commands

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ps_content) ⇒ Converter

Returns a new instance of Converter.



11
12
13
14
15
16
17
# File 'lib/postsvg/converter.rb', line 11

def initialize(ps_content)
  @ps_content = ps_content
  @graphics_state = GraphicsState.new
  @svg_generator = SvgGenerator.new
  @stack = []
  @dictionary = {}
end

Instance Attribute Details

#graphics_stateObject (readonly)

Returns the value of attribute graphics_state.



9
10
11
# File 'lib/postsvg/converter.rb', line 9

def graphics_state
  @graphics_state
end

#ps_contentObject (readonly)

Returns the value of attribute ps_content.



9
10
11
# File 'lib/postsvg/converter.rb', line 9

def ps_content
  @ps_content
end

#svg_generatorObject (readonly)

Returns the value of attribute svg_generator.



9
10
11
# File 'lib/postsvg/converter.rb', line 9

def svg_generator
  @svg_generator
end

Instance Method Details

#convertObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/postsvg/converter.rb', line 19

def convert
  # Parse PostScript
  ast = Parser.parse(ps_content)

  # Extract BoundingBox for SVG viewBox
  extract_bounding_box

  # Execute PostScript commands
  execute_program(ast[:statements])

  # Generate SVG
  svg_generator.generate(
    width: @bbox_width,
    height: @bbox_height,
    viewbox: @viewbox,
  )
end