X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FTemplate.pm;h=6da93d9b396806a0f6270c0f5054217dc3ddde36;hb=611a3dd324e413b4653c850546e50a0a7336a8bc;hp=297c025fb1fea6437f615390589096205ce96465;hpb=5cf977e52788c523150fa19225b90914e6ddc909;p=kivitendo-erp.git diff --git a/SL/Template.pm b/SL/Template.pm index 297c025fb..6da93d9b3 100644 --- a/SL/Template.pm +++ b/SL/Template.pm @@ -99,38 +99,7 @@ sub format_string { my ($self, $variable) = @_; my $form = $self->{"form"}; - my %replace = - ('order' => [quotemeta("\\"), - '', - '&', quotemeta("\n"), - '"', '\$', '%', '_', '#', quotemeta('^'), - '{', '}', '<', '>', '£', "\r", '±', '\xe1', - '²', '³', - - ], - quotemeta("\\") => '\\textbackslash ', - '' => '', - '"' => "''", - '&' => '\&', - '\$' => '\$', - '%' => '\%', - '_' => '\_', - '#' => '\#', - '{' => '\{', - '}' => '\}', - '<' => '$<$', - '>' => '$>$', - '£' => '\pounds ', - "\r" => "", - '±' => '$\pm$', - '\xe1' => '$\bullet$', - quotemeta('^') => '\^\\', - quotemeta("\n") => '\newline ', - '²' => '$^2$', - '³' => '$^3$', - ); - - map({ $variable =~ s/$_/$replace{$_}/g; } @{ $replace{"order"} }); + $variable = $main::locale->quote_special_chars('Template/LaTeX', $variable); # Allow some HTML markup to be converted into the output format's # corresponding markup code, e.g. bold or italic. @@ -446,6 +415,31 @@ sub _parse_config_lines { } } +sub _force_mandatory_packages { + my $self = shift; + my $lines = shift; + + my (%used_packages, $document_start_line); + + foreach my $i (0 .. scalar @{ $lines } - 1) { + if ($lines->[$i] =~ m/\\usepackage[^{]*{(.*?)}/) { + $used_packages{$1} = 1; + + } elsif ($lines->[$i] =~ m/\\begin{document}/) { + $document_start_line = $i; + last; + + } + } + + $document_start_line = scalar @{ $lines } - 1 if (!defined $document_start_line); + + if (!$used_packages{textcomp}) { + splice @{ $lines }, $document_start_line, 0, "\\usepackage{textcomp}\n"; + $document_start_line++; + } +} + sub parse { my $self = $_[0]; local *OUT = $_[1]; @@ -459,6 +453,7 @@ sub parse { close(IN); $self->_parse_config_lines(\@lines); + $self->_force_mandatory_packages(\@lines) if (ref $self eq 'LaTeXTemplate'); my $contents = join("", @lines); @@ -594,14 +589,7 @@ sub format_string { my ($self, $variable) = @_; my $form = $self->{"form"}; - my %replace = - ('order' => ['<', '>', quotemeta("\n")], - '<' => '<', - '>' => '>', - quotemeta("\n") => '
', - ); - - map({ $variable =~ s/$_/$replace{$_}/g; } @{ $replace{"order"} }); + $variable = $main::locale->quote_special_chars('Template/HTML', $variable); # Allow some HTML markup to be converted into the output format's # corresponding markup code, e.g. bold or italic. @@ -1342,21 +1330,7 @@ sub format_string { my $form = $self->{"form"}; my $iconv = $self->{"iconv"}; - my %replace = - ('order' => ['&', '<', '>', '"', "'", - '\x80', # Euro - quotemeta("\n"), quotemeta("\r")], - '<' => '<', - '>' => '>', - '"' => '"', - "'" => ''', - '&' => '&', - '\x80' => chr(0xa4), # Euro - quotemeta("\n") => '', - quotemeta("\r") => '', - ); - - map({ $variable =~ s/$_/$replace{$_}/g; } @{ $replace{"order"} }); + $variable = $main::locale->quote_special_chars('Template/OpenDocument', $variable); # Allow some HTML markup to be converted into the output format's # corresponding markup code, e.g. bold or italic. @@ -1366,7 +1340,7 @@ sub format_string { foreach my $key (keys(%markup_replace)) { my $value = $markup_replace{$key}; - $variable =~ s|\<${key}\>||gi; + $variable =~ s|\<${key}\>||gi; #" $variable =~ s|\</${key}\>||gi; } @@ -1409,14 +1383,7 @@ sub format_string { my ($self, $variable) = @_; my $form = $self->{"form"}; - my %replace = - ('order' => ['<', '>', quotemeta("\n")], - '<' => '<', - '>' => '>', - quotemeta("\n") => '
', - ); - - map({ $variable =~ s/$_/$replace{$_}/g; } @{ $replace{"order"} }); + $variable = $main::locale->quote_special_chars('Template/XML', $variable); # Allow no markup to be converted into the output format my @markup_replace = ('b', 'i', 's', 'u', 'sub', 'sup');