Forked from
wine / wine
72291 commits behind the upstream repository.
buildimage 4.82 KiB
#! /usr/bin/perl -w
#
# Render SVG files containing one or more images into an ICO or BMP.
#
# Copyright (C) 2010 Joel Holdsworth
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
use strict;
use warnings;
use XML::Parser;
use MIME::Base64;
use File::Copy;
# Parse the parameters
my $svgFileName = $ARGV[0];
my $outFileName = $ARGV[1];
die "Cannot open SVG file" unless defined($svgFileName);
die "Cannot open output file" unless defined($outFileName);
$outFileName =~ m/(.*)\.(.*)/;
my $outName = $1;
my $ext = lc($2);
die "Only BMP and ICO outputs are supported" unless $ext eq "bmp" or $ext eq "ico";
my $renderedSVGFileName = "$svgFileName.png";
my @pngFiles;
my @pngFilesRaw;
# Get the programs from the environment variables
my $convert = $ENV{"CONVERT"} || "convert";
my $rsvg = $ENV{"RSVG"} || "rsvg";
my $icotool = $ENV{"ICOTOOL"} || "icotool";
# Be ready to abort
sub cleanup()
{
unlink $renderedSVGFileName;
unlink $_ foreach(@pngFiles);
unlink $_ foreach(@pngFilesRaw);
}
$SIG{"INT"} = "cleanup";
$SIG{"HUP"} = "cleanup";
$SIG{"TERM"} = "cleanup";
$SIG{"__DIE__"} = "cleanup";
# run a shell command and die on error
sub shell(@)
{
my @args = @_;
system(@args) == 0 or die "@args failed: $?";
}
sub svg_element_start
{
my($expat, $element, %attr) = @_;