commit of initial update of pdf2htmlEX to poppler 68

This commit is contained in:
Stephen Gaito 2019-05-06 13:03:24 +01:00
parent 665ddaaa27
commit 356d3f103d
8 changed files with 90 additions and 87 deletions

4
.gitignore vendored
View File

@ -18,3 +18,7 @@ src/pdf2htmlEX-config.h
src/util/css_const.h
test export-ignore
Testing/*
DartConfiguration.tcl
test/test.py
*.swp

View File

@ -17,7 +17,7 @@
// Copyright (C) 2005-2007 Jeff Muizelaar <jeff@infidigm.net>
// Copyright (C) 2005, 2006 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2005 Martin Kretzschmar <martink@gnome.org>
// Copyright (C) 2005, 2009, 2012, 2013, 2015, 2017 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2005, 2009, 2012, 2013, 2015, 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2006, 2007, 2010, 2011 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2007 Koji Otani <sho@bbr.jp>
// Copyright (C) 2008, 2009 Chris Wilson <chris@chris-wilson.co.uk>
@ -69,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);
@ -378,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;
@ -411,7 +410,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,
int *codeToGID;
Guint codeToGIDLen;
codeToGID = nullptr;
codeToGIDLen = 0;
font_data = nullptr;
@ -420,7 +419,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,
fileNameC = nullptr;
GBool substitute = gFalse;
ref = *gfxFont->getID();
fontType = gfxFont->getType();
@ -456,9 +455,9 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,
error(errSyntaxError, -1, "could not create type1 face");
goto err2;
}
enc = ((Gfx8BitFont *)gfxFont)->getEncoding();
codeToGID = (int *)gmallocn(256, sizeof(int));
codeToGIDLen = 256;
for (i = 0; i < 256; ++i) {
@ -525,7 +524,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,
goto err2;
}
break;
case fontCIDType0:
case fontCIDType0C:
@ -735,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;
@ -778,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() { }
@ -810,7 +808,7 @@ CairoFontEngine::CairoFontEngine(FT_Library libA) {
for (i = 0; i < cairoFontCacheSize; ++i) {
fontCache[i] = nullptr;
}
FT_Int major, minor, patch;
// as of FT 2.1.8, CID fonts are indexed by CID instead of GID
FT_Library_Version(lib, &major, &minor, &patch);
@ -823,7 +821,7 @@ CairoFontEngine::CairoFontEngine(FT_Library libA) {
CairoFontEngine::~CairoFontEngine() {
int i;
for (i = 0; i < cairoFontCacheSize; ++i) {
if (fontCache[i])
delete fontCache[i];
@ -839,7 +837,7 @@ CairoFontEngine::getFont(GfxFont *gfxFont, PDFDoc *doc, GBool printing, XRef *xr
Ref ref;
CairoFont *font;
GfxFontType fontType;
fontEngineLocker();
ref = *gfxFont->getID();
@ -853,7 +851,7 @@ CairoFontEngine::getFont(GfxFont *gfxFont, PDFDoc *doc, GBool printing, XRef *xr
return font;
}
}
fontType = gfxFont->getType();
if (fontType == fontType3)
font = CairoType3Font::create (gfxFont, doc, this, printing, xref);

View File

@ -16,9 +16,9 @@
//
// Copyright (C) 2005-2008 Jeff Muizelaar <jeff@infidigm.net>
// Copyright (C) 2005, 2006 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2005, 2009, 2012, 2017 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2005, 2009, 2012, 2017, 2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2005 Nickolay V. Shmyrev <nshmyrev@yandex.ru>
// Copyright (C) 2006-2011, 2013, 2014, 2017 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2006-2011, 2013, 2014, 2017, 2018 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2008 Carl Worth <cworth@cworth.org>
// Copyright (C) 2008-2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2008 Michael Vrable <mvrable@cs.ucsd.edu>
@ -29,6 +29,7 @@
// Copyright (C) 2012 Patrick Pfeifer <p2000@mailinator.com>
// Copyright (C) 2012, 2015, 2016 Jason Crain <jason@aquaticape.us>
// Copyright (C) 2015 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. 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
@ -195,10 +196,10 @@ CairoOutputDev::~CairoOutputDev() {
cairo_pattern_destroy (mask);
if (shape)
cairo_pattern_destroy (shape);
if (text)
if (text)
text->decRefCnt();
if (actualText)
delete actualText;
delete actualText;
}
void CairoOutputDev::setCairo(cairo_t *cairo)
@ -225,7 +226,7 @@ void CairoOutputDev::setCairo(cairo_t *cairo)
void CairoOutputDev::setTextPage(TextPage *text)
{
if (this->text)
if (this->text)
this->text->decRefCnt();
if (actualText)
delete actualText;
@ -669,7 +670,7 @@ void CairoOutputDev::updateFont(GfxState *state) {
//FIXME: use cairo font engine?
if (text)
text->updateFont(state);
currentFont = fontEngine->getFont (state->getFont(), doc, printing, xref);
if (!currentFont)
@ -680,7 +681,7 @@ void CairoOutputDev::updateFont(GfxState *state) {
use_show_text_glyphs = state->getFont()->hasToUnicodeCMap() &&
cairo_surface_has_show_text_glyphs (cairo_get_target (cairo));
double fontSize = state->getFontSize();
double *m = state->getTextMat();
/* NOTE: adjusting by a constant is hack. The correct solution
@ -959,7 +960,7 @@ GBool CairoOutputDev::tilingPatternFill(GfxState *state, Gfx *gfxA, Catalog *cat
adjusted_stroke_width_tmp = adjusted_stroke_width;
maskTmp = mask;
mask = nullptr;
gfx = new Gfx(doc, this, resDict, &box, nullptr, nullptr, nullptr, gfxA->getXRef());
gfx = new Gfx(doc, this, resDict, &box, nullptr, nullptr, nullptr, gfxA);
if (paintType == 2)
inUncoloredPattern = gTrue;
gfx->display(str);
@ -1379,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();
@ -1493,11 +1494,11 @@ void CairoOutputDev::endString(GfxState *state)
}
cairo_path_destroy (textClipPath);
}
// append the glyph path
cairo_glyph_path (cairo, glyphs, glyphCount);
// move the path back into textClipPath
// move the path back into textClipPath
// and clear the current path
textClipPath = cairo_copy_path (cairo);
cairo_new_path (cairo);
@ -1588,7 +1589,7 @@ void CairoOutputDev::endTextObject(GfxState *state) {
}
}
void CairoOutputDev::beginActualText(GfxState *state, GooString *text)
void CairoOutputDev::beginActualText(GfxState *state, const GooString *text)
{
if (this->text)
actualText->begin(state, text);
@ -1970,7 +1971,7 @@ CairoOutputDev::getFilterForSurface(cairo_surface_t *image,
GBool interpolate)
{
if (interpolate)
return CAIRO_FILTER_BEST;
return CAIRO_FILTER_GOOD;
int orig_width = cairo_image_surface_get_width (image);
int orig_height = cairo_image_surface_get_height (image);
@ -1990,7 +1991,7 @@ CairoOutputDev::getFilterForSurface(cairo_surface_t *image,
if (scaled_width / orig_width >= 4 || scaled_height / orig_height >= 4)
return CAIRO_FILTER_NEAREST;
return CAIRO_FILTER_BEST;
return CAIRO_FILTER_GOOD;
}
void CairoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
@ -2033,7 +2034,7 @@ void CairoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
cairo_matrix_t matrix;
cairo_get_matrix (cairo, &matrix);
//XXX: it is possible that we should only do sub pixel positioning if
//XXX: it is possible that we should only do sub pixel positioning if
// we are rendering fonts */
if (!printing && prescaleImages
/* not rotated */
@ -2086,7 +2087,7 @@ void CairoOutputDev::setSoftMaskFromImageMask(GfxState *state, Object *ref, Stre
cairo_matrix_t matrix;
cairo_get_matrix (cairo, &matrix);
//XXX: it is possible that we should only do sub pixel positioning if
//XXX: it is possible that we should only do sub pixel positioning if
// we are rendering fonts */
if (!printing && prescaleImages && matrix.xy == 0.0 && matrix.yx == 0.0) {
drawImageMaskPrescaled(state, ref, str, width, height, invert, gFalse, inlineImg);
@ -2458,7 +2459,7 @@ void CairoOutputDev::drawImageMaskPrescaled(GfxState *state, Object *ref, Stream
* cairo doesn't yet do minifaction filtering causing scaled down
* images with CAIRO_FILTER_NEAREST to look really bad */
cairo_pattern_set_filter (pattern,
interpolate ? CAIRO_FILTER_BEST : CAIRO_FILTER_FAST);
interpolate ? CAIRO_FILTER_GOOD : CAIRO_FILTER_FAST);
if (state->getFillColorSpace()->getMode() == csPattern) {
cairo_matrix_init_translate (&matrix, 0, scaledHeight);
@ -2588,7 +2589,7 @@ void CairoOutputDev::drawMaskedImage(GfxState *state, Object *ref,
* so check its underlying color space as well */
int is_identity_transform;
is_identity_transform = colorMap->getColorSpace()->getMode() == csDeviceRGB ||
(colorMap->getColorSpace()->getMode() == csICCBased &&
(colorMap->getColorSpace()->getMode() == csICCBased &&
((GfxICCBasedColorSpace*)colorMap->getColorSpace())->getAlt()->getMode() == csDeviceRGB);
#endif
@ -3193,7 +3194,6 @@ public:
}
void getRow(int row_num, uint32_t *row_data) override {
int i;
Guchar *pix;
if (row_num <= current_row)
@ -3214,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) |
@ -3259,7 +3259,7 @@ void CairoOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
cairo_matrix_t matrix;
int width, height;
int scaledWidth, scaledHeight;
cairo_filter_t filter = CAIRO_FILTER_BEST;
cairo_filter_t filter = CAIRO_FILTER_GOOD;
RescaleDrawImage rescale;
LOG (printf ("drawImage %dx%d\n", widthA, heightA));
@ -3372,7 +3372,7 @@ CairoImageOutputDev::~CairoImageOutputDev()
}
void CairoImageOutputDev::saveImage(CairoImage *image)
{
{
if (numImages >= size) {
size += 16;
images = (CairoImage **) greallocn (images, size, sizeof (CairoImage *));
@ -3491,10 +3491,10 @@ void CairoImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
setCairo (cr);
cairo_translate (cr, 0, height);
cairo_scale (cr, width, -height);
CairoOutputDev::drawImage(state, ref, str, width, height, colorMap, interpolate, maskColors, inlineImg);
image->setImage (surface);
setCairo (nullptr);
cairo_surface_destroy (surface);
cairo_destroy (cr);
@ -3526,11 +3526,11 @@ void CairoImageOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stre
setCairo (cr);
cairo_translate (cr, 0, height);
cairo_scale (cr, width, -height);
CairoOutputDev::drawSoftMaskedImage(state, ref, str, width, height, colorMap, interpolate,
maskStr, maskWidth, maskHeight, maskColorMap, maskInterpolate);
image->setImage (surface);
setCairo (nullptr);
cairo_surface_destroy (surface);
cairo_destroy (cr);
@ -3561,11 +3561,11 @@ void CairoImageOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *
setCairo (cr);
cairo_translate (cr, 0, height);
cairo_scale (cr, width, -height);
CairoOutputDev::drawMaskedImage(state, ref, str, width, height, colorMap, interpolate,
maskStr, maskWidth, maskHeight, maskInvert, maskInterpolate);
image->setImage (surface);
setCairo (nullptr);
cairo_surface_destroy (surface);
cairo_destroy (cr);

View File

@ -18,12 +18,13 @@
// Copyright (C) 2005, 2006 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2005 Nickolay V. Shmyrev <nshmyrev@yandex.ru>
// Copyright (C) 2006-2011, 2013 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2008, 2009, 2011-2016 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2008, 2009, 2011-2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2008 Michael Vrable <mvrable@cs.ucsd.edu>
// Copyright (C) 2010-2013 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2015 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
// Copyright (C) 2016 Jason Crain <jason@aquaticape.us>
// Copyright (C) 2018 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. 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
@ -191,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,
@ -269,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; }
@ -335,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;
@ -359,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 {

View File

@ -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);
////////////////////////////////////////////////////
/*

View File

@ -634,7 +634,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 +758,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
}
if(ctu)
ctu->decRefCnt();
((CharCodeToUnicode *)ctu)->decRefCnt();
}
/*

View File

@ -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<LinkGoTo*>(action);
auto * real_action = dynamic_cast<const LinkGoTo*>(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<LinkURI*>(action);
auto * real_action = dynamic_cast<const LinkURI*>(action);
assert(real_action != nullptr);
dest_str = real_action->getURI()->getCString();
}

View File

@ -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;