### Home Classes Methods

### In Files

- lib/prawn/document/graphics_state.rb

### Methods

- #close_graphics_state
- #graphic_stack
- #graphic_state
- #open_graphics_state
- #restore_graphics_state
- #save_graphics_state

### Class/Module Index

Quicksearch

- Prawn
- Prawn::Configurable
- Prawn::Document
- Prawn::Document::BoundingBox
- Prawn::Document::ColumnBox
- Prawn::Document::GraphicsState
- Prawn::Document::Grid
- Prawn::Document::GridBox
- Prawn::Document::Internals
- Prawn::Document::Security
- Prawn::Document::Snapshot
- Prawn::Encoding
- Prawn::Errors
- Prawn::Font
- Prawn::Font::AFM
- Prawn::Font::DFont
- Prawn::Font::TTF
- Prawn::FontMetricCache
- Prawn::Graphics
- Prawn::Graphics::CapStyle
- Prawn::Graphics::Color
- Prawn::Graphics::Dash
- Prawn::Graphics::JoinStyle
- Prawn::Graphics::Patterns
- Prawn::Graphics::Transformation
- Prawn::Graphics::Transparency
- Prawn::ImageHandler
- Prawn::Images
- Prawn::Images::Image
- Prawn::Images::JPG
- Prawn::Images::PNG
- Prawn::Measurements
- Prawn::SoftMask
- Prawn::Stamp
- Prawn::SynchronizedCache
- Prawn::Table
- Prawn::Table::Cell
- Prawn::Table::Cell::Image
- Prawn::Table::Cell::InTable
- Prawn::Table::Cell::SpanDummy
- Prawn::Table::Cell::Subtable
- Prawn::Table::Cell::Text
- Prawn::Table::Cells
- Prawn::Table::ColumnWidthCalculator
- Prawn::Text
- Prawn::Text::Box
- Prawn::Text::Formatted
- Prawn::Text::Formatted::Box
- Prawn::Text::Formatted::Fragment
- Prawn::Text::Formatted::Parser
- Prawn::ThreadLocalCache
- PDF
- PDF::Core
- PDF::Core::Reference
- PDF::Core::Stream
- Arcfour
- Numeric

No matching classes.

# Prawn::Document::GraphicsState

### Public Instance Methods

close_graphics_state() click to toggle source

    # File lib/prawn/document/graphics_state.rb, line 37
    def close_graphics_state
      add_content "Q"
    end

graphic_stack() click to toggle source

    # File lib/prawn/document/graphics_state.rb, line 61
    def graphic_stack
      state.page.stack
    end

graphic_state() click to toggle source

    # File lib/prawn/document/graphics_state.rb, line 65
    def graphic_state
      save_graphics_state unless graphic_stack.current_state
      graphic_stack.current_state
    end

open_graphics_state() click to toggle source

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

    # File lib/prawn/document/graphics_state.rb, line 33
    def open_graphics_state
      add_content "q"
    end

restore_graphics_state() click to toggle source

Pops the last saved graphics state off the graphics state stack and restores the state to those values

    # File lib/prawn/document/graphics_state.rb, line 52
    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) click to toggle source

    # File lib/prawn/document/graphics_state.rb, line 41
    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

[Validate]

Generated with the Darkfish Rdoc Generator 2.