output: Support styles for text items.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 26 Nov 2018 01:03:16 +0000 (17:03 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 25 Dec 2018 20:36:08 +0000 (12:36 -0800)
src/output/cairo.c
src/output/text-item.c
src/output/text-item.h

index ad5dd345ab7e8fb867f5c721a6481f7d917d4346..b3ab780ba68e4a53cc68d7d03cb6e6ca32e73ff2 100644 (file)
@@ -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)
 }
 \f
 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;
 }
index 1531656276c7dd01116eff4b094fc9933362494e..2837c93bb611714ecfee4d3a8bb8b217b8fafd02 100644 (file)
@@ -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);
 }
 
index da1b208a5ea8cfd40ec5c27339cd2c8307d814a3..3cfeb28b73e9e5ed08fdd8a33d1cefbec0f27a24 100644 (file)
@@ -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);