From: Ben Pfaff Date: Sun, 29 Dec 2019 16:25:57 +0000 (+0000) Subject: cairo: Fix font scaling. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9153beacc1308b37dbaf4f64155553360aa0173;p=pspp cairo: Fix font scaling. 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.) --- diff --git a/src/output/cairo.c b/src/output/cairo.c index b1a7e27368..57c27ddc23 100644 --- a/src/output/cairo.c +++ b/src/output/cairo.c @@ -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; } diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c index 3d1ccbaa58..031656227b 100644 --- a/src/output/pivot-table.c +++ b/src/output/pivot-table.c @@ -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", \ }, \ }