Skip to content

Commit a782e84

Browse files
committed
draft svg functions signatures
1 parent 959a3d9 commit a782e84

File tree

1 file changed

+42
-31
lines changed

1 file changed

+42
-31
lines changed

src/SVG.php

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,20 +2080,22 @@ protected function parseSVGStyleFill(
20802080
/**
20812081
* Parse the SVG style clip-path.
20822082
*
2083+
* @param int $soid SVG object ID.
20832084
* @param array<string, TSVGClipPath> $clippaths Clipping paths.
20842085
*/
20852086
protected function parseSVGStyleClipPath(
2087+
int $soid,
20862088
array $clippaths = [],
20872089
): void {
20882090
foreach ($clippaths as $cp) {
2089-
$this->handleSVGTagStart('clip-path', $cp['name'], $cp['attr'], $cp['tm']);
2091+
$this->handleSVGTagStart('clip-path', $cp['name'], $soid, $cp['attr'], $cp['tm']);
20902092
}
20912093
}
20922094

20932095
/**
20942096
* Parse the SVG style.
20952097
*
2096-
* @param TSVGObj $svgobj SVG object.
2098+
* @param int $soid SVG object ID.
20972099
* @param float $posx X position in user units.
20982100
* @param float $posy Y position in user units.
20992101
* @param float $width Width in user units.
@@ -2104,42 +2106,45 @@ protected function parseSVGStyleClipPath(
21042106
* @return string the Raw PDF command.
21052107
*/
21062108
protected function parseSVGStyle(
2107-
array &$svgobj,
2109+
int $soid,
21082110
float $posx = 0,
21092111
float $posy = 0,
21102112
float $width = 1,
21112113
float $height = 1,
21122114
string $clip_fnc = '',
21132115
array $clip_par = [],
21142116
): string {
2115-
$sid = (int)array_key_last($svgobj['styles']);
2117+
$sid = (int)array_key_last($this->svgobjs[$soid]['styles']);
21162118

2117-
if (empty($svgobj['styles'][$sid]['opacity'])) {
2119+
if (empty($this->svgobjs[$soid]['styles'][$sid]['opacity'])) {
21182120
return '';
21192121
}
21202122

2121-
$this->parseSVGStyleClipPath($svgobj['clippaths']);
2123+
$this->parseSVGStyleClipPath($soid, $this->svgobjs[$soid]['clippaths']);
21222124

2123-
return $this->parseSVGStyleColor($svgobj['styles'][$sid]) .
2125+
return $this->parseSVGStyleColor($this->svgobjs[$soid]['styles'][$sid]) .
21242126
$this->parseSVGStyleClip(
2125-
$svgobj['styles'][$sid],
2127+
$this->svgobjs[$soid]['styles'][$sid],
21262128
$posx,
21272129
$posy,
21282130
$width,
21292131
$height
21302132
) .
21312133
$this->parseSVGStyleFill(
2132-
$svgobj['styles'][$sid],
2133-
$svgobj['gradients'],
2134+
$this->svgobjs[$soid]['styles'][$sid],
2135+
$this->svgobjs[$soid]['gradients'],
21342136
$posx,
21352137
$posy,
21362138
$width,
21372139
$height,
21382140
$clip_fnc,
21392141
$clip_par
21402142
) .
2141-
$this->parseSVGStyleStroke($svgobj['styles'][$sid]) .
2142-
$this->parseSVGStyleFont($svgobj['styles'][$sid], $svgobj['styles'][($sid - 1)]);
2143+
$this->parseSVGStyleStroke($this->svgobjs[$soid]['styles'][$sid]) .
2144+
$this->parseSVGStyleFont(
2145+
$this->svgobjs[$soid]['styles'][$sid],
2146+
$this->svgobjs[$soid]['styles'][($sid - 1)]
2147+
);
21432148
}
21442149

21452150
/**
@@ -2360,6 +2365,7 @@ protected function parseSVGTagENDtext(int $soid): void
23602365
*
23612366
* @param string $parser The XML parser calling the handler.
23622367
* @param string $name Name of the element for which this handler is called.
2368+
* @param int $soid ID of the current SVG object.
23632369
* @param TSVGAttribs $attribs Associative array with the element's attributes.
23642370
* @param TTMatrix $ctm Current transformation matrix (optional).
23652371
*
@@ -2370,16 +2376,16 @@ protected function parseSVGTagENDtext(int $soid): void
23702376
protected function handleSVGTagStart(
23712377
string $parser,
23722378
string $name,
2379+
int $soid,
23732380
array $attribs,
23742381
array $ctm = [1.0,0.0,0.0,1.0,0.0,0.0], // identity matrix
23752382
): void {
2376-
$name = $this->removeTagNamespace($name);
2377-
2378-
$soid = (int)array_key_last($this->svgobjs);
2379-
if ($soid < 0) {
2383+
if (empty($this->svgobjs[$soid])) {
23802384
return;
23812385
}
23822386

2387+
$name = $this->removeTagNamespace($name);
2388+
23832389
if ($this->svgobjs[$soid]['clipmode']) {
23842390
$this->svgobjs[$soid]['clippaths'][] = [
23852391
'name' => $name,
@@ -2535,7 +2541,12 @@ protected function handleSVGTagStart(
25352541
continue;
25362542
}
25372543
if (empty($child['attr']['closing_tag'])) {
2538-
$this->handleSVGTagStart('child-tag', $child['name'], $child['attr']); // @phpstan-ignore argument.type
2544+
$this->handleSVGTagStart(
2545+
'child-tag',
2546+
$child['name'],
2547+
$soid,
2548+
$child['attr'], // @phpstan-ignore argument.type
2549+
);
25392550
continue;
25402551
}
25412552
if (isset($child['attr']['content'])) {
@@ -2631,7 +2642,7 @@ protected function parseSVGTagSTARTsvg(int $soid, array $attr, array $svgstyle)
26312642
'CNZ',
26322643
);
26332644
$this->parseSVGStyle(
2634-
$this->svgobjs[$soid],
2645+
$soid,
26352646
$posx,
26362647
$posy,
26372648
$width,
@@ -2640,7 +2651,7 @@ protected function parseSVGTagSTARTsvg(int $soid, array $attr, array $svgstyle)
26402651
// parse viewbox, calculate extra transformation matrix
26412652
if (empty($attr['viewBox'])) {
26422653
$this->parseSVGStyle(
2643-
$this->svgobjs[$soid],
2654+
$soid,
26442655
$posx,
26452656
$posy,
26462657
$width,
@@ -2653,7 +2664,7 @@ protected function parseSVGTagSTARTsvg(int $soid, array $attr, array $svgstyle)
26532664
$tmp = $tmp[0];
26542665
if (sizeof($tmp) != 4) {
26552666
$this->parseSVGStyle(
2656-
$this->svgobjs[$soid],
2667+
$soid,
26572668
$posx,
26582669
$posy,
26592670
$width,
@@ -2714,7 +2725,7 @@ protected function parseSVGTagSTARTsvg(int $soid, array $attr, array $svgstyle)
27142725
$tmx = $this->graph->getCtmProduct($tmx, $newtmx);
27152726
$this->svgobjs[$soid]['out'] .= $this->getOutSVGTransformation($tmx);
27162727
$this->parseSVGStyle(
2717-
$this->svgobjs[$soid],
2728+
$soid,
27182729
$posx,
27192730
$posy,
27202731
$width,
@@ -2745,7 +2756,7 @@ protected function parseSVGTagSTARTg(int $soid, array $attr, array $svgstyle)
27452756
);
27462757
$this->svgobjs[$soid]['out'] .= $this->getOutSVGTransformation($tmx);
27472758
$this->svgobjs[$soid]['out'] .= $this->parseSVGStyle(
2748-
$this->svgobjs[$soid],
2759+
$soid,
27492760
$posx,
27502761
$posy,
27512762
$width,
@@ -2942,7 +2953,7 @@ protected function parseSVGTagSTARTpath(int $soid, array $attr, array $svgstyle)
29422953
$this->svgobjs[$soid]['out'] .= $this->graph->getStartTransform();
29432954
$this->svgobjs[$soid]['out'] .= $this->getOutSVGTransformation($tmx);
29442955
$obstyle = $this->parseSVGStyle(
2945-
$this->svgobjs[$soid],
2956+
$soid,
29462957
$posx,
29472958
$posy,
29482959
$width,
@@ -3005,7 +3016,7 @@ protected function parseSVGTagSTARTrect(int $soid, array $attr, array $svgstyle)
30053016
$this->svgobjs[$soid]['out'] .= $this->graph->getStartTransform();
30063017
$this->svgobjs[$soid]['out'] .= $this->getOutSVGTransformation($svgstyle['transfmatrix']);
30073018
$obstyle = $this->parseSVGStyle(
3008-
$this->svgobjs[$soid],
3019+
$soid,
30093020
$posx,
30103021
$posy,
30113022
$width,
@@ -3076,7 +3087,7 @@ protected function parseSVGTagSTARTcircle(int $soid, array $attr, array $svgstyl
30763087
$this->svgobjs[$soid]['out'] .= $this->graph->getStartTransform();
30773088
$this->svgobjs[$soid]['out'] .= $this->getOutSVGTransformation($svgstyle['transfmatrix']);
30783089
$obstyle = $this->parseSVGStyle(
3079-
$this->svgobjs[$soid],
3090+
$soid,
30803091
$posx,
30813092
$posy,
30823093
$width,
@@ -3152,7 +3163,7 @@ protected function parseSVGTagSTARTellipse(int $soid, array $attr, array $svgsty
31523163
$this->svgobjs[$soid]['out'] .= $this->graph->getStartTransform();
31533164
$this->svgobjs[$soid]['out'] .= $this->getOutSVGTransformation($svgstyle['transfmatrix']);
31543165
$obstyle = $this->parseSVGStyle(
3155-
$this->svgobjs[$soid],
3166+
$soid,
31563167
$posx,
31573168
$posy,
31583169
$width,
@@ -3213,7 +3224,7 @@ protected function parseSVGTagSTARTline(int $soid, array $attr, array $svgstyle)
32133224
$this->svgobjs[$soid]['out'] .= $this->graph->getStartTransform();
32143225
$this->svgobjs[$soid]['out'] .= $this->getOutSVGTransformation($svgstyle['transfmatrix']);
32153226
$this->parseSVGStyle(
3216-
$this->svgobjs[$soid],
3227+
$soid,
32173228
$posx,
32183229
$posy,
32193230
$width,
@@ -3284,7 +3295,7 @@ protected function parseSVGTagSTARTpolygon(int $soid, array $attr, array $svgsty
32843295
$this->svgobjs[$soid]['out'] .= $this->graph->getStartTransform();
32853296
$this->svgobjs[$soid]['out'] .= $this->getOutSVGTransformation($svgstyle['transfmatrix']);
32863297
$obstyle = $this->parseSVGStyle(
3287-
$this->svgobjs[$soid],
3298+
$soid,
32883299
$posx,
32893300
$posy,
32903301
$width,
@@ -3337,7 +3348,7 @@ protected function parseSVGTagSTARTimage(int $soid, array $attr, array $svgstyle
33373348
$this->svgobjs[$soid]['out'] .= $this->graph->getStartTransform();
33383349
$this->svgobjs[$soid]['out'] .= $this->getOutSVGTransformation($svgstyle['transfmatrix']);
33393350
$this->parseSVGStyle(
3340-
$this->svgobjs[$soid],
3351+
$soid,
33413352
$posx,
33423353
$posy,
33433354
$width,
@@ -3436,7 +3447,7 @@ protected function parseSVGTagSTARTtext(int $soid, array $attr, array $svgstyle,
34363447
$this->svgobjs[$soid]['out'] .= $this->graph->getStartTransform();
34373448
$this->svgobjs[$soid]['out'] .= $this->getOutSVGTransformation($svgstyle['transfmatrix']);
34383449
$this->parseSVGStyle(
3439-
$this->svgobjs[$soid], // @phpstan-ignore-line argument.type
3450+
$soid,
34403451
$posx,
34413452
$posy,
34423453
1,
@@ -3502,6 +3513,6 @@ protected function parseSVGTagSTARTuse(int $soid, array $attribs, string $parser
35023513
$attribs['attr'] = array_merge($use['attr']['attr'], $attr);
35033514
/** @var TSVGAttribs $attribs */
35043515
$attribs = (array) $attribs;
3505-
$this->handleSVGTagStart($parser, $use['name'], $attribs);
3516+
$this->handleSVGTagStart($parser, $use['name'], $soid, $attribs);
35063517
}
35073518
}

0 commit comments

Comments
 (0)