/**
  * 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 ODTTextOutlineStyle();
     $attrs = 0;
     $open = XMLUtil::getElementOpenTag('text:outline-style', $xmlCode);
     if (!empty($open)) {
         // This properties are stored in the properties of ODTStyle
         $attrs += $style->importODTStyleInternal(self::$outline_fields, $open);
     }
     $pos = 0;
     $end = 0;
     $max = strlen($xmlCode);
     $level = XMLUtil::getElement('text:outline-level-style', substr($xmlCode, $pos), $end);
     $pos += $end;
     $text_fields = ODTTextStyle::getTextProperties();
     $check = 0;
     while ($level != NULL) {
         // We can have multiple level definitons with all the same properties.
         // So we store this in our own array. The "text:level" is the array key.
         if (!empty($level)) {
             $properties = array();
             $attrs += $style->importODTStyleInternal($text_fields, $level, $properties);
             $attrs += $style->importODTStyleInternal(self::$outline_fields, $level, $properties);
             // Assign properties array to our level array
             $level_number = $style->getPropertyInternal('level', $properties);
             $style->outline_level_styles[$level_number] = $properties;
         }
         // Get XML code for next level.
         $level = XMLUtil::getElement('text:outline-level-style', substr($xmlCode, $pos), $end);
         $pos += $end;
         if ($pos >= $max) {
             break;
         }
     }
     // If style has no meaningfull content then throw it away
     if ($attrs == 0) {
         return NULL;
     }
     return $style;
 }
예제 #2
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)
 {
     $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;
 }
 /**
  * Test setProperty() and toString().
  * This is a test case for issue #120.
  */
 public function test_set_and_to_string()
 {
     $properties = array();
     $properties['style-name'] = 'Heading';
     $properties['style-parent'] = 'Standard';
     $properties['style-class'] = 'text';
     $properties['style-next'] = 'Text_20_body';
     $properties['margin-top'] = '0.423cm';
     $properties['margin-bottom'] = '0.212cm';
     $properties['keep-with-next'] = 'always';
     $properties['font-size'] = '14pt';
     $properties['font-size-asian'] = '14pt';
     $properties['font-size-complex'] = '14pt';
     $properties['font-name'] = 'Bitstream Vera Sans1';
     $properties['font-name-asian'] = 'Bitstream Vera Sans2';
     $properties['font-name-complex'] = 'Bitstream Vera Sans2';
     $expected = '<style:style style:name="Heading" style:parent-style-name="Standard" style:class="text" style:next-style-name="Text_20_body" style:family="paragraph" >' . "\n";
     $expected .= '<style:paragraph-properties fo:margin-top="0.423cm" fo:margin-bottom="0.212cm" fo:keep-with-next="always" />' . "\n";
     $expected .= '<style:text-properties fo:font-size="14pt" style:font-size-asian="14pt" style:font-size-complex="14pt" style:font-name="Bitstream Vera Sans1" style:font-name-asian="Bitstream Vera Sans2" style:font-name-complex="Bitstream Vera Sans2" />' . "\n";
     $expected .= '</style:style>' . "\n";
     $style = new ODTParagraphStyle();
     $this->assertNotNull($style);
     foreach ($properties as $key => $value) {
         $style->setProperty($key, $value);
     }
     $style_string = $style->toString();
     // We should have the following elements:
     // style:style, style:paragraph-properties, style:text-properties
     $style_style = XMLUtil::getElementOpenTag('style:style', $style_string);
     $this->assertNotNull($style_style);
     $paragraph_props = XMLUtil::getElementOpenTag('style:paragraph-properties', $style_string);
     $this->assertNotNull($paragraph_props);
     $text_props = XMLUtil::getElementOpenTag('style:text-properties', $style_string);
     $this->assertNotNull($text_props);
     // Check attribute values of element "style:style", see $expected
     // Remark: attribute 'style:family' must always be present even if it was not set
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $style_style);
     $this->assertEquals(5, $found);
     $this->assertEquals('Heading', $attributes['style:name']);
     $this->assertEquals('Standard', $attributes['style:parent-style-name']);
     $this->assertEquals('text', $attributes['style:class']);
     $this->assertEquals('Text_20_body', $attributes['style:next-style-name']);
     $this->assertEquals('paragraph', $attributes['style:family']);
     // Check attribute values of element "style:paragraph-properties", see $expected
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $paragraph_props);
     $this->assertEquals(3, $found);
     $this->assertEquals('0.423cm', $attributes['fo:margin-top']);
     $this->assertEquals('0.212cm', $attributes['fo:margin-bottom']);
     $this->assertEquals('always', $attributes['fo:keep-with-next']);
     // Check attribute values of element "style:text-properties", see $expected
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $text_props);
     $this->assertEquals(6, $found);
     $this->assertEquals('14pt', $attributes['fo:font-size']);
     $this->assertEquals('14pt', $attributes['style:font-size-asian']);
     $this->assertEquals('14pt', $attributes['style:font-size-complex']);
     $this->assertEquals('Bitstream Vera Sans1', $attributes['style:font-name']);
     $this->assertEquals('Bitstream Vera Sans2', $attributes['style:font-name-asian']);
     $this->assertEquals('Bitstream Vera Sans2', $attributes['style:font-name-complex']);
 }
 /**
  * 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 ODTMasterPageStyle();
     // Get attributes for element 'style:master-page'
     $open = XMLUtil::getElementOpenTag('style:master-page', $xmlCode);
     if (!empty($open)) {
         $style->importODTStyleInternal(self::$master_fields, $open, $style->master_style);
     }
     // Get attributes for element 'style:header'
     $open = XMLUtil::getElementOpenTag('style:header', $xmlCode);
     if (!empty($open)) {
         $style->importODTStyleInternal(self::$header_footer_fields, $open, $style->style_header);
         $content_header = XMLUtil::getElementContent('style:header', $xmlCode);
     }
     // Get attributes for element 'style:footer'
     $open = XMLUtil::getElementOpenTag('style:footer', $xmlCode);
     if (!empty($open)) {
         $style->importODTStyleInternal(self::$header_footer_fields, $open, $style->style_footer);
         $content_footer = XMLUtil::getElementContent('style:footer', $xmlCode);
     }
     // Get attributes for element 'style:header-left'
     $open = XMLUtil::getElementOpenTag('style:header-left', $xmlCode);
     if (!empty($open)) {
         $style->importODTStyleInternal(self::$header_footer_fields, $open, $style->style_header_left);
         $content_header_left = XMLUtil::getElementContent('style:header-left', $xmlCode);
     }
     // Get attributes for element 'style:footer-left'
     $open = XMLUtil::getElementOpenTag('style:footer-left', $xmlCode);
     if (!empty($open)) {
         $style->importODTStyleInternal(self::$header_footer_fields, $open, $style->style_footer_left);
         $content_footer_left = XMLUtil::getElementContent('style:footer-left', $xmlCode);
     }
     return $style;
 }
 /**
  * Test setProperty() and toString(), including tab-stops.
  * This is a test case for issue #123.
  */
 public function test_set_toc_paragraph()
 {
     $indent = 2;
     $properties = array();
     $properties['style-name'] = 'TOC-Test';
     $properties['style-parent'] = 'Index';
     $properties['style-class'] = 'index';
     $properties['style-position'] = 17 - $indent . 'cm';
     $properties['style-type'] = 'right';
     $properties['style-leader-style'] = 'dotted';
     $properties['style-leader-text'] = '.';
     $properties['margin-left'] = $indent . 'cm';
     $properties['margin-right'] = '0cm';
     $properties['text-indent'] = '0cm';
     // This variable is just used to show the expected result but is not used for test comparsion.
     // We explicitly parse the exported XML code to be independent from attributes position.
     // The attrbitues positions might change in the future if ODTParagraphStyle.php is changed.
     $expected = '<style:style style:name="TOC-Test" style:parent-style-name="Index" style:class="index" style:family="paragraph" >';
     $expected .= '<style:paragraph-properties fo:margin-left="2cm" fo:margin-right="0cm" fo:text-indent="0cm" >';
     $expected .= '<style:tab-stops>';
     $expected .= '<style:tab-stop style:position="15cm" style:type="right" style:leader-style="dotted" style:leader-text="." />';
     $expected .= '</style:tab-stops>';
     $expected .= '</style:paragraph-properties>';
     $expected .= '</style:style>';
     // Create style, set all properties and get XML code of the style
     $style = new ODTParagraphStyle();
     $this->assertNotNull($style);
     foreach ($properties as $key => $value) {
         $style->setProperty($key, $value);
     }
     $style_string = $style->toString();
     // We should have the following elements:
     // style:style, style:paragraph-properties, style:text-properties, style:tab-stops
     $style_style = XMLUtil::getElementOpenTag('style:style', $style_string);
     $this->assertNotNull($style_style);
     $paragraph_props = XMLUtil::getElementOpenTag('style:paragraph-properties', $style_string);
     $paragraph = XMLUtil::getElement('style:paragraph-properties', $style_string);
     $this->assertNotNull($paragraph_props);
     $tab_stops_props = XMLUtil::getElement('style:tab-stops', $paragraph);
     $this->assertNotNull($tab_stops_props);
     $tab_stop_props = XMLUtil::getElementOpenTag('style:tab-stop', $tab_stops_props);
     $this->assertNotNull($tab_stop_props);
     // Check attribute values of element "style:style", see $expected
     // Remark: attribute 'style:family' must always be present even if it was not set
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $style_style);
     $this->assertEquals(4, $found);
     $this->assertEquals('TOC-Test', $attributes['style:name']);
     $this->assertEquals('Index', $attributes['style:parent-style-name']);
     $this->assertEquals('index', $attributes['style:class']);
     $this->assertEquals('paragraph', $attributes['style:family']);
     // Check attribute values of element "style:paragraph-properties", see $expected
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $paragraph_props);
     $this->assertEquals(3, $found);
     $this->assertEquals('2cm', $attributes['fo:margin-left']);
     $this->assertEquals('0cm', $attributes['fo:margin-right']);
     $this->assertEquals('0cm', $attributes['fo:text-indent']);
     // Check attribute values of element "style:tab-stop", see $expected
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $tab_stop_props);
     $this->assertEquals(4, $found);
     $this->assertEquals('15cm', $attributes['style:position']);
     $this->assertEquals('right', $attributes['style:type']);
     $this->assertEquals('dotted', $attributes['style:leader-style']);
     $this->assertEquals('.', $attributes['style:leader-text']);
 }
 /**
  * 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 ODTPageLayoutStyle();
     // Get attributes for element 'style:master-page'
     $open = XMLUtil::getElementOpenTag('style:page-layout', $xmlCode);
     if (!empty($open)) {
         $style->importODTStyleInternal(self::$page_layout_fields, $open, $style->page_layout_style);
         $childs = XMLUtil::getElementContent('style:page-layout', $xmlCode);
         if (!empty($childs)) {
             // Get attributes for element 'style:page-layout-properties'
             $open = XMLUtil::getElementOpenTag('style:page-layout-properties', $childs);
             $style->content_header = XMLUtil::getElement('style:header-style', $childs);
             $style->content_footer = XMLUtil::getElement('style:footer-style', $childs);
             if (!empty($open)) {
                 $style->importODTStyleInternal(self::$layout_props_fields, $open, $style->layout_props);
                 $childs = XMLUtil::getElementContent('style:page-layout-properties', $xmlCode);
                 if (!empty($childs)) {
                     // Get 'style:background-image'
                     $open = XMLUtil::getElementOpenTag('style:background-image', $childs);
                     if (!empty($open)) {
                         $style->importODTStyleInternal(self::$bgi_fields, $open, $style->bgi_props);
                         $style->content_bgi = XMLUtil::getElementContent('style:background-image', $childs);
                     }
                     // Get 'style:columns'
                     $open = XMLUtil::getElementOpenTag('style:columns', $childs);
                     if (!empty($open)) {
                         $style->importODTStyleInternal(self::$columns_fields, $open, $style->columns_props);
                         $style->content_columns = XMLUtil::getElementContent('style:columns', $childs);
                     }
                     // Get 'style:footnote-sep'
                     $open = XMLUtil::getElementOpenTag('style:footnote-sep', $childs);
                     if (!empty($open)) {
                         $style->importODTStyleInternal(self::$footnote_fields, $open, $style->footnote_props);
                     }
                 }
             }
         }
     }
     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 ODTTextListStyle();
     $attrs = 0;
     $open = XMLUtil::getElementOpenTag('text:list-style', $xmlCode);
     if (!empty($open)) {
         // This properties are stored in the properties of ODTStyle
         $attrs += $style->importODTStyleInternal(self::$list_fields, $open);
         $content = XMLUtil::getElementContent('text:list-style', $xmlCode);
     }
     $pos = 0;
     $end = 0;
     $max = strlen($content);
     $text_fields = ODTTextStyle::getTextProperties();
     while ($pos < $max) {
         // Get XML code for next level.
         $level = XMLUtil::getNextElement($element, substr($content, $pos), $end);
         $level_content = XMLUtil::getNextElementContent($element, $level, $ignore);
         if (!empty($level)) {
             $list_style_properties = array();
             $list_level_properties = array();
             $label_properties = array();
             $text_properties = array();
             $properties = array();
             switch ($element) {
                 case 'text:list-level-style-number':
                     $attrs += $style->importODTStyleInternal(self::$style_number_fields, $level, $list_style_properties);
                     $list_level_style = 'number';
                     break;
                 case 'text:list-level-style-bullet':
                     $attrs += $style->importODTStyleInternal(self::$style_bullet_fields, $level, $list_style_properties);
                     $list_level_style = 'bullet';
                     break;
                 case 'text:list-level-style-image':
                     $attrs += $style->importODTStyleInternal(self::$style_image_fields, $level, $list_style_properties);
                     $list_level_style = 'image';
                     break;
             }
             $temp_content = XMLUtil::getElement('style:text-properties', $level_content);
             $attrs += $style->importODTStyleInternal($text_fields, $temp_content, $text_properties);
             $temp_content = XMLUtil::getElementOpenTag('style:list-level-properties', $level_content);
             $attrs += $style->importODTStyleInternal(self::$list_level_props_fields, $temp_content, $list_level_properties);
             $temp_content = XMLUtil::getElement('style:list-level-label-alignment', $level_content);
             $attrs += $style->importODTStyleInternal(self::$label_align_fields, $temp_content, $label_properties);
             // Assign properties array to our level array
             $level_number = $style->getPropertyInternal('level', $list_style_properties);
             $properties['list-style'] = $list_style_properties;
             $properties['list-level'] = $list_level_properties;
             $properties['label'] = $label_properties;
             $properties['text'] = $text_properties;
             $style->list_level_styles[$level_number] = $properties;
             // Set special property 'list-level-style' to remember element to encode
             // on call to toString()!
             $style->setPropertyForLevel($level_number, 'list-level-style', $list_level_style);
         }
         $pos += $end;
     }
     // If style has no meaningfull content then throw it away
     if ($attrs == 0) {
         return NULL;
     }
     return $style;
 }
 /**
  * This function checks the rendering of deleted text.
  */
 public function test_deleted_text()
 {
     $files = array();
     $ok = ODTTestUtils::getRenderedODTDocument($files, '<del>This is strike-through text.</del>');
     $this->assertFalse($ok == false, 'Error rendering, creating, unpacking, reading ODT doc!');
     // Examine ODT XML content.
     // Get office:text
     $office_text = XMLUtil::getElementContent('office:text', $files['content-xml']);
     $this->assertFalse($office_text == NULL, 'Element "office:text" not found!');
     // Get first paragraph
     $paragraph = XMLUtil::getElementContent('text:p', $office_text);
     $this->assertFalse($paragraph == NULL, 'Element "text:p" not found!');
     // The paragraph shouild have a text span.
     $span_attrs = XMLUtil::getElementOpenTag('text:span', $office_text);
     $span_content = XMLUtil::getElementContent('text:span', $office_text);
     $this->assertFalse($span_content == NULL, 'Element "text:p" not found!');
     // The span should have our text content and the style for bold text
     $this->assertEquals($span_content, 'This is strike-through text.');
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $span_attrs);
     $this->assertEquals(1, $found);
     $this->assertEquals('del', $attributes['text:style-name']);
 }