work
[pspp] / src / output / text-item.c
index 1531656276c7dd01116eff4b094fc9933362494e..eb3155affc948926f32b093bec2278c4553ee4d9 100644 (file)
 #include <stdlib.h>
 
 #include "libpspp/cast.h"
+#include "libpspp/pool.h"
 #include "output/driver.h"
 #include "output/output-item-provider.h"
+#include "output/tab.h"
+#include "output/table-item.h"
+#include "output/table-provider.h"
 
 #include "gl/xalloc.h"
 #include "gl/xvasprintf.h"
@@ -37,7 +41,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;
@@ -89,16 +93,43 @@ text_item_submit (struct text_item *item)
 {
   output_submit (&item->output_item);
 }
+
+struct table_item *
+text_item_to_table_item (struct text_item *text_item)
+{
+  struct pivot_value *text = pivot_value_new_user_text (
+    text_item_get_text (text_item), -1);
+
+  struct font_style *font_style = xmalloc (sizeof *font_style);
+  if (text_item->typeface)
+    font_style->typeface = xstrdup (tab->container, text_item->typeface);
+  else if (text_item->type == TEXT_ITEM_SYNTAX
+           || text_item->type == TEXT_ITEM_LOG)
+    font_style->typeface = xstrdup ("Monospace");
+  font_style->size = text_item->size;
+  font_style->bold = text_item->bold;
+  font_style->italic = text_item->italic;
+  font_style->underline = text_item->underline;
+  font_style->markup = text_item->markup;
+  text->font_style = font_style;
+
+  struct table_item *table_item = table_item_create (
+    pivot_table_create_for_text (NULL, text));
+  text_item_unref (text_item);
+  return table_item;
+}
 \f
 static void
 text_item_destroy (struct output_item *output_item)
 {
   struct text_item *item = to_text_item (output_item);
   free (item->text);
+  free (item->typeface);
   free (item);
 }
 
 const struct output_item_class text_item_class =
   {
+    "text",
     text_item_destroy,
   };