From a8323f1c16ce0eb123f0ba85279a315354674ce4 Mon Sep 17 00:00:00 2001 From: Stephen Gaito Date: Fri, 13 Dec 2019 11:27:54 +0000 Subject: [PATCH] initial pass at updating pdf2htmlEX to use poppler-0.83.0 --- pdf2htmlEX/CMakeLists.txt | 6 ++++-- .../CairoBackgroundRenderer.cc | 2 +- .../BackgroundRenderer/CairoBackgroundRenderer.h | 2 +- .../SplashBackgroundRenderer.cc | 2 +- .../SplashBackgroundRenderer.h | 2 +- pdf2htmlEX/src/DrawingTracer.cc | 8 ++++---- pdf2htmlEX/src/DrawingTracer.h | 2 +- pdf2htmlEX/src/HTMLRenderer/HTMLRenderer.h | 4 +++- pdf2htmlEX/src/HTMLRenderer/font.cc | 3 ++- pdf2htmlEX/src/HTMLRenderer/image.cc | 4 +++- pdf2htmlEX/src/HTMLRenderer/text.cc | 2 +- pdf2htmlEX/src/Preprocessor.cc | 2 +- pdf2htmlEX/src/Preprocessor.h | 2 +- pdf2htmlEX/src/pdf2htmlEX.cc | 16 +++++++++++----- pdf2htmlEX/src/util/unicode.cc | 2 +- pdf2htmlEX/src/util/unicode.h | 2 +- 16 files changed, 37 insertions(+), 24 deletions(-) diff --git a/pdf2htmlEX/CMakeLists.txt b/pdf2htmlEX/CMakeLists.txt index 68d77c7..3f65ae7 100644 --- a/pdf2htmlEX/CMakeLists.txt +++ b/pdf2htmlEX/CMakeLists.txt @@ -82,9 +82,11 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Woverloaded-virtual") # CYGWIN or GCC 4.5.x bug if(CYGWIN) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x") +# was: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x") +# the following change is untested: +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14") else() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -pthread") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread") endif() # check the C++11 features we need diff --git a/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.cc b/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.cc index a7eaed8..ae5c809 100644 --- a/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.cc +++ b/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.cc @@ -46,7 +46,7 @@ CairoBackgroundRenderer::~CairoBackgroundRenderer() void CairoBackgroundRenderer::drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, - CharCode code, int nBytes, Unicode *u, int uLen) + CharCode code, int nBytes, const Unicode *u, int uLen) { // draw characters as image when // - in fallback mode diff --git a/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.h b/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.h index d5c8637..f8bbc07 100644 --- a/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.h +++ b/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.h @@ -42,7 +42,7 @@ public: virtual void drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, - CharCode code, int nBytes, Unicode *u, int uLen); + CharCode code, int nBytes, const Unicode *u, int uLen); //for proof void beginTextObject(GfxState *state); diff --git a/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.cc b/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.cc index be14222..757f0a1 100644 --- a/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.cc +++ b/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.cc @@ -65,7 +65,7 @@ void SplashBackgroundRenderer::startPage(int pageNum, GfxState *state, XRef *xre void SplashBackgroundRenderer::drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, - CharCode code, int nBytes, Unicode *u, int uLen) + CharCode code, int nBytes, const Unicode *u, int uLen) { if (param.proof || html_renderer->is_char_covered(drawn_char_count)) { SplashOutputDev::drawChar(state,x,y,dx,dy,originX,originY,code,nBytes,u,uLen); diff --git a/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.h b/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.h index 55baeb3..b8e07c0 100644 --- a/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.h +++ b/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.h @@ -44,7 +44,7 @@ public: virtual void drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, - CharCode code, int nBytes, Unicode *u, int uLen); + CharCode code, int nBytes, const Unicode *u, int uLen); //for proof void beginTextObject(GfxState *state); diff --git a/pdf2htmlEX/src/DrawingTracer.cc b/pdf2htmlEX/src/DrawingTracer.cc index 7086565..5d23d42 100644 --- a/pdf2htmlEX/src/DrawingTracer.cc +++ b/pdf2htmlEX/src/DrawingTracer.cc @@ -136,10 +136,10 @@ void DrawingTracer::restore() #endif } -void DrawingTracer::do_path(GfxState * state, GfxPath * path) +void DrawingTracer::do_path(GfxState * state, const GfxPath * path) { //copy from CairoOutputDev::doPath - GfxSubpath *subpath; + const GfxSubpath *subpath; int i, j; double x, y; cairo_new_path(cairo); @@ -220,9 +220,9 @@ void DrawingTracer::stroke(GfxState * state) break; } - GfxPath * path = state->getPath(); + const GfxPath * path = state->getPath(); for (int i = 0; i < path->getNumSubpaths(); ++i) { - GfxSubpath * subpath = path->getSubpath(i); + const GfxSubpath * subpath = path->getSubpath(i); if (subpath->getNumPoints() <= 0) continue; double x = subpath->getX(0); diff --git a/pdf2htmlEX/src/DrawingTracer.h b/pdf2htmlEX/src/DrawingTracer.h index 3a0bc88..0d186d0 100644 --- a/pdf2htmlEX/src/DrawingTracer.h +++ b/pdf2htmlEX/src/DrawingTracer.h @@ -65,7 +65,7 @@ public: private: void finish(); // Following methods operate in user space (just before CTM is applied) - void do_path(GfxState * state, GfxPath * path); + void do_path(GfxState * state, const GfxPath * path); void draw_non_char_bbox(GfxState * state, double * bbox, int what); void draw_char_bbox(GfxState * state, double * bbox, int inTransparencyGroup); // If cairo is available, parameter state is ignored diff --git a/pdf2htmlEX/src/HTMLRenderer/HTMLRenderer.h b/pdf2htmlEX/src/HTMLRenderer/HTMLRenderer.h index c71d282..6f2c24c 100644 --- a/pdf2htmlEX/src/HTMLRenderer/HTMLRenderer.h +++ b/pdf2htmlEX/src/HTMLRenderer/HTMLRenderer.h @@ -156,7 +156,9 @@ struct HTMLRenderer : OutputDev virtual void drawString(GfxState * state, const GooString * s); - virtual void drawImage(GfxState * state, Object * ref, Stream * str, int width, int height, GfxImageColorMap * colorMap, bool interpolate, int *maskColors, bool inlineImg); + virtual void drawImage(GfxState * state, Object * ref, Stream * str, + int width, int height, GfxImageColorMap * colorMap, + bool interpolate, const int *maskColors, bool inlineImg); virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, diff --git a/pdf2htmlEX/src/HTMLRenderer/font.cc b/pdf2htmlEX/src/HTMLRenderer/font.cc index 3392a9e..466f691 100644 --- a/pdf2htmlEX/src/HTMLRenderer/font.cc +++ b/pdf2htmlEX/src/HTMLRenderer/font.cc @@ -636,7 +636,8 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo if(mapped_code > max_key) max_key = mapped_code; - Unicode u, *pu=&u; + Unicode u; + Unicode const *pu=&u; if(info.use_tounicode) { int n = ctu ? diff --git a/pdf2htmlEX/src/HTMLRenderer/image.cc b/pdf2htmlEX/src/HTMLRenderer/image.cc index ef51ffc..b4d84cc 100644 --- a/pdf2htmlEX/src/HTMLRenderer/image.cc +++ b/pdf2htmlEX/src/HTMLRenderer/image.cc @@ -12,7 +12,9 @@ namespace pdf2htmlEX { -void HTMLRenderer::drawImage(GfxState * state, Object * ref, Stream * str, int width, int height, GfxImageColorMap * colorMap, bool interpolate, int *maskColors, bool inlineImg) +void HTMLRenderer::drawImage(GfxState * state, Object * ref, Stream * str, + int width, int height, GfxImageColorMap * colorMap, + bool interpolate, const int *maskColors, bool inlineImg) { tracer.draw_image(state); diff --git a/pdf2htmlEX/src/HTMLRenderer/text.cc b/pdf2htmlEX/src/HTMLRenderer/text.cc index 06df7aa..506f947 100644 --- a/pdf2htmlEX/src/HTMLRenderer/text.cc +++ b/pdf2htmlEX/src/HTMLRenderer/text.cc @@ -74,7 +74,7 @@ void HTMLRenderer::drawString(GfxState * state, const GooString * s) int uLen; CharCode code; - Unicode *u = nullptr; + Unicode const *u = nullptr; HR_DEBUG(printf("HTMLRenderer::drawString:len=%d\n", len)); diff --git a/pdf2htmlEX/src/Preprocessor.cc b/pdf2htmlEX/src/Preprocessor.cc index 42318b2..643bbc7 100644 --- a/pdf2htmlEX/src/Preprocessor.cc +++ b/pdf2htmlEX/src/Preprocessor.cc @@ -65,7 +65,7 @@ void Preprocessor::process(PDFDoc * doc) void Preprocessor::drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, - CharCode code, int nBytes, Unicode *u, int uLen) + CharCode code, int nBytes, const Unicode *u, int uLen) { GfxFont * font = state->getFont(); if(!font) return; diff --git a/pdf2htmlEX/src/Preprocessor.h b/pdf2htmlEX/src/Preprocessor.h index d121b59..756993d 100644 --- a/pdf2htmlEX/src/Preprocessor.h +++ b/pdf2htmlEX/src/Preprocessor.h @@ -39,7 +39,7 @@ public: virtual void drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, - CharCode code, int nBytes, Unicode *u, int uLen); + CharCode code, int nBytes, const Unicode *u, int uLen); // Start a page. // UGLY: These 2 versions are for different versions of poppler diff --git a/pdf2htmlEX/src/pdf2htmlEX.cc b/pdf2htmlEX/src/pdf2htmlEX.cc index 3223752..edf32ee 100644 --- a/pdf2htmlEX/src/pdf2htmlEX.cc +++ b/pdf2htmlEX/src/pdf2htmlEX.cc @@ -407,8 +407,11 @@ int main(int argc, char **argv) param.tmp_dir.c_str()); bool finished = false; - // read config file - globalParams = new GlobalParams(!param.poppler_data_dir.empty() ? param.poppler_data_dir.c_str() : NULL); + // read poppler config file + globalParams = std::make_unique( + !param.poppler_data_dir.empty() ? param.poppler_data_dir.c_str() : NULL + ); + // open PDF file PDFDoc * doc = nullptr; try @@ -435,8 +438,11 @@ int main(int argc, char **argv) cerr << "Document has copy-protection bit set." << endl; } - param.first_page = min(max(param.first_page, 1), doc->getNumPages()); - param.last_page = min(max(param.last_page, param.first_page), doc->getNumPages()); + param.first_page = + min(max(param.first_page, 1), doc->getNumPages()); + param.last_page = + min(max(param.last_page, param.first_page), + doc->getNumPages()); unique_ptr(new HTMLRenderer(argv[0], param))->process(doc); @@ -454,7 +460,7 @@ int main(int argc, char **argv) // clean up delete doc; - delete globalParams; + globalParams.reset(); // check for memory leaks // Poppler Object class (Object.h) no longer has memCheck diff --git a/pdf2htmlEX/src/util/unicode.cc b/pdf2htmlEX/src/util/unicode.cc index 31ec4f8..2ebc88e 100644 --- a/pdf2htmlEX/src/util/unicode.cc +++ b/pdf2htmlEX/src/util/unicode.cc @@ -55,7 +55,7 @@ Unicode unicode_from_font (CharCode code, GfxFont * font) return map_to_private(code); } -Unicode check_unicode(Unicode * u, int len, CharCode code, GfxFont * font) +Unicode check_unicode(Unicode const * u, int len, CharCode code, GfxFont * font) { if(len == 0) return map_to_private(code); diff --git a/pdf2htmlEX/src/util/unicode.h b/pdf2htmlEX/src/util/unicode.h index c789dea..d4a5d48 100644 --- a/pdf2htmlEX/src/util/unicode.h +++ b/pdf2htmlEX/src/util/unicode.h @@ -83,7 +83,7 @@ Unicode unicode_from_font (CharCode code, GfxFont * font); * if we got multi-unicode values, it might be expanded ligature, try to restore it * if we cannot figure it out at the end, use a private mapping */ -Unicode check_unicode(Unicode * u, int len, CharCode code, GfxFont * font); +Unicode check_unicode(Unicode const * u, int len, CharCode code, GfxFont * font); } // namespace pdf2htmlEX