Commit 86bf1b3d authored by Enrico Ros's avatar Enrico Ros
Browse files

applying patch_045,046

svn path=/branches/kpdf/annotations/kdegraphics/kpdf/; revision=424907
parent 2f3f5cca
......@@ -598,7 +598,7 @@ void Part::slotNewConfig()
// changed before applying changes.
// Watch File
bool watchFile = Settings::watchFile();
bool watchFile = Settings::watchFile();
if ( watchFile && m_watcher->isStopped() )
m_watcher->startScan();
if ( !watchFile && !m_watcher->isStopped() )
......
......@@ -233,10 +233,10 @@ static const char *macGlyphNames[258] = {
// FoFiTrueType
//------------------------------------------------------------------------
FoFiTrueType *FoFiTrueType::make(char *fileA, int lenA) {
FoFiTrueType *FoFiTrueType::make(char *fileA, int lenA, int faceIndexA) {
FoFiTrueType *ff;
ff = new FoFiTrueType(fileA, lenA, gFalse);
ff = new FoFiTrueType(fileA, lenA, gFalse, faceIndexA);
if (!ff->parsedOk) {
delete ff;
return NULL;
......@@ -244,7 +244,7 @@ FoFiTrueType *FoFiTrueType::make(char *fileA, int lenA) {
return ff;
}
FoFiTrueType *FoFiTrueType::load(char *fileName) {
FoFiTrueType *FoFiTrueType::load(char *fileName, int faceIndexA) {
FoFiTrueType *ff;
char *fileA;
int lenA;
......@@ -252,7 +252,7 @@ FoFiTrueType *FoFiTrueType::load(char *fileName) {
if (!(fileA = FoFiBase::readFile(fileName, &lenA))) {
return NULL;
}
ff = new FoFiTrueType(fileA, lenA, gTrue);
ff = new FoFiTrueType(fileA, lenA, gTrue, faceIndexA);
if (!ff->parsedOk) {
delete ff;
return NULL;
......@@ -260,7 +260,7 @@ FoFiTrueType *FoFiTrueType::load(char *fileName) {
return ff;
}
FoFiTrueType::FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA):
FoFiTrueType::FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA, int faceIndexA):
FoFiBase(fileA, lenA, freeFileDataA)
{
tables = NULL;
......@@ -269,6 +269,7 @@ FoFiTrueType::FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA):
nCmaps = 0;
nameToGID = NULL;
parsedOk = gFalse;
faceIndex = faceIndexA;
parse();
}
......@@ -1262,18 +1263,47 @@ Guint FoFiTrueType::computeTableChecksum(Guchar *data, int length) {
return checksum;
}
#define toTag(a,b,c,d) (((unsigned int)(a)<<24) | ((unsigned int)(b)<<16) | ((unsigned int)(c)<<8) | (d))
void FoFiTrueType::parse() {
int pos, i, j;
unsigned int head;
parsedOk = gTrue;
pos = 0;
// read the table directory
nTables = getU16BE(4, &parsedOk);
head = getU32BE(pos, &parsedOk);
if (! parsedOk)
return;
if (head == toTag('t','t','c','f')) {
/* TTC font */
// unsigned int tableDir;
int dircount;
dircount = getU32BE(8, &parsedOk);
if (!parsedOk)
return;
if (! dircount) {
parsedOk = gFalse;
return;
}
if (faceIndex >= dircount)
faceIndex = 0;
pos = getU32BE(12 + faceIndex * 4, &parsedOk);
if (! parsedOk)
return;
}
pos += 4;
nTables = getU16BE(pos, &parsedOk);
if (!parsedOk) {
return;
}
pos += 8;
tables = (TrueTypeTable *)gmalloc(nTables * sizeof(TrueTypeTable));
pos = 12;
for (i = 0; i < nTables; ++i) {
tables[i].tag = getU32BE(pos, &parsedOk);
tables[i].checksum = getU32BE(pos + 4, &parsedOk);
......
......@@ -30,11 +30,12 @@ class FoFiTrueType: public FoFiBase {
public:
// Create a FoFiTrueType object from a memory buffer.
static FoFiTrueType *make(char *fileA, int lenA);
static FoFiTrueType *make(char *fileA, int lenA, int faceIndexA=0);
// Create a FoFiTrueType object from a file on disk.
static FoFiTrueType *load(char *fileName);
static FoFiTrueType *load(char *fileName, int faceIndexA=0);
FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA, int faceIndexA=0);
virtual ~FoFiTrueType();
// Return the number of cmaps defined by this font.
......@@ -100,7 +101,6 @@ public:
private:
FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA);
void cvtEncoding(const char **encoding,
FoFiOutputFunc outputFunc,
void *outputStream);
......@@ -128,6 +128,7 @@ private:
GHash *nameToGID;
GBool parsedOk;
int faceIndex;
};
#endif
......@@ -135,6 +135,7 @@ public:
// Create a FoFiType1C object from a file on disk.
static FoFiType1C *load(char *fileName);
FoFiType1C(char *fileA, int lenA, GBool freeFileDataA);
virtual ~FoFiType1C();
// Return the font name.
......@@ -170,7 +171,6 @@ public:
private:
FoFiType1C(char *fileA, int lenA, GBool freeFileDataA);
void eexecCvtGlyph(Type1CEexecBuf *eb, const char *glyphName,
int offset, int nBytes,
Type1CIndex *subrIdx,
......
......@@ -53,9 +53,9 @@ static int gMemAlloc = 0;
#endif /* DEBUG_MEM */
void *gmalloc(int size) {
void *gmalloc(size_t size) {
#ifdef DEBUG_MEM
int size1;
size_t size1;
char *mem;
GMemHdr *hdr;
void *data;
......@@ -94,11 +94,11 @@ void *gmalloc(int size) {
#endif
}
void *grealloc(void *p, int size) {
void *grealloc(void *p, size_t size) {
#ifdef DEBUG_MEM
GMemHdr *hdr;
void *q;
int oldSize;
size_t oldSize;
if (size == 0) {
if (p)
......@@ -137,7 +137,7 @@ void *grealloc(void *p, int size) {
void gfree(void *p) {
#ifdef DEBUG_MEM
int size;
size_t size;
GMemHdr *hdr;
GMemHdr *prevHdr, *q;
int lst;
......
......@@ -19,13 +19,13 @@ extern "C" {
* Same as malloc, but prints error message and exits if malloc()
* returns NULL.
*/
extern void *gmalloc(int size);
extern void *gmalloc(size_t size);
/*
* Same as realloc, but prints error message and exits if realloc()
* returns NULL. If <p> is NULL, calls malloc instead of realloc().
*/
extern void *grealloc(void *p, int size);
extern void *grealloc(void *p, size_t size);
/*
* Same as free, but checks for and ignores NULL pointers.
......
......@@ -219,7 +219,7 @@ SplashPath *SplashFTFont::getGlyphPath(int c) {
} else {
gid = (FT_UInt)c;
}
if (FT_Load_Glyph(ff->face, gid, FT_LOAD_DEFAULT)) {
if (FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP)) {
return NULL;
}
if (FT_Get_Glyph(slot, &glyph)) {
......
......@@ -58,22 +58,19 @@ SplashFTFontEngine::~SplashFTFontEngine() {
}
SplashFontFile *SplashFTFontEngine::loadType1Font(SplashFontFileID *idA,
char *fileName,
GBool deleteFile,
SplashFontSrc *src,
const char **enc) {
return SplashFTFontFile::loadType1Font(this, idA, fileName, deleteFile, enc);
return SplashFTFontFile::loadType1Font(this, idA, src, enc);
}
SplashFontFile *SplashFTFontEngine::loadType1CFont(SplashFontFileID *idA,
char *fileName,
GBool deleteFile,
SplashFontSrc *src,
const char **enc) {
return SplashFTFontFile::loadType1Font(this, idA, fileName, deleteFile, enc);
return SplashFTFontFile::loadType1Font(this, idA, src, enc);
}
SplashFontFile *SplashFTFontEngine::loadCIDFont(SplashFontFileID *idA,
char *fileName,
GBool deleteFile) {
SplashFontSrc *src) {
Gushort *cidToGIDMap;
int nCIDs;
SplashFontFile *ret;
......@@ -81,7 +78,12 @@ SplashFontFile *SplashFTFontEngine::loadCIDFont(SplashFontFileID *idA,
// check for a CFF font
#if HAVE_FREETYPE_217_OR_OLDER
FoFiType1C *ff;
if ((ff = FoFiType1C::load(fileName))) {
if (src->isFile) {
ff = FoFiType1C::load(src->fileName->getCString());
} else {
ff = new FoFiType1C(src->buf, src->bufLen, gFalse);
}
if (ff) {
cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
delete ff;
} else {
......@@ -93,8 +95,7 @@ SplashFontFile *SplashFTFontEngine::loadCIDFont(SplashFontFileID *idA,
cidToGIDMap = NULL;
nCIDs = 0;
#endif
ret = SplashFTFontFile::loadCIDFont(this, idA, fileName, deleteFile,
cidToGIDMap, nCIDs);
ret = SplashFTFontFile::loadCIDFont(this, idA, src, cidToGIDMap, nCIDs);
if (!ret) {
gfree(cidToGIDMap);
}
......@@ -102,16 +103,17 @@ SplashFontFile *SplashFTFontEngine::loadCIDFont(SplashFontFileID *idA,
}
SplashFontFile *SplashFTFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
char *fileName,
GBool deleteFile,
SplashFontSrc *src,
Gushort *codeToGID,
int codeToGIDLen) {
int codeToGIDLen,
int faceIndex) {
#if 0
FoFiTrueType *ff;
GString *tmpFileName;
FILE *tmpFile;
SplashFontFile *ret;
if (!(ff = FoFiTrueType::load(fileName))) {
if (!(ff = FoFiTrueType::load(fileName, faceIndex))) {
return NULL;
}
tmpFileName = NULL;
......@@ -124,7 +126,8 @@ SplashFontFile *SplashFTFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
fclose(tmpFile);
ret = SplashFTFontFile::loadTrueTypeFont(this, idA,
tmpFileName->getCString(),
gTrue, codeToGID, codeToGIDLen);
gTrue, codeToGID, codeToGIDLen,
faceIndex);
if (ret) {
if (deleteFile) {
unlink(fileName);
......@@ -134,6 +137,13 @@ SplashFontFile *SplashFTFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
}
delete tmpFileName;
return ret;
#else
SplashFontFile *ret;
ret = SplashFTFontFile::loadTrueTypeFont(this, idA, src,
codeToGID, codeToGIDLen,
faceIndex);
return ret;
#endif
}
#endif // HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
......@@ -21,6 +21,7 @@
class SplashFontFile;
class SplashFontFileID;
class SplashFontSrc;
//------------------------------------------------------------------------
// SplashFTFontEngine
......@@ -34,15 +35,12 @@ public:
~SplashFTFontEngine();
// Load fonts.
SplashFontFile *loadType1Font(SplashFontFileID *idA, char *fileName,
GBool deleteFile, const char **enc);
SplashFontFile *loadType1CFont(SplashFontFileID *idA, char *fileName,
GBool deleteFile, const char **enc);
SplashFontFile *loadCIDFont(SplashFontFileID *idA, char *fileName,
GBool deleteFile);
SplashFontFile *loadTrueTypeFont(SplashFontFileID *idA, char *fileName,
GBool deleteFile,
Gushort *codeToGID, int codeToGIDLen);
SplashFontFile *loadType1Font(SplashFontFileID *idA, SplashFontSrc *src, const char **enc);
SplashFontFile *loadType1CFont(SplashFontFileID *idA, SplashFontSrc *src, const char **enc);
SplashFontFile *loadCIDFont(SplashFontFileID *idA, SplashFontSrc *src);
SplashFontFile *loadTrueTypeFont(SplashFontFileID *idA, SplashFontSrc *src,
Gushort *codeToGID, int codeToGIDLen,
int faceIndex=0);
private:
......
......@@ -16,6 +16,7 @@
#include "SplashFTFontEngine.h"
#include "SplashFTFont.h"
#include "SplashFTFontFile.h"
#include "GString.h"
//------------------------------------------------------------------------
// SplashFTFontFile
......@@ -23,16 +24,19 @@
SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA,
SplashFontFileID *idA,
char *fileNameA,
GBool deleteFileA,
SplashFontSrc *src,
const char **encA) {
FT_Face faceA;
Gushort *codeToGIDA;
const char *name;
int i;
if (FT_New_Face(engineA->lib, fileNameA, 0, &faceA)) {
return NULL;
if (src->isFile) {
if (FT_New_Face(engineA->lib, src->fileName->getCString(), 0, &faceA))
return NULL;
} else {
if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, 0, &faceA))
return NULL;
}
codeToGIDA = (Gushort *)gmalloc(256 * sizeof(int));
for (i = 0; i < 256; ++i) {
......@@ -42,48 +46,55 @@ SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA,
}
}
return new SplashFTFontFile(engineA, idA, fileNameA, deleteFileA,
return new SplashFTFontFile(engineA, idA, src,
faceA, codeToGIDA, 256);
}
SplashFontFile *SplashFTFontFile::loadCIDFont(SplashFTFontEngine *engineA,
SplashFontFileID *idA,
char *fileNameA,
GBool deleteFileA,
SplashFontSrc *src,
Gushort *codeToGIDA,
int codeToGIDLenA) {
FT_Face faceA;
if (FT_New_Face(engineA->lib, fileNameA, 0, &faceA)) {
return NULL;
if (src->isFile) {
if (FT_New_Face(engineA->lib, src->fileName->getCString(), 0, &faceA))
return NULL;
} else {
if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, 0, &faceA))
return NULL;
}
return new SplashFTFontFile(engineA, idA, fileNameA, deleteFileA,
return new SplashFTFontFile(engineA, idA, src,
faceA, codeToGIDA, codeToGIDLenA);
}
SplashFontFile *SplashFTFontFile::loadTrueTypeFont(SplashFTFontEngine *engineA,
SplashFontFileID *idA,
char *fileNameA,
GBool deleteFileA,
SplashFontSrc *src,
Gushort *codeToGIDA,
int codeToGIDLenA) {
int codeToGIDLenA,
int faceIndexA) {
FT_Face faceA;
if (FT_New_Face(engineA->lib, fileNameA, 0, &faceA)) {
return NULL;
if (src->isFile) {
if (FT_New_Face(engineA->lib, src->fileName->getCString(), faceIndexA, &faceA))
return NULL;
} else {
if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, faceIndexA, &faceA))
return NULL;
}
return new SplashFTFontFile(engineA, idA, fileNameA, deleteFileA,
return new SplashFTFontFile(engineA, idA, src,
faceA, codeToGIDA, codeToGIDLenA);
}
SplashFTFontFile::SplashFTFontFile(SplashFTFontEngine *engineA,
SplashFontFileID *idA,
char *fileNameA, GBool deleteFileA,
SplashFontSrc *srcA,
FT_Face faceA,
Gushort *codeToGIDA, int codeToGIDLenA):
SplashFontFile(idA, fileNameA, deleteFileA)
SplashFontFile(idA, srcA)
{
engine = engineA;
face = faceA;
......
......@@ -30,18 +30,18 @@ class SplashFTFontFile: public SplashFontFile {
public:
static SplashFontFile *loadType1Font(SplashFTFontEngine *engineA,
SplashFontFileID *idA, char *fileNameA,
GBool deleteFileA, const char **encA);
SplashFontFileID *idA,
SplashFontSrc *src, const char **encA);
static SplashFontFile *loadCIDFont(SplashFTFontEngine *engineA,
SplashFontFileID *idA, char *fileNameA,
GBool deleteFileA,
SplashFontFileID *idA,
SplashFontSrc *src,
Gushort *codeToCIDA, int codeToGIDLenA);
static SplashFontFile *loadTrueTypeFont(SplashFTFontEngine *engineA,
SplashFontFileID *idA,
char *fileNameA,
GBool deleteFileA,
SplashFontSrc *src,
Gushort *codeToGIDA,
int codeToGIDLenA);
int codeToGIDLenA,
int faceIndexA=0);
virtual ~SplashFTFontFile();
......@@ -53,7 +53,7 @@ private:
SplashFTFontFile(SplashFTFontEngine *engineA,
SplashFontFileID *idA,
char *fileNameA, GBool deleteFileA,
SplashFontSrc *srcA,
FT_Face faceA,
Gushort *codeToGIDA, int codeToGIDLenA);
......
......@@ -105,19 +105,19 @@ SplashFontFile *SplashFontEngine::getFontFile(SplashFontFileID *id) {
}
SplashFontFile *SplashFontEngine::loadType1Font(SplashFontFileID *idA,
char *fileName,
GBool deleteFile, const char **enc) {
SplashFontSrc *src,
const char **enc) {
SplashFontFile *fontFile;
fontFile = NULL;
#if HAVE_T1LIB_H
if (!fontFile && t1Engine) {
fontFile = t1Engine->loadType1Font(idA, fileName, deleteFile, enc);
fontFile = t1Engine->loadType1Font(idA, src, enc);
}
#endif
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
if (!fontFile && ftEngine) {
fontFile = ftEngine->loadType1Font(idA, fileName, deleteFile, enc);
fontFile = ftEngine->loadType1Font(idA, src, enc);
}
#endif
......@@ -125,28 +125,25 @@ SplashFontFile *SplashFontEngine::loadType1Font(SplashFontFileID *idA,
// semantics, this will remove the last link; otherwise it will
// return an error, leaving the file to be deleted later (if
// loadXYZFont failed, the file will always be deleted)
if (deleteFile) {
unlink(fontFile ? fontFile->fileName->getCString() : fileName);
}
src->unref();
return fontFile;
}
SplashFontFile *SplashFontEngine::loadType1CFont(SplashFontFileID *idA,
char *fileName,
GBool deleteFile,
SplashFontSrc *src,
const char **enc) {
SplashFontFile *fontFile;
fontFile = NULL;
#if HAVE_T1LIB_H
if (!fontFile && t1Engine) {
fontFile = t1Engine->loadType1CFont(idA, fileName, deleteFile, enc);
fontFile = t1Engine->loadType1CFont(idA, src, enc);
}
#endif
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
if (!fontFile && ftEngine) {
fontFile = ftEngine->loadType1CFont(idA, fileName, deleteFile, enc);
fontFile = ftEngine->loadType1CFont(idA, src, enc);
}
#endif
......@@ -154,22 +151,19 @@ SplashFontFile *SplashFontEngine::loadType1CFont(SplashFontFileID *idA,
// semantics, this will remove the last link; otherwise it will
// return an error, leaving the file to be deleted later (if
// loadXYZFont failed, the file will always be deleted)
if (deleteFile) {
unlink(fontFile ? fontFile->fileName->getCString() : fileName);
}
src->unref();
return fontFile;
}
SplashFontFile *SplashFontEngine::loadCIDFont(SplashFontFileID *idA,
char *fileName,
GBool deleteFile) {
SplashFontSrc *src) {
SplashFontFile *fontFile;
fontFile = NULL;
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
if (!fontFile && ftEngine) {
fontFile = ftEngine->loadCIDFont(idA, fileName, deleteFile);
fontFile = ftEngine->loadCIDFont(idA, src);
}
#endif
......@@ -177,25 +171,23 @@ SplashFontFile *SplashFontEngine::loadCIDFont(SplashFontFileID *idA,
// semantics, this will remove the last link; otherwise it will
// return an error, leaving the file to be deleted later (if
// loadXYZFont failed, the file will always be deleted)
if (deleteFile) {
unlink(fontFile ? fontFile->fileName->getCString() : fileName);
}
src->unref();
return fontFile;
}
SplashFontFile *SplashFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
char *fileName,
GBool deleteFile,
SplashFontSrc *src,
Gushort *codeToGID,
int codeToGIDLen) {
int codeToGIDLen,
int faceIndex) {
SplashFontFile *fontFile;
fontFile = NULL;
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
if (!fontFile && ftEngine) {
fontFile = ftEngine->loadTrueTypeFont(idA, fileName, deleteFile,
codeToGID, codeToGIDLen);
fontFile = ftEngine->loadTrueTypeFont(idA, src,
codeToGID, codeToGIDLen, faceIndex);
}
#endif
......@@ -207,9 +199,7 @@ SplashFontFile *SplashFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
// semantics, this will remove the last link; otherwise it will
// return an error, leaving the file to be deleted later (if
// loadXYZFont failed, the file will always be deleted)
if (deleteFile) {
unlink(fontFile ? fontFile->fileName->getCString() : fileName);
}
src->unref();
return fontFile;
}
......
......@@ -21,6 +21,7 @@ class SplashDTFontEngine;
class SplashFontFile;
class SplashFontFileID;
class SplashFont;
class SplashFontSrc;
//------------------------------------------------------------------------
......@@ -50,15 +51,12 @@ public:
SplashFontFile *getFontFile(SplashFontFileID *id);