/** * 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); } 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(self::$paragraph_fields, $xmlCode); } $open = XMLUtil::getElementOpenTag('style:text-properties', $xmlCode); if (!empty($open)) { $attrs += $style->importODTStyleInternal(ODTTextStyle::getTextProperties(), $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; }
/** * This function creates a paragraph 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, color, font-style, font-weight, font-size, border, font-family, font-variant, letter-spacing, * vertical-align, line-height, background-image * * 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 ODTParagraphStyle or NULL */ public static function createParagraphStyle(array $properties, array $disabled_props = NULL) { // If the property 'vertical-align' has the value 'sub' or 'super' // then for ODT it needs to be converted to the corresponding 'text-position' property. // Replace sub and super with text-position. $valign = $properties['vertical-align']; if (!empty($valign)) { if ($valign == 'sub') { $properties['text-position'] = '-33% 100%'; unset($properties['vertical-align']); } elseif ($valign == 'super') { $properties['text-position'] = '33% 100%'; unset($properties['vertical-align']); } } // Separate country from language $lang = $properties['lang']; $country = $properties['country']; if (!empty($lang)) { $parts = preg_split('/-/', $lang); $lang = $parts[0]; $country = $parts[1]; $properties['country'] = trim($country); $properties['lang'] = trim($lang); } if (!empty($properties['country'])) { if (empty($properties['country-asian'])) { $properties['country-asian'] = $properties['country']; } if (empty($properties['country-complex'])) { $properties['country-complex'] = $properties['country']; } } // Always set 'auto-text-indent = false' if 'text-indent' is set. if (!empty($properties['text-indent'])) { $properties['auto-text-indent'] = 'false'; } // Create style name (if not given). $style_name = $properties['style-name']; if (empty($style_name)) { $style_name = self::getNewStylename('Paragraph'); $properties['style-name'] = $style_name; } // FIXME: fix missing tab stop handling... //case 'tab-stop': // $tab .= $params [$property]['name'].'="'.$value.'" '; // $tab .= self::writeExtensionNames ($params [$property]['name'], $value); // break; // Create empty paragraph style. $object = new ODTParagraphStyle(); 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; }