[poppler] poppler/poppler: PSOutputDev.cc, 1.8, 1.9 PSOutputDev.h, 1.5, 1.6

Albert Astals Cid aacid at freedesktop.org
Mon Feb 13 14:38:47 PST 2006


Update of /cvs/poppler/poppler/poppler
In directory gabe:/tmp/cvs-serv10627/poppler

Modified Files:
	PSOutputDev.cc PSOutputDev.h 
Log Message:
Probably the last of inner patches missing from kpdf
Everybody will we happy now, kpdf has been finally assimilated


Index: PSOutputDev.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/PSOutputDev.cc,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- PSOutputDev.cc	18 Jan 2006 22:32:13 -0000	1.8
+++ PSOutputDev.cc	13 Feb 2006 22:38:44 -0000	1.9
@@ -1040,6 +1040,7 @@
   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 @@
     }
     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 @@
   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 @@
   } 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 @@
     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 @@
 	    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 @@
     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 @@
   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 @@
       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 @@
 
   // 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,

Index: PSOutputDev.h
===================================================================
RCS file: /cvs/poppler/poppler/poppler/PSOutputDev.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- PSOutputDev.h	30 Oct 2005 20:29:05 -0000	1.5
+++ PSOutputDev.h	13 Feb 2006 22:38:44 -0000	1.6
@@ -237,10 +237,11 @@
   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 @@
   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



More information about the poppler mailing list