gImageReader icon indicating copy to clipboard operation
gImageReader copied to clipboard

Addition of a warning if a font cannot be found in the QFontDatabase.

Open edward-dauvergne opened this issue 2 years ago • 2 comments
trafficstars

After some debugging due to a number of Linux font issues, I think I have worked out why gImageReader has not been outputting PDFs as I expected - it silently reverts back to the default font if a word element's font cannot be found. Would it be possible to warn about this? For example with something like:

index d8277ccc..b2c1b5ca 100644
--- a/qt/src/hocr/HOCRPdfExporter.cc
+++ b/qt/src/hocr/HOCRPdfExporter.cc
@@ -562,6 +562,7 @@ PoDoFo::PdfFont* HOCRPoDoFoPdfPrinter::getFont(QString family, bool bold, bool i
        if(it == m_fontCache.end()) {
                if(family.isEmpty() || !m_fontDatabase.hasFamily(family)) {
                        family = m_defaultFontFamily;
+            QMessageBox::warning(MAIN, _("Missing Font"), _("WARNING: Cannot find the font '%1' in the QFontDatabase, switching to the font '%2'.").arg(key).arg(family));
                }
                PoDoFo::PdfFont* font = nullptr;
                try {

This doesn't work, probably as the parent should be HOCRPdfExporter rather than MAIN, but it makes it crystal clear why the PDF output is not what you see in the GUI.

Cheers,

Edward

edward-dauvergne avatar May 15 '23 19:05 edward-dauvergne

Might make sense to collect all the missing fonts and then display a final warning after the export, rather than risking many popups appearing during the export.

manisandro avatar May 26 '23 21:05 manisandro

Is there a global data structure for storing this info? I haven't looked too deeply into the code yet. There are a number of font failures that would be useful to report back to the user, so they know that a better result can be obtained by switching away from the failing fonts. I could try coding something in a few weeks.

edward-dauvergne avatar May 27 '23 07:05 edward-dauvergne