X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Frender.c;h=642881e08aabe872580a8428dad647da1cc10b25;hb=9be3ebc378cac9467044f7240b1c42ab1bfe01c2;hp=35e0a7a94cb6d1382eb59d9237364e9e3f1c1f99;hpb=d2ee46757c7602fb0d6827136fdb00af1140e2e1;p=pspp diff --git a/src/output/render.c b/src/output/render.c index 35e0a7a94c..642881e08a 100644 --- a/src/output/render.c +++ b/src/output/render.c @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -25,11 +26,16 @@ #include "libpspp/hash-functions.h" #include "libpspp/hmap.h" #include "output/render.h" +#include "output/tab.h" +#include "output/table-item.h" #include "output/table.h" #include "gl/minmax.h" #include "gl/xalloc.h" +#include "gettext.h" +#define _(msgid) gettext (msgid) + /* This file uses TABLE_HORZ and TABLE_VERT enough to warrant abbreviating. */ #define H TABLE_HORZ #define V TABLE_VERT @@ -38,7 +44,11 @@ May represent the layout of an entire table presented to render_page_create(), or a rectangular subregion of a table broken out using - render_break_next() to allow a table to be broken across multiple pages. */ + render_break_next() to allow a table to be broken across multiple pages. + + A page's size is not limited to the size passed in as part of render_params. + render_pager breaks a render_page into smaller render_pages that will fit in + the available space. */ struct render_page { const struct render_params *params; /* Parameters of the target device. */ @@ -84,6 +94,15 @@ struct render_page entire page can overflow on all four sides!) */ struct hmap overflows; + /* Contains "struct render_footnote"s, one for each cell with one or more + footnotes. + + 'n_footnotes' is the number of footnotes in the table. There might be + more than hmap_count(&page->footnotes) because there can be more than + one footnote in a cell. */ + struct hmap footnotes; + size_t n_footnotes; + /* If a single column (or row) is too wide (or tall) to fit on a page reasonably, then render_break_next() will split a single row or column across multiple render_pages. This member indicates when this has @@ -120,6 +139,12 @@ struct render_page int *join_crossing[TABLE_N_AXES]; }; +static struct render_page *render_page_create (const struct render_params *, + const struct table *); + +struct render_page *render_page_ref (const struct render_page *page_); +static void render_page_unref (struct render_page *); + /* Returns the offset in struct render_page's cp[axis] array of the rule with index RULE_IDX. That is, if RULE_IDX is 0, then the offset is that of the leftmost or topmost rule; if RULE_IDX is 1, then the offset is that of the @@ -289,9 +314,9 @@ struct render_overflow int overflow[TABLE_N_AXES][2]; }; -/* Returns a hash value for (X,Y). */ +/* Returns a hash value for (,Y). */ static unsigned int -hash_overflow (int x, int y) +hash_cell (int x, int y) { return hash_int (x + (y << 16), 0); } @@ -306,7 +331,7 @@ find_overflow (const struct render_page *page, int x, int y) const struct render_overflow *of; HMAP_FOR_EACH_WITH_HASH (of, struct render_overflow, node, - hash_overflow (x, y), &page->overflows) + hash_cell (x, y), &page->overflows) if (x == of->d[H] && y == of->d[V]) return of; } @@ -314,6 +339,55 @@ find_overflow (const struct render_page *page, int x, int y) return NULL; } +/* A footnote. */ +struct render_footnote + { + struct hmap_node node; + + /* The area of the table covered by the cell that has the footnote. + + d[H][0] is the leftmost column. + d[H][1] is the rightmost column, plus 1. + d[V][0] is the top row. + d[V][1] is the bottom row, plus 1. + + The cell in its original table might occupy a larger region. This + member reflects the size of the cell in the current render_page, after + trimming off any rows or columns due to page-breaking. */ + int d[TABLE_N_AXES][2]; + + /* The index of the first footnote in the cell. */ + int idx; + }; + +static int +count_footnotes (const struct table_cell *cell) +{ + size_t i; + int n; + + n = 0; + for (i = 0; i < cell->n_contents; i++) + n += cell->contents[i].n_footnotes; + return n; +} + +static int +find_footnote_idx (const struct table_cell *cell, const struct hmap *footnotes) +{ + const struct render_footnote *f; + + if (!count_footnotes (cell)) + return 0; + + HMAP_FOR_EACH_WITH_HASH (f, struct render_footnote, node, + hash_cell (cell->d[H][0], cell->d[V][0]), footnotes) + if (f->d[H][0] == cell->d[H][0] && f->d[V][0] == cell->d[V][0]) + return f->idx; + + NOT_REACHED (); +} + /* Row or column dimensions. Used to figure the size of a table in render_page_create() and discarded after that. */ struct render_row @@ -517,6 +591,8 @@ render_page_allocate (const struct render_params *params, } hmap_init (&page->overflows); + hmap_init (&page->footnotes); + page->n_footnotes = 0; memset (page->is_edge_cutoff, 0, sizeof page->is_edge_cutoff); return page; @@ -607,7 +683,7 @@ set_join_crossings (struct render_page *page, enum table_axis axis, The new render_page will be suitable for rendering on a device whose page size is PARAMS->size, but the caller is responsible for actually breaking it up to fit on such a device, using the render_break abstraction. */ -struct render_page * +static struct render_page * render_page_create (const struct render_params *params, const struct table *table_) { @@ -618,6 +694,8 @@ render_page_create (const struct render_params *params, struct render_row *rows; int table_widths[2]; int *rules[TABLE_N_AXES]; + struct hmap footnotes; + int footnote_idx; int nr, nc; int x, y; int i; @@ -639,7 +717,9 @@ render_page_create (const struct render_params *params, } /* Calculate minimum and maximum widths of cells that do not - span multiple columns. */ + span multiple columns. Assign footnote markers. */ + hmap_init (&footnotes); + footnote_idx = 0; for (i = 0; i < 2; i++) columns[i] = xzalloc (nc * sizeof *columns[i]); for (y = 0; y < nr; y++) @@ -648,15 +728,35 @@ render_page_create (const struct render_params *params, struct table_cell cell; table_get_cell (table, x, y, &cell); - if (y == cell.d[V][0] && table_cell_colspan (&cell) == 1) + if (y == cell.d[V][0]) { - int w[2]; - int i; + int n; - params->measure_cell_width (params->aux, &cell, &w[MIN], &w[MAX]); - for (i = 0; i < 2; i++) - if (columns[i][x].unspanned < w[i]) - columns[i][x].unspanned = w[i]; + if (table_cell_colspan (&cell) == 1) + { + int w[2]; + int i; + + params->measure_cell_width (params->aux, &cell, footnote_idx, + &w[MIN], &w[MAX]); + for (i = 0; i < 2; i++) + if (columns[i][x].unspanned < w[i]) + columns[i][x].unspanned = w[i]; + } + + n = count_footnotes (&cell); + if (n > 0) + { + struct render_footnote *f = xmalloc (sizeof *f); + f->d[H][0] = cell.d[H][0]; + f->d[H][1] = cell.d[H][1]; + f->d[V][0] = cell.d[V][0]; + f->d[V][1] = cell.d[V][1]; + f->idx = footnote_idx; + hmap_insert (&footnotes, &f->node, hash_cell (x, y)); + + footnote_idx += n; + } } x = cell.d[H][1]; table_cell_free (&cell); @@ -676,7 +776,9 @@ render_page_create (const struct render_params *params, { int w[2]; - params->measure_cell_width (params->aux, &cell, &w[MIN], &w[MAX]); + params->measure_cell_width (params->aux, &cell, + find_footnote_idx (&cell, &footnotes), + &w[MIN], &w[MAX]); for (i = 0; i < 2; i++) distribute_spanned_width (w[i], &columns[i][cell.d[H][0]], rules[H], table_cell_colspan (&cell)); @@ -725,7 +827,8 @@ render_page_create (const struct render_params *params, if (table_cell_rowspan (&cell) == 1) { int w = joined_width (page, H, cell.d[H][0], cell.d[H][1]); - int h = params->measure_cell_height (params->aux, &cell, w); + int h = params->measure_cell_height ( + params->aux, &cell, find_footnote_idx (&cell, &footnotes), w); if (h > r->unspanned) r->unspanned = r->width = h; } @@ -752,7 +855,8 @@ render_page_create (const struct render_params *params, if (y == cell.d[V][0] && table_cell_rowspan (&cell) > 1) { int w = joined_width (page, H, cell.d[H][0], cell.d[H][1]); - int h = params->measure_cell_height (params->aux, &cell, w); + int h = params->measure_cell_height ( + params->aux, &cell, find_footnote_idx (&cell, &footnotes), w); distribute_spanned_width (h, &rows[cell.d[V][0]], rules[V], table_cell_rowspan (&cell)); } @@ -777,6 +881,10 @@ render_page_create (const struct render_params *params, } } + hmap_swap (&page->footnotes, &footnotes); + hmap_destroy (&footnotes); + page->n_footnotes = footnote_idx; + free (rules[H]); free (rules[V]); @@ -794,7 +902,7 @@ render_page_ref (const struct render_page *page_) /* Decreases PAGE's reference count and destroys PAGE if this causes the reference count to fall to zero. */ -void +static void render_page_unref (struct render_page *page) { if (page != NULL && --page->ref_cnt == 0) @@ -822,13 +930,13 @@ render_page_unref (struct render_page *page) /* Returns the size of PAGE along AXIS. (This might be larger than the page size specified in the parameters passed to render_page_create(). Use a render_break to break up a render_page into page-sized chunks.) */ -int +static int render_page_get_size (const struct render_page *page, enum table_axis axis) { return page->cp[axis][page->n[axis] * 2 + 1]; } -int +static int render_page_get_best_breakpoint (const struct render_page *page, int height) { int y; @@ -861,8 +969,26 @@ is_rule (int z) return !(z & 1); } +bool +render_direction_rtl (void) +{ + /* TRANSLATORS: Do not translate this string. If the script of your language + reads from right to left (eg Persian, Arabic, Hebrew etc), then replace + this string with "output-direction-rtl". Otherwise either leave it + untranslated or copy it verbatim. */ + const char *dir = _("output-direction-ltr"); + if ( 0 == strcmp ("output-direction-rtl", dir)) + return true; + + if ( 0 != strcmp ("output-direction-ltr", dir)) + fprintf (stderr, "This localisation has been incorrectly translated. Complain to the translator.\n"); + + return false; +} + static void -render_rule (const struct render_page *page, const int d[TABLE_N_AXES]) +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_axis a; @@ -901,25 +1027,38 @@ render_rule (const struct render_page *page, const int d[TABLE_N_AXES]) { int bb[TABLE_N_AXES][2]; - bb[H][0] = page->cp[H][d[H]]; - bb[H][1] = page->cp[H][d[H] + 1]; - bb[V][0] = page->cp[V][d[V]]; - bb[V][1] = page->cp[V][d[V] + 1]; + bb[H][0] = ofs[H] + page->cp[H][d[H]]; + bb[H][1] = ofs[H] + page->cp[H][d[H] + 1]; + if (render_direction_rtl ()) + { + int temp = bb[H][0]; + bb[H][0] = render_page_get_size (page, H) - bb[H][1]; + bb[H][1] = render_page_get_size (page, H) - temp; + } + bb[V][0] = ofs[V] + page->cp[V][d[V]]; + bb[V][1] = ofs[V] + page->cp[V][d[V] + 1]; page->params->draw_line (page->params->aux, bb, styles); } } static void -render_cell (const struct render_page *page, const struct table_cell *cell) +render_cell (const struct render_page *page, const int ofs[TABLE_N_AXES], + const struct table_cell *cell) { const struct render_overflow *of; int bb[TABLE_N_AXES][2]; int clip[TABLE_N_AXES][2]; - bb[H][0] = clip[H][0] = page->cp[H][cell->d[H][0] * 2 + 1]; - bb[H][1] = clip[H][1] = page->cp[H][cell->d[H][1] * 2]; - bb[V][0] = clip[V][0] = page->cp[V][cell->d[V][0] * 2 + 1]; - bb[V][1] = clip[V][1] = page->cp[V][cell->d[V][1] * 2]; + bb[H][0] = clip[H][0] = ofs[H] + page->cp[H][cell->d[H][0] * 2 + 1]; + bb[H][1] = clip[H][1] = ofs[H] + page->cp[H][cell->d[H][1] * 2]; + if (render_direction_rtl ()) + { + int temp = bb[H][0]; + bb[H][0] = clip[H][0] = render_page_get_size (page, H) - bb[H][1]; + bb[H][1] = clip[H][1] = render_page_get_size (page, H) - temp; + } + bb[V][0] = clip[V][0] = ofs[V] + page->cp[V][cell->d[V][0] * 2 + 1]; + bb[V][1] = clip[V][1] = ofs[V] + page->cp[V][cell->d[V][1] * 2]; of = find_overflow (page, cell->d[H][0], cell->d[V][0]); if (of) @@ -932,24 +1071,25 @@ render_cell (const struct render_page *page, const struct table_cell *cell) { bb[axis][0] -= of->overflow[axis][0]; if (cell->d[axis][0] == 0 && !page->is_edge_cutoff[axis][0]) - clip[axis][0] = page->cp[axis][cell->d[axis][0] * 2]; + clip[axis][0] = ofs[axis] + page->cp[axis][cell->d[axis][0] * 2]; } if (of->overflow[axis][1]) { bb[axis][1] += of->overflow[axis][1]; if (cell->d[axis][1] == page->n[axis] && !page->is_edge_cutoff[axis][1]) - clip[axis][1] = page->cp[axis][cell->d[axis][1] * 2 + 1]; + clip[axis][1] = ofs[axis] + page->cp[axis][cell->d[axis][1] * 2 + 1]; } } } - page->params->draw_cell (page->params->aux, cell, bb, clip); + page->params->draw_cell (page->params->aux, cell, + find_footnote_idx (cell, &page->footnotes), bb, clip); } /* Draws the cells of PAGE indicated in BB. */ static void render_page_draw_cells (const struct render_page *page, - int bb[TABLE_N_AXES][2]) + int ofs[TABLE_N_AXES], int bb[TABLE_N_AXES][2]) { int x, y; @@ -960,7 +1100,7 @@ render_page_draw_cells (const struct render_page *page, int d[TABLE_N_AXES]; d[H] = x; d[V] = y; - render_rule (page, d); + render_rule (page, ofs, d); x++; } else @@ -969,7 +1109,7 @@ render_page_draw_cells (const struct render_page *page, table_get_cell (page->table, x / 2, y / 2, &cell); if (y / 2 == bb[V][0] / 2 || y / 2 == cell.d[V][0]) - render_cell (page, &cell); + render_cell (page, ofs, &cell); x = rule_ofs (cell.d[H][1]); table_cell_free (&cell); } @@ -977,8 +1117,8 @@ render_page_draw_cells (const struct render_page *page, /* Renders PAGE, by calling the 'draw_line' and 'draw_cell' functions from the render_params provided to render_page_create(). */ -void -render_page_draw (const struct render_page *page) +static void +render_page_draw (const struct render_page *page, int ofs[TABLE_N_AXES]) { int bb[TABLE_N_AXES][2]; @@ -987,7 +1127,7 @@ render_page_draw (const struct render_page *page) bb[V][0] = 0; bb[V][1] = page->n[V] * 2 + 1; - render_page_draw_cells (page, bb); + render_page_draw_cells (page, ofs, bb); } /* Returns the greatest value i, 0 <= i < n, such that cp[i] <= x0. */ @@ -1043,20 +1183,20 @@ get_clip_max_extent (int x1, const int cp[], int n) /* Renders the cells of PAGE that intersect (X,Y)-(X+W,Y+H), by calling the 'draw_line' and 'draw_cell' functions from the render_params provided to render_page_create(). */ -void +static void render_page_draw_region (const struct render_page *page, - int x, int y, int w, int h) + int ofs[TABLE_N_AXES], int clip[TABLE_N_AXES][2]) { int bb[TABLE_N_AXES][2]; - bb[H][0] = get_clip_min_extent (x, page->cp[H], page->n[H] * 2 + 1); - bb[H][1] = get_clip_max_extent (x + w, page->cp[H], page->n[H] * 2 + 1); - bb[V][0] = get_clip_min_extent (y, page->cp[V], page->n[V] * 2 + 1); - bb[V][1] = get_clip_max_extent (y + h, page->cp[V], page->n[V] * 2 + 1); + bb[H][0] = get_clip_min_extent (clip[H][0], page->cp[H], page->n[H] * 2 + 1); + bb[H][1] = get_clip_max_extent (clip[H][1], page->cp[H], page->n[H] * 2 + 1); + bb[V][0] = get_clip_min_extent (clip[V][0], page->cp[V], page->n[V] * 2 + 1); + bb[V][1] = get_clip_max_extent (clip[V][1], page->cp[V], page->n[V] * 2 + 1); - render_page_draw_cells (page, bb); + render_page_draw_cells (page, ofs, bb); } - + /* Breaking up tables to fit on a page. */ /* An iterator for breaking render_pages into smaller chunks. */ @@ -1076,15 +1216,12 @@ static struct render_page *render_page_select (const struct render_page *, int z0, int p0, int z1, int p1); -/* Initializes render_break B for breaking PAGE along AXIS. - - Ownership of PAGE is transferred to B. The caller must use - render_page_ref() if it needs to keep a copy of PAGE. */ +/* Initializes render_break B for breaking PAGE along AXIS. */ static void -render_break_init (struct render_break *b, struct render_page *page, +render_break_init (struct render_break *b, const struct render_page *page, enum table_axis axis) { - b->page = page; + b->page = render_page_ref (page); b->axis = axis; b->z = page->h[axis][0]; b->pixel = 0; @@ -1205,7 +1342,8 @@ render_break_next (struct render_break *b, int size) table_get_cell (page->table, x, z, &cell); w = joined_width (page, H, cell.d[H][0], cell.d[H][1]); better_pixel = page->params->adjust_break ( - page->params->aux, &cell, w, pixel); + page->params->aux, &cell, + find_footnote_idx (&cell, &page->footnotes), w, pixel); x = cell.d[H][1]; table_cell_free (&cell); @@ -1300,22 +1438,111 @@ cell_is_breakable (const struct render_break *b, int cell) struct render_pager { - int width; - struct render_page *page; + const struct render_params *params; + + struct render_page **pages; + size_t n_pages, allocated_pages; + + size_t cur_page; struct render_break x_break; struct render_break y_break; }; -/* Creates and returns a new render_pager for breaking PAGE into smaller - chunks. Takes ownership of PAGE. */ -struct render_pager * -render_pager_create (struct render_page *page) +static const struct render_page * +render_pager_add_table (struct render_pager *p, struct table *table) +{ + struct render_page *page; + + if (p->n_pages >= p->allocated_pages) + p->pages = x2nrealloc (p->pages, &p->allocated_pages, sizeof *p->pages); + page = p->pages[p->n_pages++] = render_page_create (p->params, table); + return page; +} + +static void +render_pager_start_page (struct render_pager *p) { - struct render_pager *p = xmalloc (sizeof *p); - p->width = page->params->size[H]; - p->page = render_page_ref (page); - render_break_init (&p->x_break, page, H); + render_break_init (&p->x_break, p->pages[p->cur_page++], H); render_break_init_empty (&p->y_break); +} + +static void +add_footnote_page (struct render_pager *p, const struct render_page *body) +{ + const struct table *table = body->table; + int nc = table_nc (table); + int nr = table_nr (table); + int footnote_idx = 0; + struct tab_table *t; + int x, y; + + if (!body->n_footnotes) + return; + + t = tab_create (2, body->n_footnotes); + for (y = 0; y < nr; y++) + for (x = 0; x < nc; ) + { + struct table_cell cell; + + table_get_cell (table, x, y, &cell); + if (y == cell.d[V][0]) + { + size_t i; + + for (i = 0; i < cell.n_contents; i++) + { + const struct cell_contents *cc = &cell.contents[i]; + size_t j; + + for (j = 0; j < cc->n_footnotes; j++) + { + const char *f = cc->footnotes[j]; + + tab_text (t, 0, footnote_idx, TAB_LEFT, ""); + tab_footnote (t, 0, footnote_idx, "(none)"); + tab_text (t, 1, footnote_idx, TAB_LEFT, f); + footnote_idx++; + } + } + } + x = cell.d[H][1]; + table_cell_free (&cell); + } + render_pager_add_table (p, &t->table); +} + +/* Creates and returns a new render_pager for rendering TABLE_ITEM on the + device with the given PARAMS. */ +struct render_pager * +render_pager_create (const struct render_params *params, + const struct table_item *table_item) +{ + const char *caption = table_item_get_caption (table_item); + const char *title = table_item_get_title (table_item); + const struct render_page *body_page; + struct render_pager *p; + + p = xzalloc (sizeof *p); + p->params = params; + + /* Title. */ + if (title) + render_pager_add_table (p, table_from_string (TAB_LEFT, title)); + + /* Body. */ + body_page = render_pager_add_table (p, table_ref (table_item_get_table ( + table_item))); + + /* Caption. */ + if (caption) + render_pager_add_table (p, table_from_string (TAB_LEFT, caption)); + + /* Footnotes. */ + add_footnote_page (p, body_page); + + render_pager_start_page (p); + return p; } @@ -1325,9 +1552,13 @@ render_pager_destroy (struct render_pager *p) { if (p) { + size_t i; + render_break_destroy (&p->x_break); render_break_destroy (&p->y_break); - render_page_unref (p->page); + for (i = 0; i < p->n_pages; i++) + render_page_unref (p->pages[i]); + free (p->pages); free (p); } } @@ -1342,18 +1573,20 @@ render_pager_has_next (const struct render_pager *p_) while (!render_break_has_next (&p->y_break)) { render_break_destroy (&p->y_break); - if (render_break_has_next (&p->x_break)) + if (!render_break_has_next (&p->x_break)) { - struct render_page *x_slice; - - x_slice = render_break_next (&p->x_break, p->width); - render_break_init (&p->y_break, x_slice, V); + render_break_destroy (&p->x_break); + if (p->cur_page >= p->n_pages) + { + render_break_init_empty (&p->x_break); + render_break_init_empty (&p->y_break); + return false; + } + render_pager_start_page (p); } else - { - render_break_init_empty (&p->y_break); - return false; - } + render_break_init (&p->y_break, + render_break_next (&p->x_break, p->params->size[H]), V); } return true; } @@ -1367,26 +1600,33 @@ render_pager_has_next (const struct render_pager *p_) int render_pager_draw_next (struct render_pager *p, int space) { - struct render_page *page = (render_pager_has_next (p) - ? render_break_next (&p->y_break, space) - : NULL); - if (page) + int ofs[TABLE_N_AXES] = { 0, 0 }; + size_t start_page = SIZE_MAX; + + while (render_pager_has_next (p)) { - int used = render_page_get_size (page, V); + struct render_page *page; + + if (start_page == p->cur_page) + break; + start_page = p->cur_page; + + page = render_break_next (&p->y_break, space - ofs[V]); + if (!page) + break; - render_page_draw (page); + render_page_draw (page, ofs); + ofs[V] += render_page_get_size (page, V); render_page_unref (page); - return used; } - else - return 0; + return ofs[V]; } /* Draws all of P's content. */ void render_pager_draw (const struct render_pager *p) { - render_page_draw (p->page); + render_pager_draw_region (p, 0, 0, INT_MAX, INT_MAX); } /* Draws the region of P's content that lies in the region (X,Y)-(X+W,Y+H). @@ -1396,7 +1636,24 @@ void render_pager_draw_region (const struct render_pager *p, int x, int y, int w, int h) { - render_page_draw_region (p->page, x, y, w, h); + int ofs[TABLE_N_AXES] = { 0, 0 }; + int clip[TABLE_N_AXES][2]; + size_t i; + + clip[H][0] = x; + clip[H][1] = x + w; + for (i = 0; i < p->n_pages; i++) + { + const struct render_page *page = p->pages[i]; + int size = render_page_get_size (page, V); + + clip[V][0] = MAX (y, ofs[V]) - ofs[V]; + clip[V][1] = MIN (y + h, ofs[V] + size) - ofs[V]; + if (clip[V][1] > clip[V][0]) + render_page_draw_region (page, ofs, clip); + + ofs[V] += size; + } } /* Returns the size of P's content along AXIS; i.e. the content's width if AXIS @@ -1404,13 +1661,33 @@ render_pager_draw_region (const struct render_pager *p, int render_pager_get_size (const struct render_pager *p, enum table_axis axis) { - return render_page_get_size (p->page, axis); + int size = 0; + size_t i; + + for (i = 0; i < p->n_pages; i++) + { + int subsize = render_page_get_size (p->pages[i], axis); + size = axis == H ? MAX (size, subsize) : size + subsize; + } + + return size; } int render_pager_get_best_breakpoint (const struct render_pager *p, int height) { - return render_page_get_best_breakpoint (p->page, height); + int y = 0; + size_t i; + + for (i = 0; i < p->n_pages; i++) + { + int size = render_page_get_size (p->pages[i], V); + if (y + size >= height) + return render_page_get_best_breakpoint (p->pages[i], height - y) + y; + y += size; + } + + return height; } /* render_page_select() and helpers. */ @@ -1436,8 +1713,8 @@ static struct render_overflow *insert_overflow (struct render_page_selection *, const struct table_cell *); /* Creates and returns a new render_page whose contents are a subregion of - PAGE's contents. The new render_page includes cells Z0 through Z1 along - AXIS, plus any headers on AXIS. + PAGE's contents. The new render_page includes cells Z0 through Z1 + (exclusive) along AXIS, plus any headers on AXIS. If P0 is nonzero, then it is a number of pixels to exclude from the left or top (according to AXIS) of cell Z0. Similarly, P1 is a number of pixels to @@ -1453,6 +1730,7 @@ static struct render_page * render_page_select (const struct render_page *page, enum table_axis axis, int z0, int p0, int z1, int p1) { + const struct render_footnote *f; struct render_page_selection s; enum table_axis a = axis; enum table_axis b = !a; @@ -1619,6 +1897,21 @@ render_page_select (const struct render_page *page, enum table_axis axis, table_cell_free (&cell); } + /* Copy footnotes from PAGE into subpage. */ + HMAP_FOR_EACH (f, struct render_footnote, node, &page->footnotes) + if ((f->d[a][0] >= z0 && f->d[a][0] < z1) + || (f->d[a][1] - 1 >= z0 && f->d[a][1] - 1 < z1)) + { + struct render_footnote *nf = xmalloc (sizeof *nf); + nf->d[a][0] = MAX (z0, f->d[a][0]) - z0 + page->h[a][0]; + nf->d[a][1] = MIN (z1, f->d[a][1]) - z0 + page->h[a][0]; + nf->d[b][0] = f->d[b][0]; + nf->d[b][1] = f->d[b][1]; + nf->idx = f->idx; + hmap_insert (&subpage->footnotes, &nf->node, + hash_cell (nf->d[H][0], nf->d[V][0])); + } + return subpage; } @@ -1671,7 +1964,7 @@ insert_overflow (struct render_page_selection *s, of = xzalloc (sizeof *of); cell_to_subpage (s, cell, of->d); hmap_insert (&s->subpage->overflows, &of->node, - hash_overflow (of->d[H], of->d[V])); + hash_cell (of->d[H], of->d[V])); old = find_overflow (s->page, cell->d[H][0], cell->d[V][0]); if (old != NULL)