SVG scaling is now supported!
This commit is contained in:
@@ -3,7 +3,7 @@ module Squib
|
||||
|
||||
# Renders a png file at the given location.
|
||||
# See {file:samples/image.rb samples/image.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
|
||||
# Note: scaling not currently supported.
|
||||
# Note: scaling not currently supported for PNGs.
|
||||
#
|
||||
# @param range: the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
|
||||
# @param file: the . See {file:API.md#Specifying+Files Specifying Files}
|
||||
@@ -17,17 +17,18 @@ module Squib
|
||||
end
|
||||
|
||||
# Renders an entire svg file at the given location. Uses the SVG-specified units and DPI to determine the pixel width and height.
|
||||
# See {file:samples/image.rb samples/image.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
|
||||
# Note: scaling not currently supported.
|
||||
# See {file:samples/load-images.rb samples/load-images.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
|
||||
#
|
||||
# @param range: the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
|
||||
# @param file: the . See {file:API.md#Specifying+Files Specifying Files}
|
||||
# @param x: the x-coordinate to place
|
||||
# @param y: the y-coordinate to place
|
||||
def svg(range: :all, file: nil, x: 0, y: 0)
|
||||
# @param width: the pixel width that the image should scale to. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document.
|
||||
# @param height: the pixel width that the image should scale to. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document.
|
||||
def svg(range: :all, file: nil, x: 0, y: 0, width: :native, height: :native)
|
||||
range = rangeify(range)
|
||||
file = fileify(file)
|
||||
range.each{ |i| @cards[i].svg(file, x, y) }
|
||||
range.each{ |i| @cards[i].svg(file, x, y, width, height) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -8,11 +8,14 @@ module Squib
|
||||
cc.paint(alpha)
|
||||
end
|
||||
|
||||
def svg(file, x, y)
|
||||
require 'rsvg2'
|
||||
def svg(file, x, y, width, height)
|
||||
svg = RSVG::Handle.new_from_file(file)
|
||||
tmp = Cairo::ImageSurface.new(svg.width, svg.height)
|
||||
width = svg.width if width == :native
|
||||
height = svg.height if height == :native
|
||||
puts "Width and height #{width} #{height}, svg was #{svg.width} #{svg.height}"
|
||||
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)
|
||||
cairo_context.set_source(tmp, x, y)
|
||||
cairo_context.paint
|
||||
|
||||
@@ -50,14 +50,13 @@ module Squib
|
||||
module_function :fontify
|
||||
|
||||
def radiusify(radius, x_radius, y_radius)
|
||||
unless radius.nil?
|
||||
ret_x = radius
|
||||
ret_y = radius
|
||||
if radius.nil?
|
||||
return x_radius, y_radius
|
||||
else
|
||||
return radius,radius
|
||||
end
|
||||
ret_x = x_radius unless x_radius.nil?
|
||||
rex_y = y_radius unless y_radius.nil?
|
||||
return ret_x,ret_y
|
||||
end
|
||||
module_function :radiusify
|
||||
|
||||
def xyify
|
||||
#TODO: Allow negative numbers that subtract from the card width & height
|
||||
|
||||
Reference in New Issue
Block a user