Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

Issue 733 poppler 0.59.0 #738

Open
wants to merge 3 commits into
base: incoming
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 71 additions & 29 deletions 3rdparty/poppler/git/CairoFontEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
// Copyright (C) 2005-2007 Jeff Muizelaar <[email protected]>
// Copyright (C) 2005, 2006 Kristian Høgsberg <[email protected]>
// Copyright (C) 2005 Martin Kretzschmar <[email protected]>
// Copyright (C) 2005, 2009, 2012, 2013 Albert Astals Cid <[email protected]>
// Copyright (C) 2005, 2009, 2012, 2013, 2015, 2017 Albert Astals Cid <[email protected]>
// Copyright (C) 2006, 2007, 2010, 2011 Carlos Garcia Campos <[email protected]>
// Copyright (C) 2007 Koji Otani <[email protected]>
// Copyright (C) 2008, 2009 Chris Wilson <[email protected]>
// Copyright (C) 2008, 2012 Adrian Johnson <[email protected]>
// Copyright (C) 2008, 2012, 2014, 2016 Adrian Johnson <[email protected]>
// Copyright (C) 2009 Darren Kenny <[email protected]>
// Copyright (C) 2010 Suzuki Toshiya <[email protected]>
// Copyright (C) 2010 Jan Kümmel <[email protected]>
// Copyright (C) 2012 Hib Eris <[email protected]>
// Copyright (C) 2013 Thomas Freitag <[email protected]>
// Copyright (C) 2015, 2016 Jason Crain <[email protected]>
//
// 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
Expand Down Expand Up @@ -58,16 +59,11 @@
#pragma implementation
#endif

/*
* pdf2htmlEX: disabled multi thread
#if MULTITHREADED
# define fontEngineLocker() MutexLocker locker(&mutex)
#else
*/
# define fontEngineLocker()
/*
#endif
*/

