X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Ftext-item.c;h=7cd1ef3841c7f810459cc70c638f0eb2789612b6;hb=b754fbf65fcd1b4fb466bbba6af71e6717df01e3;hp=16588ae5c54e2beef6a1e96d3fbfd170a29572c3;hpb=dfd1972f7bcb550a4fc3b05dbe7e71d12334b0a7;p=pspp diff --git a/src/output/text-item.c b/src/output/text-item.c index 16588ae5c5..7cd1ef3841 100644 --- a/src/output/text-item.c +++ b/src/output/text-item.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,26 +16,55 @@ #include -#include +#include "output/text-item.h" #include #include #include -#include -#include -#include +#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 "xalloc.h" -#include "xvasprintf.h" +#include "gl/xalloc.h" +#include "gl/xvasprintf.h" #include "gettext.h" #define _(msgid) gettext (msgid) -static struct text_item * -allocate_text_item (enum text_item_type type, char *text) +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 * +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; @@ -47,7 +76,7 @@ allocate_text_item (enum text_item_type type, char *text) struct text_item * text_item_create (enum text_item_type type, const char *text) { - return allocate_text_item (type, xstrdup (text)); + return text_item_create_nocopy (type, xstrdup (text)); } /* Creates and returns a new text item containing a copy of FORMAT, which is @@ -60,7 +89,7 @@ text_item_create_format (enum text_item_type type, const char *format, ...) va_list args; va_start (args, format); - item = allocate_text_item (type, xvasprintf (format, args)); + item = text_item_create_nocopy (type, xvasprintf (format, args)); va_end (args); return item; @@ -87,16 +116,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; +} 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, };