diff --git a/Documentation/images/PrintDiveLog.jpg b/Documentation/images/PrintDiveLog.jpg
index 7a485c4ff..8ff972dd7 100644
Binary files a/Documentation/images/PrintDiveLog.jpg and b/Documentation/images/PrintDiveLog.jpg differ
diff --git a/Documentation/images/Printpreview.jpg b/Documentation/images/Printpreview.jpg
index ab5db7fa5..7297d80cc 100644
Binary files a/Documentation/images/Printpreview.jpg and b/Documentation/images/Printpreview.jpg differ
diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt
index 815bb9b2a..943d2268d 100644
--- a/Documentation/user-manual.txt
+++ b/Documentation/user-manual.txt
@@ -2711,8 +2711,9 @@ process could be used for the Cloud-based storage of dive logs.
[[S_PrintDivelog]]
== Printing a dive log
-_Subsurface_ provides a simple interface to print a whole dive log or only a
-few selected dives, including dive profiles and other contextual information.
+_Subsurface_ provides a simple interface to print a whole dive log or only a few selected dives.
+ Pre-installed templates or a custom written template can be used to choose where the data will
+ be fitted into the page.
Before printing, two decisions are required:
@@ -2727,15 +2728,10 @@ below).
image::images/PrintDiveLog.jpg["FIGURE: Print dialogue",align="center"]
-Under _Print type_ users need to select one of three options:
+Under _Print type_ users need to select one of two options:
-- Print the complete Dive List: to do this, _Table Print_ should be selected.
-- Print the selected dives (dive profiles and all other information) at 6
- dives per printed page: to do this, users should select _6 dives per page_.
-- Print the selected dives (dive profiles and all other information) at 2
- dives per printed page: to do this, users should select _2 dives per page_.
-- Print the selected dives (dive profiles and all other information) at 1
- dive per printed page: to do this, users should select _1 dive per page_.
+- _Dive list_ print: print dives from the list with profiles and other information.
+- _Statistics_ print: print yearly statistics of the dives.
Under _Print options_ users need to select:
@@ -2744,12 +2740,20 @@ Under _Print options_ users need to select:
selected dives_.
- Printing in colour, achieved by checking the box with _Print in colour_.
-The _Ordering_ affects the layout of the page (or part of it) for each dive.
-The dive profile could be printed at the top of each dive, with the textual
-information underneath, or it could be printed with the textual information at
-the top with the dive profile underneath. Users should select the appropriate option in the
-print dialogue. See the image below which has a layout with
-text below the dive profile.
+Under _Template_ users can select:
+
+- A template to be used as the page layout.
+
+- _Delete_ a template from the template list
+- _Import_ a new template to the template list
+- _Export_ a template from the template list
+- _Edit_ a template (choose colors, fonts, font-type)
+
+When editing a template the following options are available:
+
+- _Style_: edit font type, size, choose color palette; this will not affect the template HTML code
+- _Template_: edit the template HTML code; by saving, the "Custom" template in the template list will be replaced
+- _Colors_: edit the current color palette; the new color palette will overwrite the "Custom" color palette
Users can _Preview_ the printed page by selecting the _Preview_ button on the
dialogue. After preview, changes to the options in the print dialogue can be
@@ -2767,6 +2771,11 @@ the output for one particular page.
image::images/Printpreview.jpg["FIGURE: Print preview page",align="center"]
+=== Write a custom printing template (advanced)
+
+Writing a custom template is an effective way to produce highly customized printouts. Subsurface uses HTML templates with Grantlee as the printing backend.
+
+See <<_appendix_f_write_a_custom_printing_template ,APPENDIX F>> for information on how to write your own template.
[[S_Configure]]
== Configuring a dive computer
@@ -4137,3 +4146,134 @@ If you have downloaded your dives to different dive logging software
before they were overwritten, there is a high change that Subsurface can
import these. However, if the logs are only on your dive computer, they
cannot be salvaged after being over written by new dives.
+
+== APPENDIX F: Write a custom printing template
+
+_Subsurface_ provides a customizable printing support which is based on templates that are transformed by the _Grantlee_
+backend to correct _HTML_ syntax, The _HTML_ output is then rendered by _Subsurface_.
+
+To write a custom template the following elements must exist so that the template will be correctly handled and rendered.
+
+=== Main dive loop
+_Subsurface_ exports a dive list called (*dives*) to the _Grantlee_ backend. It is possible to iterate over the list as follows:
+
+.template.html
+....
+ {% for dive in dives %}
+
{{ dive.number }}
+ {% endfor %}
+....
+
+.output.html
+....
+ 1
+ 2
+ 3
+....
+
+Additional information about _Grantlee_ can be found http://www.grantlee.org/apidox/for_themers.html[here]
+
+=== Grantlee exported variables
+Only a subset of the dive data is exported:
+|====================
+|*Name*|*Description*
+|number| (*int*) dive number
+|id| (*int*) unique dive ID, should be used to fetch the dive profile
+|date| (*string*) data of the dive
+|time| (*string*) time of the dive
+|location| (*string*) location of the dive
+|duration| (*string*) duration of the dive
+|depth| (*string*) depth of the dive
+|divemaster| (*string*) divemaster data
+|buddy| (*string*) buddy data
+|airTemp| (*string*) air temperature of dive
+|waterTemp| (*string*) water temperature of dive
+|notes| (*string*) dive notes
+|rating| (*int*) dive rating ranges from 0 to 5
+|sac| (*string*) sac value
+|tags| (*string*) all dive tags concatenate together
+|gas| (*string*) used gas cylinder
+|=====================
+
+_Subsurface_ also exports *template_options* data. This data must be used as _CSS_ values to provide a dynamically
+editable template. The exported data is shown in the following table:
+|====================
+|*Name*|*Description*
+|font| (*string*) font family
+|borderwidth| (*int*) border-width value dynamically calculated as 0.1% of the page width with minimum value of 1px
+|font_size| (*double*) size of fonts in vw, ranges between 1.0 and 2.0
+|line_spacing| (*double*) distance between text lines, ranges between 1.0 and 3.0
+|color1| (*string*) background color
+|color2| (*string*) primary table cell color
+|color3| (*string*) secondary table cell color
+|color4| (*string*) primary text color
+|color5| (*string*) secondary text color
+|color6| (*string*) border colors
+|=====================
+
+.template.html
+....
+ border-width: {{ template_options.borderwidth }}px;
+....
+
+.output.html
+....
+ border-width: 3px;
+....
+
+Another variable that _Subsurface_ exports is *print_options*. This variable contains a single member:
+|=====================
+|*Name*|*Description*
+|grayscale | Use _CSS_ filters to convert the page into grayscale (should be added to body style to enable printing grayscale prints)
+|=====================
+
+
+.template.html
+....
+ body {
+ {{ print_options.grayscale }};
+ }
+....
+
+.output.html
+....
+ body {
+ -webkit-filter: grayscale(100%);
+ }
+....
+
+=== Defined CSS selectors
+
+As the dive profile is placed after rendering, _Subsurface_ uses a special _CSS_ selectors to do some searches
+in the HTML output. The _CSS_ selectors in the following table should be added.
+
+|====================
+|*Selector*|*Type*|*Description*
+|dive_{{ dive.id }} | id | is used to fetch the relevant dive profile
+|diveProfile | class | each div that will contain a dive profile should have this class selector in addition to the dive_{{ dive.id }} id selector
+|dontbreak | class | prevents the div with this class to be divided into two pages, this can be used
+in flow layout templates only (when data-numberofdives = 0)
+|=====================
+
+IMPORTANT: Rendering dive profiles is not supported for flow layout templates (when data-numberofdives = 0).
+
+=== Special attributes
+
+There are two ways of rendering- either rendering a specific number of dives in each page or make _Subsurface_ try to
+fit as much dives as possible into one page (_flow_ rendering).
+
+The *data-numberofdives* data attribute is added to the body tag to set the rendering mode
+
+- render 6 dives per page:
+
+....
+
+....
+
+- render as much dives as possible:
+
+....
+
+....
+
+IMPORTANT: All CSS units should be in relative lengths only, to support printing on any page size.
diff --git a/printer.cpp b/printer.cpp
index b0caa0815..f0197d446 100644
--- a/printer.cpp
+++ b/printer.cpp
@@ -59,6 +59,11 @@ void Printer::putProfileImage(QRect profilePlaceholder, QRect viewPort, QPainter
void Printer::flowRender()
{
+ // add extra padding at the bottom to pages with height not divisible by view port
+ int paddingBottom = pageSize.height() - (webView->page()->mainFrame()->contentsSize().height() % pageSize.height());
+ QString styleString = QString::fromUtf8("padding-bottom: ") + QString::number(paddingBottom) + "px;";
+ webView->page()->mainFrame()->findFirstElement("body").setAttribute("style", styleString);
+
// render the Qwebview
QPainter painter;
QRect viewPort(0, 0, 0, 0);
@@ -90,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();
}
}
@@ -187,6 +199,7 @@ void Printer::print()
return;
}
+
QPrinter *printerPtr;
printerPtr = static_cast(paintDevice);
@@ -194,18 +207,17 @@ void Printer::print()
connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
dpi = printerPtr->resolution();
//rendering resolution = selected paper size in inchs * printer dpi
-#if QT_VERSION >= 0x050300
- pageSize.setHeight(printerPtr->pageLayout().paintRectPixels(dpi).height());
- pageSize.setWidth(printerPtr->pageLayout().paintRectPixels(dpi).width());
-#else
- pageSize.setHeight(printerPtr->pageRect(QPrinter::Inch).height() * dpi);
- pageSize.setWidth(printerPtr->pageRect(QPrinter::Inch).width() * dpi);
-#endif
+ pageSize.setHeight(qCeil(printerPtr->pageRect(QPrinter::Inch).height() * dpi));
+ pageSize.setWidth(qCeil(printerPtr->pageRect(QPrinter::Inch).width() * dpi));
webView->page()->setViewportSize(pageSize);
webView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
// export border width with at least 1 pixel
templateOptions->border_width = std::max(1, pageSize.width() / 1000);
- webView->setHtml(t.generate());
+ if (printOptions->type == print_options::DIVELIST) {
+ webView->setHtml(t.generate());
+ } else if (printOptions->type == print_options::STATISTICS ) {
+ webView->setHtml(t.generateStatistics());
+ }
if (printOptions->color_selected && printerPtr->colorMode()) {
printerPtr->setColorMode(QPrinter::Color);
} else {
@@ -223,71 +235,13 @@ void Printer::print()
}
int Pages;
if (divesPerPage == 0) {
- // add extra padding at the bottom to pages with height not divisible by view port
- int paddingBottom = pageSize.height() - (webView->page()->mainFrame()->contentsSize().height() % pageSize.height());
- QString styleString = QString::fromUtf8("padding-bottom: ") + QString::number(paddingBottom) + "px;";
- webView->page()->mainFrame()->findFirstElement("body").setAttribute("style", styleString);
flowRender();
} else {
- Pages = ceil(getTotalWork(printOptions) / (float)divesPerPage);
+ Pages = qCeil(getTotalWork(printOptions) / (float)divesPerPage);
render(Pages);
}
}
-void Printer::print_statistics()
-{
- QPrinter *printerPtr;
- printerPtr = static_cast(paintDevice);
- stats_t total_stats;
-
- total_stats.selection_size = 0;
- total_stats.total_time.seconds = 0;
-
- QString html;
- html += "";
- html += "";
- html += "| Year | ";
- html += "Dives | ";
- html += "Total Time | ";
- html += "Avg Time | ";
- html += "Shortest Time | ";
- html += "Longest Time | ";
- html += "Avg Depth | ";
- html += "Min Depth | ";
- html += "Max Depth | ";
- html += "Avg SAC | ";
- html += "Min SAC | ";
- html += "Max SAC | ";
- html += "Min Temp | ";
- html += "Max Temp | ";
- html += "
";
- int i = 0;
- while (stats_yearly != NULL && stats_yearly[i].period) {
- html += "";
- html += "| " + QString::number(stats_yearly[i].period) + " | ";
- html += "" + QString::number(stats_yearly[i].selection_size) + " | ";
- html += "" + QString::fromUtf8(get_time_string(stats_yearly[i].total_time.seconds, 0)) + " | ";
- html += "" + QString::fromUtf8(get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size)) + " | ";
- html += "" + QString::fromUtf8(get_minutes(stats_yearly[i].shortest_time.seconds)) + " | ";
- html += "" + QString::fromUtf8(get_minutes(stats_yearly[i].longest_time.seconds)) + " | ";
- html += "" + get_depth_string(stats_yearly[i].avg_depth) + " | ";
- html += "" + get_depth_string(stats_yearly[i].min_depth) + " | ";
- html += "" + get_depth_string(stats_yearly[i].max_depth) + " | ";
- html += "" + get_volume_string(stats_yearly[i].avg_sac) + " | ";
- html += "" + get_volume_string(stats_yearly[i].min_sac) + " | ";
- html += "" + get_volume_string(stats_yearly[i].max_sac) + " | ";
- html += "" + QString::number(stats_yearly[i].min_temp == 0 ? 0 : get_temp_units(stats_yearly[i].min_temp, NULL)) + " | ";
- html += "" + QString::number(stats_yearly[i].max_temp == 0 ? 0 : get_temp_units(stats_yearly[i].max_temp, NULL)) + " | ";
- html += "
";
- total_stats.selection_size += stats_yearly[i].selection_size;
- total_stats.total_time.seconds += stats_yearly[i].total_time.seconds;
- i++;
- }
- html += "
";
- webView->setHtml(html);
- webView->print(printerPtr);
-}
-
void Printer::previewOnePage()
{
if (printMode == PREVIEW) {
@@ -296,9 +250,24 @@ void Printer::previewOnePage()
pageSize.setHeight(paintDevice->height());
pageSize.setWidth(paintDevice->width());
webView->page()->setViewportSize(pageSize);
- webView->setHtml(t.generate());
+ // initialize the border settings
+ templateOptions->border_width = std::max(1, pageSize.width() / 1000);
+ if (printOptions->type == print_options::DIVELIST) {
+ webView->setHtml(t.generate());
+ } else if (printOptions->type == print_options::STATISTICS ) {
+ webView->setHtml(t.generateStatistics());
+ }
- // 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);
+ }
}
}
diff --git a/printer.h b/printer.h
index 5c7652a8d..979cacd6a 100644
--- a/printer.h
+++ b/printer.h
@@ -39,7 +39,6 @@ public:
Printer(QPaintDevice *paintDevice, print_options *printOptions, template_options *templateOptions, PrintMode printMode);
~Printer();
void print();
- void print_statistics();
void previewOnePage();
signals:
diff --git a/printing_templates/Six Dives.html b/printing_templates/Six Dives.html
index 3f2c7b95e..9d4d1341e 100644
--- a/printing_templates/Six Dives.html
+++ b/printing_templates/Six Dives.html
@@ -40,11 +40,11 @@
.mainContainer {
width: 50%;
- height: 33.333333%;
+ height: 33.333%;
margin-left: 0%;
margin-right: 0%;
- margin-top: 0;
- margin-bottom: 0;
+ margin-top: 0%;
+ margin-bottom: 0%;
overflow: hidden;
page-break-inside: avoid;
float: left;
@@ -111,12 +111,20 @@
text-overflow: ellipsis;
line-height: {{ template_options.line_spacing }};
}
+
+ #sixdivespack {
+ width: 100%;
+ height: 100%;
+ }
{% block main_rows %}
{% for dive in dives %}
+ {% if forloop.counter|divisibleby:6 %}
+
+ {% endif %}
+ {% if forloop.counter|divisibleby:6 %}
+
+ {% endif %}
{% endfor %}
{% endblock %}