Browse Source

Example of svg id being supplied, better input handling of svg ids

dev
Andy Meneely 12 years ago
parent
commit
b4702e1d4a
  1. 1
      lib/squib/api/image.rb
  2. 8
      lib/squib/input_helpers.rb
  3. 5
      samples/load_images.rb
  4. 15
      samples/spanner.svg

1
lib/squib/api/image.rb

@ -30,6 +30,7 @@ module Squib
def svg(range: :all, file: nil, id: nil, x: 0, y: 0, width: :native, height: :native)
range = rangeify(range)
file = fileify(file)
id = idify(id)
range.each{ |i| @cards[i].svg(file, id, x, y, width, height) }
end

8
lib/squib/input_helpers.rb

@ -58,6 +58,14 @@ module Squib
end
module_function :radiusify
def idify(svgid)
unless svgid.nil?
svgid = '#' << svgid unless svgid.start_with? '#'
end
svgid
end
module_function :idify
def xyify
#TODO: Allow negative numbers that subtract from the card width & height
end

5
samples/load_images.rb

@ -10,5 +10,10 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1) do
# SVGs can be scaled too
svg file: 'spanner.svg', x: 50, y: 50, width: 250, height: 250
# We can also limit our rendering to a single object, if the SVG ID is set
# Squib prepends a #-sign if one is not specified
svg file: 'spanner.svg', id: '#backdrop', x: 50, y: 350, width: 75, height: 75
svg file: 'spanner.svg', id: 'backdrop', x: 50, y: 450, width: 125, height: 125
save prefix: 'load_images_', format: :png
end

15
samples/spanner.svg

@ -10,7 +10,7 @@
viewBox="0 0 128 128"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
inkscape:version="0.48.3.1 r9886"
width="100%"
height="100%"
sodipodi:docname="spanner.svg">
@ -36,15 +36,15 @@
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1680"
inkscape:window-height="988"
inkscape:window-width="1280"
inkscape:window-height="1002"
id="namedview14"
showgrid="false"
inkscape:zoom="2.8284271"
inkscape:cx="98.928938"
inkscape:cy="62.194589"
inkscape:window-x="1432"
inkscape:window-y="109"
inkscape:window-x="1912"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="g3767"
inkscape:document-units="in"
@ -60,8 +60,9 @@
x="5.3126979"
height="501.3746"
width="501.3746"
id="rect3765"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:10.62539577;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
id="backdrop"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:10.62539577;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
inkscape:label="#rect3765" />
<path
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="M 36.267098,-7.709219 C 16.393265,5.1318032 3.2161811,27.462365 3.2161811,52.884128 c 0,39.825874 32.2852369,72.111092 72.1110909,72.111092 23.870397,0 44.964938,-11.67699 58.089488,-29.545518 -11.26063,7.275808 -24.65607,11.517748 -39.060173,11.517748 -39.825853,0 -72.11109,-32.285221 -72.11109,-72.111095 0,-15.95546 5.248882,-30.6218942 14.021601,-42.565574 z"

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Loading…
Cancel
Save