From eb69dd02010a6e02f75549dca009e9b0c489e46d Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Wed, 1 Aug 2018 09:11:04 +0200 Subject: [PATCH] TessPDFRenderer: Improve robustness of API (issue #1804) Signed-off-by: Stefan Weil --- src/api/pdfrenderer.cpp | 6 +++--- src/api/renderer.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/api/pdfrenderer.cpp b/src/api/pdfrenderer.cpp index 20abf9b7..0ddcd306 100644 --- a/src/api/pdfrenderer.cpp +++ b/src/api/pdfrenderer.cpp @@ -182,9 +182,9 @@ static const int kMaxBytesPerCodepoint = 20; TessPDFRenderer::TessPDFRenderer(const char *outputbase, const char *datadir, bool textonly) - : TessResultRenderer(outputbase, "pdf") { + : TessResultRenderer(outputbase, "pdf"), + datadir_(datadir) { obj_ = 0; - datadir_ = datadir; textonly_ = textonly; offsets_.push_back(0); } @@ -654,7 +654,7 @@ bool TessPDFRenderer::BeginDocumentHandler() { if (n >= sizeof(buf)) return false; AppendPDFObject(buf); - n = snprintf(buf, sizeof(buf), "%s/pdf.ttf", datadir_); + n = snprintf(buf, sizeof(buf), "%s/pdf.ttf", datadir_.c_str()); if (n >= sizeof(buf)) return false; FILE *fp = fopen(buf, "rb"); if (!fp) { diff --git a/src/api/renderer.h b/src/api/renderer.h index 30da61d2..0a723176 100644 --- a/src/api/renderer.h +++ b/src/api/renderer.h @@ -21,6 +21,7 @@ // To avoid collision with other typenames include the ABSOLUTE MINIMUM // complexity of includes here. Use forward declarations wherever possible // and hide includes of complex types in baseapi.cpp. +#include // for std::string #include "genericvector.h" #include "platform.h" @@ -202,7 +203,7 @@ class TESS_API TessPDFRenderer : public TessResultRenderer { long int obj_; // counter for PDF objects GenericVector offsets_; // offset of every PDF object in bytes GenericVector pages_; // object number for every /Page object - const char *datadir_; // where to find the custom font + std::string datadir_; // where to find the custom font bool textonly_; // skip images if set // Bookkeeping only. DIY = Do It Yourself. void AppendPDFObjectDIY(size_t objectsize);