[poppler] 5 commits - poppler/CairoFontEngine.cc poppler/CairoFontEngine.h poppler/CairoOutputDev.cc poppler/CairoOutputDev.h

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Sat Nov 1 05:52:10 PDT 2008


 poppler/CairoFontEngine.cc |   57 ++++++++++++++++++++++++++-------------------
 poppler/CairoFontEngine.h  |   20 +++++++++------
 poppler/CairoOutputDev.cc  |    7 -----
 poppler/CairoOutputDev.h   |    2 -
 4 files changed, 48 insertions(+), 38 deletions(-)

New commits:
commit 0741a402632ec5a8641ff11707142bf2731c1833
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Nov 1 22:27:48 2008 +1030

    Restore the cairo Type3 font image prescaling funtionality

diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
index 07be458..b58e99b 100644
--- a/poppler/CairoFontEngine.cc
+++ b/poppler/CairoFontEngine.cc
@@ -63,11 +63,13 @@ CairoFont::CairoFont(Ref ref,
 		     cairo_font_face_t *cairo_font_face,
 		     Gushort *codeToGID,
 		     int codeToGIDLen,
-		     GBool substitute) : ref(ref),
-					 cairo_font_face(cairo_font_face),
-					 codeToGID(codeToGID),
-					 codeToGIDLen(codeToGIDLen),
-					 substitute(substitute)  { }
+		     GBool substitute,
+		     GBool printing) : ref(ref),
+				       cairo_font_face(cairo_font_face),
+				       codeToGID(codeToGID),
+				       codeToGIDLen(codeToGIDLen),
+				       substitute(substitute),
+				       printing(printing)      { }
 
 CairoFont::~CairoFont() {
   cairo_font_face_destroy (cairo_font_face);
@@ -75,8 +77,8 @@ CairoFont::~CairoFont() {
 }
 
 GBool
-CairoFont::matches(Ref &other) {
-  return (other.num == ref.num && other.gen == ref.gen);
+CairoFont::matches(Ref &other, GBool printingA) {
+  return (other.num == ref.num && other.gen == ref.gen && printing == printingA);
 }
 
 cairo_font_face_t *
@@ -337,7 +339,8 @@ CairoFreeTypeFont::CairoFreeTypeFont(Ref ref,
 								   cairo_font_face,
 								   codeToGID,
 								   codeToGIDLen,
-								   substitute),
+								   substitute,
+								   gTrue),
 							 face(face) { }
 
 CairoFreeTypeFont::~CairoFreeTypeFont() { }
@@ -546,6 +549,7 @@ typedef struct _type3_font_info {
   XRef *xref;
   Catalog *catalog;
   CairoFontEngine *fontEngine;
+  GBool printing;
 } type3_font_info_t;
 
 static void
@@ -601,6 +605,7 @@ _render_type3_glyph (cairo_scaled_font_t  *scaled_font,
 
   output_dev = new CairoOutputDev();
   output_dev->setCairo(cr);
+  output_dev->setPrinting(info->printing);
 
   mat = font->getFontBBox();
   box.x1 = mat[0];
@@ -637,7 +642,8 @@ _render_type3_glyph (cairo_scaled_font_t  *scaled_font,
 
 
 CairoType3Font *CairoType3Font::create(GfxFont *gfxFont, XRef *xref,
-				       Catalog *catalog, CairoFontEngine *fontEngine) {
+				       Catalog *catalog, CairoFontEngine *fontEngine,
+				       GBool printing) {
   Object refObj, strObj;
   type3_font_info_t *info;
   cairo_font_face_t *font_face;
@@ -659,6 +665,7 @@ CairoType3Font *CairoType3Font::create(GfxFont *gfxFont, XRef *xref,
   info->xref = xref;
   info->catalog = catalog;
   info->fontEngine = fontEngine;
+  info->printing = printing;
 
   cairo_font_face_set_user_data (font_face, &type3_font_key, (void *) info, _free_type3_font_info);
 
@@ -676,7 +683,7 @@ CairoType3Font *CairoType3Font::create(GfxFont *gfxFont, XRef *xref,
     }
   }
 
-  return new CairoType3Font(ref, xref, catalog, font_face, codeToGID, codeToGIDLen);
+  return new CairoType3Font(ref, xref, catalog, font_face, codeToGID, codeToGIDLen, printing);
 }
 
 CairoType3Font::CairoType3Font(Ref ref,
@@ -684,13 +691,15 @@ CairoType3Font::CairoType3Font(Ref ref,
 			       Catalog *cat,
 			       cairo_font_face_t *cairo_font_face,
 			       Gushort *codeToGID,
-			       int codeToGIDLen) : CairoFont(ref,
-							     cairo_font_face,
-							     codeToGID,
-							     codeToGIDLen,
-							     gFalse),
-						   xref(xref),
-						   catalog(catalog) { }
+			       int codeToGIDLen,
+			       GBool printing) : CairoFont(ref,
+							   cairo_font_face,
+							   codeToGID,
+							   codeToGIDLen,
+							   gFalse,
+							   printing),
+						 xref(xref),
+						 catalog(catalog) { }
 
 CairoType3Font::~CairoType3Font() { }
 
@@ -724,7 +733,7 @@ CairoFontEngine::~CairoFontEngine() {
 }
 
 CairoFont *
-CairoFontEngine::getFont(GfxFont *gfxFont, XRef *xref, Catalog *catalog) {
+CairoFontEngine::getFont(GfxFont *gfxFont, XRef *xref, Catalog *catalog, GBool printing) {
   int i, j;
   Ref ref;
   CairoFont *font;
@@ -734,7 +743,7 @@ CairoFontEngine::getFont(GfxFont *gfxFont, XRef *xref, Catalog *catalog) {
 
   for (i = 0; i < cairoFontCacheSize; ++i) {
     font = fontCache[i];
-    if (font && font->matches(ref)) {
+    if (font && font->matches(ref, printing)) {
       for (j = i; j > 0; --j) {
 	fontCache[j] = fontCache[j-1];
       }
@@ -745,7 +754,7 @@ CairoFontEngine::getFont(GfxFont *gfxFont, XRef *xref, Catalog *catalog) {
   
   fontType = gfxFont->getType();
   if (fontType == fontType3)
-    font = CairoType3Font::create (gfxFont, xref, catalog, this);
+    font = CairoType3Font::create (gfxFont, xref, catalog, this, printing);
   else
     font = CairoFreeTypeFont::create (gfxFont, xref, lib, useCIDs);
 
diff --git a/poppler/CairoFontEngine.h b/poppler/CairoFontEngine.h
index 2474dc6..c672078 100644
--- a/poppler/CairoFontEngine.h
+++ b/poppler/CairoFontEngine.h
@@ -42,13 +42,14 @@ class CairoFontEngine;
 class CairoFont {
 public:
   CairoFont(Ref ref,
-	      cairo_font_face_t *face,
-	      Gushort *codeToGID,
-	      int codeToGIDLen,
-	      GBool substitute);
+	    cairo_font_face_t *face,
+	    Gushort *codeToGID,
+	    int codeToGIDLen,
+	    GBool substitute,
+	    GBool printing);
   virtual ~CairoFont();
 
-  GBool matches(Ref &other);
+  GBool matches(Ref &other, GBool printing);
   cairo_font_face_t *getFontFace(void);
   unsigned long getGlyph(CharCode code, Unicode *u, int uLen);
   double getSubstitutionCorrection(GfxFont *gfxFont);
@@ -62,6 +63,7 @@ protected:
   int codeToGIDLen;
 
   GBool substitute;
+  GBool printing;
 };
 
 //------------------------------------------------------------------------
@@ -82,13 +84,15 @@ private:
 class CairoType3Font : public CairoFont {
 public:
   static CairoType3Font *create(GfxFont *gfxFont, XRef *xref,
-				Catalog *catalog, CairoFontEngine *fontEngine);
+				Catalog *catalog, CairoFontEngine *fontEngine,
+				GBool printing);
   virtual ~CairoType3Font();
 
 private:
   CairoType3Font(Ref ref, XRef *xref, Catalog *catalog,
 		 cairo_font_face_t *cairo_font_face,
-		 Gushort *codeToGID, int codeToGIDLen);
+		 Gushort *codeToGID, int codeToGIDLen,
+		 GBool printing);
   XRef *xref;
   Catalog *catalog;
 };
@@ -108,7 +112,7 @@ public:
   CairoFontEngine(FT_Library libA);
   ~CairoFontEngine();
 
-  CairoFont *getFont(GfxFont *gfxFont, XRef *xref, Catalog *catalog);
+  CairoFont *getFont(GfxFont *gfxFont, XRef *xref, Catalog *catalog, GBool printing);
 
 private:
   CairoFont *fontCache[cairoFontCacheSize];
diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc
index a1a2379..26b8010 100644
--- a/poppler/CairoOutputDev.cc
+++ b/poppler/CairoOutputDev.cc
@@ -416,7 +416,7 @@ void CairoOutputDev::updateFont(GfxState *state) {
 
   needFontUpdate = gFalse;
 
-  currentFont = fontEngine->getFont (state->getFont(), xref, catalog);
+  currentFont = fontEngine->getFont (state->getFont(), xref, catalog, printing);
 
   if (!currentFont)
     return;
diff --git a/poppler/CairoOutputDev.h b/poppler/CairoOutputDev.h
index 878d3e3..46be9dc 100644
--- a/poppler/CairoOutputDev.h
+++ b/poppler/CairoOutputDev.h
@@ -212,7 +212,7 @@ public:
   GBool isReverseVideo() { return gFalse; }
   
   void setCairo (cairo_t *cr);
-  void setPrinting (GBool printing) { this->printing = printing; }
+  void setPrinting (GBool printing) { this->printing = printing; needFontUpdate = gTrue; }
 
   void setInType3Char(GBool inType3Char) { this->inType3Char = inType3Char; }
   void getType3GlyphWidth (double *wx, double *wy) { *wx = t3_glyph_wx; *wy = t3_glyph_wy; }
commit 91a7c3fdd44f30b0b50ed05a3313bbb1b5c86e71
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Nov 1 20:57:24 2008 +1030

    Remove cairo font matrix y flip when inside a Type 3 char
    
    Not sure why this was previously required but it now produces
    incorrect results.

diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc
index 70911b5..a1a2379 100644
--- a/poppler/CairoOutputDev.cc
+++ b/poppler/CairoOutputDev.cc
@@ -438,11 +438,6 @@ void CairoOutputDev::updateFont(GfxState *state) {
   matrix.yy = -m[3] * fontSize;
   matrix.x0 = 0;
   matrix.y0 = 0;
-  if (inType3Char) {
-    cairo_matrix_t m;
-    cairo_matrix_init_scale (&m, 1, -1);
-    cairo_matrix_multiply (&matrix, &m, &matrix);
-  }
   cairo_set_font_matrix (cairo, &matrix);
 }
 
commit 3bf4d7d75b455a9a0b5ee3a8c78b218e5af5185a
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Nov 1 20:50:07 2008 +1030

    Transform the glyph advance by the font matrix

diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
index a18f566..07be458 100644
--- a/poppler/CairoFontEngine.cc
+++ b/poppler/CairoFontEngine.cc
@@ -614,6 +614,7 @@ _render_type3_glyph (cairo_scaled_font_t  *scaled_font,
   gfx->display(charProcs->getVal(glyph, &charProc));
 
   output_dev->getType3GlyphWidth (&wx, &wy);
+  cairo_matrix_transform_distance (&matrix, &wx, &wy);
   metrics->x_advance = wx;
   metrics->y_advance = wy;
   if (output_dev->hasType3GlyphBBox()) {
commit 4aa32bad61d008a854fdc9e902d6834bb1687d7e
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Nov 1 20:49:04 2008 +1030

    Use the font BBox, not the font matrix to set the Gfx BBox

diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
index 6910196..a18f566 100644
--- a/poppler/CairoFontEngine.cc
+++ b/poppler/CairoFontEngine.cc
@@ -602,6 +602,7 @@ _render_type3_glyph (cairo_scaled_font_t  *scaled_font,
   output_dev = new CairoOutputDev();
   output_dev->setCairo(cr);
 
+  mat = font->getFontBBox();
   box.x1 = mat[0];
   box.y1 = mat[1];
   box.x2 = mat[2];
commit 987955440c7711f440c3d2b5cc8c05ec07228a77
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Nov 1 20:47:05 2008 +1030

    Ensure both the font matrix and y-axis flip are in the matrix
    
    we use for transforming the glyph metrics.

diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
index dc975be..6910196 100644
--- a/poppler/CairoFontEngine.cc
+++ b/poppler/CairoFontEngine.cc
@@ -566,7 +566,7 @@ _render_type3_glyph (cairo_scaled_font_t  *scaled_font,
   Dict *charProcs;
   Object charProc;
   CairoOutputDev *output_dev;
-  cairo_matrix_t matrix;
+  cairo_matrix_t matrix, invert_y_axis;
   double *mat;
   double wx, wy;
   PDFRectangle box;
@@ -595,8 +595,8 @@ _render_type3_glyph (cairo_scaled_font_t  *scaled_font,
   matrix.yy = mat[3];
   matrix.x0 = mat[4];
   matrix.y0 = mat[5];
-  cairo_transform (cr, &matrix);
-  cairo_matrix_init_scale (&matrix, 1, -1);
+  cairo_matrix_init_scale (&invert_y_axis, 1, -1);
+  cairo_matrix_multiply (&matrix, &matrix, &invert_y_axis);
   cairo_transform (cr, &matrix);
 
   output_dev = new CairoOutputDev();


More information about the poppler mailing list