Skip to content

Commit eb69dd0

Browse files
committed
TessPDFRenderer: Improve robustness of API (issue #1804)
Signed-off-by: Stefan Weil <[email protected]>
1 parent 9ce4d05 commit eb69dd0

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/api/pdfrenderer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ static const int kMaxBytesPerCodepoint = 20;
182182

183183
TessPDFRenderer::TessPDFRenderer(const char *outputbase, const char *datadir,
184184
bool textonly)
185-
: TessResultRenderer(outputbase, "pdf") {
185+
: TessResultRenderer(outputbase, "pdf"),
186+
datadir_(datadir) {
186187
obj_ = 0;
187-
datadir_ = datadir;
188188
textonly_ = textonly;
189189
offsets_.push_back(0);
190190
}
@@ -654,7 +654,7 @@ bool TessPDFRenderer::BeginDocumentHandler() {
654654
if (n >= sizeof(buf)) return false;
655655
AppendPDFObject(buf);
656656

657-
n = snprintf(buf, sizeof(buf), "%s/pdf.ttf", datadir_);
657+
n = snprintf(buf, sizeof(buf), "%s/pdf.ttf", datadir_.c_str());
658658
if (n >= sizeof(buf)) return false;
659659
FILE *fp = fopen(buf, "rb");
660660
if (!fp) {

src/api/renderer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// To avoid collision with other typenames include the ABSOLUTE MINIMUM
2222
// complexity of includes here. Use forward declarations wherever possible
2323
// and hide includes of complex types in baseapi.cpp.
24+
#include <string> // for std::string
2425
#include "genericvector.h"
2526
#include "platform.h"
2627

@@ -202,7 +203,7 @@ class TESS_API TessPDFRenderer : public TessResultRenderer {
202203
long int obj_; // counter for PDF objects
203204
GenericVector<long int> offsets_; // offset of every PDF object in bytes
204205
GenericVector<long int> pages_; // object number for every /Page object
205-
const char *datadir_; // where to find the custom font
206+
std::string datadir_; // where to find the custom font
206207
bool textonly_; // skip images if set
207208
// Bookkeeping only. DIY = Do It Yourself.
208209
void AppendPDFObjectDIY(size_t objectsize);

0 commit comments

Comments
 (0)