//------------------------------------------------------------------------
// CairoFont
Expand Down Expand Up @@ -116,7 +112,7 @@ CairoFont::getGlyph(CharCode code,
double
CairoFont::getSubstitutionCorrection(GfxFont *gfxFont)
{
double w1, w2;
double w1, w2, w3;
CharCode code;
char *name;

Expand Down Expand Up @@ -146,7 +142,8 @@ CairoFont::getSubstitutionCorrection(GfxFont *gfxFont)
cairo_font_options_destroy(options);
w2 = extents.x_advance;
}
if (!gfxFont->isSymbolic()) {
w3 = ((Gfx8BitFont *)gfxFont)->getWidth(0);
if (!gfxFont->isSymbolic() && w2 > 0 && w1 > w3) {
// if real font is substantially narrower than substituted
// font, reduce the font size accordingly
if (w1 > 0.01 && w1 < 0.9 * w2) {
Expand Down Expand Up @@ -260,12 +257,16 @@ _ft_done_face (void *closure)
else
_ft_open_faces = data->next;

if (data->fd != -1) {
#if defined(__SUNPRO_CC) && defined(__sun) && defined(__SVR4)
munmap ((char*)data->bytes, data->size);
munmap ((char*)data->bytes, data->size);
#else
munmap (data->bytes, data->size);
munmap (data->bytes, data->size);
#endif
close (data->fd);
close (data->fd);
} else {
gfree (data->bytes);
}

FT_Done_Face (data->face);
gfree (data);
Expand Down Expand Up @@ -322,6 +323,8 @@ _ft_new_face (FT_Library lib,
munmap (tmpl.bytes, tmpl.size);
#endif
close (tmpl.fd);
} else {
gfree (tmpl.bytes);
}
*face_out = l->face;
*font_face_out = cairo_font_face_reference (l->font_face);
Expand Down Expand Up @@ -399,7 +402,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,
GfxFontType fontType;
GfxFontLoc *fontLoc;
char **enc;
char *name;
const char *name;
FoFiTrueType *ff;
FoFiType1C *ff1c;
Ref ref;
Expand All @@ -421,8 +424,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,
ref = *gfxFont->getID();
fontType = gfxFont->getType();

// pdf2htmlEX: changed gFlase to nullptr
if (!(fontLoc = gfxFont->locateFont(xref, nullptr))) {
if (!(fontLoc = gfxFont->locateFont(xref, NULL))) {
error(errSyntaxError, -1, "Couldn't find a font for '{0:s}'",
gfxFont->getName() ? gfxFont->getName()->getCString()
: "(unnamed)");
Expand Down Expand Up @@ -462,7 +464,18 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,
for (i = 0; i < 256; ++i) {
codeToGID[i] = 0;
if ((name = enc[i])) {
codeToGID[i] = FT_Get_Name_Index(face, name);
codeToGID[i] = FT_Get_Name_Index(face, (char*)name);
if (codeToGID[i] == 0) {
Unicode u;
u = globalParams->mapNameToUnicodeText (name);
codeToGID[i] = FT_Get_Char_Index (face, u);
}
if (codeToGID[i] == 0) {
name = GfxFont::getAlternateName(name);
if (name) {
codeToGID[i] = FT_Get_Name_Index(face, (char*)name);
}
}
}
}
break;
Expand Down Expand Up @@ -491,6 +504,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,
codeToGIDLen = n;
/* Fall through */
case fontTrueType:
case fontTrueTypeOT:
if (font_data != NULL) {
ff = FoFiTrueType::make(font_data, font_data_len);
} else {
Expand All @@ -501,7 +515,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,
goto err2;
}
/* This might be set already for the CIDType2 case */
if (fontType == fontTrueType) {
if (fontType == fontTrueType || fontType == fontTrueTypeOT) {
codeToGID = ((Gfx8BitFont *)gfxFont)->getCodeToGIDMap(ff);
codeToGIDLen = 256;
}
Expand Down Expand Up @@ -532,13 +546,45 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,
}

if (! _ft_new_face (lib, fileNameC, font_data, font_data_len, &face, &font_face)) {
gfree(codeToGID);
codeToGID = NULL;
error(errSyntaxError, -1, "could not create cid face\n");
goto err2;
}
break;


case fontCIDType0COT:
codeToGID = NULL;
n = 0;
if (((GfxCIDFont *)gfxFont)->getCIDToGID()) {
n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen();
if (n) {
codeToGID = (int *)gmallocn(n, sizeof(int));
memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(),
n * sizeof(int));
}
}
codeToGIDLen = n;

if (!codeToGID) {
if (!useCIDs) {
if (font_data != NULL) {
ff = FoFiTrueType::make(font_data, font_data_len);
} else {
ff = FoFiTrueType::load(fileNameC);
}
if (ff) {
if (ff->isOpenTypeCFF()) {
codeToGID = ff->getCIDToGIDMap((int *)&codeToGIDLen);
}
delete ff;
}
}
}
if (! _ft_new_face (lib, fileNameC, font_data, font_data_len, &face, &font_face)) {
error(errSyntaxError, -1, "could not create cid (OT) face\n");
goto err2;
}
break;

default:
fprintf (stderr, "font type %d not handled\n", (int)fontType);
goto err2;
Expand All @@ -554,6 +600,8 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref,
err2:
/* hmm? */
delete fontLoc;
gfree (codeToGID);
gfree (font_data);
fprintf (stderr, "some font thing failed\n");
return NULL;
}
Expand Down Expand Up @@ -659,7 +707,8 @@ _render_type3_glyph (cairo_scaled_font_t *scaled_font,
output_dev->startDoc(info->doc, info->fontEngine);
output_dev->startPage (1, gfx->getState(), gfx->getXRef());
output_dev->setInType3Char(gTrue);
gfx->display(charProcs->getVal(glyph, &charProc));
charProc = charProcs->getVal(glyph);
gfx->display(&charProc);

output_dev->getType3GlyphWidth (&wx, &wy);
cairo_matrix_transform_distance (&matrix, &wx, &wy);
Expand All @@ -678,7 +727,6 @@ _render_type3_glyph (cairo_scaled_font_t *scaled_font,

delete gfx;
delete output_dev;
charProc.free();

return CAIRO_STATUS_SUCCESS;
}
Expand Down Expand Up @@ -768,12 +816,9 @@ CairoFontEngine::CairoFontEngine(FT_Library libA) {
FT_Library_Version(lib, &major, &minor, &patch);
useCIDs = major > 2 ||
(major == 2 && (minor > 1 || (minor == 1 && patch > 7)));
/*
* pdf2htmlEX: disabled multi thread
#if MULTITHREADED
gInitMutex(&mutex);
#endif
*/
}

CairoFontEngine::~CairoFontEngine() {
Expand All @@ -783,12 +828,9 @@ CairoFontEngine::~CairoFontEngine() {
if (fontCache[i])
delete fontCache[i];
}
/*
* pdf2htmlEX: disabled multi thread
#if MULTITHREADED
gDestroyMutex(&mutex);
#endif
*/
}

CairoFont *
Expand Down Expand Up @@ -827,4 +869,4 @@ CairoFontEngine::getFont(GfxFont *gfxFont, PDFDoc *doc, GBool printing, XRef *xr
}
fontCache[0] = font;
return font;
}
}
11 changes: 4 additions & 7 deletions 3rdparty/poppler/git/CairoFontEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CairoFont {
class CairoFreeTypeFont : public CairoFont {
public:
static CairoFreeTypeFont *create(GfxFont *gfxFont, XRef *xref, FT_Library lib, GBool useCIDs);
virtual ~CairoFreeTypeFont();
~CairoFreeTypeFont();

private:
CairoFreeTypeFont(Ref ref, cairo_font_face_t *cairo_font_face,
Expand All @@ -88,9 +88,9 @@ class CairoType3Font : public CairoFont {
static CairoType3Font *create(GfxFont *gfxFont, PDFDoc *doc,
CairoFontEngine *fontEngine,
GBool printing, XRef *xref);
virtual ~CairoType3Font();
~CairoType3Font();

virtual GBool matches(Ref &other, GBool printing);
GBool matches(Ref &other, GBool printing) override;

private:
CairoType3Font(Ref ref, PDFDoc *doc,
Expand Down Expand Up @@ -121,12 +121,9 @@ class CairoFontEngine {
CairoFont *fontCache[cairoFontCacheSize];
FT_Library lib;
GBool useCIDs;
/*
* pdf2htmlEX: disabled multi thread
#if MULTITHREADED
GooMutex mutex;
#endif
*/
};

#endif
#endif
Loading