Class: PDF::Core::GraphicStateStack

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(previous_state = nil) ⇒ GraphicStateStack

Returns a new instance of GraphicStateStack.



17
18
19
# File 'lib/pdf/core/graphics_state.rb', line 17

def initialize(previous_state = nil)
  self.stack = [GraphicState.new(previous_state)]
end

Instance Attribute Details

#stackObject

Returns the value of attribute stack.



15
16
17
# File 'lib/pdf/core/graphics_state.rb', line 15

def stack
  @stack
end

Instance Method Details

#current_stateObject



33
34
35
# File 'lib/pdf/core/graphics_state.rb', line 33

def current_state
  stack.last
end

#empty?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/pdf/core/graphics_state.rb', line 41

def empty?
  stack.empty?
end

#present?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/pdf/core/graphics_state.rb', line 37

def present?
  !stack.empty?
end

#restore_graphic_stateObject



25
26
27
28
29
30
31
# File 'lib/pdf/core/graphics_state.rb', line 25

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) ⇒ Object



21
22
23
# File 'lib/pdf/core/graphics_state.rb', line 21

def save_graphic_state(graphic_state = nil)
  stack.push(GraphicState.new(graphic_state || current_state))
end