PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.32
E2Pdf – Export Pdf Tool for WordPress v1.32.32
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
e2pdf / vendors / svggraph / ColourGroup.php

ColourGroup.php in E2Pdf – Export Pdf Tool for WordPress 1.32.32, at vendors/svggraph/ColourGroup.php

110 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Copyright (C) 2020-2022 Graham Breach
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 /**
19 * For more information, please contact <graham@goat1000.com>
20 */
21
22 namespace Goat1000\SVGGraph;
23
24 /**
25 * Class for related stroke and fill colours
26 */
27 class ColourGroup {
28 private $stroke;
29
30 public function __construct(&$graph, $item, $key, $dataset,
31 $stroke_opt = 'stroke_colour', $fill = null, $item_opt = null,
32 $stroke_opt_is_colour = false)
33 {
34 $stroke = $stroke_opt_is_colour ? $stroke_opt :
35 $graph->getItemOption($stroke_opt, $dataset, $item, $item_opt);
36 if(is_array($stroke)) {
37 $this->stroke = new Colour($graph, $stroke);
38 return;
39 }
40
41 list ($stroke_colour, $opacity, $filters) = $this->colourParts($stroke);
42
43 // not a fill colour?
44 if($stroke_colour !== 'fill' && $stroke_colour !== 'fillColour') {
45 $this->stroke = new Colour($graph, $stroke);
46 return;
47 }
48
49 $allow_grad_pat = ($stroke_colour === 'fill');
50
51 if($fill !== null) {
52 $stroke_colour = new Colour($graph, $fill, $allow_grad_pat, $allow_grad_pat);
53 } else {
54 $stroke_colour = $graph->getColour($item, $key, $dataset, $allow_grad_pat,
55 $allow_grad_pat);
56 }
57
58 if($stroke_colour->isNone())
59 $stroke_colour = new Colour($graph, 'black');
60
61 $not_solid = $stroke_colour->isGradient() || $stroke_colour->isPattern();
62
63 // if there are no modifications to make, we're done
64 if($not_solid || ($opacity >= 1 && $filters == '')) {
65 $this->stroke = $stroke_colour;
66 return;
67 }
68
69 $stroke = $stroke_colour->solid();
70 if($opacity < 1)
71 $stroke .= ':' . $opacity;
72 if($filters != '')
73 $stroke .= '/' . $filters;
74
75 $this->stroke = new Colour($graph, $stroke);
76 }
77
78 /**
79 * Splits a colour into parts
80 */
81 private static function colourParts($colour)
82 {
83 $opacity = 1;
84 $filters = '';
85
86 if(!empty($colour)) {
87 // get opacity / filters
88 $spos = strpos($colour, '/');
89 if($spos !== false) {
90 $filters = substr($colour, $spos + 1);
91 $colour = substr($colour, 0, $spos);
92 }
93
94 $spos = strpos($colour, ':');
95 if($spos !== false) {
96 $opacity = substr($colour, $spos + 1);
97 $colour = substr($colour, 0, $spos);
98 }
99 }
100
101 return [$colour, $opacity, $filters];
102 }
103
104 public function stroke()
105 {
106 return $this->stroke;
107 }
108 }
109
110