lib/squib/graphics/image.rb in squib-0.3.0 vs lib/squib/graphics/image.rb in squib-0.4.0
- old
+ new
@@ -25,11 +25,11 @@
height == :native && height = png.height.to_f
Squib.logger.warn "PNG scaling results in antialiasing."
cc.scale(width.to_f / png.width.to_f, height.to_f / png.height.to_f)
end
cc.rotate(angle)
- cc.translate(-1 * x, -1 * y)
+ cc.translate(-x, -y)
cc.set_source(png, x, y)
cc.operator = blend unless blend == :none
if mask.nil?
cc.paint(alpha)
else
@@ -42,27 +42,28 @@
# :nodoc:
# @api private
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)
- tmp_cc = Cairo::Context.new(tmp)
- tmp_cc.scale(width.to_f / svg.width.to_f, height.to_f / svg.height.to_f)
- tmp_cc.render_rsvg_handle(svg, id)
+ svg = RSVG::Handle.new_from_file(file)
+ width = svg.width if width == :native
+ height = svg.height if height == :native
+ scale_width = width.to_f / svg.width.to_f
+ scale_height = height.to_f / svg.height.to_f
use_cairo do |cc|
cc.translate(x, y)
cc.rotate(angle)
- cc.translate(-1 * x, -1 * y)
+ cc.scale(scale_width, scale_height)
cc.operator = blend unless blend == :none
+ #FIXME Alpha is no longer used since we are not using cc.paint anymore
if mask.nil?
- cc.set_source(tmp, x, y)
- cc.paint(alpha)
+ cc.render_rsvg_handle(svg, id)
else
+ tmp = Cairo::ImageSurface.new(width / scale_width, height / scale_height)
+ tmp_cc = Cairo::Context.new(tmp)
+ tmp_cc.render_rsvg_handle(svg, id)
cc.set_source_squibcolor(mask)
- cc.mask(tmp, x, y)
+ cc.mask(tmp, 0, 0)
end
end
end
end