[poppler] Branch 'poppler-0.10' - poppler/Annot.cc poppler/Annot.h poppler/Gfx.h

Albert Astals Cid aacid at kemper.freedesktop.org
Sun Jan 4 07:57:18 PST 2009


 poppler/Annot.cc |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
 poppler/Annot.h  |    2 ++
 poppler/Gfx.h    |    7 ++++---
 3 files changed, 53 insertions(+), 5 deletions(-)

New commits:
commit 3e7c630815bee768086f690d6e1e99a75e746db0
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sun Jan 4 16:54:32 2009 +0100

    Fix some checked checkboxes not rendering correctly
    
    If we are forcing ZaDb/ZapfDingbats to correctly draw a checkmark in the checkbox, but the file does not have such font defined we need to create a fake one so the system really renders it
    Fixes bug 19359

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 7c01d7b..3cc13a0 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -2140,6 +2140,7 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxFontDict *fontDict
   double fontSize, fontSize2, borderWidth, x, xPrev, y, w, wMax;
   int tfPos, tmPos, i, j;
   GBool freeText = gFalse;      // true if text should be freed before return
+  GBool freeFont = gFalse;
 
   //~ if there is no MK entry, this should use the existing content stream,
   //~ and only replace the marked content portion of it
@@ -2174,7 +2175,6 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxFontDict *fontDict
   }
 
   // force ZapfDingbats
-  //~ this should create the font if needed (?)
   if (forceZapfDingbats) {
     if (tfPos >= 0) {
       tok = (GooString *)daToks->get(tfPos);
@@ -2191,7 +2191,20 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxFontDict *fontDict
     tok = (GooString *)daToks->get(tfPos);
     if (tok->getLength() >= 1 && tok->getChar(0) == '/') {
       if (!fontDict || !(font = fontDict->lookup(tok->getCString() + 1))) {
-        error(-1, "Unknown font in field's DA string");
+        if (forceZapfDingbats) {
+          // We are forcing ZaDb but the font does not exist
+          // so create a fake one
+          Ref r; // dummy Ref, it's not used at all in this codepath
+          r.num = 0;
+          r.gen = 0;
+          Dict *d = new Dict(xref);
+          font = new Gfx8BitFont(xref, "ZaDb", r, new GooString("ZapfDingbats"), fontType1, d);
+          delete d;
+          freeFont = gTrue;
+          addDingbatsResource = gTrue;
+        } else {
+          error(-1, "Unknown font in field's DA string");
+        }
       }
     } else {
       error(-1, "Invalid font name in 'Tf' operator in field's DA string");
@@ -2496,6 +2509,9 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxFontDict *fontDict
     delete text;
   }
   delete convertedText;
+  if (freeFont) {
+    font->decRefCnt();
+  }
 }
 
 // Draw the variable text or caption for a field.
@@ -3102,12 +3118,41 @@ void AnnotWidget::draw(Gfx *gfx, GBool printing) {
     return;
   }
 
+  addDingbatsResource = gFalse;
   generateFieldAppearance ();
 
   // draw the appearance stream
   appearance.fetch(xref, &obj);
+  if (addDingbatsResource) {
+    // We are forcing ZaDb but the font does not exist
+    // so create a fake one
+    Object baseFontObj, subtypeObj;
+    baseFontObj.initName("ZapfDingbats");
+    subtypeObj.initName("Type1");
+
+    Object fontDictObj;
+    Dict *fontDict = new Dict(xref);
+    fontDict->decRef();
+    fontDict->add(copyString("BaseFont"), &baseFontObj);
+    fontDict->add(copyString("Subtype"), &subtypeObj);
+    fontDictObj.initDict(fontDict);
+
+    Object fontsDictObj;
+    Dict *fontsDict = new Dict(xref);
+    fontsDict->decRef();
+    fontsDict->add(copyString("ZaDb"), &fontDictObj);
+    fontsDictObj.initDict(fontsDict);
+
+    Dict *dict = new Dict(xref);
+    dict->add(copyString("Font"), &fontsDictObj);
+    gfx->pushResources(dict);
+    delete dict;
+  }
   gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
 		 rect->x1, rect->y1, rect->x2, rect->y2);
+  if (addDingbatsResource) {
+    gfx->popResources();
+  }
   obj.free();
 }
 
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 6dd7850..0b8ad2a 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -21,6 +21,7 @@
 // Copyright (C) 2008 Hugo Mercier <hmercier31 at gmail.com>
 // Copyright (C) 2008 Pino Toscano <pino at kde.org>
 // Copyright (C) 2008 Tomas Are Haavet <tomasare at gmail.com>
+// Copyright (C) 2009 Albert Astals Cid <aacid at kde.org>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -1194,6 +1195,7 @@ private:
   // AnnotBorderBS border;                // BS
   Dict *parent;                           // Parent
   GBool regen;
+  GBool addDingbatsResource;
 };
 
 //------------------------------------------------------------------------
diff --git a/poppler/Gfx.h b/poppler/Gfx.h
index 6787738..a75a92a 100644
--- a/poppler/Gfx.h
+++ b/poppler/Gfx.h
@@ -17,6 +17,7 @@
 // Copyright (C) 2007 Iñigo Martínez <inigomartinez at gmail.com>
 // Copyright (C) 2008 Brad Hards <bradh at kde.org>
 // Copyright (C) 2008 Carlos Garcia Campos <carlosgc at gnome.org>
+// Copyright (C) 2009 Albert Astals Cid <aacid at kde.org>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -163,6 +164,9 @@ public:
   // Get the current graphics state object.
   GfxState *getState() { return state; }
 
+  void pushResources(Dict *resDict);
+  void popResources();
+
 private:
 
   XRef *xref;			// the xref table for this PDF file
@@ -333,9 +337,6 @@ private:
   GBool contentIsHidden();
   void pushMarkedContent();
   void popMarkedContent();
-
-  void pushResources(Dict *resDict);
-  void popResources();
 };
 
 #endif


More information about the poppler mailing list