Skip to content

Commit

Permalink
* Add support for gradient patterns.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.dotswitch.net/var/svn/dotswitch/projects/library/plugins/purl@2117 c432a1ab-ec09-0410-8e5f-fb625be92370
  • Loading branch information
nanki committed Oct 23, 2008
1 parent e4857e2 commit f82b179
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/purl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def initialize(options = {})
load_feature Features::Resize
load_feature Features::ResizeMacro
load_feature Features::Cairo
load_feature Features::CairoGradient
yield self
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/purl/features/cairo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def operators
Op.new(:xtc, 1),
Op.new(:rgb, 4),
Op.new(:rgba, 5),
Op.new(:pattern, 2),
Op.new(:linewidth, 2),
Op.new(:stroke, 1),
Op.new(:fill, 1),
Expand Down Expand Up @@ -41,6 +42,11 @@ def rgba(ctx, r, g, b, a)
Result.new(ctx)
end

def pattern(ctx, pattern)
ctx.set_source pattern
Result.new(ctx)
end

def linewidth(ctx, w)
ctx.set_line_width w
Result.new(ctx)
Expand Down
41 changes: 41 additions & 0 deletions lib/purl/features/cairo_gradient.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Purl
module Features::CairoGradient
class << self
def operators
[
Op.new(:'grad.linear', 4, :grad_linear),
Op.new(:'grad.radial', 6, :grad_radial),
Op.new(:'grad.concentric', 4, :grad_concentric),
Op.new(:rgbo, 5, :rgb_stop),
Op.new(:rgbao, 6, :rgba_stop),
]
end

def grad_linear(x1, y1, x2, y2)
Result.new(::Cairo::LinearPattern.new(x1, y1, x2, y2))
end

def grad_radial(x1, y1, r1, x2, y2, r2)
Result.new(::Cairo::RadialPattern.new(x1, y1, r1, x2, y2, r2))
end

def grad_concentric(x, y, r1, r2)
Result.new(::Cairo::RadialPattern.new(x, y, r1, x, y, r2))
end

def rgb_stop(grad, r, g, b, offset)
raise UnexpectedArgument unless ::Cairo::GradientPattern === grad
grad.add_color_stop_rgb offset, r, g, b

Result.new(grad)
end

def rgba_stop(grad, r, g, b, a, offset)
raise UnexpectedArgument unless ::Cairo::GradientPattern === grad
grad.add_color_stop_rgba offset, r, g, b, a

Result.new(grad)
end
end
end
end

0 comments on commit f82b179

Please sign in to comment.