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:



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

#stackObject

Graphic state stack



8
9
10
# File 'lib/pdf/core/graphics_state.rb', line 8

def stack
  @stack
end

Instance Method Details

#current_stateGraphicState

Current graphic state

Returns:



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

Returns:

  • (Boolean)

See Also:



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

Returns:

  • (Boolean)

See Also:



45
46
47
# File 'lib/pdf/core/graphics_state.rb', line 45

def present?
  !stack.empty?
end

#restore_graphic_statevoid

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

Parameters:



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