diff options
Diffstat (limited to 'LedgerSMB')
-rwxr-xr-x | LedgerSMB/Template.pm | 27 | ||||
-rwxr-xr-x | LedgerSMB/Template/LaTeX.pm (renamed from LedgerSMB/Template/PDF.pm) | 36 | ||||
-rw-r--r-- | LedgerSMB/Template/ODS.pm | 22 | ||||
-rwxr-xr-x | LedgerSMB/Template/PS.pm | 114 |
4 files changed, 74 insertions, 125 deletions
diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm index ad48ad52..672078c0 100755 --- a/LedgerSMB/Template.pm +++ b/LedgerSMB/Template.pm @@ -26,6 +26,16 @@ in string form or the name of the file that is the template to be processed. The format to be used. Currently HTML, PS, PDF, TXT and CSV are supported. +=item format_options (optional) + +A hash of format-specific options. See the appropriate LSMB::T::foo for +details. + +=item output_options (optional) + +A hash of output-specific options. See the appropriate output method for +details. + =item locale (optional) The locale object to use for regular gettext lookups. Having this option adds @@ -122,7 +132,6 @@ sub new { $self->{myconfig} = $args{user}; $self->{template} = $args{template}; $self->{format} = $args{format}; - $self->{format} = 'PS' if lc $self->{format} eq 'postscript'; $self->{language} = $args{language}; $self->{no_escape} = $args{no_escape}; $self->{debug} = $args{debug}; @@ -134,7 +143,21 @@ sub new { $self->{noauto} = $args{no_auto_output}; $self->{method} = $args{method}; $self->{method} ||= $args{media}; - + $self->{format_args} = $args{format_options}; + $self->{output_args} = $args{output_options}; + + # SC: Muxing pre-format_args LaTeX format specifications. Now with + # DVI support. + if (lc $self->{format} eq 'dvi') { + $self->{format} = 'LaTeX'; + $self->{format_args}{filetype} = 'dvi'; + } elsif (lc $self->{format} eq 'pdf') { + $self->{format} = 'LaTeX'; + $self->{format_args}{filetype} = 'pdf'; + } elsif (lc $self->{format} eq 'ps' or lc $self->{format} eq 'postscript') { + $self->{format} = 'LaTeX'; + $self->{format_args}{filetype} = 'ps'; + } bless $self, $class; if ($self->{format} !~ /^\p{IsAlnum}+$/) { diff --git a/LedgerSMB/Template/PDF.pm b/LedgerSMB/Template/LaTeX.pm index ef7ca519..77e2a2d4 100755 --- a/LedgerSMB/Template/PDF.pm +++ b/LedgerSMB/Template/LaTeX.pm @@ -1,7 +1,16 @@ =head1 NAME -LedgerSMB::Template::PDF Template support module for LedgerSMB +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 @@ -17,7 +26,7 @@ Currently does nothing. =item process ($parent, $cleanvars) -Processes the template for PDF. +Processes the template for the appropriate output format. =item postprocess ($parent) @@ -36,7 +45,7 @@ including contact information of contributors, maintainers, and copyright holders, see the CONTRIBUTORS file. =cut -package LedgerSMB::Template::PDF; +package LedgerSMB::Template::LaTeX; use Error qw(:try); use Template::Latex; @@ -85,8 +94,15 @@ sub process { } 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 => 'pdf', + LATEX_FORMAT => $format, INCLUDE_PATH => $parent->{include_path}, START_TAG => quotemeta('<?lsmb'), END_TAG => quotemeta('?>'), @@ -99,16 +115,20 @@ sub process { $source, {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs, 'escape' => \&preprocess}, - "$parent->{outputfile}.pdf", binmode => 1)) { + "$parent->{outputfile}.$format", binmode => 1)) { throw Error::Simple $template->error(); } - $parent->{mimetype} = 'application/pdf'; + if ($format eq 'dvi') { + $parent->{mimetype} = 'application/x-dvi'; + } else { + $parent->{mimetype} = 'application/$format'; + } + $parent->{rendered} = "$parent->{outputfile}.$format"; } sub postprocess { my $parent = shift; - $parent->{rendered} = "$parent->{outputfile}.pdf"; - return "$parent->{outputfile}.pdf"; + 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/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('<?lsmb'), - END_TAG => 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; |