[poppler] poppler/poppler: CairoFontEngine.cc, 1.8, 1.9 CairoFontEngine.h, 1.3, 1.4 CairoOutputDev.cc, 1.7, 1.8 CairoOutputDevImage.cc, 1.3, 1.4

Kristian Hogsberg krh at freedesktop.org
Sun May 1 22:39:13 PDT 2005


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

Modified Files:
	CairoFontEngine.cc CairoFontEngine.h CairoOutputDev.cc 
	CairoOutputDevImage.cc 
Log Message:
2005-05-01  Kristian Høgsberg  <krh at redhat.com>

        * poppler/CairoFontEngine.cc:
        * poppler/CairoFontEngine.h:
        * poppler/CairoOutputDev.cc: Back out workaround for cairo 0.4.0
        font API and port to new cairo head.



Index: CairoFontEngine.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/CairoFontEngine.cc,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- CairoFontEngine.cc	23 Apr 2005 20:16:02 -0000	1.8
+++ CairoFontEngine.cc	2 May 2005 05:39:11 -0000	1.9
@@ -60,15 +60,14 @@
 // CairoFont
 //------------------------------------------------------------------------
 
-/* For the 0.3 release of poppler we're creating a CairoFont, and
- * thus, an FT_Face for each size of each font we encounter.  We
- * should of course be able to share FT_Face instances across all
- * sizes of a font.  However, to do that we need to be able to create
- * a cairo_unscaled_font_t, which is not possible with the cairo-0.4.0
- * API which is what we're targeting with this release. */
+void cairo_font_face_destroy (void *data)
+{
+  CairoFont *font = (CairoFont *) data;
 
-CairoFont::CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib, 
-		     double m11, double m12, double m21, double m22) {
+  delete font;
+}
+
+CairoFont::CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib) {
   Ref embRef;
   Object refObj, strObj;
   GooString *tmpFileName, *fileName, *substName,*tmpFileName2;
@@ -80,12 +79,12 @@
   char *name;
   FoFiTrueType *ff;
   FoFiType1C *ff1c;
-  cairo_matrix_t *matrix;
+  static cairo_user_data_key_t cairo_font_face_key;
   
   codeToGID = NULL;
   codeToGIDLen = 0;
   substIdx = -1;
-  cairo_font = NULL;
+  cairo_font_face = NULL;
   
   ref = *gfxFont->getID();
   fontType = gfxFont->getType();
@@ -245,21 +244,20 @@
     unlink (fileName->getCString());
   }
 
-  this->m11 = m11;
-  this->m12 = m12;
-  this->m21 = m21;
-  this->m22 = m22;
-  matrix = cairo_matrix_create ();
-  cairo_matrix_set_affine (matrix, m11, m12, m21, m22, 0, 0);
-  cairo_font = cairo_ft_font_create_for_ft_face (face, FT_LOAD_NO_HINTING,
-						 matrix);
-  cairo_matrix_destroy (matrix);
-  if (cairo_font == NULL) {
+  cairo_font_face = cairo_ft_font_face_create_for_ft_face (face,
+							   FT_LOAD_NO_HINTING |
+							   FT_LOAD_NO_BITMAP);
+  if (cairo_font_face == NULL) {
     error(-1, "could not create cairo font\n");
     goto err2; /* this doesn't do anything, but it looks like we're
 		* handling the error */
   }
 
+  cairo_font_face_set_user_data (cairo_font_face, 
+				 &cairo_font_face_key,
+				 this,
+				 cairo_font_face_destroy);
+
   return;
  err2:
   /* hmm? */
@@ -267,27 +265,17 @@
 }
 
 CairoFont::~CairoFont() {
-  cairo_font_destroy (cairo_font);
-
-  /* cairo_font_t's created from an FT_Face are never cached so we can
-   * free the font here.  There might be glyphs in the cairo glyph
-   * cache referencing this font, but since we're throwing this font
-   * away, they won't be used and will slowly fall out of the
-   * cache. */
   FT_Done_Face (face);
 }
 
 GBool
