/** * 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); }
protected function _replaceTableWidth() { $matches = array(); if (empty($this->temp_table_style) || empty($this->temp_cols)) { return; } // Search through all column styles for the column width ('style:width="..."'). // If every column has a absolute width set, add them all and replace the table // with with the result. // Abort if a column has a percentage width or no width. $sum = 0; for ($index = 0; $index < $this->temp_maxcols; $index++) { $style_name = $this->temp_table_column_styles[$index]; $found = preg_match('/style:column-width="[^"]*"/', $this->autostyles[$style_name], $matches); if ($found != 1) { return; } $width = substr($matches[0], strlen('style:column-width=')); $width = trim($width, '"'); $length = strlen($width); if ($width[$length - 1] == '%') { return; } $width = $this->units->toPoints($width, 'x'); $sum += (double) trim($width, 'pt'); } $this->autostyles[$this->temp_table_style] = preg_replace('/style:width="[^"]*"/', 'style:width="' . $sum . 'pt"', $this->autostyles[$this->temp_table_style]); }
/** * Ensure that conversion to points works correctly. */ public function test_toPoints() { $units = new helper_plugin_odt_units(); // Set base values. $units->setTwipsPerPixelX(16); $units->setTwipsPerPixelY(20); $units->setPixelPerEm(14); $this->assertEquals($units->getPixelPerEm(), 14); $this->assertEquals($units->toPoints('1cm'), '28.346456514353pt'); $this->assertEquals($units->toPoints('1mm'), '2.8346456514353pt'); $this->assertEquals($units->toPoints('1in'), '0.089605556pt'); $this->assertEquals($units->toPoints('1pc'), '12pt'); $this->assertEquals($units->toPoints('1px', 'x'), '0.8pt'); $this->assertEquals($units->toPoints('1px', 'y'), '1pt'); $this->assertEquals($units->toPoints('1em'), '14pt'); }
protected function _replaceTableWidth() { $matches = array(); if (empty($this->temp_table_style) || empty($this->temp_cols)) { return; } // Search through all column styles for the column width ('style:width="..."'). // If every column has a absolute width set, add them all and replace the table // width with the result. // Abort if a column has a percentage width or no width. $sum = 0; for ($index = 0; $index < $this->temp_maxcols; $index++) { $style_name = $this->temp_table_column_styles[$index]; $style_obj = $this->docHandler->getStyle($style_name); if ($style_obj != NULL && $style_obj->getProperty('column-width') != NULL) { $width = $style_obj->getProperty('column-width'); $length = strlen($width); $width = $this->units->toPoints($width, 'x'); $sum += (double) trim($width, 'pt'); } else { return; } } $style_obj = $this->docHandler->getStyle($this->temp_table_style); if ($style_obj != NULL) { $style_obj->setProperty('width', $sum . 'pt'); } }
protected function _replaceTableWidth() { $matches = array(); $table = $this->state->findClosestWithClass('table', 'table'); if ($table == NULL) { // ??? Should not happen. return; } $table_style = $table->getTableStyle(); $column_defs = $table->getTableColumnDefs(); if (empty($table_style) || empty($column_defs)) { return; } // Search through all column styles for the column width ('style:width="..."'). // If every column has a absolute width set, add them all and replace the table // width with the result. // Abort if a column has a percentage width or no width. $sum = 0; $table_column_styles = $table->getTableColumnStyles(); for ($index = 0; $index < $table->getTableMaxColumns(); $index++) { $style_name = $table_column_styles[$index]; $style_obj = $this->docHandler->getStyle($style_name); if ($style_obj != NULL && $style_obj->getProperty('column-width') != NULL) { $width = $style_obj->getProperty('column-width'); $length = strlen($width); $width = $this->units->toPoints($width, 'x'); $sum += (double) trim($width, 'pt'); } else { return; } } $style_obj = $this->docHandler->getStyle($table_style); if ($style_obj != NULL) { $style_obj->setProperty('width', $sum . 'pt'); } }
/** * Sets the twips per pixel (Y axis) unit used for px to pt conversion. * * @param int $value The value to be set. */ public function setTwipsPerPixelY($value) { self::$twips_per_pixel_y = $value; }