summaryrefslogtreecommitdiffstats
path: root/src/driver
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2008-05-03 16:45:58 +0000
committerKore Nordmann <github@kore-nordmann.de>2008-05-03 16:45:58 +0000
commitcce8cbce35d5b21fcc2a9ccb7a62d398e7501594 (patch)
treeffe26b9b859949faa191b133e463767fbff91da6 /src/driver
parent7c549929d1e2a9ed82c06f33c320269f4a367150 (diff)
downloadzetacomponents-graph-cce8cbce35d5b21fcc2a9ccb7a62d398e7501594.zip
zetacomponents-graph-cce8cbce35d5b21fcc2a9ccb7a62d398e7501594.tar.gz
- Speedup glyph lookup by adding a glyph cache per font
Diffstat (limited to 'src/driver')
-rw-r--r--src/driver/svg_font.php20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/driver/svg_font.php b/src/driver/svg_font.php
index 341fa48..65fe289 100644
--- a/src/driver/svg_font.php
+++ b/src/driver/svg_font.php
@@ -47,6 +47,13 @@ class ezcGraphSvgFont
protected $usedGlyphs = array();
/**
+ * Cache for glyph size to save XPath lookups.
+ *
+ * @var array
+ */
+ protected $glyphCache = array();
+
+ /**
* Used kernings
*
* @var array
@@ -140,10 +147,16 @@ class ezcGraphSvgFont
*
* @param string $fontPath
* @param string $char
- * @return SimpleXMLElement
+ * @return float
*/
protected function getGlyph( $fontPath, $char )
{
+ // Check if glyphwidth has already been calculated.
+ if ( isset( $this->glyphCache[$fontPath][$char] ) )
+ {
+ return $this->glyphCache[$fontPath][$char];
+ }
+
$matches = $this->fonts[$fontPath]->xpath(
$query = "glyph[@unicode=" . self::xpathEscape( $char ) . "]"
);
@@ -153,7 +166,8 @@ class ezcGraphSvgFont
// Just ignore missing glyphs. The client will still render them
// using a default font. We try to estimate some width by using a
// common other character.
- return ( $char === 'o' ? false : $this->getGlyph( $fontPath, 'o' ) );
+ return $this->glyphCache[$fontPath][$char] =
+ ( $char === 'o' ? false : $this->getGlyph( $fontPath, 'o' ) );
}
$glyph = $matches[0];
@@ -163,7 +177,7 @@ class ezcGraphSvgFont
}
// There should only ever be one match
- return $glyph;
+ return $this->glyphCache[$fontPath][$char] = $glyph;
}
/**
OpenPOWER on IntegriCloud