/** * 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; }
/** * This function creates a table cell 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: * background-color, vertical-align * * 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 * @return ODTTableCellStyle or NULL */ public static function createTableCellStyle(array $properties, array $disabled_props = NULL) { // Create style name (if not given). $style_name = $properties['style-name']; if (empty($style_name)) { $style_name = self::getNewStylename('TableCell'); $properties['style-name'] = $style_name; } // Create empty table cell style. $object = new ODTTableCellStyle(); 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; }