From 17ce0a83d97bede1a166b9841be7b1348477189a Mon Sep 17 00:00:00 2001 From: tetragon Date: Tue, 2 Oct 2007 02:54:28 +0000 Subject: Adding format_options and output_options template constructor arguments Merging PDF and Postscript generation to the same file Adding DVI support git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1684 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/Template/LaTeX.pm | 134 ++++++++++++++++++++++++++++++++++++++++++++ LedgerSMB/Template/ODS.pm | 22 +++++++- LedgerSMB/Template/PDF.pm | 114 ------------------------------------- LedgerSMB/Template/PS.pm | 114 ------------------------------------- 4 files changed, 155 insertions(+), 229 deletions(-) create mode 100755 LedgerSMB/Template/LaTeX.pm delete mode 100755 LedgerSMB/Template/PDF.pm delete mode 100755 LedgerSMB/Template/PS.pm (limited to 'LedgerSMB/Template') diff --git a/LedgerSMB/Template/LaTeX.pm b/LedgerSMB/Template/LaTeX.pm new file mode 100755 index 00000000..77e2a2d4 --- /dev/null +++ b/LedgerSMB/Template/LaTeX.pm @@ -0,0 +1,134 @@ + +=head1 NAME + +LedgerSMB::Template::LaTeX Template support module for LedgerSMB + +=head1 SYNOPSIS + +Muxed LaTeX rendering support. Handles PDF, Postscript, and DVI output. + +=head1 DETAILS + +The final output format is determined by the format_option of filetype. The +valid filetype specifiers are 'pdf', 'ps', and 'dvi'. + +=head1 METHODS + +=over + +=item get_template ($name) + +Returns the appropriate template filename for this format. + +=item preprocess ($vars) + +Currently does nothing. + +=item process ($parent, $cleanvars) + +Processes the template for the appropriate output format. + +=item postprocess ($parent) + +Currently does nothing. + +=back + +=head1 Copyright (C) 2007, The LedgerSMB core team. + +This work contains copyrighted information from a number of sources all used +with permission. + +It is released under the GNU General Public License Version 2 or, at your +option, any later version. See COPYRIGHT file for details. For a full list +including contact information of contributors, maintainers, and copyright +holders, see the CONTRIBUTORS file. +=cut + +package LedgerSMB::Template::LaTeX; + +use Error qw(:try); +use Template::Latex; +use LedgerSMB::Template::TTI18N; + +sub get_template { + my $name = shift; + return "${name}.tex"; +} + +sub preprocess { + my $rawvars = shift; + my $vars; + my $type = ref $rawvars; + + return $rawvars if $type =~ /^LedgerSMB::Locale/; + if ($type eq 'ARRAY') { + for (@{$rawvars}) { + push @{$vars}, preprocess($_); + } + } elsif (!$type) { + #XXX Fix escaping + $rawvars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g; + $rawvars =~ s/"(.*)"/``$1''/gs; + return $rawvars; + } else { + for ( keys %{$rawvars} ) { + $vars->{$_} = preprocess($rawvars->{$_}); + } + } + return $vars; +} + +sub process { + my $parent = shift; + my $cleanvars = shift; + my $template; + my $source; + $parent->{outputfile} ||= + "${LedgerSMB::Sysconfig::tempdir}/$parent->{template}-output-$$"; + + if (ref $parent->{template} eq 'SCALAR') { + $source = $parent->{template}; + } elsif (ref $parent->{template} eq 'ARRAY') { + $source = join "\n", @{$parent->{template}}; + } else { + $source = get_template($parent->{template}); + } + $Template::Latex::DEBUG = 1 if $parent->{debug}; + my $format = 'ps'; + if ($parent->{format_args}{filetype} eq 'dvi') { + $format = 'dvi'; + } elsif ($parent->{format_args}{filetype} eq 'pdf') { + $format = 'pdf'; + } + $template = Template::Latex->new({ + LATEX_FORMAT => $format, + INCLUDE_PATH => $parent->{include_path}, + START_TAG => quotemeta(' quotemeta('?>'), + DELIMITER => ';', + DEBUG => ($parent->{debug})? 'dirs': undef, + DEBUG_FORMAT => '', + }) || throw Error::Simple Template::Latex->error(); + + if (not $template->process( + $source, + {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs, + 'escape' => \&preprocess}, + "$parent->{outputfile}.$format", binmode => 1)) { + throw Error::Simple $template->error(); + } + if ($format eq 'dvi') { + $parent->{mimetype} = 'application/x-dvi'; + } else { + $parent->{mimetype} = 'application/$format'; + } + $parent->{rendered} = "$parent->{outputfile}.$format"; +} + +sub postprocess { + my $parent = shift; + return $parent->{rendered}; +} + +1; diff --git a/LedgerSMB/Template/ODS.pm b/LedgerSMB/Template/ODS.pm index 414e732a..a1402042 100644 --- a/LedgerSMB/Template/ODS.pm +++ b/LedgerSMB/Template/ODS.pm @@ -119,6 +119,26 @@ sub _cell_handler { $currcol++; } +sub _formula_handler { + my $cell = $ods->getCell(-1, $rowcount, $currcol); + + if (@style_stack and $celltype{$style_stack[0][0]}) { + $ods->cellValueType($cell, $celltype{$style_stack[0][0]}[0]); + } elsif ($_->{att}->{type}) { + my $type = $_->{att}->{type}; + if ($type =~ /^(string|blank|url)$/i) { + $ods->cellValueType($cell, 'string'); + } elsif ($type =~ /^(number|formula)$/i) { + $ods->cellValueType($cell, 'float'); + } + } + $ods->cellFormula($cell, "oooc:=$_->{att}->{text}"); + if (@style_stack) { + $ods->cellStyle($cell, $style_stack[0][0]); + } + $currcol++; +} + sub _border_set { my ($format, $properties, $border) = @_; my $edge = $border; @@ -759,7 +779,7 @@ sub _ods_process { worksheet => \&_worksheet_handler, row => \&_row_handler, cell => \&_cell_handler, - formula => \&_cell_handler, + formula => \&_formula_handler, format => \&_format_handler, }, twig_handlers => { diff --git a/LedgerSMB/Template/PDF.pm b/LedgerSMB/Template/PDF.pm deleted file mode 100755 index ef7ca519..00000000 --- a/LedgerSMB/Template/PDF.pm +++ /dev/null @@ -1,114 +0,0 @@ - -=head1 NAME - -LedgerSMB::Template::PDF Template support module for LedgerSMB - -=head1 METHODS - -=over - -=item get_template ($name) - -Returns the appropriate template filename for this format. - -=item preprocess ($vars) - -Currently does nothing. - -=item process ($parent, $cleanvars) - -Processes the template for PDF. - -=item postprocess ($parent) - -Currently does nothing. - -=back - -=head1 Copyright (C) 2007, The LedgerSMB core team. - -This work contains copyrighted information from a number of sources all used -with permission. - -It is released under the GNU General Public License Version 2 or, at your -option, any later version. See COPYRIGHT file for details. For a full list -including contact information of contributors, maintainers, and copyright -holders, see the CONTRIBUTORS file. -=cut - -package LedgerSMB::Template::PDF; - -use Error qw(:try); -use Template::Latex; -use LedgerSMB::Template::TTI18N; - -sub get_template { - my $name = shift; - return "${name}.tex"; -} - -sub preprocess { - my $rawvars = shift; - my $vars; - my $type = ref $rawvars; - - return $rawvars if $type =~ /^LedgerSMB::Locale/; - if ($type eq 'ARRAY') { - for (@{$rawvars}) { - push @{$vars}, preprocess($_); - } - } elsif (!$type) { - #XXX Fix escaping - $rawvars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g; - $rawvars =~ s/"(.*)"/``$1''/gs; - return $rawvars; - } else { - for ( keys %{$rawvars} ) { - $vars->{$_} = preprocess($rawvars->{$_}); - } - } - return $vars; -} - -sub process { - my $parent = shift; - my $cleanvars = shift; - my $template; - my $source; - $parent->{outputfile} ||= - "${LedgerSMB::Sysconfig::tempdir}/$parent->{template}-output-$$"; - - if (ref $parent->{template} eq 'SCALAR') { - $source = $parent->{template}; - } elsif (ref $parent->{template} eq 'ARRAY') { - $source = join "\n", @{$parent->{template}}; - } else { - $source = get_template($parent->{template}); - } - $template = Template::Latex->new({ - LATEX_FORMAT => 'pdf', - INCLUDE_PATH => $parent->{include_path}, - START_TAG => quotemeta(' quotemeta('?>'), - DELIMITER => ';', - DEBUG => ($parent->{debug})? 'dirs': undef, - DEBUG_FORMAT => '', - }) || throw Error::Simple Template::Latex->error(); - - if (not $template->process( - $source, - {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs, - 'escape' => \&preprocess}, - "$parent->{outputfile}.pdf", binmode => 1)) { - throw Error::Simple $template->error(); - } - $parent->{mimetype} = 'application/pdf'; -} - -sub postprocess { - my $parent = shift; - $parent->{rendered} = "$parent->{outputfile}.pdf"; - return "$parent->{outputfile}.pdf"; -} - -1; diff --git a/LedgerSMB/Template/PS.pm b/LedgerSMB/Template/PS.pm deleted file mode 100755 index fc732590..00000000 --- a/LedgerSMB/Template/PS.pm +++ /dev/null @@ -1,114 +0,0 @@ - -=head1 NAME - -LedgerSMB::Template::PS Template support module for LedgerSMB - -=head1 METHODS - -=over - -=item get_template ($name) - -Returns the appropriate template filename for this format. - -=item preprocess ($vars) - -Currently does nothing. - -=item process ($parent, $cleanvars) - -Processes the template for Postscript. - -=item postprocess ($parent) - -Currently does nothing. - -=back - -=head1 Copyright (C) 2007, The LedgerSMB core team. - -This work contains copyrighted information from a number of sources all used -with permission. - -It is released under the GNU General Public License Version 2 or, at your -option, any later version. See COPYRIGHT file for details. For a full list -including contact information of contributors, maintainers, and copyright -holders, see the CONTRIBUTORS file. -=cut - -package LedgerSMB::Template::PS; - -use Error qw(:try); -use Template::Latex; -use LedgerSMB::Template::TTI18N; - -sub get_template { - my $name = shift; - return "${name}.tex"; -} - -sub preprocess { - my $rawvars = shift; - my $vars; - my $type = ref $rawvars; - - return $rawvars if $type =~ /^LedgerSMB::Locale/; - if ($type eq 'ARRAY') { - for (@{$rawvars}) { - push @{$vars}, preprocess($_); - } - } elsif (!$type) { - #XXX Fix escaping - $rawvars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g; - $rawvars =~ s/"(.*)"/``$1''/gs; - return $rawvars; - } else { - for ( keys %{$rawvars} ) { - $vars->{$_} = preprocess($rawvars->{$_}); - } - } - return $vars; -} - -sub process { - my $parent = shift; - my $cleanvars = shift; - my $template; - my $source; - $parent->{outputfile} ||= - "${LedgerSMB::Sysconfig::tempdir}/$parent->{template}-output-$$"; - - if (ref $parent->{template} eq 'SCALAR') { - $source = $parent->{template}; - } elsif (ref $parent->{template} eq 'ARRAY') { - $source = join "\n", @{$parent->{template}}; - } else { - $source = get_template($parent->{template}); - } - $template = Template::Latex->new({ - LATEX_FORMAT => 'ps', - INCLUDE_PATH => $parent->{include_path}, - START_TAG => quotemeta(' quotemeta('?>'), - DELIMITER => ';', - DEBUG => ($parent->{debug})? 'dirs': undef, - DEBUG_FORMAT => '', - }) || throw Error::Simple Template::Latex->error(); - - if (not $template->process( - $source, - {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs, - 'escape' => \&preprocess}, - "$parent->{outputfile}.ps", binmode => 1)) { - throw Error::Simple $template->error(); - } - $parent->{mimetype} = 'application/postscript'; -} - -sub postprocess { - my $parent = shift; - $parent->{rendered} = "$parent->{outputfile}.ps"; - return "$parent->{outputfile}.ps"; -} - -1; -- cgit v1.2.3