From c516421bc2ba8bcd70e1ac3e7173f3e9524ecb24 Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Fri, 21 Aug 2015 11:02:10 +0200 Subject: Printing: check the print type in the preview section Preview output should be identical to the actual printing code, so call the flow rendering method for all flow templates. Also don't create new pages while rendering a one page preview, just exit after the first page is full. Signed-off-by: Lubomir I. Ivanov Signed-off-by: Gehad elrobey --- printer.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'printer.cpp') diff --git a/printer.cpp b/printer.cpp index b4d937094..66fed7cf3 100644 --- a/printer.cpp +++ b/printer.cpp @@ -95,7 +95,14 @@ void Printer::flowRender() // rendering progress is 4/5 of total work emit(progessUpdated((end * 80.0 / fullPageResolution) + done)); - static_cast(paintDevice)->newPage(); + + // add new pages only in print mode, while previewing we don't add new pages + if (printMode == Printer::PRINT) + static_cast(paintDevice)->newPage(); + else { + painter.end(); + return; + } start = dontbreakElement.geometry().y(); } } @@ -297,7 +304,16 @@ void Printer::previewOnePage() templateOptions->border_width = std::max(1, pageSize.width() / 1000); webView->setHtml(t.generate()); - // render only one page - render(1); + bool ok; + int divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok); + if (!ok) { + divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed + //TODO: show warning + } + if (divesPerPage == 0) { + flowRender(); + } else { + render(1); + } } } -- cgit v1.2.3-70-g09d2