manisandro / gImageReader

A Gtk/Qt front-end to tesseract-ocr.
GNU General Public License v3.0
1.57k stars 187 forks source link

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

Open edward-dauvergne opened 1 year ago

edward-dauvergne commented 1 year ago

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

manisandro commented 1 year ago

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.

edward-dauvergne commented 1 year ago

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.