Module: Prawn::Document::GraphicsState
- Included in:
- Prawn::Document
- Defined in:
- lib/prawn/document/graphics_state.rb
Instance Method Summary collapse
- #close_graphics_state ⇒ Object
- #graphic_stack ⇒ Object
- #graphic_state ⇒ Object
-
#open_graphics_state ⇒ Object
Pushes the current graphics state on to the graphics state stack so we can restore it when finished with a change we want to isolate (such as modifying the transformation matrix).
-
#restore_graphics_state ⇒ Object
Pops the last saved graphics state off the graphics state stack and restores the state to those values.
- #save_graphics_state(graphic_state = nil) ⇒ Object
Instance Method Details
#close_graphics_state ⇒ Object
38 39 40 |
# File 'lib/prawn/document/graphics_state.rb', line 38 def close_graphics_state add_content "Q" end |
#graphic_stack ⇒ Object
62 63 64 |
# File 'lib/prawn/document/graphics_state.rb', line 62 def graphic_stack state.page.stack end |
#graphic_state ⇒ Object
66 67 68 69 |
# File 'lib/prawn/document/graphics_state.rb', line 66 def graphic_state save_graphics_state unless graphic_stack.current_state graphic_stack.current_state end |
#open_graphics_state ⇒ Object
Pushes the current graphics state on to the graphics state stack so we can restore it when finished with a change we want to isolate (such as modifying the transformation matrix). Used in pairs with restore_graphics_state or passed a block
Example without a block:
save_graphics_state
rotate 30
text "rotated text"
restore_graphics_state
Example with a block:
save_graphics_state do
rotate 30
text "rotated text"
end
34 35 36 |
# File 'lib/prawn/document/graphics_state.rb', line 34 def open_graphics_state add_content "q" end |
#restore_graphics_state ⇒ Object
Pops the last saved graphics state off the graphics state stack and restores the state to those values
53 54 55 56 57 58 59 60 |
# File 'lib/prawn/document/graphics_state.rb', line 53 def restore_graphics_state if graphic_stack.empty? raise PDF::Core::Errors::EmptyGraphicStateStack, "\n You have reached the end of the graphic state stack" end close_graphics_state graphic_stack.restore_graphic_state end |
#save_graphics_state(graphic_state = nil) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/prawn/document/graphics_state.rb', line 42 def save_graphics_state(graphic_state = nil) graphic_stack.save_graphic_state(graphic_state) open_graphics_state if block_given? yield restore_graphics_state end end |