/**
  * This function checks if a image is included with the correct size.
  * Therefore an test image with known size is choosen (TestPicture500x256.png).
  */
 public function test_image_size_2()
 {
     $units = new helper_plugin_odt_units();
     $renderer = new renderer_plugin_odt_page();
     $renderer->document_start();
     $renderer->_odtAddImage(TMP_DIR . '/data/TestPicture500x256.png');
     // There should be a frame
     $start = strpos($renderer->doc, '<draw:frame');
     $end = strpos($renderer->doc, '</draw:frame>');
     $frame = substr($renderer->doc, $start, $end + strlen('</draw:frame>') - $start);
     $this->assertFalse(empty($frame));
     // Check that the width has the unit 'cm' and that it is
     // calculated according to the formula ($width/96.0)*2.54
     $result = preg_match('/svg:width="[^"]*"/', $renderer->doc, $widths);
     $this->assertEquals($result, 1);
     $unit = substr($widths[0], strlen('svg:width='));
     $unit = trim($unit, '"');
     $width = $units->getDigits($unit);
     $unit = $units->stripDigits($unit);
     $this->assertEquals($unit, 'cm');
     $this->assertEquals($width, 500 / 96.0 * 2.54);
     // Check that the height has the unit 'cm' and that it is
     // calculated according to the formula ($height/96.0)*2.54
     $result = preg_match('/svg:height="[^"]*"/', $renderer->doc, $heights);
     $this->assertEquals($result, 1);
     $unit = substr($heights[0], strlen('svg:height='));
     $unit = trim($unit, '"');
     $height = $units->getDigits($unit);
     $unit = $units->stripDigits($unit);
     $this->assertEquals($unit, 'cm');
     $this->assertEquals($height, 256 / 96.0 * 2.54);
 }
예제 #2
0
 /**
  * Start a table
  *
  * @param int $maxcols maximum number of columns
  * @param int $numrows NOT IMPLEMENTED
  */
 function table_open($maxcols = NULL, $numrows = NULL)
 {
     // Close any open paragraph.
     $this->p_close();
     // Do additional actions if the parent element is a list.
     // In this case we need to finish the list and re-open it later
     // after the table has been closed! --> tables may not be part of a list item in ODT!
     $interrupted = false;
     $table_style_name = $this->docHandler->getStyleName('table');
     if ($this->state->getInListItem()) {
         // We are in a list item. Query indentation settings.
         $list = $this->state->findClosestWithClass('list');
         if ($list != NULL) {
             $list_style_name = $list->getStyleName();
             $list_style = $this->docHandler->getStyle($list_style_name);
             if ($list_style != NULL) {
                 // The list level stored in the list item/from the parser
                 // might not be correct. Count 'list' states to get level.
                 $level = $this->state->countClass('list');
                 // Create a table style for indenting the table.
                 // We try to achieve this by substracting the list indentation
                 // from the width of the table and right align it!
                 // (if not done yet, the name must be unique!)
                 $style_name = 'Table_Indentation_Level' . $level;
                 if (!$this->docHandler->styleExists($style_name)) {
                     $properties = array();
                     $properties['style-name'] = $style_name;
                     $style_obj = $this->factory->createTableTableStyle($properties);
                     if ($style_obj != NULL) {
                         $max = $this->page->getAbsWidthMindMargins();
                         $indent = 0 + $this->units->getDigits($list_style->getPropertyFromLevel($level, 'margin-left'));
                         $style_obj->setProperty('width', $max - $indent . 'cm');
                         $style_obj->setProperty('align', 'right');
                         $this->docHandler->addAutomaticStyle($style_obj);
                     }
                 }
                 $table_style_name = $style_name;
             }
         }
         // Close all open lists and remember their style (may be nested!)
         $lists = array();
         $first = true;
         $iterations = 0;
         while ($this->state->getInList() === true) {
             // Close list items
             if ($first == true) {
                 $first = false;
                 $this->listcontent_close();
             }
             $this->listitem_close();
             // Now we are in the list state!
             // Get the lists style name before closing it.
             $lists[] = $this->state->getStyleName();
             $this->list_close();
             if ($this->state == NULL || $this->state->getElement() == 'root') {
                 break;
             }
             // Just to prevent endless loops in case of an error!
             $iterations++;
             if ($iterations == 50) {
                 $this->doc .= 'Error: ENDLESS LOOP!';
                 break;
             }
         }
         $interrupted = true;
     }
     $this->state->enter('table:table', 'table');
     if ($interrupted == true) {
         // Set marker that list has been interrupted
         $this->state->setListInterrupted(true);
         // Save the lists array as temporary data
         // in THIS state because this is the state that we get back
         // to in table_close!!!
         // (we closed the ODT list, we can't access its state info anymore!
         //  So we use the table state to save the style name!)
         $this->state->setTemp($lists);
     }
     if ($table_style_name == NULL) {
         $this->doc .= '<table:table>';
     } else {
         $this->doc .= '<table:table table:style-name="' . $table_style_name . '">';
     }
     for ($i = 0; $i < $maxcols; $i++) {
         $this->doc .= '<table:table-column />';
     }
 }