From 660d222c1c6e484e5887ac9920d095ea7aaa0e38 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 23 Dec 2022 13:17:56 -0800 Subject: [PATCH] table: Rename TAB_* to TABLE_CELL_* and reduce from 16 to 8 bits each. --- src/output/cairo-fsm.c | 16 ++++++++-------- src/output/html.c | 2 +- src/output/pivot-output.c | 8 ++++---- src/output/table-provider.h | 2 +- src/output/table.c | 16 ++++++++-------- src/output/table.h | 24 ++++++++++-------------- 6 files changed, 32 insertions(+), 36 deletions(-) diff --git a/src/output/cairo-fsm.c b/src/output/cairo-fsm.c index bedf3147ea..dc14f7e7a6 100644 --- a/src/output/cairo-fsm.c +++ b/src/output/cairo-fsm.c @@ -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; diff --git a/src/output/html.c b/src/output/html.c index a2e63f9438..e69a8a7751 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -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) diff --git a/src/output/pivot-output.c b/src/output/pivot-output.c index c3751d04d8..59a2dd4e2a 100644 --- a/src/output/pivot-output.c +++ b/src/output/pivot-output.c @@ -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))); diff --git a/src/output/table-provider.h b/src/output/table-provider.h index f87293721f..6670902d73 100644 --- a/src/output/table-provider.h +++ b/src/output/table-provider.h @@ -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; diff --git a/src/output/table.c b/src/output/table.c index 34227c91b4..d0f145cad3 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -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; diff --git a/src/output/table.h b/src/output/table.h index ed56891dc4..a5d294a516 100644 --- a/src/output/table.h +++ b/src/output/table.h @@ -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. */ -- 2.30.2