Zeta Components - high quality PHP components

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:

  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.   );

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

static 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

xpathEscape

static 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

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

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
Documentation generated by phpDocumentor 1.4.3