summaryrefslogtreecommitdiff
path: root/poppler
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2006-02-02 22:50:01 +0000
committerAlbert Astals Cid <aacid@kde.org>2006-02-02 22:50:01 +0000
commit1ddeed60d07c3a7e011f3f594fa9299379d0b000 (patch)
tree7e344cb8130bb7146205d05859783f05119e84b5 /poppler
parent34df4cfa5cd8788ccf2ea698cbedd05b209041f5 (diff)
don't use files to pass fonts to freetype
Diffstat (limited to 'poppler')
-rw-r--r--poppler/GfxFont.cc49
-rw-r--r--poppler/GfxFont.h2
-rw-r--r--poppler/GlobalParams.cc1
-rw-r--r--poppler/GlobalParams.h1
-rw-r--r--poppler/SplashOutputDev.cc94
5 files changed, 99 insertions, 48 deletions
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 39f00301..962c140b 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -361,7 +361,7 @@ CharCodeToUnicode *GfxFont::readToUnicodeCMap(Dict *fontDict, int nBits,
void GfxFont::findExtFontFile() {
static char *type1Exts[] = { ".pfa", ".pfb", ".ps", "", NULL };
- static char *ttExts[] = { ".ttf", NULL };
+ static char *ttExts[] = { ".ttf", ".ttc", NULL };
if (name) {
if (type == fontType1) {
@@ -1522,6 +1522,53 @@ GooString *GfxCIDFont::getCollection() {
return cMap ? cMap->getCollection() : (GooString *)NULL;
}
+Gushort *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *mapsizep) {
+ Gushort *map;
+ int cmapPlatform, cmapEncoding;
+ int unicodeCmap, macRomanCmap, msSymbolCmap, cmap;
+ GBool useMacRoman, useUnicode;
+ char *charName;
+ Unicode u;
+ int code, i;
+ int mapsize;
+ int cidlen;
+
+ *mapsizep = 0;
+
+ /* we use only unicode cmap */
+ cmap = -1;
+ for (i = 0; i < ff->getNumCmaps(); ++i) {
+ cmapPlatform = ff->getCmapPlatform(i);
+ cmapEncoding = ff->getCmapEncoding(i);
+ if ((cmapPlatform == 3 && cmapEncoding == 1) || cmapPlatform == 0)
+ cmap = i;
+ }
+ if (cmap < 0)
+ return NULL;
+
+ cidlen = 0;
+ mapsize = 64;
+ map = (Gushort *)gmalloc(mapsize * sizeof(Gushort));
+
+ while (cidlen < ctu->getLength()) {
+ int n;
+ if ((n = ctu->mapToUnicode((CharCode)cidlen, &u, 1)) == 0) {
+ cidlen++;
+ continue;
+ }
+ if (cidlen >= mapsize) {
+ while (cidlen >= mapsize)
+ mapsize *= 2;
+ map = (Gushort *)grealloc(map, mapsize * sizeof(Gushort));
+ }
+ map[cidlen] = ff->mapCodeToGID(cmap, u);
+ cidlen++;
+ }
+
+ *mapsizep = cidlen;
+ return map;
+}
+
//------------------------------------------------------------------------
// GfxFontDict
//------------------------------------------------------------------------
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index 5e6eb09f..15d1b9ae 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -310,6 +310,8 @@ public:
Gushort *getCIDToGID() { return cidToGID; }
int getCIDToGIDLen() { return cidToGIDLen; }
+ Gushort *getCodeToGIDMap(FoFiTrueType *ff, int *length);
+
private:
CMap *cMap; // char code --> CID
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index df4c04ca..45f2b6d7 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -1278,6 +1278,7 @@ DisplayFontParam *GlobalParams::getDisplayFont(GfxFont *font) {
{
dfp = new DisplayFontParam(fontName->copy(), displayFontTT);
dfp->tt.fileName = new GooString((char*)s);
+ FcPatternGetInteger(m, FC_INDEX, 0, &(dfp->tt.faceIndex));
}
else if (!strncasecmp(ext,".pfa",4) || !strncasecmp(ext,".pfb",4))
{
diff --git a/poppler/GlobalParams.h b/poppler/GlobalParams.h
index 9418df7a..8c30dffc 100644
--- a/poppler/GlobalParams.h
+++ b/poppler/GlobalParams.h
@@ -55,6 +55,7 @@ struct DisplayFontParamT1 {
struct DisplayFontParamTT {
GooString *fileName;
+ int faceIndex;
};
class DisplayFontParam {
diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc
index 171d72aa..5dcb614d 100644
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -941,10 +941,13 @@ void SplashOutputDev::updateFont(GfxState *state) {
GfxFontType fontType;
SplashOutFontFileID *id;
SplashFontFile *fontFile;
+ SplashFontSrc *fontsrc;
FoFiTrueType *ff;
Ref embRef;
Object refObj, strObj;
- GooString *tmpFileName, *fileName, *substName;
+ GooString *fileName, *substName;
+ char *tmpBuf;
+ int tmpBufLen;
FILE *tmpFile;
Gushort *codeToGID;
DisplayFontParam *dfp;
@@ -954,10 +957,12 @@ void SplashOutputDev::updateFont(GfxState *state) {
char *name;
Unicode uBuf[8];
int c, substIdx, n, code, cmap;
+ int faceIndex = 0;
needFontUpdate = gFalse;
font = NULL;
- tmpFileName = NULL;
+ fileName = NULL;
+ tmpBuf = NULL;
substIdx = -1;
dfp = NULL;
@@ -978,22 +983,9 @@ void SplashOutputDev::updateFont(GfxState *state) {
// if there is an embedded font, write it to disk
if (gfxFont->getEmbeddedFontID(&embRef)) {
- if (!openTempFile(&tmpFileName, &tmpFile, "wb", NULL)) {
- error(-1, "Couldn't create temporary font file");
+ tmpBuf = gfxFont->readEmbFontFile(xref, &tmpBufLen);
+ if (! tmpBuf)
goto err2;
- }
- refObj.initRef(embRef.num, embRef.gen);
- refObj.fetch(xref, &strObj);
- refObj.free();
- strObj.streamReset();
- while ((c = strObj.streamGetChar()) != EOF) {
- fputc(c, tmpFile);
- }
- strObj.streamClose();
- strObj.free();
- fclose(tmpFile);
- fileName = tmpFileName;
-
// if there is an external font file, use it
} else if (!(fileName = gfxFont->getExtFontFile())) {
@@ -1016,18 +1008,23 @@ void SplashOutputDev::updateFont(GfxState *state) {
case displayFontTT:
fileName = dfp->tt.fileName;
fontType = gfxFont->isCIDFont() ? fontCIDType2 : fontTrueType;
+ faceIndex = dfp->tt.faceIndex;
break;
}
}
+ fontsrc = new SplashFontSrc;
+ if (fileName)
+ fontsrc->setFile(fileName, gFalse);
+ else
+ fontsrc->setBuf(tmpBuf, tmpBufLen, gFalse);
+
// load the font file
switch (fontType) {
case fontType1:
- if (!(fontFile = fontEngine->loadType1Font(
- id,
- fileName->getCString(),
- fileName == tmpFileName,
- ((Gfx8BitFont *)gfxFont)->getEncoding()))) {
+ fontFile = fontEngine->loadType1Font(id, fontsrc,
+ ((Gfx8BitFont *)gfxFont)->getEncoding());
+ if (! fontFile) {
error(-1, "Couldn't create a font for '%s'",
gfxFont->getName() ? gfxFont->getName()->getCString()
: "(unnamed)");
@@ -1035,11 +1032,9 @@ void SplashOutputDev::updateFont(GfxState *state) {
}
break;
case fontType1C:
- if (!(fontFile = fontEngine->loadType1CFont(
- id,
- fileName->getCString(),
- fileName == tmpFileName,
- ((Gfx8BitFont *)gfxFont)->getEncoding()))) {
+ fontFile = fontEngine->loadType1CFont(id, fontsrc,
+ ((Gfx8BitFont *)gfxFont)->getEncoding());
+ if (! fontFile) {
error(-1, "Couldn't create a font for '%s'",
gfxFont->getName() ? gfxFont->getName()->getCString()
: "(unnamed)");
@@ -1047,7 +1042,8 @@ void SplashOutputDev::updateFont(GfxState *state) {
}
break;
case fontTrueType:
- if ((ff = FoFiTrueType::load(fileName->getCString()))) {
+ if ((ff = FoFiTrueType::load(fileName->getCString())) ||
+ (ff = new FoFiTrueType(tmpBuf, tmpBufLen, gFalse))) {
codeToGID = ((Gfx8BitFont *)gfxFont)->getCodeToGIDMap(ff);
n = 256;
delete ff;
@@ -1057,8 +1053,7 @@ void SplashOutputDev::updateFont(GfxState *state) {
}
if (!(fontFile = fontEngine->loadTrueTypeFont(
id,
- fileName->getCString(),
- fileName == tmpFileName,
+ fontsrc,
codeToGID, n))) {
error(-1, "Couldn't create a font for '%s'",
gfxFont->getName() ? gfxFont->getName()->getCString()
@@ -1068,10 +1063,8 @@ void SplashOutputDev::updateFont(GfxState *state) {
break;
case fontCIDType0:
case fontCIDType0C:
- if (!(fontFile = fontEngine->loadCIDFont(
- id,
- fileName->getCString(),
- fileName == tmpFileName))) {
+ fontFile = fontEngine->loadCIDFont(id, fontsrc);
+ if (! fontFile) {
error(-1, "Couldn't create a font for '%s'",
gfxFont->getName() ? gfxFont->getName()->getCString()
: "(unnamed)");
@@ -1084,7 +1077,8 @@ void SplashOutputDev::updateFont(GfxState *state) {
if (dfp) {
// create a CID-to-GID mapping, via Unicode
if ((ctu = ((GfxCIDFont *)gfxFont)->getToUnicode())) {
- if ((ff = FoFiTrueType::load(fileName->getCString()))) {
+ if ((ff = FoFiTrueType::load(fileName->getCString())) ||
+ (ff = new FoFiTrueType(tmpBuf, tmpBufLen, gFalse))) {
// look for a Unicode cmap
for (cmap = 0; cmap < ff->getNumCmaps(); ++cmap) {
if ((ff->getCmapPlatform(cmap) == 3 &&
@@ -1116,16 +1110,28 @@ void SplashOutputDev::updateFont(GfxState *state) {
} else {
if (((GfxCIDFont *)gfxFont)->getCIDToGID()) {
n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen();
- codeToGID = (Gushort *)gmallocn(n, sizeof(Gushort));
- memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(),
- n * sizeof(Gushort));
+ if (n) {
+ codeToGID = (Gushort *)gmallocn(n, sizeof(Gushort));
+ memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(),
+ n * sizeof(Gushort));
+ } else {
+ if (fileName)
+ ff = FoFiTrueType::load(fileName->getCString());
+ else
+ ff = new FoFiTrueType(tmpBuf, tmpBufLen, gFalse);
+ if (! ff)
+ goto err2;
+ codeToGID = ((GfxCIDFont *)gfxFont)->getCodeToGIDMap(ff, &n);
+ delete ff;
+ }
}
}
if (!(fontFile = fontEngine->loadTrueTypeFont(
id,
- fileName->getCString(),
- fileName == tmpFileName,
- codeToGID, n))) {
+ fontsrc,
+ codeToGID,
+ n,
+ faceIndex))) {
error(-1, "Couldn't create a font for '%s'",
gfxFont->getName() ? gfxFont->getName()->getCString()
: "(unnamed)");
@@ -1153,17 +1159,11 @@ void SplashOutputDev::updateFont(GfxState *state) {
}
font = fontEngine->getFont(fontFile, mat);
- if (tmpFileName) {
- delete tmpFileName;
- }
return;
err2:
delete id;
err1:
- if (tmpFileName) {
- delete tmpFileName;
- }
return;
}