Source for file Font.php

Documentation is available at Font.php

  1. <?php
  2.  
  3. /**
  4.  * Transforms FONT tags to the proper form (SPAN with CSS styling)
  5.  * 
  6.  * This transformation takes the three proprietary attributes of FONT and
  7.  * transforms them into their corresponding CSS attributes.  These are color,
  8.  * face, and size.
  9.  * 
  10.  * @note Size is an interesting case because it doesn't map cleanly to CSS.
  11.  *        Thanks to
  12.  *        http://style.cleverchimp.com/font_size_intervals/altintervals.html
  13.  *        for reasonable mappings.
  14.  */
  15. {
  16.     
  17.     public $transform_to = 'span';
  18.     
  19.     protected $_size_lookup = array(
  20.         '0' => 'xx-small',
  21.         '1' => 'xx-small',
  22.         '2' => 'small',
  23.         '3' => 'medium',
  24.         '4' => 'large',
  25.         '5' => 'x-large',
  26.         '6' => 'xx-large',
  27.         '7' => '300%',
  28.         '-1' => 'smaller',
  29.         '-2' => '60%',
  30.         '+1' => 'larger',
  31.         '+2' => '150%',
  32.         '+3' => '200%',
  33.         '+4' => '300%'
  34.     );
  35.     
  36.     public function transform($tag$config$context{
  37.         
  38.         if ($tag instanceof HTMLPurifier_Token_End{
  39.             $new_tag clone $tag;
  40.             $new_tag->name $this->transform_to;
  41.             return $new_tag;
  42.         }
  43.         
  44.         $attr $tag->attr;
  45.         $prepend_style '';
  46.         
  47.         // handle color transform
  48.         if (isset($attr['color'])) {
  49.             $prepend_style .= 'color:' $attr['color'';';
  50.             unset($attr['color']);
  51.         }
  52.         
  53.         // handle face transform
  54.         if (isset($attr['face'])) {
  55.             $prepend_style .= 'font-family:' $attr['face'';';
  56.             unset($attr['face']);
  57.         }
  58.         
  59.         // handle size transform
  60.         if (isset($attr['size'])) {
  61.             // normalize large numbers
  62.             if ($attr['size']{0== '+' || $attr['size']{0== '-'{
  63.                 $size = (int) $attr['size'];
  64.                 if ($size < -2$attr['size''-2';
  65.                 if ($size 4)  $attr['size''+4';
  66.             else {
  67.                 $size = (int) $attr['size'];
  68.                 if ($size 7$attr['size''7';
  69.             }
  70.             if (isset($this->_size_lookup[$attr['size']])) {
  71.                 $prepend_style .= 'font-size:' .
  72.                   $this->_size_lookup[$attr['size']] ';';
  73.             }
  74.             unset($attr['size']);
  75.         }
  76.         
  77.         if ($prepend_style{
  78.             $attr['style'= isset($attr['style']?
  79.                 $prepend_style $attr['style':
  80.                 $prepend_style;
  81.         }
  82.         
  83.         $new_tag clone $tag;
  84.         $new_tag->name $this->transform_to;
  85.         $new_tag->attr $attr;
  86.         
  87.         return $new_tag;
  88.         
  89.     }
  90. }

Documentation generated on Thu, 19 Jun 2008 18:49:14 -0400 by phpDocumentor 1.4.2