summaryrefslogtreecommitdiff
path: root/poppler
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2006-02-13 22:38:44 +0000
committerAlbert Astals Cid <aacid@kde.org>2006-02-13 22:38:44 +0000
commit0bda90310b267d3a4963096293eb2bd29b120768 (patch)
treeeb27cc42078a8b8c6573cdf6c5ed7a90c76f7a4e /poppler
parentcf9867fbbee2468a955b5845016585eeedf2debe (diff)
Probably the last of inner patches missing from kpdf
Everybody will we happy now, kpdf has been finally assimilated
Diffstat (limited to 'poppler')
-rw-r--r--poppler/PSOutputDev.cc124
-rw-r--r--poppler/PSOutputDev.h4
2 files changed, 118 insertions, 10 deletions
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 5bc5d8f6..b37a5948 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -1040,6 +1040,7 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA,
fontFileNameSize = 64;
fontFileNameLen = 0;
fontFileNames = (GooString **)gmallocn(fontFileNameSize, sizeof(GooString *));
+ psFileNames = (GooString **)gmallocn(fontFileNameSize, sizeof(GooString *));
nextTrueTypeNum = 0;
font16EncLen = 0;
font16EncSize = 0;
@@ -1124,6 +1125,13 @@ PSOutputDev::~PSOutputDev() {
}
gfree(fontFileNames);
}
+ if (psFileNames) {
+ for (i = 0; i < fontFileNameLen; ++i) {
+ if (psFileNames[i])
+ delete psFileNames[i];
+ }
+ gfree(psFileNames);
+ }
if (font16Enc) {
for (i = 0; i < font16EncLen; ++i) {
delete font16Enc[i].enc;
@@ -1491,6 +1499,7 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict) {
double w1, w2;
double *fm;
int i, j;
+ DisplayFontParam *dfp;
// check if font is already set up
for (i = 0; i < fontIDLen; ++i) {
@@ -1548,8 +1557,7 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict) {
} else if (globalParams->getPSEmbedTrueType() &&
font->getType() == fontTrueType &&
font->getExtFontFile()) {
- psName = filterPSName(font->getName());
- setupExternalTrueTypeFont(font, psName);
+ psName = setupExternalTrueTypeFont(font);
// check for embedded CID PostScript font
} else if (globalParams->getPSEmbedCIDPostScript() &&
@@ -1571,6 +1579,12 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict) {
psName = new GooString(type3Name);
setupType3Font(font, psName, parentResDict);
+ // check for external CID TrueType font file
+ } else if (globalParams->getPSEmbedCIDTrueType() &&
+ font->getType() == fontCIDType2 &&
+ font->getExtFontFile()) {
+ psName = setupExternalCIDTrueTypeFont(font, font->getExtFontFile());
+
// do 8-bit font substitution
} else if (!font->isCIDFont()) {
subst = gTrue;
@@ -1652,6 +1666,14 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict) {
font16Enc[font16EncLen].enc->getCString());
}
+ // try the display font for embedding
+ } else if (globalParams->getPSEmbedCIDTrueType() &&
+ ((GfxCIDFont *)font)->getCollection() &&
+ (dfp = globalParams->
+ getDisplayFont(font)) &&
+ dfp->kind == displayFontTT) {
+ psName = setupExternalCIDTrueTypeFont(font, dfp->tt.fileName, dfp->tt.faceIndex);
+
// give up - can't do anything with this font
} else {
error(-1, "Couldn't find a font to substitute for '%s' ('%s' character collection)",
@@ -1861,8 +1883,12 @@ void PSOutputDev::setupExternalType1Font(GooString *fileName, GooString *psName)
fontFileNameSize += 64;
fontFileNames = (GooString **)greallocn(fontFileNames,
fontFileNameSize, sizeof(GooString *));
+ psFileNames = (GooString **)greallocn(psFileNames,
+ fontFileNameSize, sizeof(GooString *));
}
- fontFileNames[fontFileNameLen++] = fileName->copy();
+ fontFileNames[fontFileNameLen] = fileName->copy();
+ psFileNames[fontFileNameLen] = psName->copy();
+ fontFileNameLen++;
// beginning comment
writePSFmt("%%%%BeginResource: font %s\n", psName->getCString());
@@ -1975,25 +2001,24 @@ void PSOutputDev::setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id,
writePS("%%EndResource\n");
}
-void PSOutputDev::setupExternalTrueTypeFont(GfxFont *font, GooString *psName) {
- char unique[32];
+GooString *PSOutputDev::setupExternalTrueTypeFont(GfxFont *font) {
GooString *fileName;
char *fontBuf;
int fontLen;
FoFiTrueType *ffTT;
Gushort *codeToGID;
+ GooString *psName;
int i;
// check if font is already embedded
fileName = font->getExtFontFile();
for (i = 0; i < fontFileNameLen; ++i) {
if (!fontFileNames[i]->cmp(fileName)) {
- sprintf(unique, "_%d", nextTrueTypeNum++);
- psName->append(unique);
- break;
+ return psFileNames[i]->copy();
}
}
+ psName = filterPSName(font->getName());
// add entry to fontFileNames list
if (i == fontFileNameLen) {
if (fontFileNameLen >= fontFileNameSize) {
@@ -2001,9 +2026,14 @@ void PSOutputDev::setupExternalTrueTypeFont(GfxFont *font, GooString *psName) {
fontFileNames =
(GooString **)greallocn(fontFileNames,
fontFileNameSize, sizeof(GooString *));
+ psFileNames =
+ (GooString **)greallocn(psFileNames,
+ fontFileNameSize, sizeof(GooString *));
}
}
- fontFileNames[fontFileNameLen++] = fileName->copy();
+ fontFileNames[fontFileNameLen] = fileName->copy();
+ psFileNames[fontFileNameLen] = psName->copy();
+ fontFileNameLen++;
// beginning comment
writePSFmt("%%%%BeginResource: font %s\n", psName->getCString());
@@ -2026,6 +2056,82 @@ void PSOutputDev::setupExternalTrueTypeFont(GfxFont *font, GooString *psName) {
// ending comment
writePS("%%EndResource\n");
+ return psName;
+}
+
+GooString *PSOutputDev::setupExternalCIDTrueTypeFont(GfxFont *font, GooString *fileName, int faceIndex) {
+// char *fontBuf;
+// int fontLen;
+ FoFiTrueType *ffTT;
+ Gushort *codeToGID;
+ GooString *psName;
+ int i;
+ GooString *myFileName;
+
+ myFileName = fileName->copy();
+ if (faceIndex > 0) {
+ char tmp[32];
+ sprintf(tmp, ",%d", faceIndex);
+ myFileName->append(tmp);
+ }
+ // check if font is already embedded
+ for (i = 0; i < fontFileNameLen; ++i) {
+ if (!fontFileNames[i]->cmp(myFileName)) {
+ delete myFileName;
+ return psFileNames[i]->copy();
+ }
+ }
+
+ psName = filterPSName(font->getName());
+ // add entry to fontFileNames list
+ if (i == fontFileNameLen) {
+ if (fontFileNameLen >= fontFileNameSize) {
+ fontFileNameSize += 64;
+ fontFileNames =
+ (GooString **)grealloc(fontFileNames,
+ fontFileNameSize * sizeof(GooString *));
+ psFileNames =
+ (GooString **)grealloc(psFileNames,
+ fontFileNameSize * sizeof(GooString *));
+ }
+ }
+ fontFileNames[fontFileNameLen] = myFileName;
+ psFileNames[fontFileNameLen] = psName->copy();
+ fontFileNameLen++;
+
+ // beginning comment
+ writePSFmt("%%%%BeginResource: font %s\n", psName->getCString());
+ embFontList->append("%%+ font ");
+ embFontList->append(psName->getCString());
+ embFontList->append("\n");
+
+ // convert it to a CID type2 font
+ if ((ffTT = FoFiTrueType::load(fileName->getCString(), faceIndex))) {
+ int n = ((GfxCIDFont *)font)->getCIDToGIDLen();
+ if (n) {
+ codeToGID = (Gushort *)gmalloc(n * sizeof(Gushort));
+ memcpy(codeToGID, ((GfxCIDFont *)font)->getCIDToGID(), n * sizeof(Gushort));
+ } else {
+ codeToGID = ((GfxCIDFont *)font)->getCodeToGIDMap(ffTT, &n);
+ }
+ if (globalParams->getPSLevel() >= psLevel3) {
+ // Level 3: use a CID font
+ ffTT->convertToCIDType2(psName->getCString(),
+ codeToGID, n, gTrue,
+ outputFunc, outputStream);
+ } else {
+ // otherwise: use a non-CID composite font
+ ffTT->convertToType0(psName->getCString(),
+ codeToGID, n, gTrue,
+ outputFunc, outputStream);
+ }
+ gfree(codeToGID);
+ delete ffTT;
+ }
+
+ // ending comment
+ writePS("%%EndResource\n");
+ return psName;
}
void PSOutputDev::setupEmbeddedCIDType0Font(GfxFont *font, Ref *id,
diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h
index fad04a26..05c0fc60 100644
--- a/poppler/PSOutputDev.h
+++ b/poppler/PSOutputDev.h
@@ -237,10 +237,11 @@ private:
void setupExternalType1Font(GooString *fileName, GooString *psName);
void setupEmbeddedType1CFont(GfxFont *font, Ref *id, GooString *psName);
void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GooString *psName);
- void setupExternalTrueTypeFont(GfxFont *font, GooString *psName);
+ GooString *setupExternalTrueTypeFont(GfxFont *font);
void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GooString *psName);
void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GooString *psName,
GBool needVerticalMetrics);
+ GooString *setupExternalCIDTrueTypeFont(GfxFont *font, GooString *fileName, int faceIndex = 0);
void setupType3Font(GfxFont *font, GooString *psName, Dict *parentResDict);
void setupImages(Dict *resDict);
void setupImage(Ref id, Stream *str);
@@ -301,6 +302,7 @@ private:
int fontFileIDLen; // number of entries in fontFileIDs array
int fontFileIDSize; // size of fontFileIDs array
GooString **fontFileNames; // list of names of all embedded external fonts
+ GooString **psFileNames; // list of names of all embedded external fonts
int fontFileNameLen; // number of entries in fontFileNames array
int fontFileNameSize; // size of fontFileNames array
int nextTrueTypeNum; // next unique number to append to a TrueType