Changeset 323
- Timestamp:
- 02/26/08 23:36:12 (9 months ago)
- Files:
-
- cleversvg/trunk/base/csBaseElement.class.php (modified) (21 diffs)
- cleversvg/trunk/base/csBaseGradient.class.php (modified) (5 diffs)
- cleversvg/trunk/quick_examples.php (modified) (1 diff)
- cleversvg/trunk/tests/csDocumentTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cleversvg/trunk/base/csBaseElement.class.php
r318 r323 1 1 <?php 2 2 /** 3 * SVG Base Element abstract class. Shapes and Groups all herit from this class. 4 * 3 * SVG Base Element abstract class. Shapes and Groups all herit from this class. 4 * 5 5 * @author Nicolas Perriault <nperriault@gmail.com> 6 6 * @package cleversvg … … 10 10 { 11 11 12 protected 12 protected 13 13 $dom_document = null, 14 14 $attributes = array(), … … 19 19 /** 20 20 * Manage object cloning 21 * 21 * 22 22 */ 23 23 public function __clone() … … 28 28 /** 29 29 * Adds a transformation to current shape 30 * 30 * 31 31 * @param string $type Transform type (matrix, translate, etc...) 32 32 * @param array $params Parameters of transformation … … 43 43 if (!in_array($type, $types)) 44 44 { 45 throw new csException(sprintf('"%s" is not a valid transform type', 45 throw new csException(sprintf('"%s" is not a valid transform type', 46 46 $type)); 47 47 } 48 48 $this->transforms[$type] = $params; 49 49 } 50 50 51 51 /** 52 52 * Computes DOMXML Node 53 * 53 * 54 54 * @param boolean $embedded Is SVG element embedded ? 55 55 * @return DOMElement … … 84 84 } 85 85 } 86 86 87 87 // Transformations, if any 88 88 if (count($this->transforms) > 0) … … 91 91 foreach ($this->transforms as $transform_name => $transform_params) 92 92 { 93 $transforms[] = sprintf('%s(%s)', 94 $transform_name, 93 $transforms[] = sprintf('%s(%s)', 94 $transform_name, 95 95 implode(',', $transform_params)); 96 96 97 97 } 98 98 $element_node->setAttribute('transform', implode(' ', $transforms)); 99 99 } 100 100 101 101 return $element_node; 102 102 } 103 103 104 104 /** 105 105 * Gets the current depth 106 * 106 * 107 107 * @return mixed (int depth or NULL) 108 108 */ … … 118 118 } 119 119 } 120 120 121 121 /** 122 122 * Returns a DOM DOcument 123 * 124 * @return DOMDocument 123 * 124 * @return DOMDocument 125 125 */ 126 126 public function getDomDocument() … … 132 132 return $this->dom_document; 133 133 } 134 134 135 135 /** 136 136 * Gets the node name of current SVG element 137 * 138 * @param boolean $embedded 137 * 138 * @param boolean $embedded 139 139 * @return string 140 140 */ 141 p ublicfunction getElementName($embedded=false)141 protected function getElementName($embedded=false) 142 142 { 143 143 if ($embedded === true) … … 151 151 return $node_name; 152 152 } 153 154 /** 155 * Specifies a transformation in the form of a transformation matrix of 153 154 /** 155 * Specifies a transformation in the form of a transformation matrix of 156 156 * six values 157 * 157 * 158 158 * @param int $a 159 159 * @param int $b … … 167 167 $this->addTransform('matrix', array($a, $b, $c, $d, $e, $f)); 168 168 } 169 169 170 170 /** 171 171 * Rotates shape 172 * 172 * 173 173 * @param int $angle 174 174 * @param int $cx … … 179 179 $this->addTransform('rotate', array($angle, $cx, $cy)); 180 180 } 181 181 182 182 /** 183 183 * Scales shape 184 * 184 * 185 185 * @param int $xscale 186 * @param int $yscale 186 * @param int $yscale 187 187 */ 188 188 public function scale($xscale, $yscale=null) … … 195 195 $this->addTransform('scale', $params); 196 196 } 197 197 198 198 /** 199 199 * Specifies a skew transformation along the x-axis 200 * 200 * 201 201 * @param int $angle 202 202 */ … … 205 205 $this->addTransform('skewX', array($angle)); 206 206 } 207 207 208 208 /** 209 209 * Specifies a skew transformation along the y-axis 210 * 210 * 211 211 * @param int $angle 212 212 */ … … 215 215 $this->addTransform('skewY', array($angle)); 216 216 } 217 217 218 218 /** 219 219 * Translates shape 220 * 220 * 221 221 * @param int $tx 222 222 * @param int $ty … … 231 231 $this->addTransform('translate', $params); 232 232 } 233 234 /** 235 * Deletes an attribute 236 * 233 234 /** 235 * Deletes an attribute 236 * 237 237 */ 238 238 protected function deteleAttribute($name) … … 243 243 } 244 244 } 245 245 246 246 /** 247 247 * Sets an attribute for current element 248 * 248 * 249 249 * @param string $name 250 250 * @param mixed $value … … 262 262 } 263 263 } 264 264 265 265 /** 266 266 * Sets the depth of object 267 * 267 * 268 268 * @param int $depth 269 269 */ … … 275 275 } 276 276 } 277 277 278 278 /** 279 279 * Gets the DOM id of current element tag 280 * 280 * 281 281 * @return mixed (string id or NULL) 282 282 */ … … 292 292 } 293 293 } 294 294 295 295 /** 296 296 * Sets the DOM id of current element tag 297 * 297 * 298 298 * @param string $id 299 299 */ … … 308 308 /** 309 309 * Sets a SVG style via an associative array 310 * 310 * 311 311 * @param array $style 312 312 */ 313 313 public function setStyle($style) 314 314 { 315 // Styles properties bellow should be treated as attributes and not 316 // in a style attribute (FF 1.5 compat) 315 // Styles properties bellow should be treated as attributes and not 316 // in a style attribute (FF 1.5 compat) 317 317 $convert_styles = array('stroke', 'stroke-width', 'fill'); 318 318 foreach ($style as $style_name => $style_value) cleversvg/trunk/base/csBaseGradient.class.php
r318 r323 2 2 /** 3 3 * SVG base gradient abstract class 4 * 4 * 5 5 * @author Nicolas Perriault <nperriault@gmail.com> 6 6 * @package cleversvg … … 10 10 { 11 11 12 protected 12 protected 13 13 $stops = array(), 14 14 $xml_node_name = 'unknown'; 15 15 16 16 /** 17 * Adds a <stop/> elementto specify gradient marker points 18 * 17 * Adds a <stop/> elementto specify gradient marker points 18 * 19 19 * @param mixed $offset Stop offset (can be percentage) 20 20 * @param string $stop_color (optional, default=black) … … 23 23 public function addStop($offset, $stop_color='black', $stop_opacity=1) 24 24 { 25 $this->stops[] = array('offset' => $offset, 26 'stop-color' => $stop_color, 25 $this->stops[] = array('offset' => $offset, 26 'stop-color' => $stop_color, 27 27 'stop-opacity' => $stop_opacity); 28 28 } 29 29 30 30 /** 31 31 * Computes DOMXML Node 32 * 32 * 33 33 * @param boolean $embedded Is SVG element embedded ? 34 34 * @return DOMElement … … 38 38 $dom = $this->getDomDocument(); 39 39 $element_node = parent::compile($embedded); 40 40 41 41 // Add stops 42 42 if (count($this->stops) > 0) … … 52 52 } 53 53 } 54 54 55 55 return $element_node; 56 56 } 57 57 58 58 /** 59 59 * Gets the node name of current SVG element 60 * 61 * @param boolean $embedded 60 * 61 * @param boolean $embedded 62 62 * @return string 63 63 */ 64 p ublicfunction getStopNodeName($embedded)64 protected function getStopNodeName($embedded) 65 65 { 66 66 return $embedded === true ? 'svg:stop' : 'stop'; 67 67 } 68 68 69 69 } cleversvg/trunk/quick_examples.php
r309 r323 50 50 51 51 //When you're done, render the document as a standalone one 52 echo $doc->toXML( );52 echo $doc->toXML(true); 53 53 54 54 //Or an embedded one : cleversvg/trunk/tests/csDocumentTest.php
r322 r323 3 3 require_once dirname(__FILE__).'/../cleversvg.php'; 4 4 5 /** 6 * csDocument PHPUnit tests 7 * 8 */ 5 9 class csDocumentTest extends PHPUnit_Framework_TestCase 6 10 {
