From: Ben Pfaff Date: Mon, 26 Nov 2018 01:03:16 +0000 (-0800) Subject: output: Support styles for text items. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=7e0d00ad64b1957062f6f06c119e8808b9e6b727 output: Support styles for text items. --- diff --git a/src/output/cairo.c b/src/output/cairo.c index ad5dd345ab..b3ab780ba6 100644 --- a/src/output/cairo.c +++ b/src/output/cairo.c @@ -21,6 +21,7 @@ #include "libpspp/assertion.h" #include "libpspp/cast.h" #include "libpspp/message.h" +#include "libpspp/pool.h" #include "libpspp/start-date.h" #include "libpspp/str.h" #include "libpspp/string-map.h" @@ -1614,14 +1615,26 @@ xr_render_eject (void) } static struct xr_render_fsm * -xr_create_text_renderer (struct xr_driver *xr, const char *text) +xr_create_text_renderer (struct xr_driver *xr, const struct text_item *item) { - struct table_item *table_item; - struct xr_render_fsm *fsm; + struct tab_table *tab = tab_create (1, 1); - table_item = table_item_create (table_from_string (TAB_LEFT, text), - NULL, NULL); - fsm = xr_render_table (xr, table_item); + struct cell_style *style = pool_alloc (tab->container, sizeof *style); + *style = (struct cell_style) CELL_STYLE_INITIALIZER; + if (item->font) + { + puts (item->font); + style->font = pool_strdup (tab->container, item->font); + } + style->font_size = item->font_size; + style->bold = item->bold; + style->italic = item->italic; + style->underline = item->underline; + tab->styles[0] = style; + + tab_text (tab, 0, 0, TAB_LEFT, text_item_get_text (item)); + struct table_item *table_item = table_item_create (&tab->table, NULL, NULL); + struct xr_render_fsm *fsm = xr_render_table (xr, table_item); table_item_unref (table_item); return fsm; @@ -1659,7 +1672,7 @@ xr_render_text (struct xr_driver *xr, const struct text_item *text_item) break; default: - return xr_create_text_renderer (xr, text); + return xr_create_text_renderer (xr, text_item); } return NULL; @@ -1670,12 +1683,11 @@ xr_render_message (struct xr_driver *xr, const struct message_item *message_item) { const struct msg *msg = message_item_get_msg (message_item); - struct xr_render_fsm *fsm; - char *s; - - s = msg_to_string (msg, message_item->command_name); - fsm = xr_create_text_renderer (xr, s); + char *s = msg_to_string (msg, message_item->command_name); + struct text_item *item = text_item_create (TEXT_ITEM_PARAGRAPH, s); free (s); + struct xr_render_fsm *fsm = xr_create_text_renderer (xr, item); + text_item_unref (item); return fsm; } diff --git a/src/output/text-item.c b/src/output/text-item.c index 1531656276..2837c93bb6 100644 --- a/src/output/text-item.c +++ b/src/output/text-item.c @@ -37,7 +37,7 @@ struct text_item * text_item_create_nocopy (enum text_item_type type, char *text) { - struct text_item *item = xmalloc (sizeof *item); + struct text_item *item = xzalloc (sizeof *item); output_item_init (&item->output_item, &text_item_class); item->text = text; item->type = type; @@ -95,6 +95,7 @@ text_item_destroy (struct output_item *output_item) { struct text_item *item = to_text_item (output_item); free (item->text); + free (item->font); free (item); } diff --git a/src/output/text-item.h b/src/output/text-item.h index da1b208a5e..3cfeb28b73 100644 --- a/src/output/text-item.h +++ b/src/output/text-item.h @@ -64,6 +64,9 @@ struct text_item struct output_item output_item; char *text; /* The content. */ enum text_item_type type; /* Type. */ + char *font; + int font_size; + bool bold, italic, underline; }; struct text_item *text_item_create (enum text_item_type, const char *text);