Class: PDF::Core::GraphicStateStack

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/core/graphics_state.rb

Overview

Graphics state saving and restoring

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(previous_state = nil) ⇒ GraphicStateStack

Returns a new instance of GraphicStateStack.

Parameters:

Source Code
lib/pdf/core/graphics_state.rb, line 11
11
def initialize(previous_state = nil)
12
  self.stack = [GraphicState.new(previous_state)]
13
end

Instance Attribute Details

#stackObject

Graphic state stack

Source Code
lib/pdf/core/graphics_state.rb, line 8
8
def stack
9
  @stack
10
end

Instance Method Details

#current_stateGraphicState

Current graphic state

Returns:

Source Code
lib/pdf/core/graphics_state.rb, line 37
37
def current_state
38
  stack.last
39
end

#empty?Boolean

Tells whether there are no saved graphic states

Returns:

  • (Boolean)

See Also:

Source Code
lib/pdf/core/graphics_state.rb, line 53
53
def empty?
54
  stack.empty?
55
end

#present?Boolean

Tells whether there are any saved graphic states

Returns:

  • (Boolean)

See Also:

Source Code
lib/pdf/core/graphics_state.rb, line 45
45
def present?
46
  !stack.empty?
47
end

#restore_graphic_statevoid

This method returns an undefined value.

Restores previous graphic state

Source Code
lib/pdf/core/graphics_state.rb, line 26
26
def restore_graphic_state
27
  if stack.empty?
28
    raise PDF::Core::Errors::EmptyGraphicStateStack,
29
      "\n You have reached the end of the graphic state stack"
30
  end
31
  stack.pop
32
end

#save_graphic_state(graphic_state = nil) ⇒ void

This method returns an undefined value.

Pushes graphic state onto stack

Parameters:

Source Code
lib/pdf/core/graphics_state.rb, line 19
19
def save_graphic_state(graphic_state = nil)
20
  stack.push(GraphicState.new(graphic_state || current_state))
21
end