/** * 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 ODTUnknownStyle(); $style->setStyleContent($xmlCode); return $style; }
/** * This function opens a textbox in a frame. * * The currently supported CSS properties are: * background-color, color, padding, margin, display, border-radius, min-height. * The background-image is simulated using a picture frame. * FIXME: Find a way to successfuly use the background-image in the graphic style (see comments). * * The div should be closed by calling '_odtDivCloseAsFrame'. * * @author LarsDW223 * * @param array $properties */ function _odtOpenTextBoxUseProperties($properties) { if ($this->state->getInFrame()) { // Do not open a nested frame as this will make the content ofthe nested frame disappear. //return; } $this->div_z_index += 5; $this->style_count++; $odt_bg = $properties['background-color']; $odt_fo = $properties['color']; $padding_left = $properties['padding-left']; $padding_right = $properties['padding-right']; $padding_top = $properties['padding-top']; $padding_bottom = $properties['padding-bottom']; $margin_left = $properties['margin-left']; $margin_right = $properties['margin-right']; $margin_top = $properties['margin-top']; $margin_bottom = $properties['margin-bottom']; $display = $properties['display']; $fo_border = $properties['border']; $border_color = $properties['border-color']; $border_width = $properties['border-width']; $radius = $properties['border-radius']; $picture = $properties['background-image']; $pic_positions = preg_split('/\\s/', $properties['background-position']); $min_height = $properties['min-height']; $width = $properties['width']; $horiz_pos = $properties['float']; $pic_link = ''; $pic_width = ''; $pic_height = ''; if (!empty($picture)) { // If a picture/background-image is set in the CSS, than we insert it manually here. // This is a workaround because ODT does not support the background-image attribute in a span. $pic_link = $this->_odtAddImageAsFileOnly($picture); list($pic_width, $pic_height) = $this->_odtGetImageSizeString($picture); } if (empty($horiz_pos)) { $horiz_pos = 'center'; } if (empty($width)) { $width = '100%'; } if (empty($border_color)) { $border_color = $odt_bg; } if (!empty($pic_positions[0])) { $pic_positions[0] = $this->adjustXLengthValueForODT($pic_positions[0]); } if (empty($min_height)) { $min_height = '1pt'; } // Different handling for relative and absolute size... if ($width[strlen($width) - 1] == '%') { // Convert percentage values to absolute size, respecting page margins $width = trim($width, '%'); $width_abs = $this->_getAbsWidthMindMargins($width) . 'cm'; } else { // Absolute values may include not supported units. // Adjust. $width_abs = $this->adjustXLengthValueForODT($width); } // Add our styles. $style_name = 'odt_auto_style_div_' . $this->style_count; $style = '<style:style style:name="' . $style_name . '_text_frame" style:family="graphic"> <style:graphic-properties draw:textarea-horizontal-align="left" style:horizontal-pos="' . $horiz_pos . '" fo:background-color="' . $odt_bg . '" style:background-transparency="100%" '; if (!empty($odt_bg)) { $style .= 'draw:fill="solid" draw:fill-color="' . $odt_bg . '" '; } else { $style .= 'draw:fill="none" '; } if (!empty($border_color)) { $style .= 'svg:stroke-color="' . $border_color . '" '; } if (!empty($border_width)) { $style .= 'svg:stroke-width="' . $border_width . '" '; } if (!empty($padding_left)) { $style .= 'fo:padding-left="' . $padding_left . '" '; } if (!empty($padding_right)) { $style .= 'fo:padding-right="' . $padding_right . '" '; } if (!empty($padding_top)) { $style .= 'fo:padding-top="' . $padding_top . '" '; } if (!empty($padding_bottom)) { $style .= 'fo:padding-bottom="' . $padding_bottom . '" '; } if (!empty($margin_left)) { $style .= 'fo:margin-left="' . $margin_left . '" '; } if (!empty($margin_right)) { $style .= 'fo:margin-right="' . $margin_right . '" '; } if (!empty($margin_top)) { $style .= 'fo:margin-top="' . $margin_top . '" '; } if (!empty($margin_bottom)) { $style .= 'fo:margin-bottom="' . $margin_bottom . '" '; } if (!empty($fo_border)) { $style .= 'fo:border="' . $fo_border . '" '; } $style .= 'fo:min-height="' . $min_height . '" style:wrap="none"'; $style .= '>'; // FIXME: Delete the part below 'if ( $picture != NULL ) {...}' // and use this background-image definition. For some reason the background-image is not displayed. // Help is welcome. /*$style .= '<style:background-image '; $style .= 'xlink:href="'.$pic_link.'" xlink:type="simple" xlink:actuate="onLoad" style:position="center center" style:repeat="no-repeat" draw:opacity="100%"/>';*/ $style .= '</style:graphic-properties>'; $style .= '</style:style>'; $style .= '<style:style style:name="' . $style_name . '_image_frame" style:family="graphic"> <style:graphic-properties svg:stroke-color="' . $odt_bg . '" draw:fill="none" draw:fill-color="' . $odt_bg . '" draw:textarea-horizontal-align="left" draw:textarea-vertical-align="center" style:wrap="none"/> </style:style> <style:style style:name="' . $style_name . '_text_box" style:family="paragraph"> <style:text-properties fo:color="' . $odt_fo . '"/> <style:paragraph-properties fo:margin-left="' . $padding_left . '" fo:margin-right="10pt" fo:text-indent="0cm"/> </style:style>'; // Add style to our document // (as unknown style because style-family graphic is not supported) $style_obj = ODTUnknownStyle::importODTStyle($style); $this->docHandler->addAutomaticStyle($style_obj); // Group the frame so that they are stacked one on each other. $this->p_close(); $this->p_open(); $this->linebreak(); if ($display == NULL) { $this->doc .= '<draw:g>'; } else { $this->doc .= '<draw:g draw:display="' . $display . '">'; } $anchor_type = 'paragraph'; // FIXME: Later try to get nested frames working - probably with anchor = as-char if ($this->state->getInFrame()) { $anchor_type = 'as-char'; } // Draw a frame with the image in it, if required. // FIXME: delete this part if 'background-image' in graphic style is working. if ($picture != NULL) { $this->doc .= '<draw:frame draw:style-name="' . $style_name . '_image_frame" draw:name="Bild1" text:anchor-type="paragraph" svg:x="' . $pic_positions[0] . '" svg:y="' . $pic_positions[0] . '" svg:width="' . $pic_width . '" svg:height="' . $pic_height . '" draw:z-index="' . ($this->div_z_index + 1) . '"> <draw:image xlink:href="' . $pic_link . '" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> </draw:frame>'; } // Draw a frame with a text box in it. the text box will be left opened // to grow with the content (requires fo:min-height in $style_name). $this->doc .= '<draw:frame draw:style-name="' . $style_name . '_text_frame" draw:name="Bild1" text:anchor-type="' . $anchor_type . '" svg:x="0cm" svg:y="0cm" svg:width="' . $width_abs . '" svg:height="' . $min_height . '" '; $this->doc .= 'draw:z-index="' . ($this->div_z_index + 0) . '">'; $this->doc .= '<draw:text-box '; // If required use round corners. if (!empty($radius)) { $this->doc .= 'draw:corner-radius="' . $radius . '" '; } $this->doc .= '>'; $this->state->enter('frame', 'frame'); $this->state->setInFrame(true); $this->state->setInParagraph(false); }
/** * This function creates a page layout style with the parameters given in $properies. * * The currently supported properties are: * style-name, width, height, margin-top, margin-bottom, margin-right and margin-left. * All properties except the style-name are expected to be numeric values. * The function will add 'cm' itself, so do not add any units. * * 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 ODTUnknownStyle or NULL */ public static function createPageLayoutStyle(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('Page'); $properties['style-name'] = $style_name; } $style = '<style:page-layout style:name="' . $style_name . '"> <style:page-layout-properties fo:page-width="' . $properties['width'] . 'cm" fo:page-height="' . $properties['height'] . 'cm" style:num-format="1" style:print-orientation="landscape" fo:margin-top="' . $properties['margin-top'] . 'cm" fo:margin-bottom="' . $properties['margin-bottom'] . 'cm" fo:margin-left="' . $properties['margin-left'] . 'cm" fo:margin-right="' . $properties['margin-right'] . 'cm" style:writing-mode="lr-tb" style:footnote-max-height="0cm"> <style:footnote-sep style:width="0.018cm" style:distance-before-sep="0.1cm" style:distance-after-sep="0.1cm" style:adjustment="left" style:rel-width="25%" style:color="#000000"/> </style:page-layout-properties> <style:header-style/> <style:footer-style/> </style:page-layout>'; // Create empty page style. // Not supported yet, so we create an "unknown" style $object = new ODTUnknownStyle(); if ($object == NULL) { return NULL; } $object->setStyleContent($style); 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(); $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; }