Image rotation support for png and svg commands

With unit tests and other refactorings
This commit is contained in:
Andy Meneely
2014-11-03 22:47:06 -05:00
parent bb1befc22b
commit d4f0105785
4 changed files with 101 additions and 7 deletions
+10 -3
View File
@@ -14,10 +14,14 @@ module Squib
# :nodoc:
# @api private
def png(file, x, y, alpha, blend)
def png(file, x, y, alpha, blend, angle)
Squib.logger.debug {"Rendering: #{file} @#{x},#{y} #{width}x#{height}, alpha: #{alpha}, blend: #{blend}, angle: #{angle}"}
return if file.nil? or file.eql? ''
png = Squib.cache_load_image(file)
use_cairo do |cc|
cc.translate(x, y)
cc.rotate(angle)
cc.translate(-1 * x, -1 * y)
cc.set_source(png, x, y)
cc.operator = blend unless blend == :none
cc.paint(alpha)
@@ -26,8 +30,8 @@ module Squib
# :nodoc:
# @api private
def svg(file, id, x, y, width, height, alpha, blend)
Squib.logger.debug {"Rendering: #{file}, #{id} #{x}, #{y}, #{width}, #{height}, #{alpha}, #{blend}"}
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}"}
return if file.nil? or file.eql? ''
svg = RSVG::Handle.new_from_file(file)
width = svg.width if width == :native
@@ -37,6 +41,9 @@ module Squib
tmp_cc.scale(width.to_f / svg.width.to_f, height.to_f / svg.height.to_f)
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)