Source for file svgGrapher.internal.fontSizeEquiv.php

Documentation is available at svgGrapher.internal.fontSizeEquiv.php

  1. <?php
  2. /**
  3. * Plugin internal fontSizeEquiv.
  4. *
  5.  * @version $Id: svgGrapher.internal.fontSizeEquiv.php,v 1.5 2007/10/23 09:22:53 geelweb Exp $
  6.  * @author Guillaume L. <guillaume@geelweb.org>
  7.  * @copyright Copyright © 2006, Guillaume Luchet.
  8.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  9. @package SvgGrapher
  10. @subpackage Internal
  11. */
  12.  
  13. /**
  14.  *
  15.  */
  16. require_once SVGGRAPHER_CLASS_PATH '/mains/SvgStyle.php';
  17.  
  18. /**
  19.  * svgGrapher_internal_fontSizeEquiv()
  20.  *
  21.  * Get a size in pixel.
  22.  *
  23.  * @param mixed $font Object Style or svg string style
  24.  * @param integer $dpiDefault Screen resolution
  25.  * @return integer 
  26.  */
  27. function svgGrapher_internal_fontSizeEquiv($font$dpiDefault=DEFAULT_DPI_RESOLUTION{
  28.     $point 1/72// 1 pt = 1/72 pouce.
  29.     $pica 12 $point// 1pc = 12pt.
  30.     $cm 0.3937// 1cm = 0.3937 pouce.
  31.     $mm 0.03937// 1mm = 0.03937 pouce.
  32.     $svgUnites array('pt''px''pc''cm''mm''in''em''ex''%');
  33.     $tailleEnPixel false;
  34.     $rxFontSize '/(\d+)\s?([' implode('|'$svgUnites']+)?/';
  35.  
  36.     if(!is_object($font)) {
  37.         $font new SvgStyle($font);
  38.     }
  39.  
  40.     $fontSize ($font->getAttribute('font-size'!== false
  41.         $font->getAttribute('font-size'12;
  42.  
  43.     // Chaine de style complete.
  44.     if(preg_match($rxFontSize$fontSize$matches)) {
  45.         $fontSize $matches[1];
  46.         $fontUnite (isset($matches[2])) $matches[2'px';
  47.  
  48.         switch($fontUnite{
  49.             case 'pt':
  50.                 $tailleEnPixel ($fontSize $point$dpiDefault;
  51.                 break;
  52.             case 'pc':
  53.                 $tailleEnPixel ($fontSize $pica$dpiDefault;
  54.                 break;
  55.             case 'cm':
  56.                 $tailleEnPixel ($fontSize $cm$dpiDefault;
  57.                 break;
  58.             case 'mm':
  59.                 $tailleEnPixel ($fontSize $mm$dpiDefault;
  60.                 break;
  61.             case 'in':
  62.                 $tailleEnPixel $fontSize $dpiDefault;
  63.                 break;
  64.             // unite relative, impossible d'en definir une taille equivalente en px...
  65.             case 'em':
  66.             case 'ex':
  67.             case '%':
  68.                 $tailleEnPixel false;
  69.                 break;
  70.             case 'px':
  71.             default:
  72.                 $tailleEnPixel $fontSize;
  73.         }
  74.     }
  75.  
  76.     return ($tailleEnPixel === falsefalse ceil($tailleEnPixel);
  77. }
  78.  
  79. ?>

Documentation generated on Tue, 23 Oct 2007 11:32:10 +0200 by phpDocumentor 1.4.0