Source for file svgGrapher.internal.getComputedTextLength.php
Documentation is available at svgGrapher.internal.getComputedTextLength.php
* Plugin internal getComputedTextLength.
* @version $Id: svgGrapher.internal.getComputedTextLength.php,v 1.5 2007/10/23 08:59:08 geelweb Exp $
* @author Guillaume L. <guillaume@geelweb.org>
* @copyright Copyright © 2006, Guillaume Luchet.
* @license http://opensource.org/licenses/bsd-license.php BSD License
require_once SVGGRAPHER_ELEMENTS_PATH .
'/TextElement.php';
* svgGrapher_internal_getComputedTextLength()
* Get the text size for a givan font.
* It's ok just with standard fonts :
* If $textElm is a string a TextElement will be create with style $st and
* @param mixed $textElm TextElement or svg string style
* @param mixed $st svg Style element
* @param mixed $tr svg Transform element
'times new roman' =>
'times',
'courier new' =>
'cour' );
// Convertie $textElm en objet de type SvgText si il s'agit d'un "string".
// Lui affecte $st en style et $tr en element de transformation.
$textElm->setAttribute('style', $st);
$textElm->setAttribute('transform', $tr);
$text =
$textElm->content;
$style =
$textElm->getAttribute('style');
$transform =
$textElm->getAttribute('transform');
$fontFamily =
($style->getAttribute('font-family') !==
false) ?
strtolower( $style->getAttribute('font-family') ) :
'arial';
$fontSize =
($style->getAttribute('font-size') !==
false) ?
$style->getAttribute('font-size') :
12;
$fontAngle =
($transform->get('rotate') !==
false) ?
trim( substr($transform->get('rotate'), 0, 3) ) :
0;
// Fonction svgGrapher_internal_fontSizeEquivPt inclus par SvgGrapher.
throw
new Exception('FontSize in relative units, cannot determine FontSize');
$fontFileName =
$svgFonts[$fontFamily];
if($style->getAttribute('font-weight') ==
'bold') {
$fontFileName .=
$fontBold;
if($style->getAttribute('font-style') ==
'italic') {
$fontFileName .=
$fontItalic;
$bbox =
imagettfbbox($sizeEquiv, $fontAngle, $fontFileName, $text);
$tmp_bbox['left'] =
0 -
min($bbox[0], $bbox[2], $bbox[4], $bbox[6]);
$tmp_bbox['top'] =
0 -
min($bbox[1], $bbox[3], $bbox[5], $bbox[7]);
$tmp_bbox['width'] =
max($bbox[0], $bbox[2], $bbox[4], $bbox[6]) -
min($bbox[0], $bbox[2], $bbox[4], $bbox[6]) +
1;
$tmp_bbox['height'] =
max($bbox[1], $bbox[3], $bbox[5], $bbox[7]) -
min($bbox[1], $bbox[3], $bbox[5], $bbox[7]);
Documentation generated on Tue, 23 Oct 2007 11:32:11 +0200 by phpDocumentor 1.4.0