linea21-externals
[ class tree: linea21-externals ] [ index: linea21-externals ] [ all elements ]

Source for file Font.class.php

Documentation is available at Font.class.php

  1. <?php
  2. /*
  3.  * This work is hereby released into the Public Domain.
  4.  * To view a copy of the public domain dedication,
  5.  * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
  6.  * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
  7.  *
  8.  */
  9.  
  10. require_once dirname(__FILE__)."/../Graph.class.php";
  11.  
  12. /**
  13.  * Common font characteristics and methods.
  14.  * Declared abstract only so that it can't be instanciated.
  15.  * Users have to call 'new awPHPFont' or 'new awFileFont',
  16.  * or any of their inherited classes (awFont1, awTuffy, awTTFFont, etc.)
  17.  *
  18.  * @package linea21.externals
  19.  * @subpackage artichow
  20.  */
  21. abstract class awFont {
  22.  
  23.     /**
  24.      * Build the font
  25.      *
  26.      */
  27.     public function __construct({
  28.         
  29.     }
  30.  
  31.     /**
  32.      * Draw a text
  33.      *
  34.      * @param awDriver $driver 
  35.      * @param awPoint $p Draw text at this point
  36.      * @param awText $text The text
  37.      * @param int $width Text box width
  38.      */
  39.     public function draw(awDriver $driverawPoint $pointawText $text$width NULL{
  40.         
  41.         $driver->string($this$text$point$width);
  42.         
  43.     }
  44.  
  45. }
  46.  
  47. registerClass('Font'TRUE);
  48.  
  49. /**
  50.  * Class for fonts that cannot be transformed,
  51.  * like the built-in PHP fonts for example.
  52.  * 
  53.  * @package linea21.externals
  54.  * @subpackage artichow
  55.  */
  56. class awPHPFont extends awFont {
  57.     
  58.     /**
  59.      * The used font identifier
  60.      * 
  61.      * @var int 
  62.      */
  63.     public $font;
  64.     
  65.     public function __construct($font NULL{
  66.         parent::__construct();
  67.         
  68.         if($font !== NULL{
  69.             $this->font = (int)$font;
  70.         }
  71.     }
  72.     
  73. }
  74.  
  75. registerClass('PHPFont');
  76.  
  77. /**
  78.  * Class for fonts that can be transformed (rotated, skewed, etc.),
  79.  * like TTF or FDB fonts for example.
  80.  *
  81.  * @package linea21.externals
  82.  * @subpackage artichow
  83.  */
  84. class awFileFont extends awFont {
  85.     
  86.     /**
  87.      * The name of the font, without the extension
  88.      *
  89.      * @var string 
  90.      */
  91.     protected $name;
  92.     
  93.     /**
  94.      * The size of the font
  95.      *
  96.      * @var int 
  97.      */
  98.     protected $size;
  99.     
  100.     /**
  101.      * The font filename extension
  102.      * 
  103.      * @var string 
  104.      */
  105.     protected $extension;
  106.     
  107.     public function __construct($name$size{
  108.         parent::__construct();
  109.         
  110.         $this->setName($name);
  111.         $this->setSize($size);
  112.     }
  113.     
  114.     /**
  115.      * Set the name of the font. The $name variable can contain the full path,
  116.      * or just the filename. Artichow will try to do The Right Thing,
  117.      * as well as set the extension property correctly if possible.
  118.      *
  119.      * @param string $name 
  120.      */
  121.     public function setName($name{
  122.         $fontInfo pathinfo((string)$name);
  123.         
  124.         if(strpos($fontInfo['dirname']'/'!== 0{
  125.             // Path is not absolute, use ARTICHOW_FONT
  126.             $name ARTICHOW_FONT.DIRECTORY_SEPARATOR.$fontInfo['basename'];
  127.             $fontInfo pathinfo($name);
  128.         }
  129.         
  130.         $this->name = $fontInfo['dirname'].DIRECTORY_SEPARATOR.$fontInfo['basename'];
  131.         
  132.         if(array_key_exists('extension'$fontInfoand $fontInfo['extension'!== ''{
  133.             $this->setExtension($fontInfo['extension']);
  134.         }
  135.     }
  136.     
  137.     /**
  138.      * Return the name of the font, i.e. the absolute path and the filename, without the extension.
  139.      *
  140.      * @return string 
  141.      */
  142.     public function getName({
  143.         return $this->name;
  144.     }
  145.     
  146.     /**
  147.      * Set the size of the font, in pixels
  148.      *
  149.      * @param int $size 
  150.      */
  151.     public function setSize($size{
  152.         $this->size = (int)$size;
  153.     }
  154.     
  155.     /**
  156.      * Return the size of the font, in pixels
  157.      *
  158.      * @return int 
  159.      */
  160.     public function getSize({
  161.         return $this->size;
  162.     }
  163.     
  164.     /**
  165.      * Set the extension, without the dot
  166.      *
  167.      * @param string $extension 
  168.      */
  169.     public function setExtension($extension{
  170.         $this->extension = (string)$extension;
  171.     }
  172.     
  173.     /**
  174.      * Get the filename extension for that font
  175.      * 
  176.      * @return string 
  177.      */
  178.     public function getExtension({
  179.         return $this->extension;
  180.     }
  181.  
  182. }
  183.  
  184. registerClass('FileFont');
  185.  
  186. /**
  187.  * Class representing TTF fonts
  188.  * 
  189.  * @package linea21.externals
  190.  * @subpackage artichow
  191.  */
  192. class awTTFFont extends awFileFont {
  193.     
  194.     public function __construct($name$size{
  195.         parent::__construct($name$size);
  196.         
  197.         if($this->getExtension(=== NULL{
  198.             $this->setExtension('ttf');
  199.         }
  200.     }
  201.  
  202. }
  203.  
  204. registerClass('TTFFont');
  205.  
  206. /* <php5> */
  207.  
  208. $php '';
  209.  
  210. for($i 1$i <= 5$i++{
  211.  
  212.     $php .= '
  213.     class awFont'.$i.' extends awPHPFont {
  214.  
  215.         public function __construct() {
  216.             parent::__construct('.$i.');
  217.         }
  218.  
  219.     }
  220.     ';
  221.  
  222.     if(ARTICHOW_PREFIX !== 'aw'{
  223.         $php .= '
  224.         class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
  225.         }
  226.         ';
  227.     }
  228.  
  229. }
  230.  
  231. eval($php);
  232.  
  233. $php '';
  234.  
  235. foreach($fonts as $font{
  236.  
  237.     $php .= '
  238.     class aw'.$font.' extends awFileFont {
  239.  
  240.         public function __construct($size) {
  241.             parent::__construct(\''.$font.'\', $size);
  242.         }
  243.  
  244.     }
  245.     ';
  246.  
  247.     if(ARTICHOW_PREFIX !== 'aw'{
  248.         $php .= '
  249.         class '.ARTICHOW_PREFIX.$font.' extends aw'.$font.' {
  250.         }
  251.         ';
  252.     }
  253.  
  254. }
  255.  
  256. eval($php);
  257.  
  258. /* </php5> */
  259. /* <php4> --
  260.  
  261. $php = '';
  262.  
  263. for($i = 1; $i <= 5; $i++) {
  264.  
  265.     $php .= '
  266.     class awFont'.$i.' extends awPHPFont {
  267.  
  268.         function awFont'.$i.'() {
  269.             parent::awPHPFont('.$i.');
  270.         }
  271.  
  272.     }
  273.     ';
  274.  
  275.     if(ARTICHOW_PREFIX !== 'aw') {
  276.         $php .= '
  277.         class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
  278.         }
  279.         ';
  280.     }
  281.  
  282. }
  283.  
  284. eval($php);
  285.  
  286. $php = '';
  287.  
  288. foreach($fonts as $font) {
  289.  
  290.     $php .= '
  291.     class aw'.$font.' extends awFileFont {
  292.  
  293.         function aw'.$font.'($size) {
  294.             parent::awFileFont(\''.$font.'\', $size);
  295.         }
  296.  
  297.     }
  298.     ';
  299.  
  300.     if(ARTICHOW_PREFIX !== 'aw') {
  301.         $php .= '
  302.         class '.ARTICHOW_PREFIX.$font.' extends aw'.$font.' {
  303.         }
  304.         ';
  305.     }
  306.  
  307. }
  308.  
  309. eval($php);
  310.  
  311. -- </php4> */
  312.  
  313. /*
  314.  * Environment modification for GD2 and TTF fonts
  315.  */
  316. if(function_exists('putenv')) {
  317.     putenv('GDFONTPATH='.ARTICHOW_FONT);
  318. }
  319.  
  320. ?>

Documentation generated on Fri, 16 Oct 2009 09:32:46 +0200 by phpDocumentor 1.4.1