Skip to content

Commit 91290ac

Browse files
committed
draft svg parser (WIP)
1 parent c309075 commit 91290ac

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

examples/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
// test SVG
121121
//$svgid01 = $pdf->addSVG('./images/tcpdf_box.svg');
122122
//$svgid01_out = $pdf->getSetSVG($svgid01, 0, 60, 100, 50, $page01['height']);
123+
//echo($svgid01_out); exit; //DEBUG
123124
//$pdf->page->addContent($svgid01_out);
124125

125126
// ----------

src/SVG.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ protected function getSVGPath(
967967
$params[$prk] = $this->getUnitValuePoints($prv, self::REFUNITVAL, self::SVGUNIT);
968968
if (abs($params[$prk]) < $this->svgminunitlen) {
969969
// approximate little values to zero
970-
$params[$prk] = 0;
970+
$params[$prk] = 0.0;
971971
}
972972
}
973973

@@ -992,7 +992,9 @@ protected function getSVGPath(
992992
$coord['firstcmd'] = false;
993993
}
994994

995-
return $out . ' ' . $pop . "\n";
995+
$out .= ' ' . $pop . "\n";
996+
997+
return $out;
996998
}
997999

9981000
/**
@@ -1726,7 +1728,10 @@ protected function parseSVGStyleStroke(
17261728

17271729
$out .= $this->graph->getStyleCmd($strokestyle);
17281730

1729-
$svgstyle['objstyle'] .= 'D'; // @phpstan-ignore-line
1731+
$objstyle = 'D';
1732+
if (strpos($svgstyle['objstyle'], $objstyle) === false) {
1733+
$svgstyle['objstyle'] .= $objstyle; // @phpstan-ignore-line
1734+
}
17301735

17311736
return $out;
17321737
}
@@ -2087,7 +2092,10 @@ protected function parseSVGStyleFill(
20872092
}
20882093
}
20892094

2090-
$svgstyle['objstyle'] .= ($svgstyle['fill-rule'] == 'evenodd') ? 'F*' : 'F';
2095+
$objstyle = ($svgstyle['fill-rule'] == 'evenodd') ? 'F*' : 'F';
2096+
if (strpos($svgstyle['objstyle'], $objstyle) === false) {
2097+
$svgstyle['objstyle'] .= $objstyle; // @phpstan-ignore-line
2098+
}
20912099

20922100
$out .= $col->getPdfColor();
20932101

@@ -2130,7 +2138,7 @@ protected function parseSVGStyleClipPath(
21302138
* @param string $clip_fnc Optional clipping function name.
21312139
* @param array<mixed> $clip_par Optional clipping function parameters.
21322140
*
2133-
* @return string the Raw PDF command.
2141+
* @return string the object style.
21342142
*/
21352143
protected function parseSVGStyle(
21362144
\XMLParser $parser,
@@ -2178,7 +2186,10 @@ protected function parseSVGStyle(
21782186
$this->svgobjs[$soid]['styles'][$psid]
21792187
);
21802188

2181-
return $out;
2189+
// @phpstan-ignore assign.propertyType
2190+
$this->svgobjs[$soid]['out'] .= $out;
2191+
2192+
return $svgstyle['objstyle'];
21822193
}
21832194

21842195
/**
@@ -3010,13 +3021,15 @@ protected function parseSVGTagSTARTpath(\XMLParser $parser, int $soid, array $at
30103021
[$width, 0.0, 0.0, $height, $posx, $posy]
30113022
);
30123023

3024+
30133025
if ($this->svgobjs[$soid]['clipmode']) {
30143026
// @phpstan-ignore assign.propertyType
30153027
$this->svgobjs[$soid]['out'] .= $this->getOutSVGTransformation($tmx);
30163028
// @phpstan-ignore assign.propertyType
30173029
$this->svgobjs[$soid]['out'] .= $this->getSVGPath($ptd, 'CNZ');
30183030
return;
30193031
}
3032+
30203033
// @phpstan-ignore assign.propertyType
30213034
$this->svgobjs[$soid]['out'] .= $this->graph->getStartTransform();
30223035
// @phpstan-ignore assign.propertyType
@@ -3031,6 +3044,7 @@ protected function parseSVGTagSTARTpath(\XMLParser $parser, int $soid, array $at
30313044
'getSVGPath',
30323045
[$ptd, 'CNZ'],
30333046
);
3047+
30343048
if (!empty($obstyle)) {
30353049
// @phpstan-ignore assign.propertyType
30363050
$this->svgobjs[$soid]['out'] .= $this->getSVGPath($ptd, $obstyle);

0 commit comments

Comments
 (0)