root/cleversvg/trunk/base/csBaseShape.class.php

Revision 326, 2.0 kB (checked in by nperriault, 10 months ago)

refs #40 - More tests + bug fixes

  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2 /**
3  * SVG Base Shape abstract class. All shapes inherit from this base class.
4  *
5  * @author     Nicolas Perriault <nperriault@gmail.com>
6  * @package    cleversvg
7  * @subpackage elements
8  */
9 class csBaseShape extends csBaseElement
10 {
11
12   /**
13    * Computes DOMXML Node
14    *
15    * @param  boolean  $embedded  Is SVG element embedded ?
16    * @return DOMElement
17    */
18   public function compile($embedded=false)
19   {
20     $element_node = parent::compile($embedded);
21
22     // Transformations, if any
23     if (count($this->transforms) > 0)
24     {
25       $transforms = array();
26       foreach ($this->transforms as $transform_name => $transform_params)
27       {
28         $transforms[] = sprintf('%s(%s)',
29                                 $transform_name,
30                                 implode(',', $transform_params));
31
32       }
33       $element_node->setAttribute('transform', implode(' ', $transforms));
34     }
35
36     return $element_node;
37   }
38
39   /**
40    * Sets the class name of element
41    *
42    * @param  mixed  $class
43    */
44   public function setClass($class)
45   {
46     $this->setAttribute('class', $class);
47   }
48
49   /**
50    * Sets the fill color of shape
51    *
52    * @param  mixed  $color
53    */
54   public function setFill($color)
55   {
56     $this->setAttribute('fill', $color, 'none');
57   }
58
59   /**
60    * Sets the fill opacity of shape
61    *
62    * @param  mixed  $fill_opacity
63    */
64   public function setFillOpacity($fill_opacity)
65   {
66     $this->setAttribute('fill-opacity', $fill_opacity, '0');
67   }
68
69   /**
70    * Sets the global opacity of shape
71    *
72    * @param  mixed  $opacity
73    */
74   public function setOpacity($opacity)
75   {
76     $this->setAttribute('opacity', $opacity, '0');
77   }
78
79   /**
80    * Sets the color of shape stroke
81    *
82    * @param  string  $color
83    */
84   public function setStroke($color)
85   {
86     $this->setAttribute('stroke', $color, 'none');
87   }
88
89   /**
90    * Sets the width of shape stroke
91    *
92    * @param  mixed  $width
93    */
94   public function setStrokeWidth($width)
95   {
96     $this->setAttribute('stroke-width', $width, 1);
97   }
98
99 }
100
Note: See TracBrowser for help on using the browser.