diff --git a/.gitignore b/.gitignore index a56d2ea..81be867 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ test export-ignore Testing/* DartConfiguration.tcl test/test.py +*.swp diff --git a/3rdparty/poppler/git/CairoFontEngine.cc b/3rdparty/poppler/git/CairoFontEngine.cc index 0bd6e91..b894000 100644 --- a/3rdparty/poppler/git/CairoFontEngine.cc +++ b/3rdparty/poppler/git/CairoFontEngine.cc @@ -17,7 +17,7 @@ // Copyright (C) 2005-2007 Jeff Muizelaar // Copyright (C) 2005, 2006 Kristian Høgsberg // Copyright (C) 2005 Martin Kretzschmar -// Copyright (C) 2005, 2009, 2012, 2013, 2015, 2017 Albert Astals Cid +// Copyright (C) 2005, 2009, 2012, 2013, 2015, 2017, 2018 Albert Astals Cid // Copyright (C) 2006, 2007, 2010, 2011 Carlos Garcia Campos // Copyright (C) 2007 Koji Otani // Copyright (C) 2008, 2009 Chris Wilson @@ -34,16 +34,6 @@ // //======================================================================== -//======================================================================== -// -// Copied from Ubuntu 18.04 apt-get source poppler (poppler-0.62.0) -// Copied on 2019/March/26 -// Copied by Stephen Gaito in order to update pdf2htmlEX poppler dependencies -// Corrected includes to -// -//======================================================================== - - #include #include @@ -79,17 +69,17 @@ // CairoFont //------------------------------------------------------------------------ -CairoFont::CairoFont(Ref ref, - cairo_font_face_t *cairo_font_face, - int *codeToGID, - Guint codeToGIDLen, - GBool substitute, - GBool printing) : ref(ref), - cairo_font_face(cairo_font_face), - codeToGID(codeToGID), - codeToGIDLen(codeToGIDLen), - substitute(substitute), - printing(printing) { } +CairoFont::CairoFont(Ref refA, + cairo_font_face_t *cairo_font_faceA, + int *codeToGIDA, + Guint codeToGIDLenA, + GBool substituteA, + GBool printingA) : ref(refA), + cairo_font_face(cairo_font_faceA), + codeToGID(codeToGIDA), + codeToGIDLen(codeToGIDLenA), + substitute(substituteA), + printing(printingA) { } CairoFont::~CairoFont() { cairo_font_face_destroy (cairo_font_face); @@ -190,7 +180,7 @@ _ft_new_face_uncached (FT_Library lib, FT_Face face; cairo_font_face_t *font_face; - if (font_data == NULL) { + if (font_data == nullptr) { if (FT_New_Face (lib, filename, 0, &face)) return gFalse; } else { @@ -296,7 +286,7 @@ _ft_new_face (FT_Library lib, tmpl.fd = -1; - if (font_data == NULL) { + if (font_data == nullptr) { /* if we fail to mmap the file, just pass it to FreeType instead */ tmpl.fd = open (filename, O_RDONLY); if (tmpl.fd == -1) @@ -307,7 +297,7 @@ _ft_new_face (FT_Library lib, return _ft_new_face_uncached (lib, filename, font_data, font_data_len, face_out, font_face_out); } - tmpl.bytes = (unsigned char *) mmap (NULL, st.st_size, + tmpl.bytes = (unsigned char *) mmap (nullptr, st.st_size, PROT_READ, MAP_PRIVATE, tmpl.fd, 0); if (tmpl.bytes == MAP_FAILED) { @@ -361,7 +351,7 @@ _ft_new_face (FT_Library lib, l = (struct _ft_face_data *) gmallocn (1, sizeof (struct _ft_face_data)); *l = tmpl; - l->prev = NULL; + l->prev = nullptr; l->next = _ft_open_faces; if (_ft_open_faces) _ft_open_faces->prev = l; @@ -388,22 +378,21 @@ _ft_new_face (FT_Library lib, #define _ft_new_face _ft_new_face_uncached #endif -CairoFreeTypeFont::CairoFreeTypeFont(Ref ref, - cairo_font_face_t *cairo_font_face, - int *codeToGID, - Guint codeToGIDLen, - GBool substitute) : CairoFont(ref, - cairo_font_face, - codeToGID, - codeToGIDLen, - substitute, +CairoFreeTypeFont::CairoFreeTypeFont(Ref refA, + cairo_font_face_t *cairo_font_faceA, + int *codeToGIDA, + Guint codeToGIDLenA, + GBool substituteA) : CairoFont(refA, + cairo_font_faceA, + codeToGIDA, + codeToGIDLenA, + substituteA, gTrue) { } CairoFreeTypeFont::~CairoFreeTypeFont() { } CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Library lib, GBool useCIDs) { - Object refObj, strObj; GooString *fileName; char *fileNameC; char *font_data; @@ -422,19 +411,19 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, int *codeToGID; Guint codeToGIDLen; - codeToGID = NULL; + codeToGID = nullptr; codeToGIDLen = 0; - font_data = NULL; + font_data = nullptr; font_data_len = 0; - fileName = NULL; - fileNameC = NULL; + fileName = nullptr; + fileNameC = nullptr; GBool substitute = gFalse; ref = *gfxFont->getID(); fontType = gfxFont->getType(); - if (!(fontLoc = gfxFont->locateFont(xref, NULL))) { + if (!(fontLoc = gfxFont->locateFont(xref, nullptr))) { error(errSyntaxError, -1, "Couldn't find a font for '{0:s}'", gfxFont->getName() ? gfxFont->getName()->getCString() : "(unnamed)"); @@ -444,7 +433,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, // embedded font if (fontLoc->locType == gfxFontLocEmbedded) { font_data = gfxFont->readEmbFontFile(xref, &font_data_len); - if (NULL == font_data) + if (nullptr == font_data) goto err2; // external font @@ -454,7 +443,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, substitute = gTrue; } - if (fileName != NULL) { + if (fileName != nullptr) { fileNameC = fileName->getCString(); } @@ -491,7 +480,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, break; case fontCIDType2: case fontCIDType2OT: - codeToGID = NULL; + codeToGID = nullptr; n = 0; if (((GfxCIDFont *)gfxFont)->getCIDToGID()) { n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen(); @@ -501,7 +490,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, n * sizeof(int)); } } else { - if (font_data != NULL) { + if (font_data != nullptr) { ff = FoFiTrueType::make(font_data, font_data_len); } else { ff = FoFiTrueType::load(fileNameC); @@ -515,7 +504,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, /* Fall through */ case fontTrueType: case fontTrueTypeOT: - if (font_data != NULL) { + if (font_data != nullptr) { ff = FoFiTrueType::make(font_data, font_data_len); } else { ff = FoFiTrueType::load(fileNameC); @@ -539,12 +528,12 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, case fontCIDType0: case fontCIDType0C: - codeToGID = NULL; + codeToGID = nullptr; codeToGIDLen = 0; if (!useCIDs) { - if (font_data != NULL) { + if (font_data != nullptr) { ff1c = FoFiType1C::make(font_data, font_data_len); } else { ff1c = FoFiType1C::load(fileNameC); @@ -562,7 +551,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, break; case fontCIDType0COT: - codeToGID = NULL; + codeToGID = nullptr; n = 0; if (((GfxCIDFont *)gfxFont)->getCIDToGID()) { n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen(); @@ -576,7 +565,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, if (!codeToGID) { if (!useCIDs) { - if (font_data != NULL) { + if (font_data != nullptr) { ff = FoFiTrueType::make(font_data, font_data_len); } else { ff = FoFiTrueType::load(fileNameC); @@ -613,7 +602,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, gfree (codeToGID); gfree (font_data); fprintf (stderr, "some font thing failed\n"); - return NULL; + return nullptr; } //------------------------------------------------------------------------ @@ -713,7 +702,7 @@ _render_type3_glyph (cairo_scaled_font_t *scaled_font, box.y1 = mat[1]; box.x2 = mat[2]; box.y2 = mat[3]; - gfx = new Gfx(info->doc, output_dev, resDict, &box, NULL); + gfx = new Gfx(info->doc, output_dev, resDict, &box, nullptr); output_dev->startDoc(info->doc, info->fontEngine); output_dev->startPage (1, gfx->getState(), gfx->getXRef()); output_dev->setInType3Char(gTrue); @@ -745,7 +734,6 @@ _render_type3_glyph (cairo_scaled_font_t *scaled_font, CairoType3Font *CairoType3Font::create(GfxFont *gfxFont, PDFDoc *doc, CairoFontEngine *fontEngine, GBool printing, XRef *xref) { - Object refObj, strObj; type3_font_info_t *info; cairo_font_face_t *font_face; Ref ref; @@ -788,18 +776,18 @@ CairoType3Font *CairoType3Font::create(GfxFont *gfxFont, PDFDoc *doc, return new CairoType3Font(ref, doc, font_face, codeToGID, codeToGIDLen, printing, xref); } -CairoType3Font::CairoType3Font(Ref ref, - PDFDoc *doc, - cairo_font_face_t *cairo_font_face, - int *codeToGID, - Guint codeToGIDLen, - GBool printing, XRef *xref) : CairoFont(ref, - cairo_font_face, - codeToGID, - codeToGIDLen, +CairoType3Font::CairoType3Font(Ref refA, + PDFDoc *docA, + cairo_font_face_t *cairo_font_faceA, + int *codeToGIDA, + Guint codeToGIDLenA, + GBool printingA, XRef *xref) : CairoFont(refA, + cairo_font_faceA, + codeToGIDA, + codeToGIDLenA, gFalse, - printing), - doc(doc) { } + printingA), + doc(docA) { } CairoType3Font::~CairoType3Font() { } @@ -818,7 +806,7 @@ CairoFontEngine::CairoFontEngine(FT_Library libA) { lib = libA; for (i = 0; i < cairoFontCacheSize; ++i) { - fontCache[i] = NULL; + fontCache[i] = nullptr; } FT_Int major, minor, patch; diff --git a/3rdparty/poppler/git/CairoFontEngine.h b/3rdparty/poppler/git/CairoFontEngine.h index d814755..601fbae 100644 --- a/3rdparty/poppler/git/CairoFontEngine.h +++ b/3rdparty/poppler/git/CairoFontEngine.h @@ -15,7 +15,7 @@ // under GPL version 2 or later // // Copyright (C) 2005, 2006 Kristian Høgsberg -// Copyright (C) 2005 Albert Astals Cid +// Copyright (C) 2005, 2018 Albert Astals Cid // Copyright (C) 2006, 2007 Jeff Muizelaar // Copyright (C) 2006, 2010 Carlos Garcia Campos // Copyright (C) 2008, 2017 Adrian Johnson @@ -26,15 +26,6 @@ // //======================================================================== -//======================================================================== -// -// Copied from Ubuntu 18.04 apt-get source poppler (poppler-0.62.0) -// Copied on 2019/March/26 -// Copied by Stephen Gaito in order to update pdf2htmlEX poppler dependencies -// Corrected includes to -// -//======================================================================== - #ifndef CAIROFONTENGINE_H #define CAIROFONTENGINE_H @@ -60,6 +51,8 @@ public: GBool substitute, GBool printing); virtual ~CairoFont(); + CairoFont(const CairoFont &) = delete; + CairoFont& operator=(const CairoFont &other) = delete; virtual GBool matches(Ref &other, GBool printing); cairo_font_face_t *getFontFace(void); @@ -123,6 +116,8 @@ public: // Create a font engine. CairoFontEngine(FT_Library libA); ~CairoFontEngine(); + CairoFontEngine(const CairoFontEngine &) = delete; + CairoFontEngine& operator=(const CairoFontEngine &other) = delete; CairoFont *getFont(GfxFont *gfxFont, PDFDoc *doc, GBool printing, XRef *xref); diff --git a/3rdparty/poppler/git/CairoOutputDev.cc b/3rdparty/poppler/git/CairoOutputDev.cc index 0759230..1de6ddd 100644 --- a/3rdparty/poppler/git/CairoOutputDev.cc +++ b/3rdparty/poppler/git/CairoOutputDev.cc @@ -16,9 +16,9 @@ // // Copyright (C) 2005-2008 Jeff Muizelaar // Copyright (C) 2005, 2006 Kristian Høgsberg -// Copyright (C) 2005, 2009, 2012, 2017 Albert Astals Cid +// Copyright (C) 2005, 2009, 2012, 2017, 2018 Albert Astals Cid // Copyright (C) 2005 Nickolay V. Shmyrev -// Copyright (C) 2006-2011, 2013, 2014, 2017 Carlos Garcia Campos +// Copyright (C) 2006-2011, 2013, 2014, 2017, 2018 Carlos Garcia Campos // Copyright (C) 2008 Carl Worth // Copyright (C) 2008-2017 Adrian Johnson // Copyright (C) 2008 Michael Vrable @@ -29,21 +29,13 @@ // Copyright (C) 2012 Patrick Pfeifer // Copyright (C) 2012, 2015, 2016 Jason Crain // Copyright (C) 2015 Suzuki Toshiya +// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, . Work sponsored by the LiMux project of the city of Munich // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git // //======================================================================== -//======================================================================== -// -// Copied from Ubuntu 18.04 apt-get source poppler (poppler-0.62.0) -// Copied on 2019/March/26 -// Copied by Stephen Gaito in order to update pdf2htmlEX poppler dependencies -// Corrected includes to -// -//======================================================================== - #include #ifdef USE_GCC_PRAGMAS @@ -78,6 +70,11 @@ // #define LOG_CAIRO +// To limit memory usage and improve performance when printing, limit +// cairo images to this size. 8192 is sufficient for an A2 sized +// 300ppi image. +#define MAX_PRINT_IMAGE_SIZE 8192 + #ifdef LOG_CAIRO #define LOG(x) (x) #else @@ -100,7 +97,7 @@ static inline void printMatrix(cairo_matrix_t *matrix){ //------------------------------------------------------------------------ CairoImage::CairoImage (double x1, double y1, double x2, double y2) { - this->image = NULL; + this->image = nullptr; this->x1 = x1; this->y1 = y1; this->x2 = x2; @@ -132,26 +129,26 @@ FT_Library CairoOutputDev::ft_lib; GBool CairoOutputDev::ft_lib_initialized = gFalse; CairoOutputDev::CairoOutputDev() { - doc = NULL; + doc = nullptr; if (!ft_lib_initialized) { FT_Init_FreeType(&ft_lib); ft_lib_initialized = gTrue; } - fontEngine = NULL; + fontEngine = nullptr; fontEngine_owner = gFalse; - glyphs = NULL; - fill_pattern = NULL; + glyphs = nullptr; + fill_pattern = nullptr; fill_color.r = fill_color.g = fill_color.b = 0; - stroke_pattern = NULL; + stroke_pattern = nullptr; stroke_color.r = stroke_color.g = stroke_color.b = 0; stroke_opacity = 1.0; fill_opacity = 1.0; - textClipPath = NULL; - strokePathClip = NULL; - cairo = NULL; - currentFont = NULL; + textClipPath = nullptr; + strokePathClip = nullptr; + cairo = nullptr; + currentFont = nullptr; #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0) prescaleImages = gFalse; #else @@ -165,23 +162,23 @@ CairoOutputDev::CairoOutputDev() { text_matrix_valid = gTrue; antialias = CAIRO_ANTIALIAS_DEFAULT; - groupColorSpaceStack = NULL; - maskStack = NULL; - group = NULL; - mask = NULL; - shape = NULL; - cairo_shape = NULL; + groupColorSpaceStack = nullptr; + maskStack = nullptr; + group = nullptr; + mask = nullptr; + shape = nullptr; + cairo_shape = nullptr; knockoutCount = 0; - text = NULL; - actualText = NULL; + text = nullptr; + actualText = nullptr; // the SA parameter supposedly defaults to false, but Acrobat // apparently hardwires it to true stroke_adjust = gTrue; align_stroke_coords = gFalse; adjusted_stroke_width = gFalse; - xref = NULL; + xref = nullptr; } CairoOutputDev::~CairoOutputDev() { @@ -207,7 +204,7 @@ CairoOutputDev::~CairoOutputDev() { void CairoOutputDev::setCairo(cairo_t *cairo) { - if (this->cairo != NULL) { + if (this->cairo != nullptr) { cairo_status_t status = cairo_status (this->cairo); if (status) { error(errInternal, -1, "cairo context error: {0:s}\n", cairo_status_to_string(status)); @@ -215,15 +212,15 @@ void CairoOutputDev::setCairo(cairo_t *cairo) cairo_destroy (this->cairo); assert(!cairo_shape); } - if (cairo != NULL) { + if (cairo != nullptr) { this->cairo = cairo_reference (cairo); /* save the initial matrix so that we can use it for type3 fonts. */ //XXX: is this sufficient? could we miss changes to the matrix somehow? cairo_get_matrix(cairo, &orig_matrix); setContextAntialias(cairo, antialias); } else { - this->cairo = NULL; - this->cairo_shape = NULL; + this->cairo = nullptr; + this->cairo_shape = nullptr; } } @@ -238,8 +235,8 @@ void CairoOutputDev::setTextPage(TextPage *text) this->text->incRefCnt(); actualText = new ActualText(text); } else { - this->text = NULL; - actualText = NULL; + this->text = nullptr; + actualText = nullptr; } } @@ -290,7 +287,7 @@ void CairoOutputDev::startPage(int pageNum, GfxState *state, XRef *xrefA) { if (text) text->startPage(state); - if (xrefA != NULL) { + if (xrefA != nullptr) { xref = xrefA; } } @@ -349,7 +346,7 @@ void CairoOutputDev::restoreState(GfxState *state) { if (strokePathClip->dashes) gfree (strokePathClip->dashes); gfree (strokePathClip); - strokePathClip = NULL; + strokePathClip = nullptr; } } @@ -959,11 +956,11 @@ GBool CairoOutputDev::tilingPatternFill(GfxState *state, Gfx *gfxA, Catalog *cat cairo_translate (cairo, -box.x1, -box.y1); strokePathTmp = strokePathClip; - strokePathClip = NULL; + strokePathClip = nullptr; adjusted_stroke_width_tmp = adjusted_stroke_width; maskTmp = mask; - mask = NULL; - gfx = new Gfx(doc, this, resDict, &box, NULL, NULL, NULL, gfxA->getXRef()); + mask = nullptr; + gfx = new Gfx(doc, this, resDict, &box, nullptr, nullptr, nullptr, gfxA); if (paintType == 2) inUncoloredPattern = gTrue; gfx->display(str); @@ -1360,7 +1357,7 @@ void CairoOutputDev::clipToStrokePath(GfxState *state) { strokePathClip->dashes = (double*) gmallocn (sizeof(double), strokePathClip->dash_count); cairo_get_dash (cairo, strokePathClip->dashes, &strokePathClip->dash_offset); } else { - strokePathClip->dashes = NULL; + strokePathClip->dashes = nullptr; } strokePathClip->cap = cairo_get_line_cap (cairo); strokePathClip->join = cairo_get_line_join (cairo); @@ -1383,7 +1380,7 @@ void CairoOutputDev::fillToStrokePathClip(GfxState *state) { cairo_restore (cairo); } -void CairoOutputDev::beginString(GfxState *state, GooString *s) +void CairoOutputDev::beginString(GfxState *state, const GooString *s) { int len = s->getLength(); @@ -1512,12 +1509,12 @@ void CairoOutputDev::endString(GfxState *state) finish: gfree (glyphs); - glyphs = NULL; + glyphs = nullptr; if (use_show_text_glyphs) { gfree (clusters); - clusters = NULL; + clusters = nullptr; gfree (utf8); - utf8 = NULL; + utf8 = nullptr; } } @@ -1588,11 +1585,11 @@ void CairoOutputDev::endTextObject(GfxState *state) { cairo_clip (cairo_shape); } cairo_path_destroy (textClipPath); - textClipPath = NULL; + textClipPath = nullptr; } } -void CairoOutputDev::beginActualText(GfxState *state, GooString *text) +void CairoOutputDev::beginActualText(GfxState *state, const GooString *text) { if (this->text) actualText->begin(state, text); @@ -1620,7 +1617,7 @@ static cairo_surface_t *cairo_surface_create_similar_clip (cairo_t *cairo, cairo_content_t content) { cairo_pattern_t *pattern; - cairo_surface_t *surface = NULL; + cairo_surface_t *surface = nullptr; cairo_push_group_with_content (cairo, content); pattern = cairo_pop_group (cairo); @@ -1732,7 +1729,7 @@ void CairoOutputDev::paintTransparencyGroup(GfxState * /*state*/, double * /*bbo cairo_paint_with_alpha (cairo, fill_opacity); } cairo_pattern_destroy(mask); - mask = NULL; + mask = nullptr; } if (shape) { @@ -1742,7 +1739,7 @@ void CairoOutputDev::paintTransparencyGroup(GfxState * /*state*/, double * /*bbo cairo_set_source_rgb (cairo_shape, 0, 0, 0); } cairo_pattern_destroy (shape); - shape = NULL; + shape = nullptr; } popTransparencyGroup(); @@ -1890,7 +1887,7 @@ void CairoOutputDev::popTransparencyGroup() { /* we don't need to track the shape anymore because * we are not above any knockout groups */ cairo_destroy(cairo_shape); - cairo_shape = NULL; + cairo_shape = nullptr; } } groupColorSpaceStack = css->next; @@ -1901,7 +1898,7 @@ void CairoOutputDev::popTransparencyGroup() { void CairoOutputDev::clearSoftMask(GfxState * /*state*/) { if (mask) cairo_pattern_destroy(mask); - mask = NULL; + mask = nullptr; } /* Taken from cairo/doc/tutorial/src/singular.c */ @@ -2770,7 +2767,7 @@ void CairoOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *s cairo_surface_mark_dirty (image); - setMimeData(state, str, ref, colorMap, image); + setMimeData(state, str, ref, colorMap, image, height); pattern = cairo_pattern_create_for_surface (image); cairo_surface_destroy (image); @@ -2924,7 +2921,7 @@ GBool CairoOutputDev::setMimeDataForJBIG2Globals(Stream *str, if (!globalsStr->isStream()) return gTrue; - if (setMimeIdFromRef(image, CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID, NULL, + if (setMimeIdFromRef(image, CAIRO_MIME_TYPE_JBIG2_GLOBAL_ID, nullptr, jb2Str->getGlobalsStreamRef())) return gFalse; @@ -2944,8 +2941,38 @@ GBool CairoOutputDev::setMimeDataForJBIG2Globals(Stream *str, } #endif +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 15, 10) +GBool CairoOutputDev::setMimeDataForCCITTParams(Stream *str, + cairo_surface_t *image, int height) +{ + CCITTFaxStream *ccittStr = static_cast(str); + + GooString params; + params.appendf("Columns={0:d}", ccittStr->getColumns()); + params.appendf(" Rows={0:d}", height); + params.appendf(" K={0:d}", ccittStr->getEncoding()); + params.appendf(" EndOfLine={0:d}", ccittStr->getEndOfLine() ? 1 : 0); + params.appendf(" EncodedByteAlign={0:d}", ccittStr->getEncodedByteAlign() ? 1 : 0); + params.appendf(" EndOfBlock={0:d}", ccittStr->getEndOfBlock() ? 1 : 0); + params.appendf(" BlackIs1={0:d}", ccittStr->getBlackIs1() ? 1 : 0); + params.appendf(" DamagedRowsBeforeError={0:d}", ccittStr->getDamagedRowsBeforeError()); + + char *p = strdup(params.getCString()); + if (cairo_surface_set_mime_data (image, CAIRO_MIME_TYPE_CCITT_FAX_PARAMS, + (const unsigned char*)p, + params.getLength(), + gfree, (void*)p)) + { + gfree (p); + return gFalse; + } + + return gTrue; +} +#endif + void CairoOutputDev::setMimeData(GfxState *state, Stream *str, Object *ref, - GfxImageColorMap *colorMap, cairo_surface_t *image) + GfxImageColorMap *colorMap, cairo_surface_t *image, int height) { char *strBuffer; int len; @@ -2968,13 +2995,18 @@ void CairoOutputDev::setMimeData(GfxState *state, Stream *str, Object *ref, case strJBIG2: mime_type = CAIRO_MIME_TYPE_JBIG2; break; +#endif +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 15, 10) + case strCCITTFax: + mime_type = CAIRO_MIME_TYPE_CCITT_FAX; + break; #endif default: return; } obj = str->getDict()->lookup("ColorSpace"); - colorSpace = GfxColorSpace::parse(NULL, &obj, this, state); + colorSpace = GfxColorSpace::parse(nullptr, &obj, this, state); // colorspace in stream dict may be different from colorspace in jpx // data @@ -3011,6 +3043,11 @@ void CairoOutputDev::setMimeData(GfxState *state, Stream *str, Object *ref, return; #endif +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 15, 10) + if (strKind == strCCITTFax && !setMimeDataForCCITTParams(str, image, height)) + return; +#endif + if (getStreamData (str->getNextStream(), &strBuffer, &len)) { cairo_status_t status = CAIRO_STATUS_SUCCESS; @@ -3048,10 +3085,10 @@ public: GBool printing, GfxImageColorMap *colorMapA, int *maskColorsA) { - cairo_surface_t *image = NULL; + cairo_surface_t *image = nullptr; int i; - lookup = NULL; + lookup = nullptr; colorMap = colorMapA; maskColors = maskColorsA; width = widthA; @@ -3094,7 +3131,22 @@ public: bool needsCustomDownscaling = true; #endif - if (!needsCustomDownscaling || printing || scaledWidth >= width || scaledHeight >= height) { + if (printing) { + if (width > MAX_PRINT_IMAGE_SIZE || height > MAX_PRINT_IMAGE_SIZE) { + if (width > height) { + scaledWidth = MAX_PRINT_IMAGE_SIZE; + scaledHeight = MAX_PRINT_IMAGE_SIZE * (double)height/width; + } else { + scaledHeight = MAX_PRINT_IMAGE_SIZE; + scaledWidth = MAX_PRINT_IMAGE_SIZE * (double)width/height; + } + needsCustomDownscaling = true; + } else { + needsCustomDownscaling = false; + } + } + + if (!needsCustomDownscaling || scaledWidth >= width || scaledHeight >= height) { // No downscaling. Create cairo image containing the source image data. unsigned char *buffer; ptrdiff_t stride; @@ -3142,7 +3194,6 @@ public: } void getRow(int row_num, uint32_t *row_data) override { - int i; Guchar *pix; if (row_num <= current_row) @@ -3153,7 +3204,7 @@ public: current_row++; } - if (unlikely(pix == NULL)) { + if (unlikely(pix == nullptr)) { memset(row_data, 0, width*4); if (!imageError) { error(errInternal, -1, "Bad image stream"); @@ -3163,7 +3214,7 @@ public: Guchar *p = pix; GfxRGB rgb; - for (i = 0; i < width; i++) { + for (int i = 0; i < width; i++) { rgb = lookup[*p]; row_data[i] = ((int) colToByte(rgb.r) << 16) | @@ -3224,8 +3275,17 @@ void CairoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, if (width == widthA && height == heightA) filter = getFilterForSurface (image, interpolate); - if (!inlineImg) /* don't read stream twice if it is an inline image */ - setMimeData(state, str, ref, colorMap, image); + if (!inlineImg) { /* don't read stream twice if it is an inline image */ + // cairo 1.15.10 allows mime image data to have different size to cairo image + // mime image size will be scaled to same size as cairo image +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 15, 10) + bool requireSameSize = false; +#else + bool requireSameSize = true; +#endif + if (!requireSameSize || (width == widthA && height == heightA)) + setMimeData(state, str, ref, colorMap, image, heightA); + } pattern = cairo_pattern_create_for_surface (image); cairo_surface_destroy (image); @@ -3250,7 +3310,7 @@ void CairoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, } else if (mask) { maskPattern = cairo_pattern_reference (mask); } else { - maskPattern = NULL; + maskPattern = nullptr; } cairo_save (cairo); @@ -3295,11 +3355,11 @@ void CairoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, CairoImageOutputDev::CairoImageOutputDev() { - images = NULL; + images = nullptr; numImages = 0; size = 0; - imgDrawCbk = NULL; - imgDrawCbkData = NULL; + imgDrawCbk = nullptr; + imgDrawCbkData = nullptr; } CairoImageOutputDev::~CairoImageOutputDev() @@ -3372,7 +3432,7 @@ void CairoImageOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *st CairoOutputDev::drawImageMask(state, ref, str, width, height, invert, interpolate, inlineImg); image->setImage (surface); - setCairo (NULL); + setCairo (nullptr); cairo_surface_destroy (surface); cairo_destroy (cr); } @@ -3405,7 +3465,7 @@ void CairoImageOutputDev::setSoftMaskFromImageMask(GfxState *state, Object *ref, } image->setImage (surface); - setCairo (NULL); + setCairo (nullptr); cairo_surface_destroy (surface); cairo_destroy (cr); } @@ -3435,7 +3495,7 @@ void CairoImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, CairoOutputDev::drawImage(state, ref, str, width, height, colorMap, interpolate, maskColors, inlineImg); image->setImage (surface); - setCairo (NULL); + setCairo (nullptr); cairo_surface_destroy (surface); cairo_destroy (cr); } @@ -3471,7 +3531,7 @@ void CairoImageOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stre maskStr, maskWidth, maskHeight, maskColorMap, maskInterpolate); image->setImage (surface); - setCairo (NULL); + setCairo (nullptr); cairo_surface_destroy (surface); cairo_destroy (cr); } @@ -3506,7 +3566,7 @@ void CairoImageOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream * maskStr, maskWidth, maskHeight, maskInvert, maskInterpolate); image->setImage (surface); - setCairo (NULL); + setCairo (nullptr); cairo_surface_destroy (surface); cairo_destroy (cr); } diff --git a/3rdparty/poppler/git/CairoOutputDev.h b/3rdparty/poppler/git/CairoOutputDev.h index d173235..6ee6f9e 100644 --- a/3rdparty/poppler/git/CairoOutputDev.h +++ b/3rdparty/poppler/git/CairoOutputDev.h @@ -18,26 +18,19 @@ // Copyright (C) 2005, 2006 Kristian Høgsberg // Copyright (C) 2005 Nickolay V. Shmyrev // Copyright (C) 2006-2011, 2013 Carlos Garcia Campos -// Copyright (C) 2008, 2009, 2011-2016 Adrian Johnson +// Copyright (C) 2008, 2009, 2011-2017 Adrian Johnson // Copyright (C) 2008 Michael Vrable // Copyright (C) 2010-2013 Thomas Freitag // Copyright (C) 2015 Suzuki Toshiya // Copyright (C) 2016 Jason Crain +// Copyright (C) 2018 Albert Astals Cid +// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, . Work sponsored by the LiMux project of the city of Munich // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git // //======================================================================== -//======================================================================== -// -// Copied from Ubuntu 18.04 apt-get source poppler (poppler-0.62.0) -// Copied on 2019/March/26 -// Copied by Stephen Gaito in order to update pdf2htmlEX poppler dependencies -// Corrected includes to -// -//======================================================================== - #ifndef CAIROOUTPUTDEV_H #define CAIROOUTPUTDEV_H @@ -72,6 +65,9 @@ public: // Destructor. ~CairoImage (); + CairoImage(const CairoImage &) = delete; + CairoImage& operator=(const CairoImage &) = delete; + // Set the image cairo surface void setImage (cairo_surface_t *image); @@ -196,13 +192,13 @@ public: void eoClip(GfxState *state) override; //----- text drawing - void beginString(GfxState *state, GooString *s) override; + void beginString(GfxState *state, const GooString *s) override; void endString(GfxState *state) override; void drawChar(GfxState *state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode *u, int uLen) override; - void beginActualText(GfxState *state, GooString *text) override; + void beginActualText(GfxState *state, const GooString *text) override; void endActualText(GfxState *state) override; GBool beginType3Char(GfxState *state, double x, double y, @@ -274,10 +270,10 @@ public: void setCairo (cairo_t *cr); void setTextPage (TextPage *text); - void setPrinting (GBool printing) { this->printing = printing; needFontUpdate = gTrue; } + void setPrinting (GBool printingA) { printing = printingA; needFontUpdate = gTrue; } void setAntialias(cairo_antialias_t antialias); - void setInType3Char(GBool inType3Char) { this->inType3Char = inType3Char; } + void setInType3Char(GBool inType3CharA) { inType3Char = inType3CharA; } void getType3GlyphWidth (double *wx, double *wy) { *wx = t3_glyph_wx; *wy = t3_glyph_wy; } GBool hasType3GlyphBBox () { return t3_glyph_has_bbox; } double *getType3GlyphBBox () { return t3_glyph_bbox; } @@ -292,11 +288,14 @@ protected: GBool interpolate); GBool getStreamData (Stream *str, char **buffer, int *length); void setMimeData(GfxState *state, Stream *str, Object *ref, - GfxImageColorMap *colorMap, cairo_surface_t *image); + GfxImageColorMap *colorMap, cairo_surface_t *image, int height); void fillToStrokePathClip(GfxState *state); void alignStrokeCoords(GfxSubpath *subpath, int i, double *x, double *y); #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 14, 0) GBool setMimeDataForJBIG2Globals (Stream *str, cairo_surface_t *image); +#endif +#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 15, 10) + GBool setMimeDataForCCITTParams(Stream *str, cairo_surface_t *image, int height); #endif static void setContextAntialias(cairo_t *cr, cairo_antialias_t antialias); @@ -337,7 +336,6 @@ protected: GBool printing; GBool use_show_text_glyphs; GBool text_matrix_valid; - cairo_surface_t *surface; cairo_glyph_t *glyphs; int glyphCount; cairo_text_cluster_t *clusters; @@ -361,7 +359,6 @@ protected: cairo_pattern_t *shape; cairo_pattern_t *mask; cairo_matrix_t mask_matrix; - cairo_surface_t *cairo_shape_surface; cairo_t *cairo_shape; int knockoutCount; struct ColorSpaceStack { diff --git a/3rdparty/poppler/git/CairoRescaleBox.cc b/3rdparty/poppler/git/CairoRescaleBox.cc index 8a498da..251e8e6 100644 --- a/3rdparty/poppler/git/CairoRescaleBox.cc +++ b/3rdparty/poppler/git/CairoRescaleBox.cc @@ -38,14 +38,6 @@ // //======================================================================== -//======================================================================== -// -// Copied from Ubuntu 18.04 apt-get source poppler (poppler-0.62.0) -// Copied on 2019/March/26 -// Copied by Stephen Gaito in order to update pdf2htmlEX poppler dependencies -// Corrected includes to -// -//======================================================================== /* This implements a box filter that supports non-integer box sizes */ @@ -279,9 +271,9 @@ GBool CairoRescaleBox::downScaleImage(unsigned orig_width, unsigned orig_height, int dest_y; int src_y = 0; uint32_t *scanline; - int *x_coverage = NULL; - int *y_coverage = NULL; - uint32_t *temp_buf = NULL; + int *x_coverage = nullptr; + int *y_coverage = nullptr; + uint32_t *temp_buf = nullptr; GBool retval = gFalse; unsigned int *dest; int dst_stride; diff --git a/3rdparty/poppler/git/CairoRescaleBox.h b/3rdparty/poppler/git/CairoRescaleBox.h index a79e6eb..ca307cb 100644 --- a/3rdparty/poppler/git/CairoRescaleBox.h +++ b/3rdparty/poppler/git/CairoRescaleBox.h @@ -30,21 +30,13 @@ // under GPL version 2 or later // // Copyright (C) 2012 Adrian Johnson +// Copyright (C) 2018 Albert Astals Cid // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git // //======================================================================== -//======================================================================== -// -// Copied from Ubuntu 18.04 apt-get source poppler (poppler-0.62.0) -// Copied on 2019/March/26 -// Copied by Stephen Gaito in order to update pdf2htmlEX poppler dependencies -// Corrected includes to -// -//======================================================================== - #ifndef CAIRO_RESCALE_BOX_H #define CAIRO_RESCALE_BOX_H @@ -57,6 +49,9 @@ public: CairoRescaleBox() {}; virtual ~CairoRescaleBox() {}; + CairoRescaleBox(const CairoRescaleBox &) = delete; + CairoRescaleBox& operator=(const CairoRescaleBox &) = delete; + virtual GBool downScaleImage(unsigned orig_width, unsigned orig_height, signed scaled_width, signed scaled_height, unsigned short int start_column, unsigned short int start_row, diff --git a/src/BackgroundRenderer/CairoBackgroundRenderer.cc b/src/BackgroundRenderer/CairoBackgroundRenderer.cc index d0464af..fac4904 100644 --- a/src/BackgroundRenderer/CairoBackgroundRenderer.cc +++ b/src/BackgroundRenderer/CairoBackgroundRenderer.cc @@ -81,7 +81,7 @@ void CairoBackgroundRenderer::beginTextObject(GfxState *state) CairoOutputDev::beginTextObject(state); } -void CairoBackgroundRenderer::beginString(GfxState *state, GooString * str) +void CairoBackgroundRenderer::beginString(GfxState *state, const GooString * str) { if (param.proof == 2) proof_begin_string(state, this); @@ -239,7 +239,7 @@ void CairoBackgroundRenderer::setMimeData(GfxState *state, Stream *str, Object * { if (param.svg_embed_bitmap) { - CairoOutputDev::setMimeData(state, str, ref, colorMap, image); + CairoOutputDev::setMimeData(state, str, ref, colorMap, image, cairo_image_surface_get_height (image)); return; } diff --git a/src/BackgroundRenderer/CairoBackgroundRenderer.h b/src/BackgroundRenderer/CairoBackgroundRenderer.h index e4e92d2..b354cdc 100644 --- a/src/BackgroundRenderer/CairoBackgroundRenderer.h +++ b/src/BackgroundRenderer/CairoBackgroundRenderer.h @@ -46,7 +46,7 @@ public: //for proof void beginTextObject(GfxState *state); - void beginString(GfxState *state, GooString * str); + void beginString(GfxState *state, const GooString * str); void endTextObject(GfxState *state); void updateRender(GfxState *state); diff --git a/src/BackgroundRenderer/SplashBackgroundRenderer.cc b/src/BackgroundRenderer/SplashBackgroundRenderer.cc index 5ae289d..a7a23d8 100644 --- a/src/BackgroundRenderer/SplashBackgroundRenderer.cc +++ b/src/BackgroundRenderer/SplashBackgroundRenderer.cc @@ -80,7 +80,7 @@ void SplashBackgroundRenderer::beginTextObject(GfxState *state) SplashOutputDev::beginTextObject(state); } -void SplashBackgroundRenderer::beginString(GfxState *state, GooString * str) +void SplashBackgroundRenderer::beginString(GfxState *state, const GooString * str) { if (param.proof == 2) proof_begin_string(state, this); diff --git a/src/BackgroundRenderer/SplashBackgroundRenderer.h b/src/BackgroundRenderer/SplashBackgroundRenderer.h index 067de28..8b11da6 100644 --- a/src/BackgroundRenderer/SplashBackgroundRenderer.h +++ b/src/BackgroundRenderer/SplashBackgroundRenderer.h @@ -48,7 +48,7 @@ public: //for proof void beginTextObject(GfxState *state); - void beginString(GfxState *state, GooString * str); + void beginString(GfxState *state, const GooString * str); void endTextObject(GfxState *state); void updateRender(GfxState *state); diff --git a/src/HTMLRenderer/HTMLRenderer.h b/src/HTMLRenderer/HTMLRenderer.h index 24c76cd..7ec04bf 100644 --- a/src/HTMLRenderer/HTMLRenderer.h +++ b/src/HTMLRenderer/HTMLRenderer.h @@ -126,7 +126,7 @@ struct HTMLRenderer : OutputDev virtual void eoClip(GfxState * state); virtual void clipToStrokePath(GfxState * state); - virtual void drawString(GfxState * state, GooString * s); + virtual void drawString(GfxState * state, const GooString * s); virtual void drawImage(GfxState * state, Object * ref, Stream * str, int width, int height, GfxImageColorMap * colorMap, GBool interpolate, int *maskColors, GBool inlineImg); @@ -170,7 +170,7 @@ protected: void post_process(void); void process_outline(void); - void process_outline_items(GooList * items); + void process_outline_items(const GooList * items); void process_form(std::ofstream & out); @@ -179,7 +179,7 @@ protected: void dump_css(void); // convert a LinkAction to a string that our Javascript code can understand - std::string get_linkaction_str(LinkAction *, std::string & detail); + std::string get_linkaction_str(const LinkAction *, std::string & detail); //////////////////////////////////////////////////// /* diff --git a/src/HTMLRenderer/font.cc b/src/HTMLRenderer/font.cc index cf98db4..301bf30 100644 --- a/src/HTMLRenderer/font.cc +++ b/src/HTMLRenderer/font.cc @@ -595,6 +595,11 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo bool name_conflict_warned = false; auto ctu = font->getToUnicode(); + // NOTE: Poppler has changed its effective ABI + // in now expects the USER to increment any ref counters + assert(ctu); + ((CharCodeToUnicode *)ctu)->incRefCnt(); + std::fill(cur_mapping.begin(), cur_mapping.end(), -1); std::fill(width_list.begin(), width_list.end(), -1); @@ -634,7 +639,9 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo Unicode u, *pu=&u; if(info.use_tounicode) { - int n = ctu ? (ctu->mapToUnicode(cur_code, &pu)) : 0; + int n = ctu ? + (((CharCodeToUnicode *)ctu)->mapToUnicode(cur_code, &pu)) : + 0; u = check_unicode(pu, n, cur_code, font); } else @@ -756,7 +763,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo } if(ctu) - ctu->decRefCnt(); + ((CharCodeToUnicode *)ctu)->decRefCnt(); } /* diff --git a/src/HTMLRenderer/link.cc b/src/HTMLRenderer/link.cc index b8b4129..bf61e4a 100644 --- a/src/HTMLRenderer/link.cc +++ b/src/HTMLRenderer/link.cc @@ -126,7 +126,7 @@ static string get_linkdest_detail_str(LinkDest * dest, Catalog * catalog, int & return sout.str(); } -string HTMLRenderer::get_linkaction_str(LinkAction * action, string & detail) +string HTMLRenderer::get_linkaction_str(const LinkAction * action, string & detail) { string dest_str; detail = ""; @@ -137,7 +137,7 @@ string HTMLRenderer::get_linkaction_str(LinkAction * action, string & detail) { case actionGoTo: { - auto * real_action = dynamic_cast(action); + auto * real_action = dynamic_cast(action); LinkDest * dest = nullptr; if(auto _ = real_action->getDest()) dest = _->copy(); @@ -162,7 +162,7 @@ string HTMLRenderer::get_linkaction_str(LinkAction * action, string & detail) break; case actionURI: { - auto * real_action = dynamic_cast(action); + auto * real_action = dynamic_cast(action); assert(real_action != nullptr); dest_str = real_action->getURI()->getCString(); } diff --git a/src/HTMLRenderer/outline.cc b/src/HTMLRenderer/outline.cc index 12c3896..205eac7 100644 --- a/src/HTMLRenderer/outline.cc +++ b/src/HTMLRenderer/outline.cc @@ -21,7 +21,7 @@ namespace pdf2htmlEX { using std::ostream; -void HTMLRenderer::process_outline_items(GooList * items) +void HTMLRenderer::process_outline_items(const GooList * items) { if((!items) || (items->getLength() == 0)) return; diff --git a/src/HTMLRenderer/text.cc b/src/HTMLRenderer/text.cc index 754c75b..16bb478 100644 --- a/src/HTMLRenderer/text.cc +++ b/src/HTMLRenderer/text.cc @@ -23,7 +23,7 @@ using std::none_of; using std::cerr; using std::endl; -void HTMLRenderer::drawString(GfxState * state, GooString * s) +void HTMLRenderer::drawString(GfxState * state, const GooString * s) { if(s->getLength() == 0) return; @@ -58,7 +58,7 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s) // Now ready to output // get the unicodes - char *p = s->getCString(); + const char *p = s->getCString(); int len = s->getLength(); //accumulated displacement of chars in this string, in text object space