#! /usr/bin/perl -w
# vim:syntax=perl
use strict;

use lib '/usr/share/perl5';

use Lire::Config;
use Lire::Program qw( :msg $PROG );
use Carp;

if( Lire::Config->get( 'lr_image_style' ) eq 'gd') {
	eval "use Lire::ReportParser::ChartWriter;";
	croak "Can't load Lire::ReportParser::ChartWriter" unless !$@;
} else {
	eval "use Lire::ReportParser::PloticusChartWriter;";
	croak "Can't load Lire::ReportParser::PloticusChartWriter" unless !$@;
}

use Getopt::Long;

my %opts = ( 'format' => Lire::Config->get( 'lr_image_format' ),
	     'high_quality' => Lire::Config->get( 'lr_image_style' ) eq 'hq',
	     'graph_resolution'	=> Lire::Config->get( 'lr_image_resolution' ),
	     'outputdir' => ".",
	   );
GetOptions( \%opts, "format=s", "outputdir=s" ) && @ARGV == 0
  or lr_err( "Usage $PROG [--format png|jpeg|gif|eps|pdf|svg] [--outputdir dir ] < report.xml" );

lr_info( "will generate charts for each subreport with a charttype" );

my $parser;
if( Lire::Config->get( 'lr_image_style' ) eq 'gd') {
	$parser = new Lire::ReportParser::ChartWriter( %opts );
} else {
	$parser = new Lire::ReportParser::PloticusChartWriter( %opts );
}

eval {
    $parser->parse(\*STDIN);
};
lr_err( $@ ) if $@;
lr_info( "parsing xml finished" );

exit 0;

__END__

=pod

=head1 NAME

lr_xml2chart - generate charts from an XML report

=head1 SYNOPSIS

B<lr_xml2chart> B<[> I<options> B<]> < I<file.xml> > I<file_img.xml>

=head1 OPTIONS

=over 4

=item B<-f> I<format>

The graphic format to use for the charts. It can be one of jpeg, gif, eps,
svg, pdf or png. Default is taken from the LR_IMAGE_FORMAT environment
variable. The usual default is PNG.

=item B<-o> I<outputdir>

The directory where the charts should be written. It defaults to the
current working directory.

=back

=head1 DESCRIPTION

B<lr_xml2chart> reads an XML report from stdin and generates charts for
the subreport that have a charttype attribute. The charts will be
written in the directory specified with the B<-o> option or the
current directory if that option isn't used. It will output on STDOUT
a modified version of the input report with the proper lire:image
elements referring to the charts added.

This script gets called by lr_xml2pdf(1) and lr_xml2html(1).

=head1 SEE ALSO

lr_dlf2xml(1), lr_log2report(1)

=head1 VERSION

$Id: lr_xml2chart.in,v 1.7 2004/01/21 07:23:00 wsourdeau Exp $

=head1 COPYRIGHT

Copyright (C) 2000, 2001, 2002 Stichting LogReport Foundation LogReport@LogReport.org

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program 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 General Public License for more details.

=head1 AUTHORS

Egon Willighagen, Wessel Dankers

=cut

# Local Variables:
# mode: cperl
# End:
