/**
  * Create new style by importing ODT style definition.
  *
  * @param  $xmlCode Style definition in ODT XML format
  * @return ODTStyle New specific style
  */
 public static function importODTStyle($xmlCode)
 {
     $style = new ODTTextOutlineStyle();
     $attrs = 0;
     $open = XMLUtil::getElementOpenTag('text:outline-style', $xmlCode);
     if (!empty($open)) {
         // This properties are stored in the properties of ODTStyle
         $attrs += $style->importODTStyleInternal(self::$outline_fields, $open);
     }
     $pos = 0;
     $end = 0;
     $max = strlen($xmlCode);
     $level = XMLUtil::getElement('text:outline-level-style', substr($xmlCode, $pos), $end);
     $pos += $end;
     $text_fields = ODTTextStyle::getTextProperties();
     $check = 0;
     while ($level != NULL) {
         // We can have multiple level definitons with all the same properties.
         // So we store this in our own array. The "text:level" is the array key.
         if (!empty($level)) {
             $properties = array();
             $attrs += $style->importODTStyleInternal($text_fields, $level, $properties);
             $attrs += $style->importODTStyleInternal(self::$outline_fields, $level, $properties);
             // Assign properties array to our level array
             $level_number = $style->getPropertyInternal('level', $properties);
             $style->outline_level_styles[$level_number] = $properties;
         }
         // Get XML code for next level.
         $level = XMLUtil::getElement('text:outline-level-style', substr($xmlCode, $pos), $end);
         $pos += $end;
         if ($pos >= $max) {
             break;
         }
     }
     // If style has no meaningfull content then throw it away
     if ($attrs == 0) {
         return NULL;
     }
     return $style;
 }
示例#2
0
 /**
  * Create new style by importing ODT style definition.
  *
  * @param  $xmlCode Style definition in ODT XML format
  * @return ODTStyle New specific style
  */
 public static function importODTStyle($xmlCode)
 {
     $matches = array();
     $pattern = '/<(\\w)+[^\\s\\/>]+/';
     if (preg_match($pattern, $xmlCode, $matches) !== 1) {
         return NULL;
     }
     $element = trim($matches[0], '"<>');
     $style = NULL;
     switch ($element) {
         case 'style:style':
         case 'style:default-style':
             $style = ODTStyleStyle::importODTStyle($xmlCode);
             break;
         case 'text:outline-style':
             $style = ODTTextOutlineStyle::importODTStyle($xmlCode);
             break;
         case 'text:list-style':
             $style = ODTTextListStyle::importODTStyle($xmlCode);
             break;
         case 'style:master-page':
             $style = ODTMasterPageStyle::importODTStyle($xmlCode);
             break;
         case 'style:page-layout':
             $style = ODTPageLayoutStyle::importODTStyle($xmlCode);
             break;
         default:
             break;
     }
     if ($style != NULL) {
         return $style;
     }
     // Unknown/not implemented style.
     // Create generic style which can not be changed.
     $unknown = ODTUnknownStyle::importODTStyle($xmlCode);
     $unknown->setElementName($element);
     return $unknown;
 }