Method: HexaPDF::Content::Canvas#save_graphics_state
- Defined in:
- lib/hexapdf/content/canvas.rb
#save_graphics_state ⇒ Object
:call-seq:
canvas.save_graphics_state => canvas
canvas.save_graphics_state { block } => canvas
Saves the current graphics state and returns self.
If invoked without a block a corresponding call to #restore_graphics_state must be done to ensure proper nesting. Otherwise, i.e. when invoked with a block, the graphics state is automatically restored when the block is finished.
Any saved graphics states are also restored when the content stream associated with the canvas is serialized to ensure proper nesting.
Examples:
#>pdf
# With a block
canvas.save_graphics_state do
canvas.stroke_color("hp-blue") # After the block the color is reset
canvas.line(20, 20, 70, 180).stroke
end
canvas.line(60, 20, 110, 180).stroke
# Same without a block
canvas.save_graphics_state.
stroke_color("red").
line(100, 20, 150, 180).stroke.
restore_graphics_state
canvas.line(140, 20, 190, 180).stroke
See: PDF2.0 s8.4.2, #restore_graphics_state
360 361 362 363 364 365 366 367 368 369 |
# File 'lib/hexapdf/content/canvas.rb', line 360 def save_graphics_state raise_unless_at_page_description_level invoke0(:q) @font_stack.push(@font) if block_given? yield restore_graphics_state end self end |