bug #1672636 [export] PDF export too wide

This commit is contained in:
Marc Delisle
2007-04-13 17:26:10 +00:00
parent 047a0a7128
commit 15a5a8104d
2 changed files with 42 additions and 14 deletions

View File

@@ -77,6 +77,7 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA
- patch #1681620 [interface] support reordering of $cfg['ColumnTypes'], - patch #1681620 [interface] support reordering of $cfg['ColumnTypes'],
thanks to Leonard den Ottolander thanks to Leonard den Ottolander
- bug #1690718 Can't edit if BLOB and no PK - bug #1690718 Can't edit if BLOB and no PK
- bug #1672636 [export] PDF export too wide
+ [lang] brazilian-portuguese update, thanks to Airon Luis Pereira + [lang] brazilian-portuguese update, thanks to Airon Luis Pereira
2.10.0.3 (not released yet) 2.10.0.3 (not released yet)

View File

@@ -215,7 +215,6 @@ class PMA_PDF extends TCPDF
/** /**
* Pass 1 for column widths * Pass 1 for column widths
* @todo force here a LIMIT to speed up pass 1 ?
*/ */
$this->results = PMA_DBI_query($query, null, PMA_DBI_QUERY_UNBUFFERED); $this->results = PMA_DBI_query($query, null, PMA_DBI_QUERY_UNBUFFERED);
$this->numFields = PMA_DBI_num_fields($this->results); $this->numFields = PMA_DBI_num_fields($this->results);
@@ -224,15 +223,21 @@ class PMA_PDF extends TCPDF
// if column widths not set // if column widths not set
if (!isset($this->tablewidths)){ if (!isset($this->tablewidths)){
// starting col width // sColWidth = starting col width (an average size width)
$this->sColWidth = ($this->w - $this->lMargin - $this->rMargin) / $this->numFields; $availableWidth = $this->w - $this->lMargin - $this->rMargin;
$this->sColWidth = $availableWidth / $this->numFields;
$totalTitleWidth = 0;
// loop through results header and set initial col widths/ titles/ alignment // loop through results header and set initial col widths/ titles/ alignment
// if a col title is less than the starting col width / reduce that column size // if a col title is less than the starting col width, reduce that column size
for ($i = 0; $i < $this->numFields; $i++){ for ($i = 0; $i < $this->numFields; $i++){
$stringWidth = $this->getstringwidth($this->fields[$i]->name) + 6 ; $stringWidth = $this->getstringwidth($this->fields[$i]->name) + 6 ;
// save the real title's width
$titleWidth[$i] = $stringWidth;
$totalTitleWidth += $stringWidth;
// set any column titles less than the start width to the column title width // set any column titles less than the start width to the column title width
if (($stringWidth) < $this->sColWidth){ if ($stringWidth < $this->sColWidth){
$colFits[$i] = $stringWidth ; $colFits[$i] = $stringWidth ;
} }
$this->colTitles[$i] = $this->fields[$i]->name; $this->colTitles[$i] = $this->fields[$i]->name;
@@ -261,18 +266,34 @@ class PMA_PDF extends TCPDF
} }
} }
// title width verification
if ($totalTitleWidth > $availableWidth) {
$adjustingMode = true;
} else {
$adjustingMode = false;
// we have enough space for all the titles at their
// original width so use the true title's width
foreach ($titleWidth as $key => $val) {
$colFits[$key] = $val;
}
}
// loop through the data, any column whose contents is bigger // loop through the data, any column whose contents is bigger
// than the col size is resized // than the col size is resized
// TODO: force here a LIMIT to avoid reading all rows /**
* @todo force here a LIMIT to avoid reading all rows
*/
while ($row = PMA_DBI_fetch_row($this->results)) { while ($row = PMA_DBI_fetch_row($this->results)) {
foreach ($colFits as $key => $val) { foreach ($colFits as $key => $val) {
$stringWidth = $this->getstringwidth($row[$key]) + 6 ; $stringWidth = $this->getstringwidth($row[$key]) + 6 ;
if ($stringWidth > $this->sColWidth) { if ($adjustingMode && ($stringWidth > $this->sColWidth)) {
// any col where row is bigger than the start width is now discarded // any column whose data's width is bigger than the start width is now discarded
unset($colFits[$key]); unset($colFits[$key]);
} else { } else {
// if text is not bigger than the current column width setting enlarge the column // if data's width is bigger than the current column width,
if ($stringWidth > $val) { // enlarge the column (but avoid enlarging it if the
// data's width is very big)
if ($stringWidth > $val && $stringWidth < ($this->sColWidth * 3)) {
$colFits[$key] = $stringWidth ; $colFits[$key] = $stringWidth ;
} }
} }
@@ -287,10 +308,16 @@ class PMA_PDF extends TCPDF
$totAlreadyFitted += $val; $totAlreadyFitted += $val;
} }
if ($adjustingMode) {
$surplus = (sizeof($colFits) * $this->sColWidth) - $totAlreadyFitted; $surplus = (sizeof($colFits) * $this->sColWidth) - $totAlreadyFitted;
$surplusToAdd = $surplus / ($this->numFields - sizeof($colFits));
} else {
$surplusToAdd = 0;
}
for ($i=0; $i < $this->numFields; $i++) { for ($i=0; $i < $this->numFields; $i++) {
if (!in_array($i, array_keys($colFits))) { if (!in_array($i, array_keys($colFits))) {
$this->tablewidths[$i] = $this->sColWidth + ($surplus / ($this->numFields - sizeof($colFits))); $this->tablewidths[$i] = $this->sColWidth + $surplusToAdd;
} }
if ($this->display_column[$i] == false) { if ($this->display_column[$i] == false) {
$this->tablewidths[$i] = 0; $this->tablewidths[$i] = 0;