MT#7861 Use pixels as main unit to be in accordance with svg-edit.

(cherry picked from commit bdd8562fb0ee0a98cb1296822fa1e211fa0d8c5f)
gjungwirth/voicemail_number
Irka 12 years ago
parent 9f7f55d07f
commit b2f21dd777

@ -320,8 +320,10 @@ sub set_content_ajax :Chained('base') :PathPart('editcontent/set/ajax') :Args(0)
$c->detach($c->view('JSON'));
}
sub preview_content :Chained('base') :PathPart('editcontent/preview') :Args(0) {
sub preview_content :Chained('base') :PathPart('editcontent/preview') :Args {
my ($self, $c, @args) = @_;
my($out_type) = @args;
$out_type //= '';
my $tmpl = $c->stash->{tmpl};
my $svg = $tmpl->data;
@ -367,12 +369,17 @@ sub preview_content :Chained('base') :PathPart('editcontent/preview') :Args(0) {
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/invoicetemplate'));
return;
}
$c->response->content_type('application/pdf');
$c->response->body($pdf);
if($out_type eq 'svg'){
$out = join('', @{NGCP::Panel::Utils::InvoiceTemplate::preprocess_svg_pdf($c, \$out)});
$c->response->body($out);
}else{
$c->response->content_type('application/pdf');
$c->response->body($pdf);
}
return;
}
sub embed_image :Chained('/') :PathPart('invoicetemplate/embedimage') :Args(0) {
my ($self, $c) = @_;

@ -6,39 +6,22 @@ use XML::XPath;
use IPC::System::Simple qw/capturex/;
use Template;
sub svg_pdf {
my ($c,$svg_ref,$pdf_ref) = @_;
my $svg = $$svg_ref;
my $dir = File::Temp->newdir(undef, CLEANUP => 1);
my $tempdir = $dir->dirname;
my $pagenum = 1;
my @pagefiles;
my ($pagenum,@pagefiles) = (1);
# file consists of multiple svg tags (invald!), split them up:
my(@pages) = $svg=~/(<svg.*?(?:\/svg>))/sig;
foreach my $page(@pages) {
foreach my $page ( @{preprocess_svg_pdf($c,$svg_ref)}){
my $fh;
my $pagefile = "$tempdir/$pagenum.svg";
push @pagefiles, $pagefile;
my $xp = XML::XPath->new($page);
my $g = $xp->find('//g[contains(@class,"firsty-") and contains(@class,"lasty")]');
foreach my $node($g->get_nodelist) {
my $class = $node->getAttribute('class');
my $firsty = $class; my $lasty = $class;
$firsty =~ s/^.+firsty\-(\d+).*$/$1/;
$lasty =~ s/^.+lasty\-(\d+).*$/$1/;
if(length($firsty) && length($lasty)) {
process_child_nodes($node, $firsty, $lasty);
}
}
$page = ($xp->findnodes('/'))[0]->toString();
open($fh, ">", $pagefile);
binmode($fh, ":utf8");
print $fh $page;
@ -52,16 +35,48 @@ sub svg_pdf {
# so we need to scale it down by 0.8 to get a mediabox of 595,842
# when using 90dpi.
# (it doesn't happen with inkscape, no idea what rsvg does)
my @cmd_args = (qw/-a -f pdf -z 0.8/, @pagefiles);
#-z 0.8 , --dpi-x 72 --dpi-y 72
my @cmd_args = (qw/-a -f pdf/, @pagefiles);
my $cmd = 'rsvg-convert';
my $cmd_full = $cmd.' '.join(' ', @cmd_args);
$c and $c->log->debug( $cmd_full );
print $cmd_full.";\n";
#`$cmd_full >./VMHost/data/ngcp-panel/invoice/pdf/pdf1.pdf`;
$$pdf_ref = capturex([0], $cmd, @cmd_args);
return 1;
}
sub preprocess_svg_pdf {
my ($c,$svg_ref) = @_;
my $svg = $$svg_ref;
my (@pages_content);
# file consists of multiple svg tags (invalid!), split them up:
my(@pages) = $svg=~/(<svg.*?(?:\/svg>))/sig;
foreach my $page(@pages) {
my $xp = XML::XPath->new($page);
my $server_process_spec = '';
if( my $spec_nodes = $xp->find('//@server-process-units') ){
$server_process_spec = $spec_nodes->string_value();
}
my $g = $xp->find('//g[contains(@class,"firsty-") and contains(@class,"lasty")]');
foreach my $node($g->get_nodelist) {
my $class = $node->getAttribute('class');
my $firsty = $class; my $lasty = $class;
$firsty =~ s/^.+firsty\-(\d+).*$/$1/;
$lasty =~ s/^.+lasty\-(\d+).*$/$1/;
if(length($firsty) && length($lasty)) {
process_child_nodes($node, $firsty, $lasty, $server_process_spec);
}
}
$page = ($xp->findnodes('/'))[0]->toString();
push @pages_content, $page;
}
return \@pages_content;
}
sub preprocess_svg {
my($svg_ref) = @_;
@ -76,6 +91,7 @@ sub preprocess_svg {
$node->removeAttribute('display');
}
}
#we can't process images on server side due to possible access restrictions
$$svg_ref = ($xp->findnodes('/'))[0]->toString();
$$svg_ref =~s/^<root>|<\/root>$//;
@ -101,6 +117,7 @@ sub sanitize_svg {
}
sub get_tt {
#using of the common configuration was the reason for View::SVG
my $tt = Template->new({
ENCODING => 'UTF-8',
RELATIVE => 1,
@ -142,7 +159,7 @@ sub svg_content{
return $content;
}
sub process_child_nodes {
my ($node, $firsty, $y) = @_;
my ($node, $firsty, $y, $server_process_spec) = @_;
for my $attr (qw/y y1 y2/) {
my $a = $node->getAttribute($attr);
if($a) {
@ -151,12 +168,14 @@ sub process_child_nodes {
my $newy = $y + $delta;
$node->removeAttribute($attr);
$node->appendAttribute(XML::XPath::Node::Attribute->new($attr, $newy."mm"));
$node->appendAttribute(XML::XPath::Node::Attribute->new($attr,
$newy.(($server_process_spec ne 'none')?'mm':'')
));
}
}
my @children = $node->getChildNodes();
foreach my $node(@children) {
process_child_nodes($node, $firsty, $y);
process_child_nodes($node, $firsty, $y, $server_process_spec);
}
}

@ -36,7 +36,7 @@ var svgWhiteList_ = {
"feGaussianBlur": ["class", "color-interpolation-filters", "id", "requiredFeatures", "stdDeviation"],
"filter": ["class", "color-interpolation-filters", "filterRes", "filterUnits", "height", "id", "primitiveUnits", "requiredFeatures", "width", "x", "xlink:href", "y"],
"foreignObject": ["class", "font-size", "height", "id", "opacity", "requiredFeatures", "style", "transform", "width", "x", "y"],
"g": ["class", "clip-path", "clip-rule", "id", "display", "fill", "fill-opacity", "fill-rule", "filter", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "font-family", "font-size", "font-style", "font-weight", "text-anchor", "rows", "zone-rows", "call-rows", "rows-interval", "zone-rows-interval", "call-rows-interval"],
"g": ["class", "clip-path", "clip-rule", "id", "display", "fill", "fill-opacity", "fill-rule", "filter", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "font-family", "font-size", "font-style", "font-weight", "text-anchor", "rows", "zone-rows", "call-rows", "rows-interval", "zone-rows-interval", "call-rows-interval","server-process-units"],
"image": ["class", "clip-path", "clip-rule", "filter", "height", "id", "mask", "opacity", "requiredFeatures", "style", "systemLanguage", "transform", "width", "x", "xlink:href", "xlink:title", "y"],
"line": ["class", "clip-path", "clip-rule", "fill", "fill-opacity", "fill-rule", "filter", "id", "marker-end", "marker-mid", "marker-start", "mask", "opacity", "requiredFeatures", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "transform", "x1", "x2", "y1", "y2"],
"linearGradient": ["class", "id", "gradientTransform", "gradientUnits", "requiredFeatures", "spreadMethod", "systemLanguage", "x1", "x2", "xlink:href", "y1", "y2"],

@ -16,10 +16,10 @@
MACRO svgopen BLOCK;
aux.page = aux.page + 1;
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' _ pagewidth _ 'mm" height="' _ pageheight _ 'mm">';
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' _ pagewidth _ 'mm" height="' _ pageheight _ 'mm" viewBox="0 0 595 842" server-process-units="' _ server_process_units _ '">';
draw_background;
IF open_g;
'<g x="0mm" y="0mm">';
'<g x="0" y="0">';
END;
END;
@ -54,7 +54,7 @@
x = x + f.dx;
format_field(field=f, val=zone.${f.name});
val = aux.val;
'<text font-family="' _ fontfamily _ '" font-size="' _ fontsize _ 'pt" x="' _ x _ 'mm" y="' _ y _ 'mm" text-anchor="'_ anc _'">';
'<text font-family="' _ fontfamily _ '" font-size="' _ fontsize _ apply_units('fontsize') _ '" x="' _ x _ apply_units('position') _ '" y="' _ y _ apply_units('position') _ '" text-anchor="'_ anc _'">';
val;
'</text>';
END;
@ -67,7 +67,15 @@
END;
aux.lasty = y;
END;
MACRO apply_units(item) BLOCK;
IF server_process_units == 'none';
'';
ELSIF item == 'fontsize' ;
'pt';
ELSIF item == 'position';
'mm';
END;
END;
MACRO calllist BLOCK;
fontfamily = fontfamily || 'Arial';
fontsize = fontsize || 8;
@ -87,7 +95,7 @@
l = f.masklen > val.length ? val.length : f.masklen;
val = val.substr(l - 1, val.length - 1, f.mask);
END;
'<text font-family="' _ fontfamily _ '" font-size="' _ fontsize _ 'pt" x="' _ x _ 'mm" y="' _ y _ 'mm" text-anchor="'_ anc _'">';
'<text font-family="' _ fontfamily _ '" font-size="' _ fontsize _ apply_units('fontsize') _ '" x="' _ x _ apply_units('position') _ '" y="' _ y _ apply_units('position') _ '" text-anchor="'_ anc _'">';
val;
'</text>';
END;

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Loading…
Cancel
Save