cairo: Fix font scaling.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Dec 2019 16:25:57 +0000 (16:25 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Dec 2019 16:49:43 +0000 (16:49 +0000)
It's really a mystery why a 9-point font doesn't appear 9 points tall
in PDF (etc.) output, but it doesn't.  I guess we're doing something
wrong somewhere.  But until we figure out the underlying issue, we need
to scale down font sizes for PDF and not for on-screen use.

This is a slightly better fix for font sizes than the previous commit
3c15b41c036 (pivot-table: Kluge dropping default 9-point font to make
output readable.)

src/output/cairo.c
src/output/pivot-table.c

index b1a7e273686861782b471242d296115a5aa0223c..57c27ddc23c7c9c7536e9d4199db409da86122a4 100644 (file)
@@ -164,6 +164,7 @@ struct xr_driver
 
     /* Internal state. */
     struct render_params *params;
+    double font_scale;
     int char_width, char_height;
     char *command_name;
     char *title;
@@ -592,7 +593,8 @@ apply_options (struct xr_driver *xr, struct string_map *o)
 }
 
 static struct xr_driver *
-xr_allocate (const char *name, int device_type, struct string_map *o)
+xr_allocate (const char *name, int device_type, struct string_map *o,
+             double font_scale)
 {
   struct xr_driver *xr = xzalloc (sizeof *xr);
   struct output_driver *d = &xr->driver;
@@ -601,6 +603,13 @@ xr_allocate (const char *name, int device_type, struct string_map *o)
 
   string_map_init (&xr->heading_vars);
 
+  /* This is a nasty kluge for an issue that does not make sense.  On any
+     surface other than a screen (e.g. for output to PDF or PS or SVG), the
+     fonts are way too big by default.  A "9-point" font seems to appear about
+     16 points tall.  We use a scale factor for these surfaces to help, but the
+     underlying issue is a mystery. */
+  xr->font_scale = font_scale;
+
   apply_options (xr, o);
 
   return xr;
@@ -809,7 +818,7 @@ xr_create (const char *file_name, enum settings_output_devices device_type,
   cairo_status_t status;
   double width_pt, length_pt;
 
-  xr = xr_allocate (file_name, device_type, o);
+  xr = xr_allocate (file_name, device_type, o, 72.0 / 128.0);
 
   width_pt = xr_to_pt (xr->width + xr->left_margin + xr->right_margin);
   length_pt = xr_to_pt (xr->length + xr->top_margin + xr->bottom_margin);
@@ -1491,7 +1500,7 @@ xr_layout_cell_text (struct xr_driver *xr, const struct table_cell *cell,
     {
       PangoFontDescription *desc = parse_font (
         font_style->typeface,
-        font_style->size ? font_style->size * 1000 * 72 / 128 : 10000,
+        font_style->size ? font_style->size * 1000 * xr->font_scale : 10000,
         font_style->bold, font_style->italic);
       if (desc)
         {
@@ -1847,7 +1856,7 @@ struct xr_rendering
 struct xr_driver *
 xr_driver_create (cairo_t *cairo, struct string_map *options)
 {
-  struct xr_driver *xr = xr_allocate ("cairo", 0, options);
+  struct xr_driver *xr = xr_allocate ("cairo", 0, options, 1.0);
   xr_set_cairo (xr, cairo);
   return xr;
 }
index 3d1ccbaa585199206fe2352701118fe1cd17d4ff..031656227bfe6b05dfa58b3444f73fa6ae7d893d 100644 (file)
@@ -76,6 +76,7 @@ pivot_area_get_default_style (enum pivot_area area)
       .bold = BOLD,                                             \
       .fg = { [0] = CELL_COLOR_BLACK, [1] = CELL_COLOR_BLACK},  \
       .bg = { [0] = CELL_COLOR_WHITE, [1] = CELL_COLOR_WHITE},  \
+      .size = 9,                                                \
       .typeface = (char *) "Sans Serif",                        \
     },                                                          \
   }