Simplify creation of pango layout in xr driver. 20130112030502/pspp
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 11 Jan 2013 14:26:58 +0000 (15:26 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 12 Jan 2013 08:00:57 +0000 (09:00 +0100)
Create the layouts with pango_cairo_create_layout instead of
pango_layout_new.  This seems simpler and avoids a kludge.

Reviewed-By: Ben Pfaff
src/output/cairo.c

index cd8f0b0e999decb2ae1434463885c045ae827600..89013c2a0c65f5c5b58f1ea53001f4ff0305e431 100644 (file)
@@ -299,40 +299,15 @@ xr_allocate (const char *name, int device_type, struct string_map *o)
   return xr;
 }
 
-static bool
-xr_is_72dpi (cairo_t *cr)
-{
-  cairo_surface_type_t type;
-  cairo_surface_t *surface;
-
-  surface = cairo_get_target (cr);
-  type = cairo_surface_get_type (surface);
-  return type == CAIRO_SURFACE_TYPE_PDF || type == CAIRO_SURFACE_TYPE_PS;
-}
-
 static bool
 xr_set_cairo (struct xr_driver *xr, cairo_t *cairo)
 {
-  PangoContext *context;
-  PangoFontMap *map;
   int i;
 
   xr->cairo = cairo;
 
   cairo_set_line_width (xr->cairo, xr_to_pt (xr->line_width));
 
-  map = pango_cairo_font_map_get_default ();
-  context = pango_font_map_create_context (map);
-  if (xr_is_72dpi (cairo))
-    {
-      /* Pango seems to always scale fonts according to the DPI specified
-         in the font map, even if the surface has a real DPI.  The default
-         DPI is 96, so on a 72 DPI device fonts end up being 96/72 = 133%
-         of their desired size.  We deal with this by fixing the resolution
-         here.  Presumably there is a better solution, but what? */
-      pango_cairo_context_set_resolution (context, 72.0);
-    }
-
   xr->char_width = 0;
   xr->char_height = 0;
   for (i = 0; i < XR_N_FONTS; i++)
@@ -340,7 +315,7 @@ xr_set_cairo (struct xr_driver *xr, cairo_t *cairo)
       struct xr_font *font = &xr->fonts[i];
       int char_width, char_height;
 
-      font->layout = pango_layout_new (context);
+      font->layout = pango_cairo_create_layout (cairo);
       pango_layout_set_font_description (font->layout, font->desc);
 
       pango_layout_set_text (font->layout, "0", 1);
@@ -349,8 +324,6 @@ xr_set_cairo (struct xr_driver *xr, cairo_t *cairo)
       xr->char_height = MAX (xr->char_height, char_height);
     }
 
-  g_object_unref (G_OBJECT (context));
-
   if (xr->params == NULL)
     {
       int single_width, double_width;