-CairoFont::matches(Ref &other,
-		   double m11, double m12, double m21, double m22) {
-  return (other.num == ref.num && other.gen == ref.gen &&
-	  this->m11 == m11 && this->m12 == m12 &&
-	  this->m21 == m21 && this->m22 == m22);
+CairoFont::matches(Ref &other) {
+  return (other.num == ref.num && other.gen == ref.gen);
 }
 
-cairo_font_t *
-CairoFont::getFont(void) {
-  return cairo_font;
+cairo_font_face_t *
+CairoFont::getFontFace(void) {
+  return cairo_font_face;
 }
 
 unsigned long
@@ -359,8 +347,7 @@
 }
 
 CairoFont *
-CairoFontEngine::getFont(GfxFont *gfxFont, XRef *xref,
-			 double m11, double m12, double m21, double m22) {
+CairoFontEngine::getFont(GfxFont *gfxFont, XRef *xref) {
   int i, j;
   Ref ref;
   CairoFont *font;
@@ -376,7 +363,7 @@
 
   for (i = 0; i < cairoFontCacheSize; ++i) {
     font = fontCache[i];
-    if (font && font->matches(ref, m11, m12, m21, m22)) {
+    if (font && font->matches(ref)) {
       for (j = i; j > 0; --j) {
 	fontCache[j] = fontCache[j-1];
       }
@@ -385,7 +372,7 @@
     }
   }
   
-  font = new CairoFont (gfxFont, xref, lib, m11, m12, m21, m22);
+  font = new CairoFont (gfxFont, xref, lib);
   if (fontCache[cairoFontCacheSize - 1]) {
     delete fontCache[cairoFontCacheSize - 1];
   }

Index: CairoFontEngine.h
===================================================================
RCS file: /cvs/poppler/poppler/poppler/CairoFontEngine.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- CairoFontEngine.h	22 Apr 2005 04:09:23 -0000	1.3
+++ CairoFontEngine.h	2 May 2005 05:39:11 -0000	1.4
@@ -18,18 +18,17 @@
 
 class CairoFont {
 public:
-  CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib,
-	    double m11, double m12, double m21, double m22);
+  CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib);
   ~CairoFont();
 
-  GBool matches(Ref &other, double m11, double m12, double m21, double m22);
-  cairo_font_t *getFont(void);
+  GBool matches(Ref &other);
+  cairo_font_face_t *getFontFace(void);
   unsigned long getGlyph(CharCode code, Unicode *u, int uLen);
   double getSubstitutionCorrection(GfxFont *gfxFont);
 private:
   int substIdx;
   Ref ref;
-  cairo_font_t *cairo_font;
+  cairo_font_face_t *cairo_font_face;
   FT_Face face;
 
   Gushort *codeToGID;
@@ -52,8 +51,7 @@
   CairoFontEngine(FT_Library libA);
   ~CairoFontEngine();
 
-  CairoFont *getFont(GfxFont *gfxFont, XRef *xref,
-		     double m11, double m12, double m21, double m22);
+  CairoFont *getFont(GfxFont *gfxFont, XRef *xref);
 
 private:
   CairoFont *fontCache[cairoFontCacheSize];

Index: CairoOutputDev.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/CairoOutputDev.cc,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- CairoOutputDev.cc	22 Apr 2005 04:09:23 -0000	1.7
+++ CairoOutputDev.cc	2 May 2005 05:39:11 -0000	1.8
@@ -76,7 +76,7 @@
   cairo_destroy (cairo);
   createCairo (state);
   
-  cairo_init_clip (cairo);
+  cairo_reset_clip (cairo);
   cairo_set_rgb_color (cairo, 0, 0, 0);
   cairo_set_operator (cairo, CAIRO_OPERATOR_OVER);
   cairo_set_line_cap (cairo, CAIRO_LINE_CAP_BUTT);
@@ -197,29 +197,38 @@
 }
 
 void CairoOutputDev::updateFont(GfxState *state) {
-  cairo_font_t *font;
+  cairo_font_face_t *font_face;
   double m11, m12, m21, m22;
   double w;
+  cairo_matrix_t matrix;
 
   LOG(printf ("updateFont() font=%s\n", state->getFont()->getName()->getCString()));
   
   /* Needs to be rethough, since fonts are now handled by cairo */
   needFontUpdate = gFalse;
 
+  currentFont = fontEngine->getFont (state->getFont(), xref);
+
   state->getFontTransMat(&m11, &m12, &m21, &m22);
   m11 *= state->getHorizScaling();
   m12 *= state->getHorizScaling();
 
-  /* w = currentFont->getSubstitutionCorrection(state->getFont()); */
-  m12 *= -1;
-  m22 *= -1;
+  w = currentFont->getSubstitutionCorrection(state->getFont());
+  m12 *= -w;
+  m22 *= -w;
 
   LOG(printf ("font matrix: %f %f %f %f\n", m11, m12, m21, m22));
   
-  currentFont = fontEngine->getFont (state->getFont(), xref,
-				     m11, m21, m12, m22);
-  font = currentFont->getFont();
-  cairo_set_font (cairo, font);
+  font_face = currentFont->getFontFace();
+  cairo_set_font_face (cairo, font_face);
+
+  matrix.xx = m11;
+  matrix.yx = m12;
+  matrix.xy = m21;
+  matrix.yy = m22;
+  matrix.x0 = 0;
+  matrix.y0 = 0;
+  cairo_set_font_matrix (cairo, &matrix);
 }
 
 void CairoOutputDev::doPath(GfxState *state, GfxPath *path,
@@ -451,8 +460,8 @@
 void CairoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
 				    int width, int height, GBool invert,
 				    GBool inlineImg) {
-  char *buffer;
-  char *dest;
+  unsigned char *buffer;
+  unsigned char *dest;
   cairo_surface_t *image;
   int x, y;
   ImageStream *imgStr;
@@ -461,7 +470,7 @@
   cairo_matrix_t *mat;
   int invert_bit;
 
-  buffer = (char *)malloc (width * height * 4);
+  buffer = (unsigned char *)malloc (width * height * 4);
   if (buffer == NULL) {
     error(-1, "Unable to allocate memory for image.");
     return;
@@ -523,8 +532,8 @@
 				int width, int height,
 				GfxImageColorMap *colorMap,
 				int *maskColors, GBool inlineImg) {
-  char *buffer;
-  char *dest;
+  unsigned char *buffer;
+  unsigned char *dest;
   cairo_surface_t *image;
   int x, y;
   ImageStream *imgStr;
@@ -535,7 +544,7 @@
   cairo_matrix_t *mat;
   int is_identity_transform;
   
-  buffer = (char *)malloc (width * height * 4);
+  buffer = (unsigned char *)malloc (width * height * 4);
 
   if (buffer == NULL) {
     error(-1, "Unable to allocate memory for image.");

Index: CairoOutputDevImage.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/CairoOutputDevImage.cc,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- CairoOutputDevImage.cc	14 Apr 2005 01:34:38 -0000	1.3
+++ CairoOutputDevImage.cc	2 May 2005 05:39:11 -0000	1.4
@@ -56,7 +56,7 @@
   memset (pixels, 0xff, pixels_w * pixels_h * 4);
 
   cairo = cairo_create ();
-  cairo_set_target_image (cairo, (char *)pixels, CAIRO_FORMAT_ARGB32,
+  cairo_set_target_image (cairo, (unsigned char *)pixels, CAIRO_FORMAT_ARGB32,
 			  pixels_w, pixels_h,
 			  pixels_w*4);
   



More information about the poppler mailing list