summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-08-18 12:56:10 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-08-18 12:56:10 +0000
commit5091a24682cf37af25eebd4158a0d9480aea6252 (patch)
treed4998b172a75d207daed201225a988912485e5a9 /src
parent94953ea4f75810e5e667425bfd55ce8d51672ee3 (diff)
downloadzetacomponents-graph-5091a24682cf37af25eebd4158a0d9480aea6252.zip
zetacomponents-graph-5091a24682cf37af25eebd4158a0d9480aea6252.tar.gz
- Started refactoring of font configuration
# - The next iteration will enable you to use the different font rendering # methods from ext/GD
Diffstat (limited to 'src')
-rw-r--r--src/driver/gd.php10
-rw-r--r--src/driver/svg.php5
-rw-r--r--src/graph.php10
-rw-r--r--src/interfaces/chart.php2
-rw-r--r--src/interfaces/palette.php8
-rw-r--r--src/options/font.php40
-rw-r--r--src/palette/black.php4
-rw-r--r--src/palette/tango.php4
8 files changed, 63 insertions, 20 deletions
diff --git a/src/driver/gd.php b/src/driver/gd.php
index 2f8da21..ff8a5db 100644
--- a/src/driver/gd.php
+++ b/src/driver/gd.php
@@ -209,7 +209,7 @@ class ezcGraphGdDriver extends ezcGraphDriver
$selectedLine = $lines[$line];
$selectedLine[] = $token;
- $boundings = imagettfbbox( $size, 0, $this->options->font->font, implode( ' ', $selectedLine ) );
+ $boundings = imagettfbbox( $size, 0, $this->options->font->path, implode( ' ', $selectedLine ) );
// Check if line is too long
if ( $boundings[2] > $width )
@@ -240,7 +240,7 @@ class ezcGraphGdDriver extends ezcGraphDriver
}
// Check width of last line
- $boundings = imagettfbbox( $size, 0, $this->options->font->font, implode( ' ', $lines[$line] ) );
+ $boundings = imagettfbbox( $size, 0, $this->options->font->path, implode( ' ', $lines[$line] ) );
if ( $boundings[2] > $width ) {
return false;
}
@@ -263,9 +263,9 @@ class ezcGraphGdDriver extends ezcGraphDriver
{
// Test font
// @TODO: try to find font at standard locations if no path was provided
- if ( !is_file( $this->options->font->font ) || !is_readable( $this->options->font->font ) )
+ if ( !is_file( $this->options->font->path ) || !is_readable( $this->options->font->path ) )
{
- throw new ezcGraphGdDriverInvalidFontException( $this->options->font->font );
+ throw new ezcGraphGdDriverInvalidFontException( $this->options->font->path );
}
// Try to get a font size for the text to fit into the box
@@ -306,7 +306,7 @@ class ezcGraphGdDriver extends ezcGraphDriver
foreach ( $this->strings as $text )
{
$size = $text['options']->minimalUsedFont;
- $font = $text['options']->font;
+ $font = $text['options']->path;
$drawColor = $this->allocate( $text['options']->color );
$completeHeight = count( $text['text'] ) * $size + ( count( $text['text'] ) - 1 ) * $this->options->lineSpacing;
diff --git a/src/driver/svg.php b/src/driver/svg.php
index 2b5ff90..51f356a 100644
--- a/src/driver/svg.php
+++ b/src/driver/svg.php
@@ -298,7 +298,7 @@ class ezcGraphSvgDriver extends ezcGraphDriver
foreach ( $this->strings as $text )
{
$size = $text['options']->minimalUsedFont;
- $font = $text['options']->font;
+ $font = $text['options']->name;
$completeHeight = count( $text['text'] ) * $size + ( count( $text['text'] ) - 1 ) * $this->options->lineSpacing;
@@ -352,8 +352,9 @@ class ezcGraphSvgDriver extends ezcGraphDriver
$textNode->setAttribute(
'style',
sprintf(
- 'font-size: %dpx; font-family: sans-serif; fill: #%02x%02x%02x; fill-opacity: %.2f; stroke: none;',
+ 'font-size: %dpx; font-family: %s; fill: #%02x%02x%02x; fill-opacity: %.2f; stroke: none;',
$size,
+ $text['options']->name,
$text['options']->color->red,
$text['options']->color->green,
$text['options']->color->blue,
diff --git a/src/graph.php b/src/graph.php
index 0b9cff3..f0a652b 100644
--- a/src/graph.php
+++ b/src/graph.php
@@ -33,6 +33,16 @@ class ezcGraph
const PIE = 1;
const LINE = 2;
const BAR = 3;
+
+ // native TTF font
+ const TTF_FONT = 1;
+ // PostScript Type1 fonts
+ const PS_FONT = 2;
+ // FreeType 2 fonts
+ const FT2_FONT = 3;
+ // Native GD bitmap fonts
+ const GD_FONT = 4;
+
}
?>
diff --git a/src/interfaces/chart.php b/src/interfaces/chart.php
index e2e58d1..3e63572 100644
--- a/src/interfaces/chart.php
+++ b/src/interfaces/chart.php
@@ -186,7 +186,7 @@ abstract class ezcGraphChart
*/
public function setFromPalette( ezcGraphPalette $palette )
{
- $this->options->font->font = $palette->fontFace;
+ $this->options->font->name = $palette->fontName;
$this->options->font->color = $palette->fontColor;
foreach ( $this->elements as $element )
diff --git a/src/interfaces/palette.php b/src/interfaces/palette.php
index bfb6147..41bbe6b 100644
--- a/src/interfaces/palette.php
+++ b/src/interfaces/palette.php
@@ -64,11 +64,11 @@ abstract class ezcGraphPalette
protected $dataSetSymbol;
/**
- * Fontface
+ * Name of font to use
*
* @var string
*/
- protected $fontFace;
+ protected $fontName;
/**
* Fontcolor
@@ -182,8 +182,8 @@ abstract class ezcGraphPalette
case 'fontColor':
return $this->checkColor( $this->fontColor );
- case 'fontFace':
- return $this->fontFace;
+ case 'fontName':
+ return $this->fontName;
case 'chartBackground':
return $this->checkColor( $this->chartBackground );
diff --git a/src/options/font.php b/src/options/font.php
index 189fed0..9f3b744 100644
--- a/src/options/font.php
+++ b/src/options/font.php
@@ -10,8 +10,16 @@
/**
* Class containing the basic options for charts
*
- * @property string $font
- * Font face.
+ * @property string $name
+ * Name of font.
+ * @property string $path
+ * Path to font file.
+ * @property string $type
+ * Type of used font. May be one of the following:
+ * - TTF_FONT Native TTF fonts
+ * - PS_FONT PostScript Type1 fonts
+ * - FT2_FONT FreeType 2 fonts
+ * - GD_FONT Native GD bitmap fonts
* @property float $minFontSize
* Minimum font size for displayed texts.
* @property float $maxFontSize
@@ -36,6 +44,10 @@ class ezcGraphFontOptions extends ezcBaseOptions
*/
public function __construct( array $options = array() )
{
+ $this->properties['name'] = 'sans-serif';
+ $this->properties['path'] = 'Graph/tests/data/font.ttf';
+ $this->properties['type'] = ezcGraph::TTF_FONT;
+
$this->properties['minFontSize'] = 6;
$this->properties['maxFontSize'] = 96;
$this->properties['minimalUsedFont'] = 96;
@@ -81,16 +93,36 @@ class ezcGraphFontOptions extends ezcBaseOptions
throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphColor' );
}
break;
- case 'font':
+ case 'name':
if ( is_string( $propertyValue ) )
{
- $this->properties['font'] = $propertyValue;
+ $this->properties['name'] = $propertyValue;
}
else
{
throw new ezcBaseValueException( $propertyName, $propertyValue, 'string' );
}
break;
+ case 'path':
+ if ( is_file( $propertyValue ) && is_readable( $propertyValue ) )
+ {
+ $this->properties['path'] = $propertyValue;
+ // @TODO: Autodetect font type
+ }
+ else
+ {
+ throw new ezcBaseFileNotFoundException( $propertyValue, 'font' );
+ }
+ break;
+ case 'type':
+ if ( is_int( $propertyValue ) )
+ {
+ $this->properties['type'] = $propertyValue;
+ }
+ else
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'int' );
+ }
default:
throw new ezcBasePropertyNotFoundException( $propertyName );
break;
diff --git a/src/palette/black.php b/src/palette/black.php
index 48d3029..3c893a5 100644
--- a/src/palette/black.php
+++ b/src/palette/black.php
@@ -61,11 +61,11 @@ class ezcGraphPaletteBlack extends ezcGraphPalette
);
/**
- * Fontface
+ * Name of font to use
*
* @var string
*/
- protected $fontFace = 'Vera.ttf';
+ protected $fontName = 'sans-serif';
/**
* Fontcolor
diff --git a/src/palette/tango.php b/src/palette/tango.php
index e4ca15b..073d91b 100644
--- a/src/palette/tango.php
+++ b/src/palette/tango.php
@@ -48,11 +48,11 @@ class ezcGraphPaletteTango extends ezcGraphPalette
);
/**
- * Fontface
+ * Name of font to use
*
* @var string
*/
- protected $fontFace = 'Vera.ttf';
+ protected $fontName = 'sans-serif';
/**
* Fontcolor
OpenPOWER on IntegriCloud