[Patch] Printing of HTML message parts



Hi all,

printing of HTML message parts is a feature missing in Balsa, and some users complained about it.  The 
problem is that Webkit supports printing, but not “embedded” into the email structure.  As a workaround, 
Balsa supports printing the html part /only/ (right-click on the html view), but this lacks the headers and 
other parts in the result.

Attached is a proposal for solving the issue.  The basic idea is to let Webkit render the HTML content into a 
Cairo (image, pixel) surface, and then print the surface pretty much like an image, if necessary split over 
multiple pages.

The patch uses a resolution of approximately 200 dpi (as it is not easy to control the output width Webkit 
uses when rendering to an offline window) and a zoom factor of 2 which for me gives a “usable” output.  It is 
not vector graphics, so the quality is somewhat limited, but IMHO should be sufficient.  Maybe we should make 
the dpi and zoom factor setting configurable.

An other problem may occur when longer HTML parts are distributed over multiple pages: a line of text may be 
split into two halves, as the splitter of course has no idea about the content.  A solution might be adding a 
little overlap (maybe 2-3mm), i.e. if the last line one one page is intersected, if will (hopefully) be 
complete on top of the next page.

The print dialogue has two new options: whether text/plain shall be preferred over text/html or not, and 
whether external images shall be loaded for printing.  Note that these two options are “volatile” – the 
former is initialised from the same display option, and the latter is always off as default for privacy 
reasons.  Related to this, I took the opportunity to clean printing multipart/alternative parts by printing 
only the selected version.

As always, any comment is welcome!

Cheers,
Albrecht.

---
Patch details:
- libbalsa/html.[ch]: implement function for rendering to a Cairo surface; refactor for extracting common code
- src/balsa-print-object-html.[ch]: implement printing the HTML Cairo surface (new module)
- src/Makefile.am, src/meson.build: add new module
- src/balsa-print-object.c: use the new module for HTML (falls back to default if built w/o HTML support)
- src/balsa-print-object.h: add the “volatile” HTML printing options to BalsaPrintSetup
- src/print-gtk.c: refactor print dialogue to use GtkGrid; add new options; add function for selecting the 
proper part from multipart/alternative

All touched files: update Copyright date to 2019

Attachment: html-printing.diff.bz2
Description: application/bzip

Attachment: pgpEBUrHqOpwp.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]