Skip to content

Commit bdcd417

Browse files
committed
add draft svg path tag parser
1 parent ab4d449 commit bdcd417

File tree

1 file changed

+64
-4
lines changed

1 file changed

+64
-4
lines changed

src/SVG.php

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,7 +2505,8 @@ protected function handleSVGTagStart(
25052505
'radialGradient' => $this->parseSVGTagSTARTradialGradient($soid, $attribs['attr']),
25062506
// @phpstan-ignore argument.type
25072507
'stop' => $this->parseSVGTagSTARTstop($soid, $attribs['attr'], $svgstyle),
2508-
'path' => $this->parseSVGTagSTARTpath($soid),
2508+
// @phpstan-ignore argument.type
2509+
'path' => $this->parseSVGTagSTARTpath($soid, $attribs['attr'], $svgstyle),
25092510
'rect' => $this->parseSVGTagSTARTrect($soid),
25102511
'circle' => $this->parseSVGTagSTARTcircle($soid),
25112512
'ellipse' => $this->parseSVGTagSTARTellipse($soid),
@@ -2770,13 +2771,51 @@ protected function parseSVGTagSTARTstop(int $soid, array $attr, array $svgstyle)
27702771
* Parse the SVG Start tag 'path'.
27712772
*
27722773
* @param int $soid ID of the current SVG object.
2774+
* @param TSVGAttributes $attr SVG attributes.
2775+
* @param TSVGStyle $svgstyle Current SVG style.
27732776
*
27742777
* @return void
27752778
*/
2776-
protected function parseSVGTagSTARTpath(int $soid)
2779+
protected function parseSVGTagSTARTpath(int $soid, array $attr, array $svgstyle)
27772780
{
2778-
$soid = $soid; // @phpstan-ignore-line
2779-
//@TODO
2781+
if (!empty($this->svgobjs[$soid]['textmode']['invisible'])) {
2782+
return;
2783+
}
2784+
if (empty($attr['d'])) {
2785+
return;
2786+
}
2787+
2788+
$ptd = trim($attr['d']);
2789+
$posx = isset($attr['x']) ? $this->toUnit($this->getUnitValuePoints($attr['x'])) : 0.0;
2790+
$posy = isset($attr['y']) ? $this->toUnit($this->getUnitValuePoints($attr['y'])) : 0.0;
2791+
$width = isset($attr['width']) ? $this->toUnit($this->getUnitValuePoints($attr['width'])) : 1.0;
2792+
$height = isset($attr['height']) ? $this->toUnit($this->getUnitValuePoints($attr['height'])) : 1.0;
2793+
$tmx = $this->graph->getCtmProduct(
2794+
$svgstyle['transfmatrix'],
2795+
[$width, 0.0, 0.0, $height, $posx, $posy]
2796+
);
2797+
2798+
if ($this->svgobjs[$soid]['clipmode']) {
2799+
$this->svgobjs[$soid]['out'] .= $this->getOutSVGTransformation($tmx);
2800+
$this->svgobjs[$soid]['out'] .= $this->getSVGPath($ptd, 'CNZ');
2801+
return;
2802+
}
2803+
2804+
$this->svgobjs[$soid]['out'] .= $this->graph->getStartTransform();
2805+
$this->svgobjs[$soid]['out'] .= $this->getOutSVGTransformation($tmx);
2806+
$obstyle = $this->parseSVGStyle(
2807+
$this->svgobjs[$soid],
2808+
$posx,
2809+
$posy,
2810+
$width,
2811+
$height,
2812+
'getSVGPath',
2813+
[$ptd, 'CNZ'],
2814+
);
2815+
if (!empty($obstyle)) {
2816+
$this->svgobjs[$soid]['out'] .= $this->getSVGPath($ptd, $obstyle);
2817+
}
2818+
$this->svgobjs[$soid]['out'] .= $this->graph->getStopTransform();
27802819
}
27812820

27822821
/**
@@ -2788,6 +2827,9 @@ protected function parseSVGTagSTARTpath(int $soid)
27882827
*/
27892828
protected function parseSVGTagSTARTrect(int $soid)
27902829
{
2830+
if (!empty($this->svgobjs[$soid]['textmode']['invisible'])) {
2831+
return;
2832+
}
27912833
$soid = $soid; // @phpstan-ignore-line
27922834
//@TODO
27932835
}
@@ -2801,6 +2843,9 @@ protected function parseSVGTagSTARTrect(int $soid)
28012843
*/
28022844
protected function parseSVGTagSTARTcircle(int $soid)
28032845
{
2846+
if (!empty($this->svgobjs[$soid]['textmode']['invisible'])) {
2847+
return;
2848+
}
28042849
$soid = $soid; // @phpstan-ignore-line
28052850
//@TODO
28062851
}
@@ -2814,6 +2859,9 @@ protected function parseSVGTagSTARTcircle(int $soid)
28142859
*/
28152860
protected function parseSVGTagSTARTellipse(int $soid)
28162861
{
2862+
if (!empty($this->svgobjs[$soid]['textmode']['invisible'])) {
2863+
return;
2864+
}
28172865
$soid = $soid; // @phpstan-ignore-line
28182866
//@TODO
28192867
}
@@ -2827,6 +2875,9 @@ protected function parseSVGTagSTARTellipse(int $soid)
28272875
*/
28282876
protected function parseSVGTagSTARTline(int $soid)
28292877
{
2878+
if (!empty($this->svgobjs[$soid]['textmode']['invisible'])) {
2879+
return;
2880+
}
28302881
$soid = $soid; // @phpstan-ignore-line
28312882
//@TODO
28322883
}
@@ -2840,6 +2891,9 @@ protected function parseSVGTagSTARTline(int $soid)
28402891
*/
28412892
protected function parseSVGTagSTARTpolyline(int $soid)
28422893
{
2894+
if (!empty($this->svgobjs[$soid]['textmode']['invisible'])) {
2895+
return;
2896+
}
28432897
$soid = $soid; // @phpstan-ignore-line
28442898
//@TODO
28452899
}
@@ -2853,6 +2907,9 @@ protected function parseSVGTagSTARTpolyline(int $soid)
28532907
*/
28542908
protected function parseSVGTagSTARTpolygon(int $soid)
28552909
{
2910+
if (!empty($this->svgobjs[$soid]['textmode']['invisible'])) {
2911+
return;
2912+
}
28562913
$soid = $soid; // @phpstan-ignore-line
28572914
//@TODO
28582915
}
@@ -2866,6 +2923,9 @@ protected function parseSVGTagSTARTpolygon(int $soid)
28662923
*/
28672924
protected function parseSVGTagSTARTimage(int $soid)
28682925
{
2926+
if (!empty($this->svgobjs[$soid]['textmode']['invisible'])) {
2927+
return;
2928+
}
28692929
$soid = $soid; // @phpstan-ignore-line
28702930
//@TODO
28712931
}

0 commit comments

Comments
 (0)