示例#1
0
 function parse($value)
 {
     $font = CSS::getDefaultValue(CSS_FONT);
     if ($value === 'inherit') {
         $font->style = CSS_PROPERTY_INHERIT;
         $font->weight = CSS_PROPERTY_INHERIT;
         $font->size = CSS_PROPERTY_INHERIT;
         $font->family = CSS_PROPERTY_INHERIT;
         $font->line_height = CSS_PROPERTY_INHERIT;
         return $font;
     }
     // according to CSS 2.1 standard,
     // value of 'font' CSS property can be represented as follows:
     //   [ <'font-style'> || <'font-variant'> || <'font-weight'> ]? <'font-size'> [ / <'line-height'> ]? <'font-family'> ] |
     //   caption | icon | menu | message-box | small-caption | status-bar | inherit
     // Note that font-family value, unlike other values, can contain spaces (in this case it should be quoted)
     // Breaking value by spaces, we'll break such multi-word families.
     // Replace all white space sequences with only one space;
     // Remove spaces after commas; it will allow us
     // to split value correctly using look-backward expressions
     $value = preg_replace("/\\s+/", " ", $value);
     $value = preg_replace("/,\\s+/", ",", $value);
     $value = preg_replace("#\\s*/\\s*#", "/", $value);
     // Split value to subvalues by all whitespaces NOT preceeded by comma;
     // thus, we'll keep all alternative font-families together instead of breaking them.
     // Still we have a problem with multi-word family names.
     $subvalues = preg_split("/ /", $value);
     // Let's scan subvalues we've received and join values containing multiword family names
     $family_start = 0;
     $family_running = false;
     $family_double_quote = false;
     for ($i = 0, $num_subvalues = count($subvalues); $i < $num_subvalues; $i++) {
         $current_value = $subvalues[$i];
         if ($family_running) {
             $subvalues[$family_start] .= " " . $subvalues[$i];
             // Remove this subvalues from the subvalue list at all
             array_splice($subvalues, $i, 1);
             $num_subvalues--;
             $i--;
         }
         // Check if current subvalue contains beginning of multi-word family name
         // We can detect it by searching for single or double quote without pair
         if ($family_running && $family_double_quote && !preg_match('/^[^"]*("[^"]*")*[^"]*$/', $current_value)) {
             $family_running = false;
         } elseif ($family_running && !$family_double_quote && !preg_match("/^[^']*('[^']*')*[^']*\$/", $current_value)) {
             $family_running = false;
         } elseif (!$family_running && !preg_match("/^[^']*('[^']*')*[^']*\$/", $current_value)) {
             $family_running = true;
             $family_start = $i;
             $family_double_quote = false;
         } elseif (!$family_running && !preg_match('/^[^"]*("[^"]*")*[^"]*$/', $current_value)) {
             $family_running = true;
             $family_start = $i;
             $family_double_quote = true;
         }
     }
     // Now process subvalues one-by-one.
     foreach ($subvalues as $subvalue) {
         $subvalue = trim(strtolower($subvalue));
         $subvalue_type = detect_font_value_type($subvalue);
         switch ($subvalue_type) {
             case FONT_VALUE_STYLE:
                 $font->style = CSSFontStyle::parse($subvalue);
                 break;
             case FONT_VALUE_WEIGHT:
                 $font->weight = CSSFontWeight::parse($subvalue);
                 break;
             case FONT_VALUE_SIZE:
                 $size_subvalues = explode('/', $subvalue);
                 $font->size = CSSFontSize::parse($size_subvalues[0]);
                 if (isset($size_subvalues[1])) {
                     $handler =& CSS::get_handler(CSS_LINE_HEIGHT);
                     $font->line_height = $handler->parse($size_subvalues[1]);
                 }
                 break;
             case FONT_VALUE_FAMILY:
                 $font->family = CSSFontFamily::parse($subvalue);
                 break;
         }
     }
     return $font;
 }
 function _showTextNormal(&$driver)
 {
     // draw generic box
     parent::show($driver);
     $font_size = $this->getCSSProperty(CSS_FONT_SIZE);
     if (!$font_size) {
         $font_size = CSSFontSize::default_value();
     }
     $decoration = $this->getCSSProperty(CSS_TEXT_DECORATION);
     // draw text decoration
     $driver->decoration($decoration['U'], $decoration['O'], $decoration['T']);
     $letter_spacing = $this->getCSSProperty(CSS_LETTER_SPACING);
     if (!$letter_spacing || $letter_spacing->getPoints() == 0) {
         // Output text with the selected font
         // note that we're using $default_baseline;
         // the alignment offset - the difference between baseline and default_baseline values
         // is taken into account inside the get_top/get_bottom functions
         //
         $size = count($this->words);
         $left = $this->get_left();
         for ($i = 0; $i < $size; $i++) {
             // Activate font
             $status = $driver->setfont($this->_get_font_name($driver, $i), $this->encodings[$i], $font_size->getPoints());
             if (is_null($status)) {
                 error_log("TextBox::show: setfont call failed");
                 return null;
             }
             $driver->show_xy($this->words[$i], $left, $this->get_top() - $this->default_baseline);
             $left += $this->_word_widths[$i];
         }
     } else {
         $current_char = 0;
         $left = $this->get_left();
         $top = $this->get_top() - $this->default_baseline;
         $num_words = count($this->words);
         for ($i = 0; $i < $num_words; $i++) {
             $num_chars = strlen($this->words[$i]);
             for ($j = 0; $j < $num_chars; $j++) {
                 $status = $driver->setfont($this->_get_font_name($driver, $i), $this->encodings[$i], $font_size->getPoints());
                 $driver->show_xy($this->words[$i][$j], $left, $top);
                 $left += $this->_widths[$current_char] + $letter_spacing->getPoints();
                 $current_char++;
             }
         }
     }
     return true;
 }