lib/rabbit/renderer/engine/cairo.rb in rabbit-3.0.0 vs lib/rabbit/renderer/engine/cairo.rb in rabbit-3.0.1
- old
+ new
@@ -193,10 +193,11 @@
end
def draw_pixbuf(pixbuf, x, y, params={})
x, y = from_screen(x, y)
@context.save do
+ apply_clip(x, y, pixbuf.width, pixbuf.height, params)
@context.translate(x, y)
set_source_pixbuf(pixbuf, params)
@context.paint(params[:alpha])
end
@@ -242,15 +243,18 @@
end
def draw_rsvg_handle(handle, x, y, params={})
x, y = from_screen(x, y)
dim = handle.dimensions
- width = (params[:width] || dim.width).to_f
- height = (params[:height] || dim.height).to_f
+ w = dim.width
+ h = dim.height
+ width = (params[:width] || w).to_f
+ height = (params[:height] || h).to_f
@context.save do
+ apply_clip(x, y, w, h, params)
@context.translate(x, y)
- @context.scale(width / dim.width, height / dim.height)
+ @context.scale(width / w, height / h)
@context.render_rsvg_handle(handle)
end
_draw_reflected_rsvg_handle(handle, x, y, width, height,
params)
@@ -260,10 +264,11 @@
x, y = from_screen(x, y)
w, h = page.size
width = (params[:width] || w).to_f
height = (params[:height] || h).to_f
@context.save do
+ apply_clip(x, y, w, h, params)
@context.translate(x, y)
@context.scale(width / w, height / h)
@context.render_poppler_page(page)
end
end
@@ -391,9 +396,25 @@
@context.send(action)
case action
when :clip
block, = other_info
block.call if block
+ end
+ end
+
+ def apply_clip(x, y, w, h, params)
+ clip_x = params[:clip_x]
+ clip_y = params[:clip_y]
+ clip_width = params[:clip_width]
+ clip_height = params[:clip_height]
+ if clip_x or clip_y or clip_width or clip_height
+ @context.rectangle(x,
+ y,
+ clip_width || w,
+ clip_height || h)
+ @context.clip
+ @context.translate(x - (clip_x || x),
+ y - (clip_y || y))
end
end
def make_matrix(xx, xy, x0, yx, yy, y0)
::Cairo::Matrix.new(xx, yx, xy, yy, x0, y0)