pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: font sizes


From: Ben Pfaff
Subject: Re: font sizes
Date: Mon, 28 Jun 2010 09:36:32 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

John Darrington <address@hidden> writes:

> On Mon, Jun 28, 2010 at 08:02:47AM -0700, Ben Pfaff wrote:
>      I guess we need to do different things based on what kind of
>      device we've got?
>
> I agree that would be a strange state of affairs, and I find it
> hard to believe that pango/cairo works like that.
> Unfortunately I don't have enough experience to make an
> intelligent assesment of the situation.
>
> If you would like me to I could try to look into it a bit
> deeper to see if we can't come up with a more elegent solution.
> Although I'm not sure when I'd be able to do that.  Whilst I'm
> not particularly short of time at the moment, that kind of
> thing needs quite a few consecutive hours without interruption
> (well that's what I generally need, anyway).

That's what I generally need too.

It would be great if you could do this.  For now the following
kluge seems to fix it.  Do you think that this is OK for now?

diff --git a/src/output/cairo.c b/src/output/cairo.c
index 90ae60e..eb3c41a 100644
--- a/src/output/cairo.c
+++ b/src/output/cairo.c
@@ -247,6 +247,17 @@ xr_allocate (const char *name, int device_type, struct 
string_map *o)
 }
 
 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)
 {
   int i;
@@ -260,9 +271,20 @@ xr_set_cairo (struct xr_driver *xr, cairo_t *cairo)
   for (i = 0; i < XR_N_FONTS; i++)
     {
       struct xr_font *font = &xr->fonts[i];
+      PangoContext *context;
       int char_width, char_height;
 
-      font->layout = pango_cairo_create_layout (xr->cairo);
+      context = pango_cairo_create_context (xr->cairo);
+      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);
+        }
+      font->layout = pango_layout_new (context);
       pango_layout_set_font_description (font->layout, font->desc);
 
       pango_layout_set_text (font->layout, "0", 1);

-- 
Peter Seebach on managing engineers:
"It's like herding cats, only most of the engineers are already
 sick of laser pointers."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]