pivot-table: Make pivot_area_get_default_style() return a static copy.
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 26 Dec 2019 00:43:45 +0000 (00:43 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Dec 2019 05:28:10 +0000 (05:28 +0000)
The existing callers all want to make their own copy, but an upcoming
new caller wants an existing one, so refactor the interface a bit.

src/output/pivot-table.c
src/output/pivot-table.h

index cce72ef1defabaafad9bf2af6b60c25b3b9830bc..d4649292ac807a9fa0a79af453eb6aa8379cb328 100644 (file)
@@ -62,8 +62,8 @@ pivot_area_to_string (enum pivot_area area)
     }
 }
 
-void
-pivot_area_get_default_style (enum pivot_area area, struct area_style *style)
+const struct area_style *
+pivot_area_get_default_style (enum pivot_area area)
 {
 #define STYLE(BOLD, H, V, L, R, T, B) {                         \
     .cell_style = {                                             \
@@ -77,6 +77,7 @@ pivot_area_get_default_style (enum pivot_area area, struct area_style *style)
       .fg = { [0] = CELL_COLOR_BLACK, [1] = CELL_COLOR_BLACK},  \
       .bg = { [0] = CELL_COLOR_WHITE, [1] = CELL_COLOR_WHITE},  \
       .size = 9,                                                \
+      .typeface = (char *) "Sans Serif",                        \
     },                                                          \
   }
   static const struct area_style default_area_styles[PIVOT_N_AREAS] = {
@@ -91,8 +92,7 @@ pivot_area_get_default_style (enum pivot_area area, struct area_style *style)
     };
 #undef STYLE
 
-  *style = default_area_styles[area];
-  style->font_style.typeface = xstrdup ("SansSerif");
+  return &default_area_styles[area];
 }
 
 void
@@ -714,7 +714,7 @@ pivot_table_create__ (struct pivot_value *title, const char *subtype)
   table->sizing[TABLE_VERT].range[1] = 120;
 
   for (size_t i = 0; i < PIVOT_N_AREAS; i++)
-    pivot_area_get_default_style (i, &table->areas[i]);
+    area_style_copy (NULL, &table->areas[i], pivot_area_get_default_style (i));
 
   /* Set default border styles. */
   static const enum table_stroke default_strokes[PIVOT_N_BORDERS] = {
index c11874da2e3802efef4d291e0d352cfcea3b6186..096e50a1ebcf932ea2dd772f38ad294cdb840909 100644 (file)
@@ -107,7 +107,7 @@ enum pivot_area
   };
 
 const char *pivot_area_to_string (enum pivot_area);
-void pivot_area_get_default_style (enum pivot_area, struct area_style *);
+const struct area_style *pivot_area_get_default_style (enum pivot_area);
 
 /* Table borders for styling purposes. */
 enum pivot_border