From: Ben Pfaff Date: Fri, 1 Jan 2021 07:18:34 +0000 (-0800) Subject: output: Drop TAB_FIX and the idea of a configurable fixed-width font. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=052cf5f9ffd4fbbda175fcb0417352b332fabc37 output: Drop TAB_FIX and the idea of a configurable fixed-width font. Maybe it would be a good idea to make the fixed-width font configurable, but it makes compatibility harder. --- diff --git a/doc/invoking.texi b/doc/invoking.texi index 4d06f376dd..cd3fc1bf36 100644 --- a/doc/invoking.texi +++ b/doc/invoking.texi @@ -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: diff --git a/src/output/cairo-fsm.c b/src/output/cairo-fsm.c index 708bedec03..02478fe001 100644 --- a/src/output/cairo-fsm.c +++ b/src/output/cairo-fsm.c @@ -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; } @@ -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; } diff --git a/src/output/cairo-fsm.h b/src/output/cairo-fsm.h index bf93783541..cf2da691f4 100644 --- a/src/output/cairo-fsm.h +++ b/src/output/cairo-fsm.h @@ -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; diff --git a/src/output/cairo-pager.c b/src/output/cairo-pager.c index e87ec32524..d8dda89c31 100644 --- a/src/output/cairo-pager.c +++ b/src/output/cairo-pager.c @@ -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); diff --git a/src/output/cairo.c b/src/output/cairo.c index 313456c663..0aa35b66cc 100644 --- a/src/output/cairo.c +++ b/src/output/cairo.c @@ -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, diff --git a/src/output/html.c b/src/output/html.c index 9f9fc2db89..f731686ce7 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -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, " ", "
"); - else - { - s += strspn (s, CC_SPACES); - escape_string (html->file, s, " ", "
"); - } + s += strspn (s, CC_SPACES); + escape_string (html->file, s, " ", "
"); if (cell->n_subscripts) { diff --git a/src/output/table.h b/src/output/table.h index 5c47ffe88c..e7a801b9e7 100644 --- a/src/output/table.h +++ b/src/output/table.h @@ -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. */ diff --git a/src/output/text-item.c b/src/output/text-item.c index 34f1886d85..5f7a91d243 100644 --- a/src/output/text-item.c +++ b/src/output/text-item.c @@ -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); diff --git a/src/ui/gui/psppire-output-view.c b/src/ui/gui/psppire-output-view.c index cc00a05bda..76e0e1c126 100644 --- a/src/ui/gui/psppire-output-view.c +++ b/src/ui/gui/psppire-output-view.c @@ -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