Class: Postsvg::Renderer

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

Overview

Top-level orchestrator for PS -> SVG. Owns lifecycle: BoundingBox pre-scan, builder open/close, visitor dispatch.

Constant Summary collapse

MAX_OUTPUT_BYTES =
100 * 1024 * 1024

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(program, options) ⇒ Renderer

Returns a new instance of Renderer.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
# File 'lib/postsvg/renderer.rb', line 15

def initialize(program, options)
  raise ArgumentError, "program must be a Model::Program" unless program.is_a?(Model::Program)

  @program = program
  @options = options
  @builder = SvgBuilder.new
  @visitor = Visitors::PsVisitor.new(builder: @builder)
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



13
14
15
# File 'lib/postsvg/renderer.rb', line 13

def builder
  @builder
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/postsvg/renderer.rb', line 13

def options
  @options
end

#programObject (readonly)

Returns the value of attribute program.



13
14
15
# File 'lib/postsvg/renderer.rb', line 13

def program
  @program
end

#visitorObject (readonly)

Returns the value of attribute visitor.



13
14
15
# File 'lib/postsvg/renderer.rb', line 13

def visitor
  @visitor
end

Class Method Details

.call(program, options = Options.new) ⇒ Object



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

def self.call(program, options = Options.new)
  new(program, options).call
end

Instance Method Details

#callObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/postsvg/renderer.rb', line 24

def call
  open_svg
  wrap_y_flip do
    visitor.visit_program(program)
  rescue Postsvg::QuitSignal
    # PS +quit+ ends program execution; suppress and finalize SVG.
  end
  builder.close_svg
  result = builder.to_s
  enforce_size_limit(result)
  result
end