/**
  * 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 ODTTableStyle();
     $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:table-properties', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(self::$table_fields, $open);
     }
     // If style has no meaningfull content then throw it away
     if ($attrs == 0) {
         return NULL;
     }
     return $style;
 }
Пример #2
0
 /**
  * This function creates a table table style using the style as set in the assoziative array $properties.
  * The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'.
  * Properties which shall not be used in the style can be disabled by setting the value in disabled_props
  * to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property.
  *
  * The currently supported properties are:
  * width, border-collapse, background-color
  *
  * The function returns the name of the new style or NULL if all relevant properties are empty.
  *
  * @author LarsDW223
  * @param $properties
  * @param null $disabled_props
  * @param int $max_width_cm
  * @return ODTTableStyle or NULL
  */
 public static function createTableTableStyle(array $properties, array $disabled_props = NULL, $max_width_cm = 17)
 {
     // If we want to change the table width we must set table:align to something else
     // than "margins". Otherwise the width will not be changed.
     // Also we set a fixed default width of 100%. Otherwise setting the width of the columns
     // will have no effect in case the user does not specify any width for the whole table.
     // FIXME: This will always produce at least one attribute.
     //        It would be more elegant to change the style if we find any width attributes
     //        in the headers/columns. Maybe later.
     $properties['align'] = 'center';
     $table_width = $max_width_cm . 'cm';
     if (!empty($properties['width'])) {
         // If width has a percentage value we need to use the rel-width attribute,
         // otherwise the width attribute
         $width = $properties['width'];
         if ($width[strlen($width) - 1] != '%') {
             $properties['width'] = $table_width;
         } else {
             // Better calculate absolute width and use it instead of relative width.
             // Some applications might not support relative width.
             $table_width = $max_width_cm * trim($width, '%') / 100 . 'cm';
             $properties['width'] = $table_width;
         }
     }
     // Convert property 'border-model' to ODT
     if (!empty($properties['border-model'])) {
         if ($properties['border-model'] == 'collapse') {
             $properties['border-model'] = 'collapsing';
         } else {
             $properties['border-model'] = 'separating';
         }
     }
     // Create style name (if not given).
     $style_name = $properties['style-name'];
     if (empty($style_name)) {
         $style_name = self::getNewStylename('Table');
         $properties['style-name'] = $style_name;
     }
     // Create empty table style.
     $object = new ODTTableStyle();
     if ($object == NULL) {
         return NULL;
     }
     // Import our properties
     $object->importProperties($properties, $disabled_props);
     return $object;
 }
 /**
  * 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();
     if (preg_match('/style:family="[^"]+"/', $xmlCode, $matches) !== 1) {
         return NULL;
     }
     $family = substr($matches[0], strlen('style:family='));
     $family = trim($family, '"<>');
     switch ($family) {
         case 'text':
             return ODTTextStyle::importODTStyle($xmlCode);
         case 'paragraph':
             return ODTParagraphStyle::importODTStyle($xmlCode);
         case 'table':
             return ODTTableStyle::importODTStyle($xmlCode);
         case 'table-column':
             return ODTTableColumnStyle::importODTStyle($xmlCode);
         case 'table-row':
             return ODTTableRowStyle::importODTStyle($xmlCode);
         case 'table-cell':
             return ODTTableCellStyle::importODTStyle($xmlCode);
     }
     // Unknown/not implemented style family.
     // Return NULL, in this case ODTStyle will create a generic unknown style.
     return NULL;
 }