File xpdf-3.02-print-ext-ttf.dif of Package xpdf

diff -ur xpdf-orig/xpdf/PSOutputDev.cc xpdf-3.02/xpdf/PSOutputDev.cc
--- xpdf/PSOutputDev.cc	2007-02-27 23:05:52.000000000 +0100
+++ xpdf/PSOutputDev.cc	2007-08-06 13:47:29.000000000 +0200
@@ -1098,6 +1098,7 @@
   fontFileNameSize = 64;
   fontFileNameLen = 0;
   fontFileNames = (GString **)gmallocn(fontFileNameSize, sizeof(GString *));
+  psFileNames = (GString **)gmallocn(fontFileNameSize, sizeof(GString *));
   nextTrueTypeNum = 0;
   font8InfoLen = 0;
   font8InfoSize = 0;
@@ -1194,6 +1195,13 @@
     }
     gfree(font8Info);
   }
+  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;
@@ -1571,6 +1579,7 @@
   double w1, w2;
   double *fm;
   int i, j;
+  DisplayFontParam *dfp;
 
   // check if font is already set up
   for (i = 0; i < fontIDLen; ++i) {
@@ -1640,8 +1649,7 @@
   } 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() &&
@@ -1672,6 +1680,12 @@
 			     font->getID()->num, font->getID()->gen);
     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(), gTrue);
+
   // do 8-bit font substitution
   } else if (!font->isCIDFont()) {
     subst = gTrue;
@@ -1753,6 +1767,15 @@
 	    font16Enc[font16EncLen].enc->getCString());
     }
 
+  // try the display font for embedding
+  } else if (globalParams->getPSEmbedCIDTrueType() &&
+	     ((GfxCIDFont *)font)->getCollection() &&
+	     (dfp = globalParams->
+	      getDisplayCIDFont(font->getName(),
+				((GfxCIDFont *)font)->getCollection())) &&
+	     dfp->kind == displayFontTT) {
+    psName = setupExternalCIDTrueTypeFont(font, dfp->tt.fileName, gTrue, 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)",
@@ -1961,8 +1984,12 @@
     fontFileNameSize += 64;
     fontFileNames = (GString **)greallocn(fontFileNames,
 					  fontFileNameSize, sizeof(GString *));
+    psFileNames = (GString **)greallocn(psFileNames,
+				       fontFileNameSize, sizeof(GString *));
   }
-  fontFileNames[fontFileNameLen++] = fileName->copy();
+  fontFileNames[fontFileNameLen] = fileName->copy();
+  psFileNames[fontFileNameLen] = psName->copy();
+  fontFileNameLen++;
 
   // beginning comment
   writePSFmt("%%BeginResource: font {0:t}\n", psName);
@@ -2126,23 +2153,24 @@
   writePS("%%EndResource\n");
 }
 
-void PSOutputDev::setupExternalTrueTypeFont(GfxFont *font, GString *psName) {
+GString *PSOutputDev::setupExternalTrueTypeFont(GfxFont *font) {
   GString *fileName;
   char *fontBuf;
   int fontLen;
   FoFiTrueType *ffTT;
   Gushort *codeToGID;
+  GString *psName;
   int i;
 
   // check if font is already embedded
   fileName = font->getExtFontFile();
   for (i = 0; i < fontFileNameLen; ++i) {
     if (!fontFileNames[i]->cmp(fileName)) {
-      psName->appendf("_{0:d}", nextTrueTypeNum++);
-      break;
+      return psFileNames[i]->copy();
     }
   }
 
+  psName = filterPSName(font->getName());
   // add entry to fontFileNames list
   if (i == fontFileNameLen) {
     if (fontFileNameLen >= fontFileNameSize) {
@@ -2150,8 +2178,13 @@
       fontFileNames =
 	(GString **)greallocn(fontFileNames,
 			      fontFileNameSize, sizeof(GString *));
-    }
-    fontFileNames[fontFileNameLen++] = fileName->copy();
+      psFileNames =
+	(GString **)greallocn(psFileNames,
+			     fontFileNameSize, sizeof(GString *));
+    }
+    fontFileNames[fontFileNameLen] = fileName->copy();
+    psFileNames[fontFileNameLen] = psName->copy();
+    fontFileNameLen++;
   }
 
   // beginning comment
@@ -2186,6 +2219,82 @@
 
   // ending comment
   writePS("%%EndResource\n");
+  return psName;
+}
+
+GString *PSOutputDev::setupExternalCIDTrueTypeFont(GfxFont *font, GString *fileName, GBool needVerticalMetrics, int faceIndex) {
+  char *fontBuf;
+  int fontLen;
+  FoFiTrueType *ffTT;
+  Gushort *codeToGID;
+  GString *psName;
+  int i;
+  GString *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 =
+	(GString **)grealloc(fontFileNames,
+			     fontFileNameSize * sizeof(GString *));
+      psFileNames =
+	(GString **)grealloc(psFileNames,
+			     fontFileNameSize * sizeof(GString *));
+    }
+  }
+  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, needVerticalMetrics,
+				outputFunc, outputStream);
+      } else {
+	// otherwise: use a non-CID composite font
+	ffTT->convertToType0(psName->getCString(),
+			     codeToGID, n, needVerticalMetrics,
+			     outputFunc, outputStream);
+      }
+      gfree(codeToGID);
+      delete ffTT;
+  }
+
+  // ending comment
+  writePS("%%EndResource\n");
+  return psName;
 }
 
 void PSOutputDev::setupEmbeddedCIDType0Font(GfxFont *font, Ref *id,
diff -ur xpdf-orig/xpdf/PSOutputDev.h xpdf-3.02/xpdf/PSOutputDev.h
--- xpdf/PSOutputDev.h	2007-02-27 23:05:52.000000000 +0100
+++ xpdf/PSOutputDev.h	2007-08-06 13:45:01.000000000 +0200
@@ -256,12 +256,13 @@
   void setupEmbeddedType1CFont(GfxFont *font, Ref *id, GString *psName);
   void setupEmbeddedOpenTypeT1CFont(GfxFont *font, Ref *id, GString *psName);
   void setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GString *psName);
-  void setupExternalTrueTypeFont(GfxFont *font, GString *psName);
+  GString *setupExternalTrueTypeFont(GfxFont *font);
   void setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GString *psName);
   void setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GString *psName,
 				    GBool needVerticalMetrics);
   void setupEmbeddedOpenTypeCFFFont(GfxFont *font, Ref *id, GString *psName);
   void setupType3Font(GfxFont *font, GString *psName, Dict *parentResDict);
+  GString *setupExternalCIDTrueTypeFont(GfxFont *font, GString *fileName, GBool needVerticalMetrics, int faceIndex=0);
   void setupImages(Dict *resDict);
   void setupImage(Ref id, Stream *str);
   void setupForms(Dict *resDict);
@@ -332,6 +333,7 @@
   int fontFileIDLen;		// number of entries in fontFileIDs array
   int fontFileIDSize;		// size of fontFileIDs array
   GString **fontFileNames;	// list of names of all embedded external fonts
+  GString **psFileNames;	// list of names of all embedded external ps names
   int fontFileNameLen;		// number of entries in fontFileNames array
   int fontFileNameSize;		// size of fontFileNames array
   int nextTrueTypeNum;		// next unique number to append to a TrueType
openSUSE Build Service is sponsored by