Class: Origami::Graphics::State

Inherits:
Object
  • Object
show all
Defined in:
lib/origami/graphics/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeState

Returns a new instance of State.



51
52
53
54
55
56
57
58
# File 'lib/origami/graphics/state.rb', line 51

def initialize
  
  @stack = []
  @current_path = []
  @text_state = Text::State.new

  self.reset
end

Instance Attribute Details

#alpha_constantObject

Returns the value of attribute alpha_constant.



47
48
49
# File 'lib/origami/graphics/state.rb', line 47

def alpha_constant
  @alpha_constant
end

#alpha_sourceObject

Returns the value of attribute alpha_source.



47
48
49
# File 'lib/origami/graphics/state.rb', line 47

def alpha_source
  @alpha_source
end

#blend_modeObject

Returns the value of attribute blend_mode.



47
48
49
# File 'lib/origami/graphics/state.rb', line 47

def blend_mode
  @blend_mode
end

#clipping_pathObject

Returns the value of attribute clipping_path.



41
42
43
# File 'lib/origami/graphics/state.rb', line 41

def clipping_path
  @clipping_path
end

#ctmObject

Device-independent parameters.



40
41
42
# File 'lib/origami/graphics/state.rb', line 40

def ctm
  @ctm
end

#current_pathObject (readonly)

Returns the value of attribute current_path.



49
50
51
# File 'lib/origami/graphics/state.rb', line 49

def current_path
  @current_path
end

#dash_patternObject

Returns the value of attribute dash_pattern.



44
45
46
# File 'lib/origami/graphics/state.rb', line 44

def dash_pattern
  @dash_pattern
end

#line_capObject

Returns the value of attribute line_cap.



44
45
46
# File 'lib/origami/graphics/state.rb', line 44

def line_cap
  @line_cap
end

#line_joinObject

Returns the value of attribute line_join.



44
45
46
# File 'lib/origami/graphics/state.rb', line 44

def line_join
  @line_join
end

#line_widthObject

Returns the value of attribute line_width.



44
45
46
# File 'lib/origami/graphics/state.rb', line 44

def line_width
  @line_width
end

#miter_limitObject

Returns the value of attribute miter_limit.



44
45
46
# File 'lib/origami/graphics/state.rb', line 44

def miter_limit
  @miter_limit
end

#nonstroking_colorObject

Returns the value of attribute nonstroking_color.



42
43
44
# File 'lib/origami/graphics/state.rb', line 42

def nonstroking_color
  @nonstroking_color
end

#nonstroking_colorspaceObject

Returns the value of attribute nonstroking_colorspace.



42
43
44
# File 'lib/origami/graphics/state.rb', line 42

def nonstroking_colorspace
  @nonstroking_colorspace
end

#rendering_intentObject

Returns the value of attribute rendering_intent.



45
46
47
# File 'lib/origami/graphics/state.rb', line 45

def rendering_intent
  @rendering_intent
end

#soft_maskObject

Returns the value of attribute soft_mask.



47
48
49
# File 'lib/origami/graphics/state.rb', line 47

def soft_mask
  @soft_mask
end

#stroke_adjustmentObject

Returns the value of attribute stroke_adjustment.



46
47
48
# File 'lib/origami/graphics/state.rb', line 46

def stroke_adjustment
  @stroke_adjustment
end

#stroking_colorObject

Returns the value of attribute stroking_color.



42
43
44
# File 'lib/origami/graphics/state.rb', line 42

def stroking_color
  @stroking_color
end

#stroking_colorspaceObject

Returns the value of attribute stroking_colorspace.



42
43
44
# File 'lib/origami/graphics/state.rb', line 42

def stroking_colorspace
  @stroking_colorspace
end

#text_stateObject

Returns the value of attribute text_state.



43
44
45
# File 'lib/origami/graphics/state.rb', line 43

def text_state
  @text_state
end

Instance Method Details

#resetObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/origami/graphics/state.rb', line 60

def reset

  @ctm = Matrix.identity(3)
  @clipping_path = nil
  @stroking_colorspace = @nonstroking_colorspace = Color::Space::DEVICE_GRAY
  @stroking_color = @nonstroking_color = [ 0.0 ] #black
  @text_state.reset
  @line_width = 1.0
  @line_cap = LineCapStyle::BUTT_CAP
  @line_join = LineJoinStyle::MITER_JOIN
  @miter_limit = 10.0
  @dash_pattern = DashPattern.new([], 0)
  @rendering_intent = Color::Intent::RELATIVE
  @stroke_adjustment = false
  @blend_mode = Color::BlendMode::NORMAL
  @soft_mask = :None
  @alpha_constant = 1.0
  @alpha_source = false

end

#restoreObject

Raises:



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/origami/graphics/state.rb', line 95

def restore
  raise GraphicsStateError, "Cannot restore context : empty stack" if @stack.empty?

  @ctm, @clipping_path,
  @stroking_colorspace, @nonstroking_colorspace,
  @stroking_color, @nonstroking_color,
  @text_state, @line_width, @line_cap, @line_join,
  @miter_limit, @dash_pattern, @rendering_intent,
  @stroke_adjustment,
  @blend_mode, @soft_mask, @alpha_constant, @alpha_source = @stack.pop
end

#saveObject



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/origami/graphics/state.rb', line 81

def save  
  context = 
  [
    @ctm, @clipping_path,
    @stroking_colorspace, @nonstroking_colorspace,
    @stroking_color, @nonstroking_color,
    @text_state, @line_width, @line_cap, @line_join,
    @miter_limit, @dash_pattern, @rendering_intent,
    @stroke_adjustment,
    @blend_mode, @soft_mask, @alpha_constant, @alpha_source
  ]
  @stack.push(context)
end