| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
class csPath extends csBaseShape |
|---|
| 10 |
{ |
|---|
| 11 |
|
|---|
| 12 |
protected |
|---|
| 13 |
$xml_node_name = 'path', |
|---|
| 14 |
$path_array = array(); |
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
* Class constructor |
|---|
| 18 |
* |
|---|
| 19 |
*/ |
|---|
| 20 |
public function __construct($path_data = array(), $attrs = array()) |
|---|
| 21 |
{ |
|---|
| 22 |
$this->setPathDataArray($path_data); |
|---|
| 23 |
$this->setFill('none'); |
|---|
| 24 |
$this->attributes = array_merge($attrs, $this->attributes); |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
* Compute current path data array |
|---|
| 29 |
* |
|---|
| 30 |
*/ |
|---|
| 31 |
protected function computePath() |
|---|
| 32 |
{ |
|---|
| 33 |
$path_string = ''; |
|---|
| 34 |
foreach ($this->path_data_array as $move) |
|---|
| 35 |
{ |
|---|
| 36 |
if (isset($move[1])) |
|---|
| 37 |
{ |
|---|
| 38 |
$path_string .= sprintf('%s %s', |
|---|
| 39 |
$move[0], |
|---|
| 40 |
implode(' ', $move[1])); |
|---|
| 41 |
} |
|---|
| 42 |
else |
|---|
| 43 |
{ |
|---|
| 44 |
$path_string .= $move[0]; |
|---|
| 45 |
} |
|---|
| 46 |
} |
|---|
| 47 |
$this->setPathDataString(trim($path_string)); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
* Sets the path data from an array |
|---|
| 52 |
* |
|---|
| 53 |
* @param array |
|---|
| 54 |
*/ |
|---|
| 55 |
public function setPathDataArray($path_data_array) |
|---|
| 56 |
{ |
|---|
| 57 |
$this->path_data_array = $path_data_array; |
|---|
| 58 |
$this->computePath(); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
* Sets the path string |
|---|
| 63 |
* |
|---|
| 64 |
* @param string |
|---|
| 65 |
*/ |
|---|
| 66 |
public function setPathDataString($path_data_string) |
|---|
| 67 |
{ |
|---|
| 68 |
$last_char = substr($path_data_string, strlen($path_data_string)-1, 1); |
|---|
| 69 |
if (!strtolower($last_char) === 'z') |
|---|
| 70 |
{ |
|---|
| 71 |
$path_data_string .= ' z'; |
|---|
| 72 |
} |
|---|
| 73 |
$this->setAttribute('d', $path_data_string); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
* Init path data array and ready to receive path building directions |
|---|
| 78 |
* |
|---|
| 79 |
*/ |
|---|
| 80 |
public function begin() |
|---|
| 81 |
{ |
|---|
| 82 |
$this->path_data_array = array(); |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
public function end() |
|---|
| 86 |
{ |
|---|
| 87 |
$this->path_data_array[] = array('Z'); |
|---|
| 88 |
$this->computePath(); |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
* Move to a point |
|---|
| 93 |
* |
|---|
| 94 |
* @param int $x |
|---|
| 95 |
* @param int $y |
|---|
| 96 |
*/ |
|---|
| 97 |
public function moveTo($x, $y) |
|---|
| 98 |
{ |
|---|
| 99 |
$this->path_data_array[] = array('M', array($x, $y)); |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
* Draws a line moving to a point |
|---|
| 104 |
* |
|---|
| 105 |
* @param int $x |
|---|
| 106 |
* @param int $y |
|---|
| 107 |
*/ |
|---|
| 108 |
public function lineTo($x, $y) |
|---|
| 109 |
{ |
|---|
| 110 |
$this->path_data_array[] = array('L', array($x, $y)); |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
* Draws a horizontal line moving to a point |
|---|
| 115 |
* |
|---|
| 116 |
* @param int $x |
|---|
| 117 |
*/ |
|---|
| 118 |
public function hLineTo($x) |
|---|
| 119 |
{ |
|---|
| 120 |
$this->path_data_array[] = array('H', array($x)); |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
* Draws a vertical line moving to a point |
|---|
| 125 |
* |
|---|
| 126 |
* @param int $y |
|---|
| 127 |
*/ |
|---|
| 128 |
public function vLineTo($y) |
|---|
| 129 |
{ |
|---|
| 130 |
$this->path_data_array[] = array('V', array($y)); |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
* Draws a curve moving to a point |
|---|
| 135 |
* |
|---|
| 136 |
*/ |
|---|
| 137 |
public function curveTo($x, $y, $x1, $y1, $x2, $y2) |
|---|
| 138 |
{ |
|---|
| 139 |
$this->path_data_array[] = array('C', array($x, $y, $x1, $y1, $x2, $y2)); |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
* Draws a smooth curve moving to a point |
|---|
| 144 |
* |
|---|
| 145 |
*/ |
|---|
| 146 |
public function smoothCurveTo($x, $y, $x2, $y2) |
|---|
| 147 |
{ |
|---|
| 148 |
$this->path_data_array[] = array('S', array($x, $y, $x2, $y2)); |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
* The x-axis coordinate of one corner of the rectangular region into which an |
|---|
| 153 |
* embedded 'svg' element is placed. |
|---|
| 154 |
* |
|---|
| 155 |
* @param int |
|---|
| 156 |
*/ |
|---|
| 157 |
public function setX($x) |
|---|
| 158 |
{ |
|---|
| 159 |
$this->setAttribute('x', $x); |
|---|
| 160 |
} |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
* The y-axis coordinate of one corner of the rectangular region into which an |
|---|
| 164 |
* embedded 'svg' element is placed. |
|---|
| 165 |
* |
|---|
| 166 |
* @param int |
|---|
| 167 |
*/ |
|---|
| 168 |
public function setY($y) |
|---|
| 169 |
{ |
|---|
| 170 |
$this->setAttribute('y', $y); |
|---|
| 171 |
} |
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
} |
|---|
| 175 |
|
|---|