- if (xr->fsm != NULL && !xr->fsm->render (xr->fsm, xr))
- xr_driver_destroy_fsm (xr);
-}
-\f
-static void
-xr_layout_cell (struct xr_driver *, const struct table_cell *,
- int bb[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2],
- PangoWrapMode, int *width, int *height);
-
-static void
-dump_line (struct xr_driver *xr, int x0, int y0, int x1, int y1)
-{
- cairo_new_path (xr->cairo);
- cairo_move_to (xr->cairo, xr_to_pt (x0), xr_to_pt (y0 + xr->y));
- cairo_line_to (xr->cairo, xr_to_pt (x1), xr_to_pt (y1 + xr->y));
- cairo_stroke (xr->cairo);
-}
-
-/* Draws a horizontal line X0...X2 at Y if LEFT says so,
- shortening it to X0...X1 if SHORTEN is true.
- Draws a horizontal line X1...X3 at Y if RIGHT says so,
- shortening it to X2...X3 if SHORTEN is true. */
-static void
-horz_line (struct xr_driver *xr, int x0, int x1, int x2, int x3, int y,
- enum render_line_style left, enum render_line_style right,
- bool shorten)
-{
- if (left != RENDER_LINE_NONE && right != RENDER_LINE_NONE && !shorten)
- dump_line (xr, x0, y, x3, y);
- else
- {
- if (left != RENDER_LINE_NONE)
- dump_line (xr, x0, y, shorten ? x1 : x2, y);
- if (right != RENDER_LINE_NONE)
- dump_line (xr, shorten ? x2 : x1, y, x3, y);
- }
-}
-
-/* Draws a vertical line Y0...Y2 at X if TOP says so,
- shortening it to Y0...Y1 if SHORTEN is true.
- Draws a vertical line Y1...Y3 at X if BOTTOM says so,
- shortening it to Y2...Y3 if SHORTEN is true. */
-static void
-vert_line (struct xr_driver *xr, int y0, int y1, int y2, int y3, int x,
- enum render_line_style top, enum render_line_style bottom,
- bool shorten)
-{
- if (top != RENDER_LINE_NONE && bottom != RENDER_LINE_NONE && !shorten)
- dump_line (xr, x, y0, x, y3);
- else
- {
- if (top != RENDER_LINE_NONE)
- dump_line (xr, x, y0, x, shorten ? y1 : y2);
- if (bottom != RENDER_LINE_NONE)
- dump_line (xr, x, shorten ? y2 : y1, x, y3);
- }
-}
-
-static void
-xr_draw_line (void *xr_, int bb[TABLE_N_AXES][2],
- enum render_line_style styles[TABLE_N_AXES][2])
-{
- const int x0 = bb[H][0];
- const int y0 = bb[V][0];
- const int x3 = bb[H][1];
- const int y3 = bb[V][1];
- const int top = styles[H][0];
- const int left = styles[V][0];
- const int bottom = styles[H][1];
- const int right = styles[V][1];
-
- /* The algorithm here is somewhat subtle, to allow it to handle
- all the kinds of intersections that we need.
-
- Three additional ordinates are assigned along the x axis. The
- first is xc, midway between x0 and x3. The others are x1 and
- x2; for a single vertical line these are equal to xc, and for
- a double vertical line they are the ordinates of the left and
- right half of the double line.
-
- yc, y1, and y2 are assigned similarly along the y axis.
-
- The following diagram shows the coordinate system and output
- for double top and bottom lines, single left line, and no
- right line:
-
- x0 x1 xc x2 x3
- y0 ________________________
- | # # |
- | # # |
- | # # |
- | # # |
- | # # |
- y1 = y2 = yc |######### # |
- | # # |
- | # # |
- | # # |
- | # # |
- y3 |________#_____#_______|
- */
- struct xr_driver *xr = xr_;
-
- /* Offset from center of each line in a pair of double lines. */
- int double_line_ofs = (xr->line_space + xr->line_width) / 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 = left == RENDER_LINE_DOUBLE || right == RENDER_LINE_DOUBLE;
-
- /* When horizontal lines are doubled,
- the left-side line along y1 normally runs from x0 to x2,
- and the right-side line along y1 from x3 to x1.
- If the top-side line is also doubled, we shorten the y1 lines,
- so that the left-side line runs only to x1,
- and the right-side line only to x2.
- Otherwise, the horizontal line at y = y1 below would cut off
- the intersection, which looks ugly:
- x0 x1 x2 x3
- y0 ________________________
- | # # |
- | # # |
- | # # |
- | # # |
- y1 |######### ########|
- | |
- | |
- y2 |######################|
- | |
- | |
- y3 |______________________|
- It is more of a judgment call when the horizontal line is
- 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_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 = left == RENDER_LINE_DOUBLE;
- bool shorten_x2_lines = right == RENDER_LINE_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;
- int y1 = yc - vert_line_ofs;
- int y2 = yc + vert_line_ofs;
-
- if (!double_horz)
- horz_line (xr, x0, x1, x2, x3, yc, left, right, shorten_yc_line);
- else
- {
- horz_line (xr, x0, x1, x2, x3, y1, left, right, shorten_y1_lines);
- horz_line (xr, x0, x1, x2, x3, y2, left, right, shorten_y2_lines);
- }
-
- if (!double_vert)
- vert_line (xr, y0, y1, y2, y3, xc, top, bottom, shorten_xc_line);
- else
- {
- vert_line (xr, y0, y1, y2, y3, x1, top, bottom, shorten_x1_lines);
- vert_line (xr, y0, y1, y2, y3, x2, top, bottom, shorten_x2_lines);
- }
-}
-
-static void
-xr_measure_cell_width (void *xr_, const struct table_cell *cell,
- int *min_width, int *max_width)
-{
- struct xr_driver *xr = xr_;
- int bb[TABLE_N_AXES][2];
- int clip[TABLE_N_AXES][2];
- int h;
-
- bb[H][0] = 0;
- bb[H][1] = INT_MAX;
- bb[V][0] = 0;
- bb[V][1] = INT_MAX;
- clip[H][0] = clip[H][1] = clip[V][0] = clip[V][1] = 0;
- xr_layout_cell (xr, cell, bb, clip, PANGO_WRAP_WORD, max_width, &h);
-
- bb[H][1] = 1;
- xr_layout_cell (xr, cell, bb, clip, PANGO_WRAP_WORD, min_width, &h);
-}
-
-static int
-xr_measure_cell_height (void *xr_, const struct table_cell *cell, int width)
-{
- struct xr_driver *xr = xr_;
- int bb[TABLE_N_AXES][2];
- int clip[TABLE_N_AXES][2];
- int w, h;
-
- bb[H][0] = 0;
- bb[H][1] = width;
- bb[V][0] = 0;
- bb[V][1] = INT_MAX;
- clip[H][0] = clip[H][1] = clip[V][0] = clip[V][1] = 0;
- xr_layout_cell (xr, cell, bb, clip, PANGO_WRAP_WORD, &w, &h);
- return h;
-}
-
-static void
-xr_draw_cell (void *xr_, const struct table_cell *cell,
- int bb[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2])
-{
- struct xr_driver *xr = xr_;
- int w, h;
-
- xr_layout_cell (xr, cell, bb, clip, PANGO_WRAP_WORD, &w, &h);
-}
-\f
-static void
-xr_layout_cell (struct xr_driver *xr, const struct table_cell *cell,
- int bb[TABLE_N_AXES][2], int clip[TABLE_N_AXES][2],
- PangoWrapMode wrap, int *width, int *height)
-{
- struct xr_font *font;
-
- font = (cell->options & TAB_FIX ? &xr->fonts[XR_FONT_FIXED]
- : cell->options & TAB_EMPH ? &xr->fonts[XR_FONT_EMPHASIS]
- : &xr->fonts[XR_FONT_PROPORTIONAL]);
-
- pango_layout_set_text (font->layout, cell->contents, -1);
-
- pango_layout_set_alignment (
- font->layout,
- ((cell->options & TAB_ALIGNMENT) == TAB_RIGHT ? PANGO_ALIGN_RIGHT
- : (cell->options & TAB_ALIGNMENT) == TAB_LEFT ? PANGO_ALIGN_LEFT
- : PANGO_ALIGN_CENTER));
- pango_layout_set_width (font->layout,
- bb[H][1] == INT_MAX ? -1 : bb[H][1] - bb[H][0]);
- pango_layout_set_wrap (font->layout, wrap);
-
- if (clip[H][0] != clip[H][1])