diff --git a/pdf2htmlEX/src/ArgParser.h b/pdf2htmlEX/src/ArgParser.h index c0f8cdea..6080b917 100644 --- a/pdf2htmlEX/src/ArgParser.h +++ b/pdf2htmlEX/src/ArgParser.h @@ -96,8 +96,8 @@ class ArgParser T * location, const Tv & default_value, const char * description, bool dont_show_default); - virtual void parse (const char * arg) const; - virtual void show_usage (std::ostream & out) const; + void parse (const char * arg) const override; + void show_usage (std::ostream & out) const override; private: T * location; diff --git a/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.cc b/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.cc index e567994c..01763a47 100644 --- a/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.cc +++ b/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.cc @@ -81,11 +81,11 @@ void CairoBackgroundRenderer::beginTextObject(GfxState *state) CairoOutputDev::beginTextObject(state); } -void CairoBackgroundRenderer::beginString(GfxState *state, const GooString * str) +void CairoBackgroundRenderer::beginString(GfxState *state, const std::string & str) { if (param.proof == 2) proof_begin_string(state, this); - CairoOutputDev::beginString(state, str->toStr()); + CairoOutputDev::beginString(state, str); } void CairoBackgroundRenderer::endTextObject(GfxState *state) @@ -234,75 +234,6 @@ string CairoBackgroundRenderer::build_bitmap_path(int id) // "o" for "PDF Object" return string(html_renderer->str_fmt("%s/o%d.jpg", param.dest_dir.c_str(), id)); } -// Override CairoOutputDev::setMimeData() and dump bitmaps in SVG to external files. -void CairoBackgroundRenderer::setMimeData(GfxState *state, Stream *str, Object *ref, GfxImageColorMap *colorMap, cairo_surface_t *image) -{ - if (param.svg_embed_bitmap) - { - CairoOutputDev::setMimeData(state, str, ref, colorMap, image, cairo_image_surface_get_height (image)); - return; - } - - // TODO dump bitmaps in other formats. - if (str->getKind() != strDCT) - return; - - // TODO inline image? - if (ref == nullptr || !ref->isRef()) - return; - - // We only dump rgb or gray jpeg without /Decode array. - // - // Although jpeg support CMYK, PDF readers do color conversion incompatibly with most other - // programs (including browsers): other programs invert CMYK color if 'Adobe' marker (app14) presents - // in a jpeg file; while PDF readers don't, they solely rely on /Decode array to invert color. - // It's a bit complicated to decide whether a CMYK jpeg is safe to dump, so we don't dump at all. - // See also: - // JPEG file embedded in PDF (CMYK) https://forums.adobe.com/thread/975777 - // http://stackoverflow.com/questions/3123574/how-to-convert-from-cmyk-to-rgb-in-java-correctly - // - // In PDF, jpeg stream objects can also specify other color spaces like DeviceN and Separation, - // It is also not safe to dump them directly. - Object obj = str->getDict()->lookup("ColorSpace"); - if (!obj.isName() || (strcmp(obj.getName(), "DeviceRGB") && strcmp(obj.getName(), "DeviceGray")) ) - { - //obj.free(); - return; - } - //obj.free(); - obj = str->getDict()->lookup("Decode"); - if (obj.isArray()) - { - //obj.free(); - return; - } - //obj.free(); - - int imgId = ref->getRef().num; - auto uri = strdup((char*) html_renderer->str_fmt("o%d.jpg", imgId)); - auto st = cairo_surface_set_mime_data(image, CAIRO_MIME_TYPE_URI, - (unsigned char*) uri, strlen(uri), free, uri); - if (st) - { - free(uri); - return; - } - bitmaps_in_current_page.push_back(imgId); - - if(bitmaps_ref_count.find(imgId) != bitmaps_ref_count.end()) - return; - - bitmaps_ref_count[imgId] = 0; - - char *strBuffer; - int len; - if (getStreamData(str->getNextStream(), &strBuffer, &len)) - { - ofstream imgfile(build_bitmap_path(imgId), ofstream::binary); - imgfile.write(strBuffer, len); - free(strBuffer); - } -} } // namespace pdf2htmlEX diff --git a/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.h b/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.h index f8bbc07b..82d393f1 100644 --- a/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.h +++ b/pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.h @@ -29,30 +29,27 @@ class CairoBackgroundRenderer : public BackgroundRenderer, CairoOutputDev public: CairoBackgroundRenderer(HTMLRenderer * html_renderer, const Param & param); - virtual ~CairoBackgroundRenderer(); + ~CairoBackgroundRenderer() override; - virtual void init(PDFDoc * doc); - virtual bool render_page(PDFDoc * doc, int pageno); - virtual void embed_image(int pageno); + void init(PDFDoc * doc) override; + bool render_page(PDFDoc * doc, int pageno) override; + void embed_image(int pageno) override; // Does this device use beginType3Char/endType3Char? Otherwise, // text in Type 3 fonts will be drawn with drawChar/drawString. - virtual bool interpretType3Chars() { return !param.process_type3; } + bool interpretType3Chars() override { return !param.process_type3; } - virtual void drawChar(GfxState *state, double x, double y, + void drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, - CharCode code, int nBytes, const Unicode *u, int uLen); + CharCode code, int nBytes, const Unicode *u, int uLen) override; //for proof void beginTextObject(GfxState *state); - void beginString(GfxState *state, const GooString * str); + void beginString(GfxState *state, const std::string & str); void endTextObject(GfxState *state); void updateRender(GfxState *state); -protected: - virtual void setMimeData(GfxState *state, Stream *str, Object *ref, GfxImageColorMap *colorMap, cairo_surface_t *image); - protected: HTMLRenderer * html_renderer; const Param & param; diff --git a/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.cc b/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.cc index bd0f4d6e..7759e926 100644 --- a/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.cc +++ b/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.cc @@ -71,11 +71,11 @@ void SplashBackgroundRenderer::beginTextObject(GfxState *state) SplashOutputDev::beginTextObject(state); } -void SplashBackgroundRenderer::beginString(GfxState *state, const GooString * str) +void SplashBackgroundRenderer::beginString(GfxState *state, const std::string & str) { if (param.proof == 2) proof_begin_string(state, this); - SplashOutputDev::beginString(state, str->toStr()); + SplashOutputDev::beginString(state, str); } void SplashBackgroundRenderer::endTextObject(GfxState *state) diff --git a/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.h b/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.h index d2138c1a..a6cfa44d 100644 --- a/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.h +++ b/pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.h @@ -29,26 +29,24 @@ class SplashBackgroundRenderer : public BackgroundRenderer, SplashOutputDev //format: "png" or "jpg", or "" for a default format SplashBackgroundRenderer(const std::string & format, HTMLRenderer * html_renderer, const Param & param); - virtual ~SplashBackgroundRenderer() { } - - virtual void init(PDFDoc * doc); - virtual bool render_page(PDFDoc * doc, int pageno); - virtual void embed_image(int pageno); + void init(PDFDoc * doc) override; + bool render_page(PDFDoc * doc, int pageno) override; + void embed_image(int pageno) override; // Does this device use beginType3Char/endType3Char? Otherwise, // text in Type 3 fonts will be drawn with drawChar/drawString. - virtual bool interpretType3Chars() { return !param.process_type3; } + bool interpretType3Chars() override { return !param.process_type3; } - virtual void startPage(int pageNum, GfxState *state, XRef *xrefA); + void startPage(int pageNum, GfxState *state, XRef *xrefA) override; - virtual void drawChar(GfxState *state, double x, double y, + void drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, - CharCode code, int nBytes, const Unicode *u, int uLen); + CharCode code, int nBytes, const Unicode *u, int uLen) override; //for proof void beginTextObject(GfxState *state); - void beginString(GfxState *state, const GooString * str); + void beginString(GfxState *state, const std::string & str); void endTextObject(GfxState *state); void updateRender(GfxState *state); diff --git a/pdf2htmlEX/src/HTMLRenderer/HTMLRenderer.h b/pdf2htmlEX/src/HTMLRenderer/HTMLRenderer.h index 983962d1..1abe7e1d 100644 --- a/pdf2htmlEX/src/HTMLRenderer/HTMLRenderer.h +++ b/pdf2htmlEX/src/HTMLRenderer/HTMLRenderer.h @@ -76,7 +76,7 @@ namespace pdf2htmlEX { struct HTMLRenderer : OutputDev { HTMLRenderer(const char* progPath, Param & param); - virtual ~HTMLRenderer(); + ~HTMLRenderer() override; void process(PDFDoc * doc); @@ -88,102 +88,102 @@ struct HTMLRenderer : OutputDev // Does this device use upside-down coordinates? // (Upside-down means (0,0) is the top left corner of the page.) - virtual bool upsideDown() { return false; } + bool upsideDown() override { return false; } // Does this device use drawChar() or drawString()? - virtual bool useDrawChar() { return false; } + bool useDrawChar() override { return false; } // Does this device use functionShadedFill(), axialShadedFill(), and // radialShadedFill()? If this returns false, these shaded fills // will be reduced to a series of other drawing operations. - virtual bool useShadedFills(int type) { return (type == 2) ? true: false; } + bool useShadedFills(int type) override { return (type == 2) ? true: false; } // Does this device use beginType3Char/endType3Char? Otherwise, // text in Type 3 fonts will be drawn with drawChar/drawString. - virtual bool interpretType3Chars() { return false; } + bool interpretType3Chars() override { return false; } // Does this device need non-text content? - virtual bool needNonText() { return (param.process_nontext) ? true: false; } + bool needNonText() override { return (param.process_nontext) ? true: false; } // Does this device need to clip pages to the crop box even when the // box is the crop box? - virtual bool needClipToCropBox() { return true; } + bool needClipToCropBox() override { return true; } - virtual void setDefaultCTM(const double *ctm); + void setDefaultCTM(const std::array &ctm) override; // Start a page. - virtual void startPage(int pageNum, GfxState *state, XRef * xref); + void startPage(int pageNum, GfxState *state, XRef * xref) override; // End a page. - virtual void endPage(); + void endPage() override; /* * To optimize false alarms * We just mark as changed, and recheck if they have been changed when we are about to output a new string */ - virtual void restoreState(GfxState * state); + void restoreState(GfxState * state) override; - virtual void saveState(GfxState *state); + void saveState(GfxState *state) override; - virtual void updateAll(GfxState * state); + void updateAll(GfxState * state) override; - virtual void updateRise(GfxState * state); - virtual void updateTextPos(GfxState * state); - virtual void updateTextShift(GfxState * state, double shift); + void updateRise(GfxState * state) override; + void updateTextPos(GfxState * state) override; + void updateTextShift(GfxState * state, double shift) override; - virtual void updateFont(GfxState * state); - virtual void updateCTM(GfxState * state, double m11, double m12, double m21, double m22, double m31, double m32); - virtual void updateTextMat(GfxState * state); - virtual void updateHorizScaling(GfxState * state); + void updateFont(GfxState * state) override; + void updateCTM(GfxState * state, double m11, double m12, double m21, double m22, double m31, double m32) override; + void updateTextMat(GfxState * state) override; + void updateHorizScaling(GfxState * state) override; - virtual void updateCharSpace(GfxState * state); - virtual void updateWordSpace(GfxState * state); + void updateCharSpace(GfxState * state) override; + void updateWordSpace(GfxState * state) override; - virtual void updateRender(GfxState * state); + void updateRender(GfxState * state) override; - virtual void updateFillColorSpace(GfxState * state); - virtual void updateStrokeColorSpace(GfxState * state); - virtual void updateFillColor(GfxState * state); - virtual void updateStrokeColor(GfxState * state); + void updateFillColorSpace(GfxState * state) override; + void updateStrokeColorSpace(GfxState * state) override; + void updateFillColor(GfxState * state) override; + void updateStrokeColor(GfxState * state) override; /* * Rendering */ - virtual void clip(GfxState * state); - virtual void eoClip(GfxState * state); - virtual void clipToStrokePath(GfxState * state); + void clip(GfxState * state) override; + void eoClip(GfxState * state) override; + void clipToStrokePath(GfxState * state) override; - virtual void drawString(GfxState * state, const GooString * s); + void drawString(GfxState * state, const std::string& s) override; - virtual void drawImage(GfxState * state, Object * ref, Stream * str, + void drawImage(GfxState * state, Object * ref, Stream * str, int width, int height, GfxImageColorMap * colorMap, - bool interpolate, const int *maskColors, bool inlineImg); + bool interpolate, const int *maskColors, bool inlineImg) override; - virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, + void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, Stream *maskStr, int maskWidth, int maskHeight, GfxImageColorMap *maskColorMap, - bool maskInterpolate); + bool maskInterpolate) override; - virtual void stroke(GfxState *state); - virtual void fill(GfxState *state); - virtual void eoFill(GfxState *state); - virtual bool axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax); + void stroke(GfxState *state) override; + void fill(GfxState *state) override; + void eoFill(GfxState *state) override; + bool axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax) override; - virtual void beginTransparencyGroup(GfxState * /*state*/, const double * /*bbox*/, + void beginTransparencyGroup(GfxState * /*state*/, const std::array & /*bbox*/, GfxColorSpace * /*blendingColorSpace*/, bool /*isolated*/, bool /*knockout*/, - bool /*forSoftMask*/); - virtual void endTransparencyGroup(GfxState * /*state*/); + bool /*forSoftMask*/) override; + void endTransparencyGroup(GfxState * /*state*/) override; - virtual void processLink(AnnotLink * al); + void processLink(AnnotLink * al) override; /* * Covered text handling. diff --git a/pdf2htmlEX/src/HTMLRenderer/draw.cc b/pdf2htmlEX/src/HTMLRenderer/draw.cc index 39cfa9ca..2e0d2f34 100644 --- a/pdf2htmlEX/src/HTMLRenderer/draw.cc +++ b/pdf2htmlEX/src/HTMLRenderer/draw.cc @@ -62,7 +62,7 @@ bool HTMLRenderer::axialShadedFill(GfxState *state, GfxAxialShading *shading, do return true; } -void HTMLRenderer::beginTransparencyGroup(GfxState *state, const double *bbox, +void HTMLRenderer::beginTransparencyGroup(GfxState *state, const std::array &bbox, GfxColorSpace *blendingColorSpace, bool isolated, bool knockout, bool forSoftMask) { diff --git a/pdf2htmlEX/src/HTMLRenderer/general.cc b/pdf2htmlEX/src/HTMLRenderer/general.cc index c9a34f8c..3d686232 100644 --- a/pdf2htmlEX/src/HTMLRenderer/general.cc +++ b/pdf2htmlEX/src/HTMLRenderer/general.cc @@ -221,9 +221,9 @@ bool HTMLRenderer::renderPage(PDFDoc *doc, int pageno) return false; } -void HTMLRenderer::setDefaultCTM(const double *ctm) +void HTMLRenderer::setDefaultCTM(const std::array &ctm) { - memcpy(default_ctm, ctm, sizeof(default_ctm)); + memcpy(default_ctm, ctm.data(), sizeof(default_ctm)); } void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref) diff --git a/pdf2htmlEX/src/HTMLRenderer/text.cc b/pdf2htmlEX/src/HTMLRenderer/text.cc index 01bd032d..22fbb87b 100644 --- a/pdf2htmlEX/src/HTMLRenderer/text.cc +++ b/pdf2htmlEX/src/HTMLRenderer/text.cc @@ -23,9 +23,9 @@ using std::none_of; using std::cerr; using std::endl; -void HTMLRenderer::drawString(GfxState * state, const GooString * s) +void HTMLRenderer::drawString(GfxState * state, const std::string& s) { - if(s->empty()) + if(s.empty()) return; auto font = state->getFont(); @@ -58,8 +58,8 @@ void HTMLRenderer::drawString(GfxState * state, const GooString * s) // Now ready to output // get the unicodes - const char *p = s->c_str(); - int len = s->size(); + const char *p = s.c_str(); + int len = s.size(); //accumulated displacement of chars in this string, in text object space double dx = 0; @@ -188,7 +188,7 @@ void HTMLRenderer::drawString(GfxState * state, const GooString * s) bool HTMLRenderer::is_char_covered(int index) { - auto covered = covered_text_detector.get_chars_covered(); + const auto& covered = covered_text_detector.get_chars_covered(); if (index < 0 || index >= (int)covered.size()) { std::cerr << "Warning: HTMLRenderer::is_char_covered: index out of bound: " diff --git a/pdf2htmlEX/src/Preprocessor.cc b/pdf2htmlEX/src/Preprocessor.cc index e1ca5e12..f6011d15 100644 --- a/pdf2htmlEX/src/Preprocessor.cc +++ b/pdf2htmlEX/src/Preprocessor.cc @@ -89,12 +89,7 @@ void Preprocessor::drawChar(GfxState *state, double x, double y, cur_code_map[code] = 1; } -void Preprocessor::startPage(int pageNum, GfxState *state) -{ - startPage(pageNum, state, nullptr); -} - -void Preprocessor::startPage(int pageNum, GfxState *state, XRef * xref) +void Preprocessor::startPage(int pageNum, GfxState *state, XRef *xref) { max_width = max(max_width, state->getPageWidth()); max_height = max(max_height, state->getPageHeight()); diff --git a/pdf2htmlEX/src/Preprocessor.h b/pdf2htmlEX/src/Preprocessor.h index 756993d8..df97617a 100644 --- a/pdf2htmlEX/src/Preprocessor.h +++ b/pdf2htmlEX/src/Preprocessor.h @@ -26,25 +26,24 @@ namespace pdf2htmlEX { class Preprocessor : public OutputDev { public: Preprocessor(const Param & param); - virtual ~Preprocessor(void); + ~Preprocessor(void) override; void process(PDFDoc * doc); - virtual bool upsideDown() { return false; } - virtual bool useDrawChar() { return true; } - virtual bool interpretType3Chars() { return false; } - virtual bool needNonText() { return false; } - virtual bool needClipToCropBox() { return true; } + bool upsideDown() override { return false; } + bool useDrawChar() override { return true; } + bool interpretType3Chars() override { return false; } + bool needNonText() override { return false; } + bool needClipToCropBox() override { return true; } - virtual void drawChar(GfxState *state, double x, double y, + void drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, - CharCode code, int nBytes, const Unicode *u, int uLen); + CharCode code, int nBytes, const Unicode *u, int uLen) override; // Start a page. // UGLY: These 2 versions are for different versions of poppler - virtual void startPage(int pageNum, GfxState *state); - virtual void startPage(int pageNum, GfxState *state, XRef * xref); + void startPage(int pageNum, GfxState *state, XRef * xref) override; const char * get_code_map (long long font_id) const; double get_max_width (void) const { return max_width; }