From 32246b56b00acc8ccfddc3e91ac9765ad7d14471 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 15 Jan 2023 09:28:08 -0800 Subject: [PATCH] render: Get rid of RENDER_LINE_* in favor of similar TABLE_STROKE_*. These had the same values. They were separated for abstraction reasons that don't seem to be needed, and eliminating one of them eliminates some conversions. --- src/output/ascii.c | 30 ++++++++++++++-------------- src/output/cairo-fsm.c | 54 +++++++++++++++++++++++++------------------------- src/output/render.c | 39 ++++++++---------------------------- src/output/render.h | 13 +----------- src/output/table.h | 2 +- 5 files changed, 52 insertions(+), 86 deletions(-) diff --git a/src/output/ascii.c b/src/output/ascii.c index 6535121d8..9a279dd8d 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -245,18 +245,18 @@ ascii_line_from_render_line (int render_line) { switch (render_line) { - case RENDER_LINE_NONE: + case TABLE_STROKE_NONE: return ASCII_LINE_NONE; - case RENDER_LINE_DASHED: + case TABLE_STROKE_DASHED: return ASCII_LINE_DASHED; - case RENDER_LINE_SINGLE: - case RENDER_LINE_THICK: - case RENDER_LINE_THIN: + case TABLE_STROKE_SOLID: + case TABLE_STROKE_THICK: + case TABLE_STROKE_THIN: return ASCII_LINE_SINGLE; - case RENDER_LINE_DOUBLE: + case TABLE_STROKE_DOUBLE: return ASCII_LINE_DOUBLE; default: @@ -326,7 +326,7 @@ static bool update_page_size (struct ascii_driver *, bool issue_error); static int parse_page_size (struct driver_option *); static void ascii_draw_line (void *, int bb[TABLE_N_AXES][2], - enum render_line_style styles[TABLE_N_AXES][2], + enum table_stroke styles[TABLE_N_AXES][2], struct cell_color colors[TABLE_N_AXES][2]); static void ascii_measure_cell_width (void *, const struct table_cell *, int *min, int *max); @@ -420,13 +420,13 @@ ascii_create (struct file_handle *fh, enum settings_output_devices device_type, a->params.font_size[H] = 1; a->params.font_size[V] = 1; - static const int ascii_line_widths[RENDER_N_LINES] = { - [RENDER_LINE_NONE] = 0, - [RENDER_LINE_SINGLE] = 1, - [RENDER_LINE_DASHED] = 1, - [RENDER_LINE_THICK] = 1, - [RENDER_LINE_THIN] = 1, - [RENDER_LINE_DOUBLE] = 1, + static const int ascii_line_widths[TABLE_N_STROKES] = { + [TABLE_STROKE_NONE] = 0, + [TABLE_STROKE_SOLID] = 1, + [TABLE_STROKE_DASHED] = 1, + [TABLE_STROKE_THICK] = 1, + [TABLE_STROKE_THIN] = 1, + [TABLE_STROKE_DOUBLE] = 1, }; a->params.line_widths = ascii_line_widths; a->params.supports_margins = false; @@ -673,7 +673,7 @@ static void ascii_layout_cell (struct ascii_driver *, static void ascii_draw_line (void *a_, int bb[TABLE_N_AXES][2], - enum render_line_style styles[TABLE_N_AXES][2], + enum table_stroke styles[TABLE_N_AXES][2], struct cell_color colors[TABLE_N_AXES][2] UNUSED) { struct ascii_driver *a = a_; diff --git a/src/output/cairo-fsm.c b/src/output/cairo-fsm.c index dc14f7e7a..3ba84930d 100644 --- a/src/output/cairo-fsm.c +++ b/src/output/cairo-fsm.c @@ -194,18 +194,18 @@ xr_draw_line (struct xr_fsm *xr, int x0, int y0, int x1, int y1, int style, cairo_new_path (xr->cairo); cairo_set_line_width ( xr->cairo, - xr_to_pt (style == RENDER_LINE_THICK ? XR_LINE_WIDTH * 2 - : style == RENDER_LINE_THIN ? XR_LINE_WIDTH / 2 + xr_to_pt (style == TABLE_STROKE_THICK ? XR_LINE_WIDTH * 2 + : style == TABLE_STROKE_THIN ? XR_LINE_WIDTH / 2 : XR_LINE_WIDTH)); cairo_move_to (xr->cairo, xr_to_pt (x0), xr_to_pt (y0)); cairo_line_to (xr->cairo, xr_to_pt (x1), xr_to_pt (y1)); if (!xr->style->use_system_colors) xr_set_source_rgba (xr->cairo, color); - if (style == RENDER_LINE_DASHED) + if (style == TABLE_STROKE_DASHED) cairo_set_dash (xr->cairo, (double[]) { 2 }, 1, 0); cairo_stroke (xr->cairo); - if (style == RENDER_LINE_DASHED) + if (style == TABLE_STROKE_DASHED) cairo_set_dash (xr->cairo, NULL, 0, 0); } @@ -239,19 +239,19 @@ fill_rectangle (struct xr_fsm *xr, int x0, int y0, int x1, int y1) shortening it to X2...X3 if SHORTEN is true. */ static void xr_draw_horz_line (struct xr_fsm *xr, int x0, int x1, int x2, int x3, int y, - enum render_line_style left, enum render_line_style right, + enum table_stroke left, enum table_stroke right, const struct cell_color *left_color, const struct cell_color *right_color, bool shorten) { - if (left != RENDER_LINE_NONE && right != RENDER_LINE_NONE && !shorten + if (left != TABLE_STROKE_NONE && right != TABLE_STROKE_NONE && !shorten && cell_color_equal (left_color, right_color)) xr_draw_line (xr, x0, y, x3, y, left, left_color); else { - if (left != RENDER_LINE_NONE) + if (left != TABLE_STROKE_NONE) xr_draw_line (xr, x0, y, shorten ? x1 : x2, y, left, left_color); - if (right != RENDER_LINE_NONE) + if (right != TABLE_STROKE_NONE) xr_draw_line (xr, shorten ? x2 : x1, y, x3, y, right, right_color); } } @@ -262,26 +262,26 @@ xr_draw_horz_line (struct xr_fsm *xr, int x0, int x1, int x2, int x3, int y, shortening it to Y2...Y3 if SHORTEN is true. */ static void xr_draw_vert_line (struct xr_fsm *xr, int y0, int y1, int y2, int y3, int x, - enum render_line_style top, enum render_line_style bottom, + enum table_stroke top, enum table_stroke bottom, const struct cell_color *top_color, const struct cell_color *bottom_color, bool shorten) { - if (top != RENDER_LINE_NONE && bottom != RENDER_LINE_NONE && !shorten + if (top != TABLE_STROKE_NONE && bottom != TABLE_STROKE_NONE && !shorten && cell_color_equal (top_color, bottom_color)) xr_draw_line (xr, x, y0, x, y3, top, top_color); else { - if (top != RENDER_LINE_NONE) + if (top != TABLE_STROKE_NONE) xr_draw_line (xr, x, y0, x, shorten ? y1 : y2, top, top_color); - if (bottom != RENDER_LINE_NONE) + if (bottom != TABLE_STROKE_NONE) xr_draw_line (xr, x, shorten ? y2 : y1, x, y3, bottom, bottom_color); } } static void xrr_draw_line (void *xr_, int bb[TABLE_N_AXES][2], - enum render_line_style styles[TABLE_N_AXES][2], + enum table_stroke styles[TABLE_N_AXES][2], struct cell_color colors[TABLE_N_AXES][2]) { const int x0 = bb[H][0]; @@ -337,8 +337,8 @@ xrr_draw_line (void *xr_, int bb[TABLE_N_AXES][2], /* Are the lines along each axis single or double? (It doesn't make sense to have different kinds of line on the same axis, so we don't try to gracefully handle that case.) */ - bool double_vert = top == RENDER_LINE_DOUBLE || bottom == RENDER_LINE_DOUBLE; - bool double_horz = start_of_line == RENDER_LINE_DOUBLE || end_of_line == RENDER_LINE_DOUBLE; + bool double_vert = top == TABLE_STROKE_DOUBLE || bottom == TABLE_STROKE_DOUBLE; + bool double_horz = start_of_line == TABLE_STROKE_DOUBLE || end_of_line == TABLE_STROKE_DOUBLE; /* When horizontal lines are doubled, the left-side line along y1 normally runs from x0 to x2, @@ -365,16 +365,16 @@ xrr_draw_line (void *xr_, int bb[TABLE_N_AXES][2], single. We actually choose to cut off the line anyhow, as shown in the first diagram above. */ - bool shorten_y1_lines = top == RENDER_LINE_DOUBLE; - bool shorten_y2_lines = bottom == RENDER_LINE_DOUBLE; + bool shorten_y1_lines = top == TABLE_STROKE_DOUBLE; + bool shorten_y2_lines = bottom == TABLE_STROKE_DOUBLE; bool shorten_yc_line = shorten_y1_lines && shorten_y2_lines; int horz_line_ofs = double_vert ? double_line_ofs : 0; int xc = (x0 + x3) / 2; int x1 = xc - horz_line_ofs; int x2 = xc + horz_line_ofs; - bool shorten_x1_lines = start_of_line == RENDER_LINE_DOUBLE; - bool shorten_x2_lines = end_of_line == RENDER_LINE_DOUBLE; + bool shorten_x1_lines = start_of_line == TABLE_STROKE_DOUBLE; + bool shorten_x2_lines = end_of_line == TABLE_STROKE_DOUBLE; bool shorten_xc_line = shorten_x1_lines && shorten_x2_lines; int vert_line_ofs = double_horz ? double_line_ofs : 0; int yc = (y0 + y3) / 2; @@ -930,7 +930,7 @@ xr_layout_cell_text (struct xr_fsm *xr, const struct table_cell *cell, if (best) xr_draw_line (xr, 0, best, xr->style->size[H], best, - RENDER_LINE_SINGLE, + TABLE_STROKE_SOLID, &(struct cell_color) CELL_COLOR (0, 255, 0)); } } @@ -1032,14 +1032,14 @@ xr_fsm_create (const struct output_item *item_, }; enum { LW = XR_LINE_WIDTH, LS = XR_LINE_SPACE }; - static const int xr_line_widths[RENDER_N_LINES] = + static const int xr_line_widths[TABLE_N_STROKES] = { - [RENDER_LINE_NONE] = 0, - [RENDER_LINE_SINGLE] = LW, - [RENDER_LINE_DASHED] = LW, - [RENDER_LINE_THICK] = LW * 2, - [RENDER_LINE_THIN] = LW / 2, - [RENDER_LINE_DOUBLE] = 2 * LW + LS, + [TABLE_STROKE_NONE] = 0, + [TABLE_STROKE_SOLID] = LW, + [TABLE_STROKE_DASHED] = LW, + [TABLE_STROKE_THICK] = LW * 2, + [TABLE_STROKE_THIN] = LW / 2, + [TABLE_STROKE_DOUBLE] = 2 * LW + LS, }; struct xr_fsm *fsm = xmalloc (sizeof *fsm); diff --git a/src/output/render.c b/src/output/render.c index 08f89a177..184b52c00 100644 --- a/src/output/render.c +++ b/src/output/render.c @@ -464,29 +464,6 @@ calculate_table_width (int n, const struct render_row *rows, int *rules) /* Rendering utility functions. */ -/* Returns the line style to use for drawing a rule of the given TYPE. */ -static enum render_line_style -rule_to_render_type (unsigned char type) -{ - switch (type) - { - case TABLE_STROKE_NONE: - return RENDER_LINE_NONE; - case TABLE_STROKE_SOLID: - return RENDER_LINE_SINGLE; - case TABLE_STROKE_DASHED: - return RENDER_LINE_DASHED; - case TABLE_STROKE_THICK: - return RENDER_LINE_THICK; - case TABLE_STROKE_THIN: - return RENDER_LINE_THIN; - case TABLE_STROKE_DOUBLE: - return RENDER_LINE_DOUBLE; - default: - NOT_REACHED (); - } -} - /* Returns the width of the rule in TABLE that is at offset Z along axis A, if rendered with PARAMS. */ static int @@ -519,7 +496,7 @@ measure_rule (const struct render_params *params, const struct table *table, int width = 0; for (size_t i = 0; i < TABLE_N_STROKES; i++) if (rules & (1u << i)) - width = MAX (width, params->line_widths[rule_to_render_type (i)]); + width = MAX (width, params->line_widths[i]); return width; } @@ -949,8 +926,8 @@ render_page_get_best_breakpoint (const struct render_page *page, int height) - D is in terms of the page's rows and column rather than the underlying table's. - - The result is in the form of a render_line_style. */ -static enum render_line_style + - The result is in the form of a table_stroke. */ +static enum table_stroke get_rule (const struct render_page *page, enum table_axis axis, const int d_[TABLE_N_AXES], struct cell_color *color) { @@ -984,7 +961,7 @@ get_rule (const struct render_page *page, enum table_axis axis, int r2 = table_get_rule (page->table, axis, d[H], d[V], color); r = table_stroke_combine (r, r2); } - return rule_to_render_type (r); + return r; } static bool @@ -1015,14 +992,14 @@ static void render_rule (const struct render_page *page, const int ofs[TABLE_N_AXES], const int d[TABLE_N_AXES]) { - enum render_line_style styles[TABLE_N_AXES][2]; + enum table_stroke styles[TABLE_N_AXES][2]; struct cell_color colors[TABLE_N_AXES][2]; for (enum table_axis a = 0; a < TABLE_N_AXES; a++) { enum table_axis b = !a; - styles[a][0] = styles[a][1] = RENDER_LINE_NONE; + styles[a][0] = styles[a][1] = TABLE_STROKE_NONE; if (!is_rule (d[a]) || (page->is_edge_cutoff[a][0] && d[a] == 0) @@ -1050,8 +1027,8 @@ render_rule (const struct render_page *page, const int ofs[TABLE_N_AXES], } } - if (styles[H][0] != RENDER_LINE_NONE || styles[H][1] != RENDER_LINE_NONE - || styles[V][0] != RENDER_LINE_NONE || styles[V][1] != RENDER_LINE_NONE) + if (styles[H][0] != TABLE_STROKE_NONE || styles[H][1] != TABLE_STROKE_NONE + || styles[V][0] != TABLE_STROKE_NONE || styles[V][1] != TABLE_STROKE_NONE) { int bb[TABLE_N_AXES][2]; diff --git a/src/output/render.h b/src/output/render.h index 437c5a004..ec549eb64 100644 --- a/src/output/render.h +++ b/src/output/render.h @@ -23,17 +23,6 @@ struct table_item; -enum render_line_style - { - RENDER_LINE_NONE, - RENDER_LINE_SINGLE, - RENDER_LINE_DASHED, - RENDER_LINE_THICK, - RENDER_LINE_THIN, - RENDER_LINE_DOUBLE, - RENDER_N_LINES - }; - /* Parameters for rendering a table_item to a device. @@ -123,7 +112,7 @@ struct render_ops STYLES[TABLE_VERT][0]: style of line from left of BB to its center. STYLES[TABLE_VERT][1]: style of line from right of BB to its center. */ void (*draw_line) (void *aux, int bb[TABLE_N_AXES][2], - enum render_line_style styles[TABLE_N_AXES][2], + enum table_stroke styles[TABLE_N_AXES][2], struct cell_color colors[TABLE_N_AXES][2]); /* Draws CELL within bounding box BB. CLIP is the same as BB (the common diff --git a/src/output/table.h b/src/output/table.h index a5d294a51..c70be1e62 100644 --- a/src/output/table.h +++ b/src/output/table.h @@ -77,7 +77,7 @@ void cell_color_dump (const struct cell_color *); enum table_stroke { - TABLE_STROKE_NONE, + TABLE_STROKE_NONE = 0, /* Must be zero. */ TABLE_STROKE_SOLID, TABLE_STROKE_DASHED, TABLE_STROKE_THICK, -- 2.11.4.GIT