output: Move text_item and group_item usage closer to the SPV model.
[pspp] / src / output / text-item.c
index 231a5c1fb7e87008160f03b8433f58880115421d..7cd1ef3841c7f810459cc70c638f0eb2789612b6 100644 (file)
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
+const char *
+text_item_type_to_string (enum text_item_type type)
+{
+  switch (type)
+    {
+    case TEXT_ITEM_PAGE_TITLE:
+      return _("Page Title");
+
+    case TEXT_ITEM_TITLE:
+      return _("Title");
+
+    case TEXT_ITEM_SYNTAX:
+    case TEXT_ITEM_LOG:
+      return _("Log");
+
+    case TEXT_ITEM_EJECT_PAGE:
+      return _("Page Break");
+
+    default:
+      return _("Text");
+    }
+}
+
 /* Creates and returns a new text item containing TEXT and the specified TYPE.
    The new text item takes ownership of TEXT. */
 struct text_item *
@@ -97,38 +120,39 @@ text_item_submit (struct text_item *item)
 struct table_item *
 text_item_to_table_item (struct text_item *text_item)
 {
-  struct tab_table *tab = tab_create (1, 1);
-
-  struct cell_style *style = pool_alloc (tab->container, sizeof *style);
-  *style = (struct cell_style) CELL_STYLE_INITIALIZER;
-  if (text_item->font)
-    style->font = pool_strdup (tab->container, text_item->font);
-  style->font_size = text_item->font_size;
-  style->bold = text_item->bold;
-  style->italic = text_item->italic;
-  style->underline = text_item->underline;
-  tab->styles[0] = style;
-
-  int opts = TAB_LEFT;
-  if (text_item->markup)
-    opts |= TAB_MARKUP;
-  if (text_item->type == TEXT_ITEM_SYNTAX || text_item->type == TEXT_ITEM_LOG)
-    opts |= TAB_FIX;
-  tab_text (tab, 0, 0, opts, text_item_get_text (text_item));
-  struct table_item *table_item = table_item_create (&tab->table, NULL, NULL);
+  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
+}
+\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->font);
+  free (item->typeface);
   free (item);
 }
 
 const struct output_item_class text_item_class =
   {
+    "text",
     text_item_destroy,
   };