Class: Origami::Graphics::State

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeState

Returns a new instance of State.



43
44
45
46
47
48
49
# File 'lib/origami/graphics/state.rb', line 43

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

  reset
end

Instance Attribute Details

#alpha_constantObject

Returns the value of attribute alpha_constant.



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

def alpha_constant
  @alpha_constant
end

#alpha_sourceObject

Returns the value of attribute alpha_source.



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

def alpha_source
  @alpha_source
end

#blend_modeObject

Returns the value of attribute blend_mode.



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

def blend_mode
  @blend_mode
end

#clipping_pathObject

Returns the value of attribute clipping_path.



33
34
35
# File 'lib/origami/graphics/state.rb', line 33

def clipping_path
  @clipping_path
end

#ctmObject

Device-independent parameters.



32
33
34
# File 'lib/origami/graphics/state.rb', line 32

def ctm
  @ctm
end

#current_pathObject (readonly)

Returns the value of attribute current_path.



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

def current_path
  @current_path
end

#dash_patternObject

Returns the value of attribute dash_pattern.



36
37
38
# File 'lib/origami/graphics/state.rb', line 36

def dash_pattern
  @dash_pattern
end

#line_capObject

Returns the value of attribute line_cap.



36
37
38
# File 'lib/origami/graphics/state.rb', line 36

def line_cap
  @line_cap
end

#line_joinObject

Returns the value of attribute line_join.



36
37
38
# File 'lib/origami/graphics/state.rb', line 36

def line_join
  @line_join
end

#line_widthObject

Returns the value of attribute line_width.



36
37
38
# File 'lib/origami/graphics/state.rb', line 36

def line_width
  @line_width
end

#miter_limitObject

Returns the value of attribute miter_limit.



36
37
38
# File 'lib/origami/graphics/state.rb', line 36

def miter_limit
  @miter_limit
end

#nonstroking_colorObject

Returns the value of attribute nonstroking_color.



34
35
36
# File 'lib/origami/graphics/state.rb', line 34

def nonstroking_color
  @nonstroking_color
end

#nonstroking_colorspaceObject

Returns the value of attribute nonstroking_colorspace.



34
35
36
# File 'lib/origami/graphics/state.rb', line 34

def nonstroking_colorspace
  @nonstroking_colorspace
end

#rendering_intentObject

Returns the value of attribute rendering_intent.



37
38
39
# File 'lib/origami/graphics/state.rb', line 37

def rendering_intent
  @rendering_intent
end

#soft_maskObject

Returns the value of attribute soft_mask.



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

def soft_mask
  @soft_mask
end

#stroke_adjustmentObject

Returns the value of attribute stroke_adjustment.



38
39
40
# File 'lib/origami/graphics/state.rb', line 38

def stroke_adjustment
  @stroke_adjustment
end

#stroking_colorObject

Returns the value of attribute stroking_color.



34
35
36
# File 'lib/origami/graphics/state.rb', line 34

def stroking_color
  @stroking_color
end

#stroking_colorspaceObject

Returns the value of attribute stroking_colorspace.



34
35
36
# File 'lib/origami/graphics/state.rb', line 34

def stroking_colorspace
  @stroking_colorspace
end

#text_stateObject

Returns the value of attribute text_state.



35
36
37
# File 'lib/origami/graphics/state.rb', line 35

def text_state
  @text_state
end

Instance Method Details

#resetObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/origami/graphics/state.rb', line 51

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:



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

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



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/origami/graphics/state.rb', line 70

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

#set_nonstroking_color(color, space = @nonstroking_colorspace) ⇒ Object



136
137
138
139
140
141
# File 'lib/origami/graphics/colors.rb', line 136

def set_nonstroking_color(color, space = @nonstroking_colorspace)
  check_color(space, color)

  @nonstroking_colorspace = space
  @nonstroking_color = color
end

#set_nonstroking_colorspace(space) ⇒ Object



149
150
151
152
153
# File 'lib/origami/graphics/colors.rb', line 149

def set_nonstroking_colorspace(space)
  check_color_space(space, @nonstroking_color)

  @nonstroking_color_space = space
end

#set_stroking_color(color, space = @stroking_color_space) ⇒ Object



129
130
131
132
133
134
# File 'lib/origami/graphics/colors.rb', line 129

def set_stroking_color(color, space = @stroking_color_space)
  check_color(space, color)

  @stroking_colorspace = space
  @stroking_color = color
end

#set_stroking_colorspace(space) ⇒ Object



143
144
145
146
147
# File 'lib/origami/graphics/colors.rb', line 143

def set_stroking_colorspace(space)
  check_color_space(space, @stroking_color)

  @stroking_color_space = space
end