output: Implement styling for titles and captions.
[pspp] / src / output / table.c
index 7f37479984274dc357d50da44f03423d2ea891bd..c8dfcbb0f83910802a379d59ba29b341ce824bf0 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "libpspp/cast.h"
 #include "libpspp/compiler.h"
+#include "libpspp/pool.h"
 #include "libpspp/str.h"
 #include "output/table-item.h"
 
@@ -129,6 +130,26 @@ table_set_nr (struct table *table, int nr)
   table->n[TABLE_VERT] = nr;
 }
 \f
+struct cell_style *
+cell_style_clone (struct pool *pool, const struct cell_style *old)
+{
+  struct cell_style *new = pool_malloc (pool, sizeof *new);
+  *new = *old;
+  if (new->font)
+    new->font = pool_strdup (pool, new->font);
+  return new;
+}
+
+void
+cell_style_free (struct cell_style *style)
+{
+  if (style)
+    {
+      free (style->font);
+      free (style);
+    }
+}
+
 /* Initializes CELL with the contents of the table cell at column X and row Y
    within TABLE.  When CELL is no longer needed, the caller is responsible for
    freeing it by calling table_cell_free(CELL).
@@ -140,6 +161,10 @@ table_get_cell (const struct table *table, int x, int y,
 {
   assert (x >= 0 && x < table->n[TABLE_HORZ]);
   assert (y >= 0 && y < table->n[TABLE_VERT]);
+
+  static const struct cell_style default_style = CELL_STYLE_INITIALIZER;
+  cell->style = &default_style;
+
   table->klass->get_cell (table, x, y, cell);
 }
 
@@ -190,11 +215,13 @@ table_cell_free (struct table_cell *cell)
    between that cell and cell (0,1); and so on, up to (0,NR), which runs
    horizontally below cell (0,NR-1). */
 int
-table_get_rule (const struct table *table, enum table_axis axis, int x, int y)
+table_get_rule (const struct table *table, enum table_axis axis, int x, int y,
+                struct cell_color *color)
 {
   assert (x >= 0 && x < table->n[TABLE_HORZ] + (axis == TABLE_HORZ));
   assert (y >= 0 && y < table->n[TABLE_VERT] + (axis == TABLE_VERT));
-  return table->klass->get_rule (table, axis, x, y);
+  *color = CELL_COLOR_BLACK;
+  return table->klass->get_rule (table, axis, x, y, color);
 }
 
 void
@@ -331,10 +358,11 @@ table_unshared_get_cell (const struct table *tiu_, int x, int y,
 
 static int
 table_unshared_get_rule (const struct table *tiu_,
-                              enum table_axis axis, int x, int y)
+                         enum table_axis axis, int x, int y,
+                         struct cell_color *color)
 {
   struct table_unshared *tiu = table_unshared_cast (tiu_);
-  return table_get_rule (tiu->subtable, axis, x, y);
+  return table_get_rule (tiu->subtable, axis, x, y, color);
 }
 
 static const struct table_class table_unshared_class =
@@ -403,7 +431,8 @@ table_string_get_cell (const struct table *ts_, int x UNUSED, int y UNUSED,
 
 static int
 table_string_get_rule (const struct table *ts UNUSED,
-                       enum table_axis axis UNUSED, int x UNUSED, int y UNUSED)
+                       enum table_axis axis UNUSED, int x UNUSED, int y UNUSED,
+                       struct cell_color *color UNUSED)
 {
   return TAL_0;
 }