#! /usr/bin/perl

open(IN, "<$ARGV[0]");

while ($line = <IN>) {
	if ($line =~ /^BackSize\s*=\s*(\d+),(\d+)/) {
		$width = $1; $height = $2;
		break;
	}
}

$canvas_width = $width * 13;
$canvas_height = $height * 5;

print <<EOF;
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
Automatically generated.
-->
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://web.resource.org/cc/"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   viewBox="0 0 $canvas_width $canvas_height"
   width="$canvas_width"
   height="$canvas_height">
  <metadata>
    <rdf:RDF>
      <cc:Work about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type resource="http://purl.org/dc/dcmitype/StillImage"/>
        <cc:license resource="http://www.gnu.org/licenses/lgpl.html"/>
        <dc:title>Default pixmap theme</dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
EOF

my @suits = ("spade", "club", "diamond", "heart");
my @cardnames = ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king");

for ($i = 0; $i < 4; $i++) {
	my $suit = $suits;
	for ($j = 0; $j < 13; $j++) {
		my $pngname = 1 + $j * 4 + $i;
		my $offsetx = $j * $width;
		my $offsety = $i * $height;
		print <<EOF;
  <image id="$cardnames[$j]_$suit[$i]" x="$offsetx" y="$offsety" height="$height" width="$width" xlink:href="$pngname.png" />
EOF
	}
}
print <<EOF;
</svg>
<!--
	Disabled stuff goes here
-->
<!--
 vi: ts=4 sw=4
-->
EOF
