table: Rename TAB_* to TABLE_CELL_* and reduce from 16 to 8 bits each.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 23 Dec 2022 21:17:56 +0000 (13:17 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 5 Jan 2023 01:48:22 +0000 (17:48 -0800)
src/output/cairo-fsm.c
src/output/html.c
src/output/pivot-output.c
src/output/table-provider.h
src/output/table.c
src/output/table.h

index bedf3147ea281d4cba8ccd1c3b579cc052eb5844..dc14f7e7a64676dc41932e36e5ff0ae504cc3f3f 100644 (file)
@@ -637,9 +637,9 @@ xr_layout_cell_text (struct xr_fsm *xr, const struct table_cell *cell,
   const struct cell_style *cell_style = cell->cell_style;
   unsigned int options = cell->options;
 
-  enum table_axis X = options & TAB_ROTATE ? V : H;
+  enum table_axis X = options & TABLE_CELL_ROTATE ? V : H;
   enum table_axis Y = !X;
-  int R = options & TAB_ROTATE ? 0 : 1;
+  int R = options & TABLE_CELL_ROTATE ? 0 : 1;
 
   PangoFontDescription *desc = NULL;
   if (font_style->typeface)
@@ -665,7 +665,7 @@ xr_layout_cell_text (struct xr_fsm *xr, const struct table_cell *cell,
     cell->cell_style->halign, numeric);
 
   if (cell_style->halign == TABLE_HALIGN_DECIMAL
-      && !(cell->options & TAB_ROTATE))
+      && !(cell->options & TABLE_CELL_ROTATE))
     {
       int margin_adjustment = -px_to_xr (cell_style->decimal_offset);
 
@@ -716,7 +716,7 @@ xr_layout_cell_text (struct xr_fsm *xr, const struct table_cell *cell,
           /* XXX should we report the error? */
         }
     }
-  else if (options & TAB_ROTATE || bb[H][1] != INT_MAX)
+  else if (options & TABLE_CELL_ROTATE || bb[H][1] != INT_MAX)
     {
       const char *text = ds_cstr (&body);
       const char *decimal = text + strcspn (text, ".,");
@@ -789,7 +789,7 @@ xr_layout_cell_text (struct xr_fsm *xr, const struct table_cell *cell,
           int footnote_adjustment = MIN (footnote_width, right_margin);
 
           /* Adjust the bounding box. */
-          if (options & TAB_ROTATE)
+          if (options & TABLE_CELL_ROTATE)
             footnote_adjustment = -footnote_adjustment;
           bb[X][R] += footnote_adjustment;
 
@@ -840,9 +840,9 @@ xr_layout_cell_text (struct xr_fsm *xr, const struct table_cell *cell,
   if (clip[H][0] != clip[H][1])
     {
       cairo_save (xr->cairo);
-      if (!(options & TAB_ROTATE))
+      if (!(options & TABLE_CELL_ROTATE))
         xr_clip (xr, clip);
-      if (options & TAB_ROTATE)
+      if (options & TABLE_CELL_ROTATE)
         {
           int extra = bb[H][1] - bb[H][0] - size[V];
           int halign_offset = extra > 0 ? extra / 2 : 0;
@@ -890,7 +890,7 @@ xr_layout_cell_text (struct xr_fsm *xr, const struct table_cell *cell,
   int h = pango_to_xr (size[Y]);
   if (w > *widthp)
     *widthp = w;
-  if (bb[V][0] + h >= bb[V][1] && !(options & TAB_ROTATE))
+  if (bb[V][0] + h >= bb[V][1] && !(options & TABLE_CELL_ROTATE))
     {
       PangoLayoutIter *iter;
       int best = 0;
index a2e63f943888169a1e30458f6b7d0b100bc6e102..e69a8a775118f12a25ddaf57b99a273ea97147cd 100644 (file)
@@ -516,7 +516,7 @@ html_put_table_cell (struct html_driver *html, const struct pivot_table *pt,
       break;
     }
 
-  if (cell->options & TAB_ROTATE)
+  if (cell->options & TABLE_CELL_ROTATE)
     put_style (&style, "writing-mode", "sideways-lr");
 
   if (cell->cell_style->valign != TABLE_VALIGN_TOP)
index c3751d04d888dff563b28a1155c18143c64f8b80..59a2dd4e2a4b9ac95dea2c193ea15600b59d02db 100644 (file)
@@ -116,9 +116,9 @@ fill_cell (struct table *t, int x1, int y1, int x2, int y2,
            int style_idx, const struct pivot_value *value,
            bool rotate_label)
 {
-  int options = style_idx << TAB_STYLE_SHIFT;
+  int options = style_idx << TABLE_CELL_STYLE_SHIFT;
   if (rotate_label)
-    options |= TAB_ROTATE;
+    options |= TABLE_CELL_ROTATE;
 
   table_put (t, x1, y1, x2, y2, options, value);
 }
@@ -127,9 +127,9 @@ static void
 fill_cell_owned (struct table *t, int x1, int y1, int x2, int y2,
                  int style_idx, struct string *s, bool rotate_label)
 {
-  int options = style_idx << TAB_STYLE_SHIFT;
+  int options = style_idx << TABLE_CELL_STYLE_SHIFT;
   if (rotate_label)
-    options |= TAB_ROTATE;
+    options |= TABLE_CELL_ROTATE;
 
   table_put_owned (t, x1, y1, x2, y2, options,
                    pivot_value_new_user_text_nocopy (ds_steal_cstr (s)));
index f87293721f47846d0153d89f5ea1fa430894a164..6670902d732b102578e0e9c9ad03f3b85fe234f8 100644 (file)
@@ -45,7 +45,7 @@ struct table_cell
        or both. */
     int d[TABLE_N_AXES][2];
 
-    unsigned int options;       /* TAB_*. */
+    unsigned char options;       /* TABLE_CELL_*. */
     const struct pivot_value *value;
     const struct font_style *font_style;
     const struct cell_style *cell_style;
index 34227c91b4ab83a82868cfb99961b51e965bd8a6..d0f145cad3528a094dc3548303efedefd1fd43b2 100644 (file)
@@ -272,7 +272,7 @@ table_create (int nc, int nr, int hl, int hr, int ht, int hb)
   t->ref_cnt = 1;
 
   t->cc = pool_calloc (t->container, nr * nc, sizeof *t->cc);
-  t->ct = pool_calloc (t->container, nr * nc, sizeof *t->ct);
+  t->cp = pool_calloc (t->container, nr * nc, sizeof *t->cp);
 
   t->rh = pool_nmalloc (t->container, nc, nr + 1);
   memset (t->rh, TABLE_STROKE_NONE, nc * (nr + 1));
@@ -341,7 +341,7 @@ table_hline (struct table *t, int style, int x1, int x2, int y)
 /* Fill TABLE cells (X1,X2)-(Y1,Y2), inclusive, with VALUE and OPT. */
 void
 table_put (struct table *table, int x1, int y1, int x2, int y2,
-           unsigned opt, const struct pivot_value *value)
+           unsigned int opt, const struct pivot_value *value)
 {
   assert (0 <= x1 && x1 <= x2 && x2 < table->n[H]);
   assert (0 <= y1 && y1 <= y2 && y2 < table->n[V]);
@@ -349,7 +349,7 @@ table_put (struct table *table, int x1, int y1, int x2, int y2,
   if (x1 == x2 && y1 == y2)
     {
       table->cc[x1 + y1 * table->n[H]] = CONST_CAST (struct pivot_value *, value);
-      table->ct[x1 + y1 * table->n[H]] = opt;
+      table->cp[x1 + y1 * table->n[H]] = opt;
     }
   else
     {
@@ -364,11 +364,11 @@ table_put (struct table *table, int x1, int y1, int x2, int y2,
         {
           size_t ofs = x1 + y * table->n[H];
           void **cc = &table->cc[ofs];
-          unsigned short *ct = &table->ct[ofs];
+          unsigned char *ct = &table->cp[ofs];
           for (int x = x1; x <= x2; x++)
             {
               *cc++ = cell;
-              *ct++ = opt | TAB_JOIN;
+              *ct++ = opt | TABLE_CELL_JOIN;
             }
         }
     }
@@ -405,11 +405,11 @@ table_get_cell (const struct table *t, int x, int y, struct table_cell *cell)
   assert (y >= 0 && y < t->n[TABLE_VERT]);
 
   int index = x + y * t->n[H];
-  unsigned short opt = t->ct[index];
+  unsigned char opt = t->cp[index];
   const void *cc = t->cc[index];
 
   struct table_area_style *style
-    = t->styles[(opt & TAB_STYLE_MASK) >> TAB_STYLE_SHIFT];
+    = t->styles[(opt & TABLE_CELL_STYLE_MASK) >> TABLE_CELL_STYLE_SHIFT];
 
   static const struct pivot_value empty_value = {
     .text = {
@@ -421,7 +421,7 @@ table_get_cell (const struct table *t, int x, int y, struct table_cell *cell)
     },
   };
 
-  if (opt & TAB_JOIN)
+  if (opt & TABLE_CELL_JOIN)
     {
       const struct table_cell *jc = cc;
       *cell = *jc;
index ed56891dc4c646412d91b6cfdd524cd7e638e55d..a5d294a5167d1718b7ec4580b246657945ff7bc3 100644 (file)
@@ -178,17 +178,13 @@ void table_area_style_copy (struct pool *, struct table_area_style *,
 void table_area_style_uninit (struct table_area_style *);
 void table_area_style_free (struct table_area_style *);
 
-/* Properties of a table cell. */
+/* Cell properties. */
 enum
   {
-    TAB_NONE = 0,
-    TAB_ROTATE     = 1 << 4,    /* Rotate cell contents 90 degrees. */
-
-    TAB_STYLE_SHIFT = 5,
-    TAB_STYLE_MASK = 7 << TAB_STYLE_SHIFT,
-
-    /* Internal use by tab.c only. */
-    TAB_JOIN = 1 << 14,
+    TABLE_CELL_ROTATE     = 1 << 0,    /* Rotate cell contents 90 degrees. */
+    TABLE_CELL_JOIN       = 1 << 1,    /* Joined cell (internal use only). */
+    TABLE_CELL_STYLE_SHIFT = 2,
+    TABLE_CELL_STYLE_MASK = 7 << TABLE_CELL_STYLE_SHIFT,
   };
 
 /* A table. */
@@ -222,12 +218,12 @@ struct table
 
     /* Table contents.
 
-       Each array element in cc[] is ordinarily a "struct pivot_value *".
-       If TAB_JOIN (defined in table.c) is set in ct[] for the element,
-       however, it is a joined cell and the corresponding element of cc[]
-       points to a struct table_cell. */
+       Each array element in cc[] is ordinarily a "struct pivot_value *".  If
+       TABLE_CELL_JOIN is set in cp[] for the element, however, it is a joined
+       cell and the corresponding element of cc[] points to a struct
+       table_cell. */
     void **cc;                  /* Cell contents; void *[nr][nc]. */
-    unsigned short *ct;                /* Cell types; unsigned short[nr][nc]. */
+    unsigned char *cp;         /* Cell properties; unsigned char[nr][nc]. */
     struct table_area_style *styles[8];
 
     /* Rules. */