Class: Postsvg::GraphicsStack
- Inherits:
-
Object
- Object
- Postsvg::GraphicsStack
- Defined in:
- lib/postsvg/graphics_stack.rb
Overview
LIFO stack of immutable GraphicsContext snapshots. gsave pushes
a duplicate of the current top; grestore pops. Popping an empty
stack is a no-op (mirrors PLRM ยง7.2.2).
Instance Method Summary collapse
- #current ⇒ Object
- #depth ⇒ Object
-
#initialize(initial: GraphicsContext.new) ⇒ GraphicsStack
constructor
A new instance of GraphicsStack.
- #pop ⇒ Object (also: #grestore)
- #push ⇒ Object (also: #gsave)
- #replace(new_state) ⇒ Object
- #update(**overrides) ⇒ Object
Constructor Details
#initialize(initial: GraphicsContext.new) ⇒ GraphicsStack
Returns a new instance of GraphicsStack.
8 9 10 |
# File 'lib/postsvg/graphics_stack.rb', line 8 def initialize(initial: GraphicsContext.new) @stack = [initial] end |
Instance Method Details
#current ⇒ Object
12 13 14 |
# File 'lib/postsvg/graphics_stack.rb', line 12 def current @stack.last end |
#depth ⇒ Object
30 31 32 |
# File 'lib/postsvg/graphics_stack.rb', line 30 def depth @stack.size end |
#pop ⇒ Object Also known as: grestore
22 23 24 25 26 27 |
# File 'lib/postsvg/graphics_stack.rb', line 22 def pop return current if @stack.size == 1 @stack.pop current end |
#push ⇒ Object Also known as: gsave
16 17 18 19 |
# File 'lib/postsvg/graphics_stack.rb', line 16 def push @stack.push(current) self end |
#replace(new_state) ⇒ Object
34 35 36 37 |
# File 'lib/postsvg/graphics_stack.rb', line 34 def replace(new_state) @stack[-1] = new_state new_state end |
#update(**overrides) ⇒ Object
39 40 41 |
# File 'lib/postsvg/graphics_stack.rb', line 39 def update(**overrides) replace(current.with(**overrides)) end |