Zeta Components Manual :: Docs For Class ezcGraphSvgFont
Graph::ezcGraphSvgFont
Class ezcGraphSvgFont
Helper class, offering requrired calculation basics and font metrics to use SVG fonts with the SVG driver.
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:
- );
Source for this file: /Graph/src/driver/svg_font.php
Version: | //autogentag// |
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 static string |
getFontName(
$fontPath
)
Get name of 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 ). |
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. |
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 |
Methods
getFontName
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 |
xpathEscape
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 |
addFontToDocument
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
Calculates the width of $string in the current font in Em's.
Parameters:
Name | Type | Description |
---|---|---|
$fontPath |
string | |
$string |
string |
getGlyph
Returns the <glyph> associated with $char.
Parameters:
Name | Type | Description |
---|---|---|
$fontPath |
string | |
$char |
string |
getKerning
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
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 |