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'); } }