/**
  * Constructor.
  */
 public function __construct()
 {
     if (self::$get_family_callbacks === NULL) {
         self::$get_family_callbacks = array();
     }
     if (self::$import_odt_callbacks === NULL) {
         self::$import_odt_callbacks = array();
     }
 }
 /**
  * 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 ODTTextStyle();
     $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:text-properties', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(self::$text_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;
 }
Example #4
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;
 }