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.



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

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.



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

def alpha_constant
  @alpha_constant
end

#alpha_sourceObject

Returns the value of attribute alpha_source.



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

def alpha_source
  @alpha_source
end

#blend_modeObject

Returns the value of attribute blend_mode.



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

def blend_mode
  @blend_mode
end

#clipping_pathObject

Returns the value of attribute clipping_path.



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

def clipping_path
  @clipping_path
end

#ctmObject

Device-independent parameters.



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

def ctm
  @ctm
end

#current_pathObject (readonly)

Returns the value of attribute current_path.



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

def current_path
  @current_path
end

#dash_patternObject

Returns the value of attribute dash_pattern.



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

def dash_pattern
  @dash_pattern
end

#line_capObject

Returns the value of attribute line_cap.



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

def line_cap
  @line_cap
end

#line_joinObject

Returns the value of attribute line_join.



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

def line_join
  @line_join
end

#line_widthObject

Returns the value of attribute line_width.



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

def line_width
  @line_width
end

#miter_limitObject

Returns the value of attribute miter_limit.



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

def miter_limit
  @miter_limit
end

#nonstroking_colorObject

Returns the value of attribute nonstroking_color.



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

def nonstroking_color
  @nonstroking_color
end

#nonstroking_colorspaceObject

Returns the value of attribute nonstroking_colorspace.



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

def nonstroking_colorspace
  @nonstroking_colorspace
end

#rendering_intentObject

Returns the value of attribute rendering_intent.



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

def rendering_intent
  @rendering_intent
end

#soft_maskObject

Returns the value of attribute soft_mask.



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

def soft_mask
  @soft_mask
end

#stroke_adjustmentObject

Returns the value of attribute stroke_adjustment.



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

def stroke_adjustment
  @stroke_adjustment
end

#stroking_colorObject

Returns the value of attribute stroking_color.



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

def stroking_color
  @stroking_color
end

#stroking_colorspaceObject

Returns the value of attribute stroking_colorspace.



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

def stroking_colorspace
  @stroking_colorspace
end

#text_stateObject

Returns the value of attribute text_state.



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

def text_state
  @text_state
end

Instance Method Details

#resetObject



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

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:



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

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



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

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



139
140
141
142
143
144
# File 'lib/origami/graphics/colors.rb', line 139

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

    @nonstroking_colorspace = space
    @nonstroking_color = color
end

#set_nonstroking_colorspace(space) ⇒ Object



152
153
154
155
156
# File 'lib/origami/graphics/colors.rb', line 152

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



132
133
134
135
136
137
# File 'lib/origami/graphics/colors.rb', line 132

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



146
147
148
149
150
# File 'lib/origami/graphics/colors.rb', line 146

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

    @stroking_color_space = space
end