output: Drop TAB_FIX and the idea of a configurable fixed-width font.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 1 Jan 2021 07:18:34 +0000 (23:18 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 2 Jan 2021 03:23:40 +0000 (19:23 -0800)
Maybe it would be a good idea to make the fixed-width font configurable,
but it makes compatibility harder.

doc/invoking.texi
src/output/cairo-fsm.c
src/output/cairo-fsm.h
src/output/cairo-pager.c
src/output/cairo.c
src/output/html.c
src/output/table.h
src/output/text-item.c
src/ui/gui/psppire-output-view.c

index 4d06f376dd2662ec70216b66b7cfa2fc230c3aa0..cd3fc1bf364cd6aad1761b1819b677b20b6c3b18 100644 (file)
@@ -287,13 +287,11 @@ Sets the margins around the page.  See
 below for the allowed forms of @var{dimension} Default: @code{0.5in}.
 
 @item @option{-O prop-font=@var{font-name}}
-@itemx @option{-O fixed-font=@var{font-name}}
-Sets the font used for proportional, or fixed-pitch text.  Most
-systems support CSS-like font names such as ``serif'' and
-``monospace'', but a wide range of system-specific font are likely to
-be supported as well.
+Sets the default font used for ordinary text.  Most systems support
+CSS-like font names such as ``Sans Serif'', but a wide range of
+system-specific fonts are likely to be supported as well.
 
-Default: proportional font @code{serif}, fixed-pitch font @code{monospace}.
+Default: proportional font @code{Sans Serif}.
 
 @item @option{-O font-size=@var{font-size}}
 Sets the size of the default fonts, in thousandths of a point.  Default:
index 708bedec03756fc379a193151066c31e2197104e..02478fe00123956e1441e297943c684430258971 100644 (file)
@@ -74,9 +74,8 @@ xr_fsm_style_unshare (struct xr_fsm_style *old)
 
   struct xr_fsm_style *new = xmemdup (old, sizeof *old);
   new->ref_cnt = 1;
-  for (int i = 0; i < XR_N_FONTS; i++)
-    if (old->fonts[i])
-      new->fonts[i] = pango_font_description_copy (old->fonts[i]);
+  if (old->font)
+    new->font = pango_font_description_copy (old->font);
 
   return new;
 }
@@ -89,8 +88,7 @@ xr_fsm_style_unref (struct xr_fsm_style *style)
       assert (style->ref_cnt > 0);
       if (!--style->ref_cnt)
         {
-          for (size_t i = 0; i < XR_N_FONTS; i++)
-            pango_font_description_free (style->fonts[i]);
+          pango_font_description_free (style->font);
           free (style);
         }
     }
@@ -104,14 +102,11 @@ xr_fsm_style_equals (const struct xr_fsm_style *a,
       || a->size[V] != b->size[V]
       || a->min_break[H] != b->min_break[H]
       || a->min_break[V] != b->min_break[V]
+      || !pango_font_description_equal (a->font, b->font)
       || a->use_system_colors != b->use_system_colors
       || a->font_resolution != b->font_resolution)
     return false;
 
-  for (size_t i = 0; i < XR_N_FONTS; i++)
-    if (!pango_font_description_equal (a->fonts[i], b->fonts[i]))
-      return false;
-
   return true;
 }
 \f
