Source for file Font.php

Documentation is available at Font.php

  1. <?php
  2.  
  3. /**
  4.  * Validates shorthand CSS property font.
  5.  */
  6. {
  7.     
  8.     /**
  9.      * Local copy of component validators.
  10.      * 
  11.      * @note If we moved specific CSS property definitions to their own
  12.      *        classes instead of having them be assembled at run time by
  13.      *        CSSDefinition, this wouldn't be necessary.  We'd instantiate
  14.      *        our own copies.
  15.      */
  16.     protected $info = array();
  17.     
  18.     public function __construct($config{
  19.         $def $config->getCSSDefinition();
  20.         $this->info['font-style']   $def->info['font-style'];
  21.         $this->info['font-variant'$def->info['font-variant'];
  22.         $this->info['font-weight']  $def->info['font-weight'];
  23.         $this->info['font-size']    $def->info['font-size'];
  24.         $this->info['line-height']  $def->info['line-height'];
  25.         $this->info['font-family']  $def->info['font-family'];
  26.     }
  27.     
  28.     public function validate($string$config$context{
  29.         
  30.         static $system_fonts array(
  31.             'caption' => true,
  32.             'icon' => true,
  33.             'menu' => true,
  34.             'message-box' => true,
  35.             'small-caption' => true,
  36.             'status-bar' => true
  37.         );
  38.         
  39.         // regular pre-processing
  40.         $string $this->parseCDATA($string);
  41.         if ($string === ''return false;
  42.         
  43.         // check if it's one of the keywords
  44.         $lowercase_string strtolower($string);
  45.         if (isset($system_fonts[$lowercase_string])) {
  46.             return $lowercase_string;
  47.         }
  48.         
  49.         $bits explode(' '$string)// bits to process
  50.         $stage 0// this indicates what we're looking for
  51.         $caught array()// which stage 0 properties have we caught?
  52.         $stage_1 array('font-style''font-variant''font-weight');
  53.         $final ''// output
  54.         
  55.         for ($i 0$size count($bits)$i $size$i++{
  56.             if ($bits[$i=== ''continue;
  57.             switch ($stage{
  58.                 
  59.                 // attempting to catch font-style, font-variant or font-weight
  60.                 case 0:
  61.                     foreach ($stage_1 as $validator_name{
  62.                         if (isset($caught[$validator_name])) continue;
  63.                         $r $this->info[$validator_name]->validate(
  64.                                                 $bits[$i]$config$context);
  65.                         if ($r !== false{
  66.                             $final .= $r ' ';
  67.                             $caught[$validator_nametrue;
  68.                             break;
  69.                         }
  70.                     }
  71.                     // all three caught, continue on
  72.                     if (count($caught>= 3$stage 1;
  73.                     if ($r !== falsebreak;
  74.                 
  75.                 // attempting to catch font-size and perhaps line-height
  76.                 case 1:
  77.                     $found_slash false;
  78.                     if (strpos($bits[$i]'/'!== false{
  79.                         list($font_size$line_height=
  80.                                                     explode('/'$bits[$i]);
  81.                         if ($line_height === ''{
  82.                             // ooh, there's a space after the slash!
  83.                             $line_height false;
  84.                             $found_slash true;
  85.                         }
  86.                     else {
  87.                         $font_size $bits[$i];
  88.                         $line_height false;
  89.                     }
  90.                     $r $this->info['font-size']->validate(
  91.                                               $font_size$config$context);
  92.                     if ($r !== false{
  93.                         $final .= $r;
  94.                         // attempt to catch line-height
  95.                         if ($line_height === false{
  96.                             // we need to scroll forward
  97.                             for ($j $i 1$j $size$j++{
  98.                                 if ($bits[$j=== ''continue;
  99.                                 if ($bits[$j=== '/'{
  100.                                     if ($found_slash{
  101.                                         return false;
  102.                                     else {
  103.                                         $found_slash true;
  104.                                         continue;
  105.                                     }
  106.                                 }
  107.                                 $line_height $bits[$j];
  108.                                 break;
  109.                             }
  110.                         else {
  111.                             // slash already found
  112.                             $found_slash true;
  113.                             $j $i;
  114.                         }
  115.                         if ($found_slash{
  116.                             $i $j;
  117.                             $r $this->info['line-height']->validate(
  118.                                               $line_height$config$context);
  119.                             if ($r !== false{
  120.                                 $final .= '/' $r;
  121.                             }
  122.                         }
  123.                         $final .= ' ';
  124.                         $stage 2;
  125.                         break;
  126.                     }
  127.                     return false;
  128.                 
  129.                 // attempting to catch font-family
  130.                 case 2:
  131.                     $font_family =
  132.                         implode(' 'array_slice($bits$i$size $i));
  133.                     $r $this->info['font-family']->validate(
  134.                                               $font_family$config$context);
  135.                     if ($r !== false{
  136.                         $final .= $r ' ';
  137.                         // processing completed successfully
  138.                         return rtrim($final);
  139.                     }
  140.                     return false;
  141.             }
  142.         }
  143.         return false;
  144.     }
  145.     
  146. }

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