summaryrefslogtreecommitdiff
path: root/LedgerSMB/Template
diff options
context:
space:
mode:
authortetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-10-02 02:54:28 +0000
committertetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-10-02 02:54:28 +0000
commit17ce0a83d97bede1a166b9841be7b1348477189a (patch)
tree87dcf66115b0c1f026178fa95329dfbcb514a12f /LedgerSMB/Template
parent3e4fbb3cc4fa116159b9d10735eda8a78e4b0736 (diff)
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
Diffstat (limited to 'LedgerSMB/Template')
-rwxr-xr-xLedgerSMB/Template/LaTeX.pm (renamed from LedgerSMB/Template/PDF.pm)36
-rw-r--r--LedgerSMB/Template/ODS.pm22
-rwxr-xr-xLedgerSMB/Template/PS.pm114
3 files changed, 49 insertions, 123 deletions
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;