SVGs: now with more cropping power!

Contributes to #11
This commit is contained in:
Andy Meneely
2015-10-26 22:47:42 -04:00
parent 541c8d49ca
commit 169f9e4ac4
4 changed files with 19 additions and 2 deletions
+7
View File
@@ -72,6 +72,13 @@ module Squib
# @option opts blend [:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity] (:none) the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
# @option opts angle [FixNum] (0) Rotation of the in radians. Note that this rotates around the upper-left corner, making the placement of x-y coordinates slightly tricky. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
# @option opts mask [String] (nil) If specified, the image will be used as a mask for the given color/gradient. Transparent pixels are ignored, opaque pixels are the given color. Note: the origin for gradient coordinates is at the given x,y, not at 0,0 as it is most other places.
# @option opts crop_x [Integer] (0) Crop the loaded image at this x coordinate. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts crop_y [Integer] (0) Crop the loaded image at this y coordinate. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts crop_corner_radius [Integer] (0): Radius for rounded corners, both x and y. When set, overrides crop_corner_x_radius and crop_corner_y_radius. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts crop_corner_x_radius [Integer] (0): x radius for rounded corners of cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts crop_corner_y_radius [Integer] (0): y radius for rounded corners of cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts crop_width [Integer] (:native): Width of the cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts crop_height [Integer] (:native): Height of the cropped image. Supports Unit Conversion, see {file:README.md#Units Units}.
# @return [nil] Returns nil
# @api public
def svg(opts = {})
+7 -1
View File
@@ -31,7 +31,6 @@ module Squib
cc.rotate(trans.angle)
cc.translate(-box.x, -box.y)
# cc.translate(trans.crop_x, trans.crop_y)
trans.crop_width = png.width.to_f if trans.crop_width == :native
trans.crop_height = png.height.to_f if trans.crop_height == :native
cc.rounded_rectangle(box.x, box.y, trans.crop_width, trans.crop_height, trans.crop_corner_x_radius, trans.crop_corner_y_radius)
@@ -67,6 +66,13 @@ module Squib
cc.translate(box.x, box.y)
cc.rotate(trans.angle)
cc.scale(scale_width, scale_height)
trans.crop_width = box.width if trans.crop_width == :native
trans.crop_height = box.height if trans.crop_height == :native
cc.rounded_rectangle(0, 0, trans.crop_width / scale_width, trans.crop_height / scale_height, trans.crop_corner_x_radius, trans.crop_corner_y_radius)
cc.clip
cc.translate(-trans.crop_x, -trans.crop_y)
cc.operator = paint.blend unless paint.blend == :none
if paint.mask.to_s.empty?
cc.render_rsvg_handle(svg, svg_args.id)