[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 10/12: Compute the height of a MultiCell and
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 10/12: Compute the height of a MultiCell and check is a page must be added |
Date: |
Mon, 25 Jan 2016 22:58:39 +0000 |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 0c1e780b5d47197c8977e2e6fcd73d51dfa5f550
Author: Dany De Bontridder <address@hidden>
Date: Mon Jan 25 23:10:11 2016 +0100
Compute the height of a MultiCell and check is a page must be
added
---
include/lib/class_pdf.php | 50 ++++++++++++++++++++++++++++++++++++++++----
1 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/include/lib/class_pdf.php b/include/lib/class_pdf.php
index f3bd6bd..503ab1d 100644
--- a/include/lib/class_pdf.php
+++ b/include/lib/class_pdf.php
@@ -105,6 +105,45 @@ class PDF extends TFPDF
// Created by NOALYSS
parent::Cell(0,8,'Created by NOALYSS, online on
http://www.noalyss.eu',0,0,'C',false,'http://www.noalyss.eu');
}
+ /**
+ * Count the number of rows a p_text will take for a multicell
+ * @param $p_text String
+ * @param $p_colSize size of the column in User Unit
+ */
+ private function count_nb_row($p_text,$p_colSize)
+ {
+ // If colSize is bigger than the size of the string then it takes 1
line
+ if ( $this->GetStringWidth($p_text) <= $p_colSize) return 1;
+ $nRow=0;
+ $aWords=explode(' ',$p_text);
+ $nb_words=count($aWords);
+ $string="";
+
+ for ($i=0;$i < $nb_words;$i++){
+ // Concatenate String with current word + a space
+ $string.=$aWords[$i];
+
+ // if there is a word after add a space
+ if ( $i+1 < $nb_words) $string.=" ";
+
+ // Compute new size and compare to the colSize
+ if ( $this->GetStringWidth($string) >= $p_colSize) {
+ // If the size of the string if bigger than we add a row, the
current
+ // word is the first word of the next line
+ $nRow++;
+ $string=$aWords[$i];
+ }
+ }
+ $nRow++;
+ return $nRow;
+
+
+
+ }
+ /**
+ * Check if a page must be added due a MultiCell
+ * @return boolean
+ */
private function check_page_add()
{
// break on page
@@ -119,13 +158,14 @@ class PDF extends TFPDF
* faire un saut de page (renvoit true) si dépasse
*/
$y=$this->GetY();
-
+ $nb_row=$this->count_nb_row($this->cells[$i]->text,
$this->cells[$i]->width);
+ $height=$this->cells[$i]->height*$nb_row;
$sizetext=$this->GetStringWidth($this->cells[$i]->text);
- $this->cells[$i]->text .= sprintf("size : %d",$sizetext);
- $this->cells[$i]->text .= sprintf("cellwidth:
%d",$this->cells[$i]->width);
- $this->cells[$i]->text .= sprintf("cellheigth:
%d",$this->cells[$i]->height);
+
+ // If the text is bigger than a sheet of paper then return
false
+ if ($height >= $this->h) return false;
- if ( $y > ($this->h - $this->bMargin-20))
+ if ( $y + $height > ($this->h - $this->bMargin-20))
return true;
}
}
- [Noalyss-commit] [noalyss] branch master updated (8f47684 -> 01d9cf0), Dany De Bontridder, 2016/01/25
- [Noalyss-commit] [noalyss] 05/12: Update comment for belong_ledger, Dany De Bontridder, 2016/01/25
- [Noalyss-commit] [noalyss] 01/12: Problem read README.export-PDF, Dany De Bontridder, 2016/01/25
- [Noalyss-commit] [noalyss] 07/12: Debugging info to remove, Dany De Bontridder, 2016/01/25
- [Noalyss-commit] [noalyss] 03/12: Task #3 - Problem avec export PDF depuis COMPTA/PRINT/PRINTJRN Cannot remove a shared note, Dany De Bontridder, 2016/01/25
- [Noalyss-commit] [noalyss] 04/12: #1251 : impression PDF Les Headers et Footer ne doivent pas utiliser write_celle et ln, Dany De Bontridder, 2016/01/25
- [Noalyss-commit] [noalyss] 10/12: Compute the height of a MultiCell and check is a page must be added,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 06/12: Update unit-test to new structure, Dany De Bontridder, 2016/01/25
- [Noalyss-commit] [noalyss] 12/12: Merge branch 'rel6912-export-pdf', Dany De Bontridder, 2016/01/25
- [Noalyss-commit] [noalyss] 11/12: Fix problem with PDF and the empty page due a wrong page break, Dany De Bontridder, 2016/01/25
- [Noalyss-commit] [noalyss] 02/12: #1251 impression PDF Remove function Cell that fct cannot be overloaded Change Cell by write_cell change ln by print_row, Dany De Bontridder, 2016/01/25
- [Noalyss-commit] [noalyss] 09/12: HTML doc, Dany De Bontridder, 2016/01/25
- [Noalyss-commit] [noalyss] 08/12: update doc, Dany De Bontridder, 2016/01/25