class Origami::Graphics::State
Attributes
alpha_constant[RW]
alpha_source[RW]
blend_mode[RW]
clipping_path[RW]
ctm[RW]
Device-independent parameters.
current_path[R]
dash_pattern[RW]
line_cap[RW]
line_join[RW]
line_width[RW]
miter_limit[RW]
nonstroking_color[RW]
nonstroking_colorspace[RW]
rendering_intent[RW]
soft_mask[RW]
stroke_adjustment[RW]
stroking_color[RW]
stroking_colorspace[RW]
text_state[RW]
Public Class Methods
new()
click to toggle source
# File lib/origami/graphics/state.rb, line 44 def initialize @stack = [] @current_path = [] @text_state = Text::State.new self.reset end
Public Instance Methods
reset()
click to toggle source
# 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
restore()
click to toggle source
# 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
save()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/origami/graphics/colors.rb, line 146 def set_stroking_colorspace(space) check_color_space(space, @stroking_color) @stroking_color_space = space end
Private Instance Methods
check_cmyk_color(color)
click to toggle source
# File lib/origami/graphics/colors.rb, line 192 def check_cmyk_color(color) color.is_a?(::Array) and color.length == 4 and color.all? {|c| (0..1).include?(c) } end
check_color(space, color)
click to toggle source
# File lib/origami/graphics/colors.rb, line 168 def check_color(space, color) valid_color = case space when Color::Space::DEVICE_GRAY check_gray_color(color) when Color::Space::DEVICE_RGB check_rgb_color(color) when Color::Space::DEVICE_CMYK check_cmyk_color(color) else raise InvalidColorError, "Unknown color space #{space}" end raise InvalidColorError, "Invalid color #{color.inspect} for #{space}" unless valid_color end
check_color_space(space)
click to toggle source
# File lib/origami/graphics/colors.rb, line 160 def check_color_space(space) case space when Color::Space::DEVICE_GRAY, Color::Space::DEVICE_RGB, Color::Space::DEVICE_CMYK else raise InvalidColorError, "Unknown color space #{space}" end end
check_gray_color(color)
click to toggle source
# File lib/origami/graphics/colors.rb, line 184 def check_gray_color(color) color.is_a?(::Array) and color.length == 1 and (0..1).include?(color[0]) end
check_rgb_color(color)
click to toggle source
# File lib/origami/graphics/colors.rb, line 188 def check_rgb_color(color) color.is_a?(::Array) and color.length == 3 and color.all? {|c| (0..1).include?(c) } end