summaryrefslogtreecommitdiffstats
path: root/src/options/svg_driver.php
blob: 4a83ca4a960d70a3a5b101d31088621cdd968c50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
/**
 * File containing the ezcGraphSvgDriverOption class
 *
 * @package Graph
 * @version //autogentag//
 * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
 * @license http://ez.no/licenses/new_bsd New BSD License
 */
/**
 * Class containing the basic options for charts
 *
 * @property float $assumedCharacterWidth
 *           Assumed percentual average width of chars with the used font.
 * @property string $strokeLineCap
 *           This specifies the shape to be used at the end of open subpaths 
 *           when they are stroked.
 * @property string $strokeLineJoin
 *           This specifies the shape to be used at the edges of paths.
 * @property string $shapeRendering
 *           "The creator of SVG content might want to provide a hint to the
 *           implementation about what tradeoffs to make as it renders vector
 *           graphics elements such as 'path' elements and basic shapes such as
 *           circles and rectangles."
 * @property string $colorRendering
 *           "The creator of SVG content might want to provide a hint to the
 *           implementation about how to make speed vs. quality tradeoffs as it
 *           performs color interpolation and compositing. The 
 *           'color-rendering' property provides a hint to the SVG user agent 
 *           about how to optimize its color interpolation and compositing 
 *           operations."
 * @property string $textRendering
 *           "The creator of SVG content might want to provide a hint to the
 *           implementation about what tradeoffs to make as it renders text."
 * @property mixed $templateDocument
 *           Use existing SVG document as template to insert graph into. If
 *           insertIntoGroup is not set, a new group will be inserted in the 
 *           svg root node.
 * @property mixed $insertIntoGroup
 *           ID of a SVG group node to insert the graph. Only works with a 
 *           custom template document.
 * @property ezcGraphCoordinate $graphOffset
 *           Offset of the graph in the svg.
 * @property string $idPrefix
 *           Prefix used for the ids in SVG documents.
 * 
 * @package Graph
 */
class ezcGraphSvgDriverOptions extends ezcGraphDriverOptions
{
    /**
     * Constructor
     * 
     * @param array $options Default option array
     * @return void
     * @ignore
     */
    public function __construct( array $options = array() )
    {
        $this->properties['assumedCharacterWidth'] = .55;
        $this->properties['strokeLineJoin'] = 'round';
        $this->properties['strokeLineCap'] = 'round';
        $this->properties['shapeRendering'] = 'geometricPrecision';
        $this->properties['colorRendering'] = 'optimizeQuality';
        $this->properties['textRendering'] = 'optimizeLegibility';
        $this->properties['templateDocument'] = false;
        $this->properties['insertIntoGroup'] = false;
        $this->properties['graphOffset'] = new ezcGraphCoordinate( 0, 0 );
        $this->properties['idPrefix'] = 'ezcGraph';

        parent::__construct( $options );
    }

    /**
     * Set an option value
     * 
     * @param string $propertyName 
     * @param mixed $propertyValue 
     * @throws ezcBasePropertyNotFoundException
     *          If a property is not defined in this class
     * @return void
     * @ignore
     */
    public function __set( $propertyName, $propertyValue )
    {
        switch ( $propertyName )
        {
            case 'assumedCharacterWidth':
                $this->properties['assumedCharacterWidth'] = min( 1, max( 0, (float) $propertyValue ) );
                break;
            case 'strokeLineJoin':
                $values = array(
                    'round',
                    'butt',
                    'square',
                    'inherit',
                );

                if ( in_array( $propertyValue, $values, true ) )
                {
                    $this->properties['strokeLineJoin'] = $propertyValue;
                }
                else
                {
                    throw new ezcBaseValueException( $propertyName, $propertyValue, implode( $values, ', ' ) );
                }
                break;
            case 'strokeLineCap':
                $values = array(
                    'round',
                    'butt',
                    'square',
                    'inherit',
                );

                if ( in_array( $propertyValue, $values, true ) )
                {
                    $this->properties['strokeLineCap'] = $propertyValue;
                }
                else
                {
                    throw new ezcBaseValueException( $propertyName, $propertyValue, implode( $values, ', ' ) );
                }
                break;
            case 'shapeRendering':
                $values = array(
                    'auto',
                    'optimizeSpeed',
                    'crispEdges',
                    'geometricPrecision',
                    'inherit',
                );

                if ( in_array( $propertyValue, $values, true ) )
                {
                    $this->properties['shapeRendering'] = $propertyValue;
                }
                else
                {
                    throw new ezcBaseValueException( $propertyName, $propertyValue, implode( $values, ', ' ) );
                }
                break;
            case 'colorRendering':
                $values = array(
                    'auto',
                    'optimizeSpeed',
                    'optimizeQuality',
                    'inherit',
                );

                if ( in_array( $propertyValue, $values, true ) )
                {
                    $this->properties['colorRendering'] = $propertyValue;
                }
                else
                {
                    throw new ezcBaseValueException( $propertyName, $propertyValue, implode( $values, ', ' ) );
                }
                break;
            case 'textRendering':
                $values = array(
                    'auto',
                    'optimizeSpeed',
                    'optimizeLegibility',
                    'geometricPrecision',
                    'inherit',
                );

                if ( in_array( $propertyValue, $values, true ) )
                {
                    $this->properties['textRendering'] = $propertyValue;
                }
                else
                {
                    throw new ezcBaseValueException( $propertyName, $propertyValue, implode( $values, ', ' ) );
                }
                break;
            case 'templateDocument':
                if ( !is_file( $propertyValue ) || !is_readable( $propertyValue ) )
                {
                    throw new ezcBaseFileNotFoundException( $propertyValue );
                }
                else
                {
                    $this->properties['templateDocument'] = realpath( $propertyValue );
                }
                break;
            case 'insertIntoGroup':
                if ( !is_string( $propertyValue ) )
                {
                    throw new ezcBaseValueException( $propertyName, $propertyValue, 'string' );
                }
                else
                {
                    $this->properties['insertIntoGroup'] = $propertyValue;
                }
                break;
            case 'graphOffset':
                if ( $propertyValue instanceof ezcGraphCoordinate )
                {
                    $this->properties['graphOffset'] = $propertyValue;
                }
                else
                {
                    throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphCoordinate' );
                }
                break;
            case 'idPrefix':
                $this->properties['idPrefix'] = (string) $propertyValue;
                break;
            default:
                parent::__set( $propertyName, $propertyValue );
                break;
        }
    }

    protected function checkFont( $font )
    {
    }
}

?>
OpenPOWER on IntegriCloud