Merge pull request #2002 from stweil/err

Show error message when output file could not be created
This commit is contained in:
zdenop 2018-10-18 19:27:01 +02:00 committed by GitHub
commit bbe7a4cc10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 10 deletions

View File

@ -80,6 +80,9 @@ class TESS_API TessResultRenderer {
const char* file_extension() const { return file_extension_; } const char* file_extension() const { return file_extension_; }
const char* title() const { return title_.c_str(); } const char* title() const { return title_.c_str(); }
// Is everything fine? Otherwise something went wrong.
bool happy() { return happy_; }
/** /**
* Returns the index of the last image given to AddImage * Returns the index of the last image given to AddImage
* (i.e. images are incremented whether the image succeeded or not) * (i.e. images are incremented whether the image succeeded or not)

View File

@ -22,6 +22,7 @@
#include "config_auto.h" #include "config_auto.h"
#endif #endif
#include <cerrno> // for errno
#include <iostream> #include <iostream>
#include "allheaders.h" #include "allheaders.h"
@ -33,7 +34,7 @@
#include "renderer.h" #include "renderer.h"
#include "simddetect.h" #include "simddetect.h"
#include "strngs.h" #include "strngs.h"
#include "tprintf.h" #include "tprintf.h" // for tprintf
#if defined(_WIN32) #if defined(_WIN32)
#include <fcntl.h> #include <fcntl.h>
@ -407,16 +408,28 @@ static void PreloadRenderers(
if (b) { if (b) {
bool font_info; bool font_info;
api->GetBoolVariable("hocr_font_info", &font_info); api->GetBoolVariable("hocr_font_info", &font_info);
renderers->push_back( tesseract::TessHOcrRenderer* renderer =
new tesseract::TessHOcrRenderer(outputbase, font_info)); new tesseract::TessHOcrRenderer(outputbase, font_info);
if (renderer->happy()) {
renderers->push_back(renderer);
} else {
tprintf("Error, could not create hOCR output file: %s\n",
strerror(errno));
}
} }
api->GetBoolVariable("tessedit_create_tsv", &b); api->GetBoolVariable("tessedit_create_tsv", &b);
if (b) { if (b) {
bool font_info; bool font_info;
api->GetBoolVariable("hocr_font_info", &font_info); api->GetBoolVariable("hocr_font_info", &font_info);
renderers->push_back( tesseract::TessTsvRenderer* renderer =
new tesseract::TessTsvRenderer(outputbase, font_info)); new tesseract::TessTsvRenderer(outputbase, font_info);
if (renderer->happy()) {
renderers->push_back(renderer);
} else {
tprintf("Error, could not create TSV output file: %s\n",
strerror(errno));
}
} }
api->GetBoolVariable("tessedit_create_pdf", &b); api->GetBoolVariable("tessedit_create_pdf", &b);
@ -427,23 +440,51 @@ static void PreloadRenderers(
#endif // WIN32 #endif // WIN32
bool textonly; bool textonly;
api->GetBoolVariable("textonly_pdf", &textonly); api->GetBoolVariable("textonly_pdf", &textonly);
renderers->push_back(new tesseract::TessPDFRenderer( tesseract::TessPDFRenderer* renderer =
outputbase, api->GetDatapath(), textonly)); new tesseract::TessPDFRenderer(outputbase, api->GetDatapath(),
textonly);
if (renderer->happy()) {
renderers->push_back(renderer);
} else {
tprintf("Error, could not create PDF output file: %s\n",
strerror(errno));
}
} }
api->GetBoolVariable("tessedit_write_unlv", &b); api->GetBoolVariable("tessedit_write_unlv", &b);
if (b) { if (b) {
renderers->push_back(new tesseract::TessUnlvRenderer(outputbase)); tesseract::TessUnlvRenderer* renderer =
new tesseract::TessUnlvRenderer(outputbase);
if (renderer->happy()) {
renderers->push_back(renderer);
} else {
tprintf("Error, could not create UNLV output file: %s\n",
strerror(errno));
}
} }
api->GetBoolVariable("tessedit_create_boxfile", &b); api->GetBoolVariable("tessedit_create_boxfile", &b);
if (b) { if (b) {
renderers->push_back(new tesseract::TessBoxTextRenderer(outputbase)); tesseract::TessBoxTextRenderer* renderer =
new tesseract::TessBoxTextRenderer(outputbase);
if (renderer->happy()) {
renderers->push_back(renderer);
} else {
tprintf("Error, could not create BOX output file: %s\n",
strerror(errno));
}
} }
api->GetBoolVariable("tessedit_create_txt", &b); api->GetBoolVariable("tessedit_create_txt", &b);
if (b || renderers->empty()) { if (b || renderers->empty()) {
renderers->push_back(new tesseract::TessTextRenderer(outputbase)); tesseract::TessTextRenderer* renderer =
new tesseract::TessTextRenderer(outputbase);
if (renderer->happy()) {
renderers->push_back(renderer);
} else {
tprintf("Error, could not create TXT output file: %s\n",
strerror(errno));
}
} }
} }