Skip to content

Commit

Permalink
tesseractmain: Show error message when output file could not be created
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Oct 18, 2018
1 parent b0b8dfb commit 49d7df6
Showing 1 changed file with 51 additions and 10 deletions.
61 changes: 51 additions & 10 deletions src/api/tesseractmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "config_auto.h"
#endif

#include <cerrno> // for errno
#include <iostream>

#include "allheaders.h"
Expand All @@ -33,7 +34,7 @@
#include "renderer.h"
#include "simddetect.h"
#include "strngs.h"
#include "tprintf.h"
#include "tprintf.h" // for tprintf

#if defined(_WIN32)
#include <fcntl.h>
Expand Down Expand Up @@ -407,16 +408,28 @@ static void PreloadRenderers(
if (b) {
bool font_info;
api->GetBoolVariable("hocr_font_info", &font_info);
renderers->push_back(
new tesseract::TessHOcrRenderer(outputbase, font_info));
tesseract::TessHOcrRenderer* renderer =
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);
if (b) {
bool font_info;
api->GetBoolVariable("hocr_font_info", &font_info);
renderers->push_back(
new tesseract::TessTsvRenderer(outputbase, font_info));
tesseract::TessTsvRenderer* renderer =
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);
Expand All @@ -427,23 +440,51 @@ static void PreloadRenderers(
#endif // WIN32
bool textonly;
api->GetBoolVariable("textonly_pdf", &textonly);
renderers->push_back(new tesseract::TessPDFRenderer(
outputbase, api->GetDatapath(), textonly));
tesseract::TessPDFRenderer* renderer =
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);
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);
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);
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));
}
}
}

Expand Down

0 comments on commit 49d7df6

Please sign in to comment.