@@ -631,9 +626,6 @@ xr_layout_cell_text (struct xr_fsm *xr, const struct table_cell *cell,
   enum table_axis Y = !X;
   int R = options & TAB_ROTATE ? 0 : 1;
 
-  enum xr_font_type font_type = (options & TAB_FIX
-                                 ? XR_FONT_FIXED
-                                 : XR_FONT_PROPORTIONAL);
   PangoFontDescription *desc = NULL;
   if (font_style->typeface)
       desc = parse_font (
@@ -641,7 +633,7 @@ xr_layout_cell_text (struct xr_fsm *xr, const struct table_cell *cell,
         font_style->size ? font_style->size * 1000 : 10000,
         font_style->bold, font_style->italic);
   if (!desc)
-    desc = xr->style->fonts[font_type];
+    desc = xr->style->font;
 
   assert (xr->cairo);
   PangoContext *context = pango_cairo_create_context (xr->cairo);
@@ -921,7 +913,7 @@ xr_layout_cell_text (struct xr_fsm *xr, const struct table_cell *cell,
 
   pango_layout_set_attributes (layout, NULL);
 
-  if (desc != xr->style->fonts[font_type])
+  if (desc != xr->style->font)
     pango_font_description_free (desc);
   g_object_unref (G_OBJECT (layout));
 
@@ -1043,28 +1035,26 @@ xr_fsm_create (const struct output_item *item_,
       fsm->cairo = NULL;
     }
 
-  for (int i = 0; i < XR_N_FONTS; i++)
-    {
-      PangoContext *context = pango_cairo_create_context (cr);
-      pango_cairo_context_set_resolution (context, style->font_resolution);
-      PangoLayout *layout = pango_layout_new (context);
-      g_object_unref (context);
-
-      pango_layout_set_font_description (layout, style->fonts[i]);
+  /* Get font size. */
+  PangoContext *context = pango_cairo_create_context (cr);
+  pango_cairo_context_set_resolution (context, style->font_resolution);
+  PangoLayout *layout = pango_layout_new (context);
+  g_object_unref (context);
 
-      pango_layout_set_text (layout, "0", 1);
+  pango_layout_set_font_description (layout, style->font);
 
-      int char_size[TABLE_N_AXES];
-      pango_layout_get_size (layout, &char_size[H], &char_size[V]);
-      for (int a = 0; a < TABLE_N_AXES; a++)
-        {
-          int csa = pango_to_xr (char_size[a]);
-          fsm->rp.font_size[a] = MAX (fsm->rp.font_size[a], csa);
-        }
+  pango_layout_set_text (layout, "0", 1);
 
-      g_object_unref (G_OBJECT (layout));
+  int char_size[TABLE_N_AXES];
+  pango_layout_get_size (layout, &char_size[H], &char_size[V]);
+  for (int a = 0; a < TABLE_N_AXES; a++)
+    {
+      int csa = pango_to_xr (char_size[a]);
+      fsm->rp.font_size[a] = MAX (fsm->rp.font_size[a], csa);
     }
 
+  g_object_unref (G_OBJECT (layout));
+
   return fsm;
 }
 
index bf937835418b6b130d48c7b3edf5995223b59ab1..cf2da691f45fc0661dd3d499c13f73d745e115bd 100644 (file)
@@ -32,20 +32,13 @@ struct output_item;
    (Thus, XR_POINT units represent one point.) */
 #define XR_POINT PANGO_SCALE
 
-enum xr_font_type
-  {
-    XR_FONT_PROPORTIONAL,
-    XR_FONT_FIXED,
-    XR_N_FONTS
-  };
-
 struct xr_fsm_style
   {
     int ref_cnt;
 
     int size[TABLE_N_AXES];      /* Page size. */
     int min_break[TABLE_N_AXES]; /* Minimum cell size to allow breaking. */
-    PangoFontDescription *fonts[XR_N_FONTS];
+    PangoFontDescription *font;
     struct cell_color fg;
     bool use_system_colors;
 
index e87ec325248f2cff94d2fbdd2c57d7d1febc6a07..d8dda89c3197b79a2d03526d5970e0b931c00012 100644 (file)
@@ -215,7 +215,7 @@ xr_measure_headings (const struct xr_page_style *ps,
   for (int i = 0; i < 2; i++)
     {
       int *h = &heading_heights[i];
-      *h = xr_render_page_heading (cairo, fs->fonts[XR_FONT_PROPORTIONAL],
+      *h = xr_render_page_heading (cairo, fs->font,
                                    &ps->headings[i], -1, fs->size[H], 0,
                                    fs->font_resolution);
       if (*h)
@@ -310,15 +310,14 @@ xr_pager_add_page (struct xr_pager *p, cairo_t *cr)
                    xr_to_pt (ps->margins[H][0]),
                    xr_to_pt (ps->margins[V][0]));
 
-  const PangoFontDescription *font = fs->fonts[XR_FONT_PROPORTIONAL];
   int page_number = p->page_index++ + ps->initial_page_number;
   if (p->heading_heights[0])
-    xr_render_page_heading (cr, font, &ps->headings[0], page_number,
+    xr_render_page_heading (cr, fs->font, &ps->headings[0], page_number,
                             fs->size[H], -p->heading_heights[0],
                             fs->font_resolution);
 
   if (p->heading_heights[1])
-    xr_render_page_heading (cr, font, &ps->headings[1], page_number,
+    xr_render_page_heading (cr, fs->font, &ps->headings[1], page_number,
                             fs->size[H], fs->size[V] + ps->object_spacing,
                             fs->font_resolution);
 
index 313456c663e07290efb5a88f3104741c8df35d33..0aa35b66cc69d8fc3aaf8200d71aa337e8b12116 100644 (file)
@@ -218,10 +218,8 @@ xr_allocate (const char *name, int device_type,
       min_break[a] = size[a] / 2;
 
   int font_size = parse_int (opt (d, o, "font-size", "10000"), 1000, 1000000);
-  PangoFontDescription *fixed_font = parse_font_option
-    (d, o, "fixed-font", "monospace", font_size, false, false);
-  PangoFontDescription *proportional_font = parse_font_option (
-    d, o, "prop-font", "sans serif", font_size, false, false);
+  PangoFontDescription *font = parse_font_option (
+    d, o, "prop-font", "Sans Serif", font_size, false, false);
 
   struct cell_color fg = parse_color (opt (d, o, "foreground-color", "black"));
 
@@ -265,10 +263,7 @@ xr_allocate (const char *name, int device_type,
     .ref_cnt = 1,
     .size = { [H] = size[H], [V] = size[V] },
     .min_break = { [H] = min_break[H], [V] = min_break[V] },
-    .fonts = {
-      [XR_FONT_PROPORTIONAL] = proportional_font,
-      [XR_FONT_FIXED] = fixed_font,
-    },
+    .font = font,
     .fg = fg,
     .use_system_colors = systemcolors,
     .font_resolution = font_resolution,
@@ -595,12 +590,11 @@ xr_update_page_setup (struct output_driver *driver,
       [H] = setup->paper[H] * scale / 2,
       [V] = setup->paper[V] * scale / 2,
     },
+    .font = pango_font_description_copy (old_fs->font),
     .fg = old_fs->fg,
     .use_system_colors = old_fs->use_system_colors,
     .font_resolution = old_fs->font_resolution,
   };
-  for (size_t i = 0; i < XR_N_FONTS; i++)
-    xr->fsm_style->fonts[i] = pango_font_description_copy (old_fs->fonts[i]);
   xr_fsm_style_unref (old_fs);
 
   xr_set_surface_size (xr->dest_surface, xr->output_type,
index 9f9fc2db89df9804650921c282ddb5a650f58978..f731686ce78711ab1dc0fdfaf7da6b7a2701127a 100644 (file)
@@ -518,13 +518,8 @@ html_put_table_cell_text (struct html_driver *html,
                           const struct table_cell *cell)
 {
   const char *s = cell->text;
-  if (cell->options & TAB_FIX)
-    escape_tag (html->file, "tt", s, "&nbsp;", "<br>");
-  else
-    {
-      s += strspn (s, CC_SPACES);
-      escape_string (html->file, s, " ", "<br>");
-    }
+  s += strspn (s, CC_SPACES);
+  escape_string (html->file, s, " ", "<br>");
 
   if (cell->n_subscripts)
     {
index 5c47ffe88c0c68e7a49ee0788c91d9b926af2f1a..e7a801b9e7fccb552f068c12938b208482cc6d98 100644 (file)
@@ -180,7 +180,6 @@ void table_area_style_free (struct table_area_style *);
 enum
   {
     TAB_NONE = 0,
-    TAB_FIX        = 1 << 1,    /* Use fixed font. */
     TAB_MARKUP     = 1 << 2,    /* Text contains Pango markup. */
     TAB_NUMERIC    = 1 << 3,    /* Cell contents are numeric. */
     TAB_ROTATE     = 1 << 4,    /* Rotate cell contents 90 degrees. */
index 34f1886d855c14d0a7fed33ce7256f99cf458488..5f7a91d243413c6f0ec2b1268937f45eb64e58bc 100644 (file)
@@ -174,8 +174,6 @@ text_item_to_table_item (struct text_item *text_item)
   int opts = 0;
   if (text_item->style.markup)
     opts |= TAB_MARKUP;
-  if (text_item->type == TEXT_ITEM_SYNTAX || text_item->type == TEXT_ITEM_LOG)
-    opts |= TAB_FIX;
   table_text (tab, 0, 0, opts, text_item_get_text (text_item));
   struct table_item *table_item = table_item_create (tab);
   text_item_unref (text_item);
index cc00a05bdaa327f8188f43bdeb826bc311daa00c..76e0e1c1267493533174a79f19ae7c3952ccfdba 100644 (file)
@@ -151,18 +151,13 @@ get_xr_fsm_style (struct psppire_output_view *view)
 
   PangoFontDescription *pf;
   gtk_style_context_get (context, state, "font", &pf, NULL);
-  PangoFontDescription *ff = pango_font_description_from_string ("Monospace");
-  pango_font_description_set_size (ff, pango_font_description_get_size (pf));
 
   struct xr_fsm_style *style = xmalloc (sizeof *style);
   *style = (struct xr_fsm_style) {
     .ref_cnt = 1,
     .size = { [TABLE_HORZ] = xr_width, [TABLE_VERT] = INT_MAX },
     .min_break = { [TABLE_HORZ] = xr_width / 2, [TABLE_VERT] = 0 },
-    .fonts = {
-      [XR_FONT_PROPORTIONAL] = pf,
-      [XR_FONT_FIXED] = ff,
-    },
+    .font = pf,
     .use_system_colors = true,
     .font_resolution = 96.0,
   };
@@ -958,11 +953,6 @@ create_xr_print_driver (GtkPrintContext *context, struct psppire_output_view *vi
   for (int a = 0; a < TABLE_N_AXES; a++)
     size[a] = paper[a] - margins[a][0] - margins[a][1];
 
-  PangoFontDescription *proportional_font
-    = pango_font_description_from_string ("Sans Serif 10");
-  PangoFontDescription *fixed_font
-    = pango_font_description_from_string ("Monospace 10");
-
   view->page_style = xmalloc (sizeof *view->page_style);
   *view->page_style = (struct xr_page_style) {
     .ref_cnt = 1,
@@ -981,10 +971,7 @@ create_xr_print_driver (GtkPrintContext *context, struct psppire_output_view *vi
 
     .size = { [H] = size[H], [V] = size[V] },
     .min_break = { [H] = size[H] / 2, [V] = size[V] / 2 },
-    .fonts = {
-      [XR_FONT_PROPORTIONAL] = proportional_font,
-      [XR_FONT_FIXED] = fixed_font,
-    },
+    .font = pango_font_description_from_string ("Sans Serif 10"),
     .fg = CELL_COLOR_BLACK,
     .use_system_colors = false,
     .font_resolution = 72.0