lib/squib/graphics/image.rb in squib-0.2.0 vs lib/squib/graphics/image.rb in squib-0.3.0
- old
+ new
@@ -12,12 +12,12 @@
class Card
# :nodoc:
# @api private
- def png(file, x, y, width, height, alpha, blend, angle)
- Squib.logger.debug {"Rendering: #{file} @#{x},#{y} #{width}x#{height}, alpha: #{alpha}, blend: #{blend}, angle: #{angle}"}
+ def png(file, x, y, width, height, alpha, blend, angle, mask)
+ Squib.logger.debug {"Rendering: #{file} @#{x},#{y} #{width}x#{height}, alpha: #{alpha}, blend: #{blend}, angle: #{angle}, mask: #{mask}"}
return if file.nil? or file.eql? ''
png = Squib.cache_load_image(file)
use_cairo do |cc|
cc.translate(x, y)
if width != :native || height != :native
@@ -28,18 +28,23 @@
end
cc.rotate(angle)
cc.translate(-1 * x, -1 * y)
cc.set_source(png, x, y)
cc.operator = blend unless blend == :none
- cc.paint(alpha)
+ if mask.nil?
+ cc.paint(alpha)
+ else
+ cc.set_source_squibcolor(mask)
+ cc.mask(png, x, y)
+ end
end
end
# :nodoc:
# @api private
- def svg(file, id, x, y, width, height, alpha, blend, angle)
- Squib.logger.debug {"Rendering: #{file}, id: #{id} @#{x},#{y} #{width}x#{height}, alpha: #{alpha}, blend: #{blend}, angle: #{angle}"}
+ def svg(file, id, x, y, width, height, alpha, blend, angle, mask)
+ Squib.logger.debug {"Rendering: #{file}, id: #{id} @#{x},#{y} #{width}x#{height}, alpha: #{alpha}, blend: #{blend}, angle: #{angle}, mask: #{mask}"}
return if file.nil? or file.eql? ''
svg = RSVG::Handle.new_from_file(file)
width = svg.width if width == :native
height = svg.height if height == :native
tmp = Cairo::ImageSurface.new(width, height)
@@ -48,12 +53,17 @@
tmp_cc.render_rsvg_handle(svg, id)
use_cairo do |cc|
cc.translate(x, y)
cc.rotate(angle)
cc.translate(-1 * x, -1 * y)
- cc.set_source(tmp, x, y)
cc.operator = blend unless blend == :none
- cc.paint(alpha)
+ if mask.nil?
+ cc.set_source(tmp, x, y)
+ cc.paint(alpha)
+ else
+ cc.set_source_squibcolor(mask)
+ cc.mask(tmp, x, y)
+ end
end
end
end
end