diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-08-08 13:44:15 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-08-08 13:44:15 +0000 |
commit | 63b5d5f3f2dee22c890d219aeb8e4cc7fd228f41 (patch) | |
tree | 6ca08376fc8552ba6fe99f9e8a1e66b5345d33a3 /src | |
parent | 5e6c1783d9ecbbf9ae8b1e0ff8c39c0d1fb91ffa (diff) | |
download | zetacomponents-graph-63b5d5f3f2dee22c890d219aeb8e4cc7fd228f41.zip zetacomponents-graph-63b5d5f3f2dee22c890d219aeb8e4cc7fd228f41.tar.gz |
- Added svg rendering options
- Made line ending style for svg configurable
Diffstat (limited to 'src')
-rw-r--r-- | src/driver/svg.php | 23 | ||||
-rw-r--r-- | src/options/svg_driver.php | 107 |
2 files changed, 122 insertions, 8 deletions
diff --git a/src/driver/svg.php b/src/driver/svg.php index e567188..3f4ccef 100644 --- a/src/driver/svg.php +++ b/src/driver/svg.php @@ -72,6 +72,9 @@ class ezcGraphSvgDriver extends ezcGraphDriver $this->elements = $this->dom->createElement( 'g' ); $this->elements->setAttribute( 'id', 'chart' ); + $this->elements->setAttribute( 'color-rendering', $this->options->colorRendering ); + $this->elements->setAttribute( 'shape-rendering', $this->options->shapeRendering ); + $this->elements->setAttribute( 'text-rendering', $this->options->textRendering ); $this->elements = $svg->appendChild( $this->elements ); } } @@ -122,12 +125,13 @@ class ezcGraphSvgDriver extends ezcGraphDriver { $path->setAttribute( 'style', - sprintf( 'fill: none; stroke: #%02x%02x%02x; stroke-width: %d; stroke-opacity: %.2f;', + sprintf( 'fill: none; stroke: #%02x%02x%02x; stroke-width: %d; stroke-opacity: %.2f; stroke-linecap: %s;', $color->red, $color->green, $color->blue, $thickness, - 1 - ( $color->alpha / 255 ) + 1 - ( $color->alpha / 255 ), + $this->options->strokeLineCap ) ); } @@ -158,12 +162,13 @@ class ezcGraphSvgDriver extends ezcGraphDriver $path->setAttribute( 'd', $pointString ); $path->setAttribute( 'style', - sprintf( 'fill: none; stroke: #%02x%02x%02x; stroke-width: %d; stroke-opacity: %.2f;', + sprintf( 'fill: none; stroke: #%02x%02x%02x; stroke-width: %d; stroke-opacity: %.2f; stroke-linecap: %s;', $color->red, $color->green, $color->blue, $thickness, - 1 - ( $color->alpha / 255 ) + 1 - ( $color->alpha / 255 ), + $this->options->strokeLineCap ) ); @@ -401,12 +406,13 @@ class ezcGraphSvgDriver extends ezcGraphDriver { $arc->setAttribute( 'style', - sprintf( 'fill: none; stroke: #%02x%02x%02x; stroke-width: %d; stroke-opacity: %.2f;', + sprintf( 'fill: none; stroke: #%02x%02x%02x; stroke-width: %d; stroke-opacity: %.2f; stroke-linecap: %s;', $color->red, $color->green, $color->blue, 1, // Line Thickness - 1 - ( $color->alpha / 255 ) + 1 - ( $color->alpha / 255 ), + $this->options->strokeLineCap ) ); } @@ -521,12 +527,13 @@ class ezcGraphSvgDriver extends ezcGraphDriver { $ellipse->setAttribute( 'style', - sprintf( 'fill: none; stroke: #%02x%02x%02x; stroke-width: %d; stroke-opacity: %.2f;', + sprintf( 'fill: none; stroke: #%02x%02x%02x; stroke-width: %d; stroke-opacity: %.2f; stroke-linecap: %s;', $color->red, $color->green, $color->blue, 1, // Line Thickness - 1 - ( $color->alpha / 255 ) + 1 - ( $color->alpha / 255 ), + $this->options->strokeLineCap ) ); } diff --git a/src/options/svg_driver.php b/src/options/svg_driver.php index b07664e..6bd4ff8 100644 --- a/src/options/svg_driver.php +++ b/src/options/svg_driver.php @@ -23,6 +23,43 @@ class ezcGraphSvgDriverOptions extends ezcGraphDriverOptions protected $assumedCharacterWidth = .55; /** + * This specifies the shape to be used at the end of open subpaths when + * they are stroked. + * + * @var string + */ + protected $strokeLineCap = 'round'; + + /** + * "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." + * + * @var string + */ + protected $shapeRendering = 'geometricPrecision'; + + /** + * "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." + * + * @var string + */ + protected $colorRendering = 'optimizeQuality'; + + /** + * "The creator of SVG content might want to provide a hint to the + * implementation about what tradeoffs to make as it renders text." + * + * @var string + */ + protected $textRendering = 'optimizeLegibility'; + + /** * Set an option value * * @param string $propertyName @@ -38,6 +75,76 @@ class ezcGraphSvgDriverOptions extends ezcGraphDriverOptions case 'assumedCharacterWidth': $this->assumedCharacterWidth = min( 1, max( 0, (float) $propertyValue ) ); break; + case 'strokeLineCap': + $values = array( + 'round', + 'butt', + 'square', + 'inherit', + ); + + if ( in_array( $propertyValue, $values, true ) ) + { + $this->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->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->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->textRendering = $propertyValue; + } + else + { + throw new ezcBaseValueException( $propertyName, $propertyValue, implode( $values, ', ' ) ); + } + break; default: parent::__set( $propertyName, $propertyValue ); break; |