Class: PDF::Core::GraphicStateStack
- Inherits:
-
Object
- Object
- PDF::Core::GraphicStateStack
- Defined in:
- lib/pdf/core/graphics_state.rb
Overview
Graphics state saving and restoring
Instance Attribute Summary collapse
-
#stack ⇒ Object
Graphic state stack.
Instance Method Summary collapse
-
#current_state ⇒ GraphicState
Current graphic state.
-
#empty? ⇒ Boolean
Tells whether there are no saved graphic states.
-
#initialize(previous_state = nil) ⇒ GraphicStateStack
constructor
A new instance of GraphicStateStack.
-
#present? ⇒ Boolean
Tells whether there are any saved graphic states.
-
#restore_graphic_state ⇒ void
Restores previous graphic state.
-
#save_graphic_state(graphic_state = nil) ⇒ void
Pushes graphic state onto stack.
Constructor Details
#initialize(previous_state = nil) ⇒ GraphicStateStack
Returns a new instance of GraphicStateStack.
11 12 13 |
# File 'lib/pdf/core/graphics_state.rb', line 11 def initialize(previous_state = nil) self.stack = [GraphicState.new(previous_state)] end |
Instance Attribute Details
#stack ⇒ Object
Graphic state stack
8 9 10 |
# File 'lib/pdf/core/graphics_state.rb', line 8 def stack @stack end |
Instance Method Details
#current_state ⇒ GraphicState
Current graphic state
37 38 39 |
# File 'lib/pdf/core/graphics_state.rb', line 37 def current_state stack.last end |
#empty? ⇒ Boolean
Tells whether there are no saved graphic states
53 54 55 |
# File 'lib/pdf/core/graphics_state.rb', line 53 def empty? stack.empty? end |
#present? ⇒ Boolean
Tells whether there are any saved graphic states
45 46 47 |
# File 'lib/pdf/core/graphics_state.rb', line 45 def present? !stack.empty? end |
#restore_graphic_state ⇒ void
This method returns an undefined value.
Restores previous graphic state
26 27 28 29 30 31 32 |
# File 'lib/pdf/core/graphics_state.rb', line 26 def restore_graphic_state if stack.empty? raise PDF::Core::Errors::EmptyGraphicStateStack, "\n You have reached the end of the graphic state stack" end stack.pop end |
#save_graphic_state(graphic_state = nil) ⇒ void
This method returns an undefined value.
Pushes graphic state onto stack
19 20 21 |
# File 'lib/pdf/core/graphics_state.rb', line 19 def save_graphic_state(graphic_state = nil) stack.push(GraphicState.new(graphic_state || current_state)) end |