Class: Postsvg::Translation::Context

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

Overview

Mutable translation context carried through the SVG tree walk. Holds the emitter, the graphics state stack (so handlers can emit gsave/grestore around transforms), and the bounding box accumulator.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(emitter: RecordEmitter.new, graphics: GraphicsStack.new, bounding_box: BoundingBox.empty, clip_path_registry: ::Postsvg::Svg::ClipPathRegistry.empty, options: {}) ⇒ Context

Returns a new instance of Context.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/postsvg/translation/context.rb', line 13

def initialize(emitter: RecordEmitter.new,
               graphics: GraphicsStack.new,
               bounding_box: BoundingBox.empty,
               clip_path_registry: ::Postsvg::Svg::ClipPathRegistry.empty,
               options: {})
  @emitter = emitter
  @graphics = graphics
  @bounding_box = bounding_box
  @clip_path_registry = clip_path_registry
  @options = options.freeze
end

Instance Attribute Details

#bounding_boxObject (readonly)

Returns the value of attribute bounding_box.



10
11
12
# File 'lib/postsvg/translation/context.rb', line 10

def bounding_box
  @bounding_box
end

#clip_path_registryObject (readonly)

Returns the value of attribute clip_path_registry.



10
11
12
# File 'lib/postsvg/translation/context.rb', line 10

def clip_path_registry
  @clip_path_registry
end

#emitterObject (readonly)

Returns the value of attribute emitter.



10
11
12
# File 'lib/postsvg/translation/context.rb', line 10

def emitter
  @emitter
end

#graphicsObject (readonly)

Returns the value of attribute graphics.



10
11
12
# File 'lib/postsvg/translation/context.rb', line 10

def graphics
  @graphics
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/postsvg/translation/context.rb', line 10

def options
  @options
end

Instance Method Details

#eps?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/postsvg/translation/context.rb', line 29

def eps?
  options.fetch(:eps, false)
end

#expand_bbox!(x_range, y_range) ⇒ Object



25
26
27
# File 'lib/postsvg/translation/context.rb', line 25

def expand_bbox!(x_range, y_range)
  @bounding_box = @bounding_box.expand(x_range, y_range)
end