Path

ez components / documentation / api reference / 2008.2.1 / graph


eZ Components 2008.2.1

Graph: ezcGraphSvgFont

[ Tutorial ] [ Gallery ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcGraphSvgFont

Helper class, offering requrired calculation basics and font metrics to use SVG fonts with the SVG driver. [source]
You may convert any ttf font into a SVG font using the `ttf2svg` bianry from the batik package. Depending on the distribution it may only be available as `batik-ttf2svg-<version>`.
Usage:
1.   $font new ezcGraphSvgFont();
2.   var_dump(
3.       $font->calculateStringWidth'../tests/data/font.svg''Just a test string.' ),
4.       $font->calculateStringWidth'../tests/data/font2.svg''Just a test string.' )
5.   );

Member Variables

protected string $fonts = array()
Path to font
protected array $glyphCache = array()
Cache for glyph size to save XPath lookups.
protected float $unitsPerEm
Units per EM
protected array $usedGlyphs = array()
Used glyphs
protected array $usedKerns = array()
Used kernings

Method Summary

public void addFontToDocument( $document )
Add font definitions to SVG document
public float calculateStringWidth( $fontPath, $string )
Calculates the width of $string in the current font in Em's.
public static string getFontName( $fontPath )
Get name of font
protected float getGlyph( $fontPath, $char )
Returns the <glyph> associated with $char.
public int getKerning( $fontPath, $glyph1, $glyph2, $g1, $g2 )
Returns the amount of kerning to apply for glyphs $g1 and $g2. If no valid kerning pair can be found 0 is returned.
protected string initializeFont( $fontPath )
Initialize SVG font
protected static string xpathEscape( $char )
XPath has no standard means of escaping ' and ", with the only solution being to delimit your string with the opposite type of quote. ( And if your string contains both concat( ) it ).

Methods

addFontToDocument

void addFontToDocument( $document )
Add font definitions to SVG document
Add the SVG font definition paths for all used glyphs and kernings to the given SVG document.

Parameters

Name Type Description
$document DOMDocument  

calculateStringWidth

float calculateStringWidth( string $fontPath, string $string )
Calculates the width of $string in the current font in Em's.

Parameters

Name Type Description
$fontPath string  
$string string  

getFontName

string getFontName( string $fontPath )
Get name of font
Get the name of the given font, by extracting its font family from the SVG font file.

Parameters

Name Type Description
$fontPath string  

getGlyph

float getGlyph( string $fontPath, string $char )
Returns the <glyph> associated with $char.

Parameters

Name Type Description
$fontPath string  
$char string  

getKerning

int getKerning( string $fontPath, $glyph1, $glyph2, SimpleXMLElement $g1, SimpleXMLElement $g2 )
Returns the amount of kerning to apply for glyphs $g1 and $g2. If no valid kerning pair can be found 0 is returned.

Parameters

Name Type Description
$fontPath string  
$g1 SimpleXMLElement  
$g2 SimpleXMLElement  
$glyph1 SimpleXMLElement  
$glyph2 SimpleXMLElement  

initializeFont

string initializeFont( string $fontPath )
Initialize SVG font
Loads the SVG font $filename. This should be the path to the file generated by ttf2svg.
Returns the (normlized) name of the initilized font.

Parameters

Name Type Description
$fontPath string  

xpathEscape

string xpathEscape( string $char )
XPath has no standard means of escaping ' and ", with the only solution being to delimit your string with the opposite type of quote. ( And if your string contains both concat( ) it ).
This method will correctly delimit $char with the appropriate quote type so that it can be used in an XPath expression.

Parameters

Name Type Description
$char string  

Last updated: Mon, 09 Feb 2009