X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Ftext-item.c;h=95bb7723c84147043a2e429489f29f8ca50d1626;hb=314b82f0ec6ba67330038df4cca739eda08270b4;hp=2837c93bb611714ecfee4d3a8bb8b217b8fafd02;hpb=7e0d00ad64b1957062f6f06c119e8808b9e6b727;p=pspp diff --git a/src/output/text-item.c b/src/output/text-item.c index 2837c93bb6..95bb7723c8 100644 --- a/src/output/text-item.c +++ b/src/output/text-item.c @@ -18,13 +18,16 @@ #include "output/text-item.h" -#include #include #include #include "libpspp/cast.h" +#include "libpspp/pool.h" #include "output/driver.h" #include "output/output-item-provider.h" +#include "output/table.h" +#include "output/table-item.h" +#include "output/table-provider.h" #include "gl/xalloc.h" #include "gl/xvasprintf.h" @@ -32,6 +35,26 @@ #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"); + + 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 * @@ -89,17 +112,47 @@ 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 table *tab = table_create (1, 1, 0, 0, 0, 0); + + struct table_area_style *style = pool_alloc (tab->container, sizeof *style); + *style = (struct table_area_style) { TABLE_AREA_STYLE_INITIALIZER__, + .cell_style.halign = TABLE_HALIGN_LEFT }; + struct font_style *font_style = &style->font_style; + if (text_item->typeface) + font_style->typeface = pool_strdup (tab->container, text_item->typeface); + 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; + tab->styles[0] = style; + + int opts = 0; + if (text_item->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, NULL, NULL); + text_item_unref (text_item); + return table_item; +} 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, };