]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/XOutputDev.cc
Reused eog HIG dialog in GPdf.
[evince.git] / pdf / xpdf / XOutputDev.cc
index 3c58f5650cb44e9fc884a0a52225cd8f1be5cbdb..2100355af0338a8194e38861452d41f8dffe1e7a 100644 (file)
@@ -2,7 +2,7 @@
 //
 // XOutputDev.cc
 //
-// Copyright 1996-2002 Glyph & Cog, LLC
+// Copyright 1996-2003 Glyph & Cog, LLC
 //
 //========================================================================
 
@@ -828,6 +828,7 @@ XOutputFont *XOutputFontCache::getFont(XRef *xref, GfxFont *gfxFont,
     }
 #endif
     break;
+  case fontCIDType0:
   case fontCIDType0C:
 #if FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
     if (freetypeControl != fontRastNone) {
@@ -993,7 +994,7 @@ XOutputFont *XOutputFontCache::tryGetFont(XRef *xref, DisplayFontParam *dfp,
 
   case displayFontT1:
 #if HAVE_T1LIB_H
-    if (t1libControl != fontRastNone) {
+    if (t1libControl != fontRastNone && !gfxFont->isCIDFont()) {
       font = tryGetT1FontFromFile(xref, dfp->t1.fileName, gFalse, gfxFont,
                                  m11Orig, m12Orig, m21Orig, m22Orig,
                                  m11, m12, m21, m22, subst);
@@ -1004,7 +1005,7 @@ XOutputFont *XOutputFontCache::tryGetFont(XRef *xref, DisplayFontParam *dfp,
       if (freetypeControl != fontRastNone) {
        font = tryGetFTFontFromFile(xref, dfp->t1.fileName, gFalse, gfxFont,
                                    m11Orig, m12Orig, m21Orig, m22Orig,
-                                   m11, m12, m21, m22, subst);
+                                   m11, m12, m21, m22, gFalse, subst);
       }
     }
 #endif
@@ -1019,7 +1020,7 @@ XOutputFont *XOutputFontCache::tryGetFont(XRef *xref, DisplayFontParam *dfp,
     if (freetypeControl != fontRastNone) {
       font = tryGetFTFontFromFile(xref, dfp->tt.fileName, gFalse, gfxFont,
                                  m11Orig, m12Orig, m21Orig, m22Orig,
-                                 m11, m12, m21, m22, subst);
+                                 m11, m12, m21, m22, gFalse, subst);
     }
 #endif
 #if !FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
@@ -1090,6 +1091,11 @@ XOutputFont *XOutputFontCache::tryGetT1Font(XRef *xref,
        return NULL;
       }
       ff = new Type1CFontFile(fontBuf, fontLen);
+      if (!ff->isOk()) {
+       delete ff;
+       gfree(fontBuf);
+       return NULL;
+      }
       ff->convertToType1(outputToFile, f);
       delete ff;
       gfree(fontBuf);
@@ -1262,7 +1268,7 @@ XOutputFont *XOutputFontCache::tryGetFTFont(XRef *xref,
     // create the Font
     font = tryGetFTFontFromFile(xref, fileName, gTrue, gfxFont,
                                m11, m12, m21, m22,
-                               m11, m12, m21, m22, gFalse);
+                               m11, m12, m21, m22, gTrue, gFalse);
 
     // on systems with Unix hard link semantics, this will remove the
     // last link to the temp file
@@ -1274,7 +1280,7 @@ XOutputFont *XOutputFontCache::tryGetFTFont(XRef *xref,
   } else if ((fileName = gfxFont->getExtFontFile())) {
     font = tryGetFTFontFromFile(xref, fileName, gFalse, gfxFont,
                                m11, m12, m21, m22,
-                               m11, m12, m21, m22, gFalse);
+                               m11, m12, m21, m22, gFalse, gFalse);
 
   } else {
     font = NULL;
@@ -1293,6 +1299,7 @@ XOutputFont *XOutputFontCache::tryGetFTFontFromFile(XRef *xref,
                                                    double m22Orig,
                                                    double m11, double m12,
                                                    double m21, double m22,
+                                                   GBool embedded,
                                                    GBool subst) {
   Ref *id;
   FTFontFile *fontFile;
@@ -1303,14 +1310,16 @@ XOutputFont *XOutputFontCache::tryGetFTFontFromFile(XRef *xref,
     if (gfxFont->getType() == fontCIDType2) {
       fontFile = new FTFontFile(ftEngine, fileName->getCString(),
                                ((GfxCIDFont *)gfxFont)->getCIDToGID(),
-                               ((GfxCIDFont *)gfxFont)->getCIDToGIDLen());
-    } else { // fontCIDType0C
-      fontFile = new FTFontFile(ftEngine, fileName->getCString());
+                               ((GfxCIDFont *)gfxFont)->getCIDToGIDLen(),
+                               embedded);
+    } else { // fontCIDType0, fontCIDType0C
+      fontFile = new FTFontFile(ftEngine, fileName->getCString(), embedded);
     }
   } else {
     fontFile = new FTFontFile(ftEngine, fileName->getCString(),
                              ((Gfx8BitFont *)gfxFont)->getEncoding(),
-                             ((Gfx8BitFont *)gfxFont)->getHasEncoding());
+                             ((Gfx8BitFont *)gfxFont)->getHasEncoding(),
+                             ((Gfx8BitFont *)gfxFont)->isSymbolic());
   }
   if (!fontFile->isOk()) {
     error(-1, "Couldn't create FreeType font from '%s'",
@@ -1768,6 +1777,7 @@ XOutputDev::XOutputDev(Display *displayA, int screenNumA,
   // set up the font cache and fonts
   gfxFont = NULL;
   font = NULL;
+  needFontUpdate = gFalse;
   fontCache = new XOutputFontCache(display, depth, this,
                                   globalParams->getT1libControl(),
                                   globalParams->getFreeTypeControl());
@@ -1843,13 +1853,13 @@ void XOutputDev::startPage(int pageNum, GfxState *state) {
   XFillRectangle(display, pixmap, paperGC, 0, 0, pixmapW, pixmapH);
 
   // clear text object
-  text->clear();
+  text->startPage(state);
 }
 
 void XOutputDev::endPage() {
   XOutputState *s;
 
-  text->coalesce();
+  text->coalesce(gTrue);
 
   // clear state stack, free all GCs, free the clip region
   while (save) {
@@ -1942,6 +1952,9 @@ void XOutputDev::restoreState(GfxState *state) {
     s = save;
     save = save->next;
     delete s;
+
+    // we'll need to restore the font
+    needFontUpdate = gTrue;
   }
 }
 
@@ -1951,7 +1964,7 @@ void XOutputDev::updateAll(GfxState *state) {
   updateMiterLimit(state);
   updateFillColor(state);
   updateStrokeColor(state);
-  updateFont(state);
+  needFontUpdate = gTrue;
 }
 
 void XOutputDev::updateCTM(GfxState *state, double m11, double m12,
@@ -2059,6 +2072,8 @@ void XOutputDev::updateStrokeColor(GfxState *state) {
 void XOutputDev::updateFont(GfxState *state) {
   double m11, m12, m21, m22;
 
+  needFontUpdate = gFalse;
+
   text->updateFont(state);
 
   if (!(gfxFont = state->getFont())) {
@@ -2483,11 +2498,11 @@ void XOutputDev::addPoint(XPoint **points, int *size, int *k, int x, int y) {
 }
 
 void XOutputDev::beginString(GfxState *state, GString *s) {
-  text->beginString(state, state->getCurX(), state->getCurY());
+  text->beginWord(state, state->getCurX(), state->getCurY());
 }
 
 void XOutputDev::endString(GfxState *state) {
-  text->endString();
+  text->endWord();
 }
 
 void XOutputDev::drawChar(GfxState *state, double x, double y,
@@ -2501,7 +2516,11 @@ void XOutputDev::drawChar(GfxState *state, double x, double y,
   double *ctm;
   double saveCTM[6];
 
-  text->addChar(state, x, y, dx, dy, u, uLen);
+  if (needFontUpdate) {
+    updateFont(state);
+  }
+
+  text->addChar(state, x, y, dx, dy, code, u, uLen);
 
   if (!font) {
     return;
@@ -2575,6 +2594,9 @@ GBool XOutputDev::beginType3Char(GfxState *state,
   double x1, y1, xMin, yMin, xMax, yMax, xt, yt;
   int i, j;
 
+  if (needFontUpdate) {
+    updateFont(state);
+  }
   if (!gfxFont) {
     return gFalse;
   }
@@ -2676,7 +2698,7 @@ GBool XOutputDev::beginType3Char(GfxState *state,
       }
       text->addChar(state, 0, 0,
                    t3Font->cacheTags[i+j].wx, t3Font->cacheTags[i+j].wy,
-                   u, uLen);
+                   code, u, uLen);
       drawType3Glyph(t3Font, &t3Font->cacheTags[i+j],
                     t3Font->cacheData + (i+j) * t3Font->glyphSize,
                     xt, yt, &color);
@@ -2755,7 +2777,7 @@ void XOutputDev::endType3Char(GfxState *state) {
                  t3GlyphStack->origCTM4, t3GlyphStack->origCTM5);
   }
   text->addChar(state, 0, 0, t3GlyphStack->wx, t3GlyphStack->wy,
-               t3GlyphStack->u, t3GlyphStack->uLen);
+               t3GlyphStack->code, t3GlyphStack->u, t3GlyphStack->uLen);
   t3gs = t3GlyphStack;
   t3GlyphStack = t3gs->next;
   delete t3gs;
@@ -2850,11 +2872,61 @@ void XOutputDev::type3D1(GfxState *state, double wx, double wy,
   XRectangle rect;
   double *ctm;
   T3FontCache *t3Font;
+  double xt, yt, xMin, xMax, yMin, yMax, x1, y1;
   int i, j;
 
+  t3Font = t3GlyphStack->cache;
+  t3GlyphStack->wx = wx;
+  t3GlyphStack->wy = wy;
+
+  // check for a valid bbox
+  state->transform(0, 0, &xt, &yt);
+  state->transform(llx, lly, &x1, &y1);
+  xMin = xMax = x1;
+  yMin = yMax = y1;
+  state->transform(llx, ury, &x1, &y1);
+  if (x1 < xMin) {
+    xMin = x1;
+  } else if (x1 > xMax) {
+    xMax = x1;
+  }
+  if (y1 < yMin) {
+    yMin = y1;
+  } else if (y1 > yMax) {
+    yMax = y1;
+  }
+  state->transform(urx, lly, &x1, &y1);
+  if (x1 < xMin) {
+    xMin = x1;
+  } else if (x1 > xMax) {
+    xMax = x1;
+  }
+  if (y1 < yMin) {
+    yMin = y1;
+  } else if (y1 > yMax) {
+    yMax = y1;
+  }
+  state->transform(urx, ury, &x1, &y1);
+  if (x1 < xMin) {
+    xMin = x1;
+  } else if (x1 > xMax) {
+    xMax = x1;
+  }
+  if (y1 < yMin) {
+    yMin = y1;
+  } else if (y1 > yMax) {
+    yMax = y1;
+  }
+  if (xMin - xt < t3Font->glyphX ||
+      yMin - yt < t3Font->glyphY ||
+      xMax - xt > t3Font->glyphX + t3Font->glyphW ||
+      yMax - yt > t3Font->glyphY + t3Font->glyphH) {
+    error(-1, "Bad bounding box in Type 3 glyph");
+    return;
+  }
+
   // allocate a cache entry
   t3GlyphStack->cacheable = gTrue;
-  t3Font = t3GlyphStack->cache;
   i = t3GlyphStack->cacheIdx;
   for (j = 0; j < t3Font->cacheAssoc; ++j) {
     if ((t3Font->cacheTags[i+j].mru & 0x7fff) == t3Font->cacheAssoc - 1) {
@@ -2866,8 +2938,6 @@ void XOutputDev::type3D1(GfxState *state, double wx, double wy,
       ++t3Font->cacheTags[i+j].mru;
     }
   }
-  t3GlyphStack->wx = wx;
-  t3GlyphStack->wy = wy;
   t3GlyphStack->cacheTag->wx = wx;
   t3GlyphStack->cacheTag->wy = wy;