/**
  * 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;
 }
 /**
  * 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 ODTTableCellStyle();
     $attrs = 0;
     $open = XMLUtil::getElementOpenTag('style:style', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(ODTStyleStyle::getStyleProperties(), $open);
     } else {
         $open = XMLUtil::getElementOpenTag('style:default-style', $xmlCode);
         if (!empty($open)) {
             $style->setDefault(true);
             $attrs += $style->importODTStyleInternal(ODTStyleStyle::getStyleProperties(), $open);
         }
     }
     $open = XMLUtil::getElementOpenTag('style:paragraph-properties', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(ODTParagraphStyle::getParagraphProperties(), $xmlCode);
     }
     $open = XMLUtil::getElementOpenTag('style:text-properties', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(ODTTextStyle::getTextProperties(), $open);
     }
     $open = XMLUtil::getElementOpenTag('style:table-cell-properties', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(self::$table_cell_fields, $open);
     }
     // If style has no meaningfull content then throw it away
     if ($attrs == 0) {
         return NULL;
     }
     return $style;
 }
 /**
  * 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 ODTParagraphStyle();
     $attrs = 0;
     $open = XMLUtil::getElementOpenTag('style:style', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(ODTStyleStyle::getStyleProperties(), $open, $style->style_properties);
     } else {
         $open = XMLUtil::getElementOpenTag('style:default-style', $xmlCode);
         if (!empty($open)) {
             $style->setDefault(true);
             $attrs += $style->importODTStyleInternal(ODTStyleStyle::getStyleProperties(), $open, $style->style_properties);
         }
     }
     $open = XMLUtil::getElementOpenTag('style:paragraph-properties', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(self::$paragraph_fields, $xmlCode);
     }
     $open = XMLUtil::getElementOpenTag('style:text-properties', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(ODTTextStyle::getTextProperties(), $open, $style->text_properties);
     }
     // Get all tab-stops.
     $tabs = XMLUtil::getElementContent('style:tab-stops', $xmlCode);
     if ($tabs != NULL) {
         $max = strlen($tabs);
         $pos = 0;
         $index = 0;
         $tab = XMLUtil::getElement('style:tab-stop', $tabs, $end);
         $pos = $end;
         while ($tab != NULL) {
             $style->tab_stops[$index] = array();
             $attrs += $style->importODTStyleInternal(self::$tab_stop_fields, $tab, $style->tab_stops[$index]);
             $index++;
             $tab = XMLUtil::getElement('style:tab-stop', substr($tabs, $pos), $end);
             $pos += $end;
         }
     }
     // If style has no meaningfull content then throw it away
     if ($attrs == 0) {
         return NULL;
     }
     return $style;
 }
 /**
  * Set a property for a specific level.
  * 
  * @param $level    The level for which to set the property (1 to 10)
  * @param $property The name of the property to set
  * @param $value    New value to set
  */
 public function setPropertyForLevel($level, $property, $value)
 {
     if ($property == 'list-level-style') {
         // Property 'list-level-style' is a special property just to remember
         // which element needs to be encoded on a call to toString().
         // It may not be included in the output of toString()!!!
         $this->setPropertyInternal($property, 'list-level-style', $value, 'list-level-style', $this->list_level_styles[$level]['list-style']);
     } else {
         // First check fields/properties common to each list-level-style
         $text_fields = ODTTextStyle::getTextProperties();
         if (array_key_exists($property, $text_fields)) {
             $this->setPropertyInternal($property, $text_fields[$property][0], $value, $text_fields[$property][1], $this->list_level_styles[$level]['text']);
             return;
         }
         if (array_key_exists($property, self::$list_level_props_fields)) {
             $this->setPropertyInternal($property, self::$list_level_props_fields[$property][0], $value, self::$list_level_props_fields[$property][1], $this->list_level_styles[$level]['list-level']);
             return;
         }
         if (array_key_exists($property, self::$label_align_fields)) {
             $this->setPropertyInternal($property, self::$label_align_fields[$property][0], $value, self::$label_align_fields[$property][1], $this->list_level_styles[$level]['label']);
             return;
         }
         // Now check fields specific to the list-level-style.
         $element = $this->getPropertyFromLevel($level, 'list-level-style');
         switch ($element) {
             case 'number':
                 $fields = self::$style_number_fields;
                 break;
             case 'bullet':
                 $fields = self::$style_bullet_fields;
                 break;
             case 'image':
                 $fields = self::$style_image_fields;
                 break;
         }
         if (array_key_exists($property, $fields)) {
             $this->setPropertyInternal($property, $fields[$property][0], $value, $fields[$property][1], $this->list_level_styles[$level]['list-style']);
         }
     }
 }