[PATCH 2/3] Print: add a safe guard for row heights in the table print

Lubomir I. Ivanov neolit123 at gmail.com
Tue Aug 5 10:34:41 PDT 2014


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

If a row height is more than the available height on a page
(minus the height of a heading row) we have to skip this row (dive).
The current profile print simply does not support that and it does
not make much sense. For that to happen either the page will have
to be tiny or the user must have entered a very long text for "buddy",
"dive master", "location" or there must be some sort of a
very-large-font-while-printing type of a problem.

Technically, rows spanning on multiple pages is doable, but probably
not worth the effort.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
 qt-ui/printlayout.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp
index 899aa15..6fe4102 100644
--- a/qt-ui/printlayout.cpp
+++ b/qt-ui/printlayout.cpp
@@ -375,7 +375,7 @@ void PrintLayout::printTable()
 	 * use 10% each, then the sum of passes[] here should be 80%.
 	 * two should be enough! */
 	const int passes[] = { 70, 10 };
-	int tableHeight = 0, lastAccIndex = 0, rowH, accH, headings, headingRowHeightD2;
+	int tableHeight = 0, lastAccIndex = 0, rowH, accH, headings, headingRowHeightD2, headingRowHeight;
 	bool isHeading = false;
 
 	for (unsigned int pass = 0; pass < sizeof(passes) / sizeof(passes[0]); pass++) {
@@ -383,12 +383,14 @@ void PrintLayout::printTable()
 		total = model.rows - lastAccIndex;
 		for (i = lastAccIndex; i < model.rows; i++) {
 			rowH = table.rowHeight(i);
-			 // skip huge rows. we don't support row spanning on multiple pages.
-			if (rowH >= pageH)
+			if (i == 0) { // first row is always a heading. it's height is constant.
+				headingRowHeight = rowH;
+				headingRowHeightD2 = rowH / 2;
+			}
+			if (rowH > pageH - headingRowHeight) // skip huge rows. we don't support row spanning on multiple pages.
 				continue;
 			accH += rowH;
 			if (isHeading) {
-				headingRowHeightD2 = rowH >> 1;
 				headings += rowH;
 				isHeading = false;
 			}
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list