From 397e4b99a356c51cab364f14373c15982db14d87 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 17 May 2005 07:09:35 +0000 Subject: [PATCH] Fix PR 11119. --- src/ChangeLog | 16 ++++++++++++++++ src/som.c | 16 ++++++++++++++++ src/som.h | 5 +++++ src/tab.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) diff --git a/src/ChangeLog b/src/ChangeLog index c111507a..c7c31594 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,19 @@ +Tue May 17 00:06:43 2005 Ben Pfaff + + Fix PR 11119. + + * som.c: (output_encodings) If some cell in the table won't fit + with the horizontal or vertical headers, cancel those headers. + + * som.h: (struct som_table_class) Add fits_width, fits_length, + set_headers members. + + * tab.c: (tabi_fits_width) New function. + (tabi_fits_length) New function. + (tabi_set_headers) New function. + (global var tab_table_class) Add the new functions as appropriate + members. + Mon May 16 22:34:06 2005 Ben Pfaff Fix rest of PR 13054. diff --git a/src/som.c b/src/som.c index d2418814..733fc3c8 100644 --- a/src/som.c +++ b/src/som.c @@ -144,6 +144,7 @@ som_submit (struct som_entity *t) static void output_entity (struct outp_driver *driver, struct som_entity *entity) { + bool fits_width, fits_length; d = driver; assert (d->driver_open); @@ -163,6 +164,19 @@ output_entity (struct outp_driver *driver, struct som_entity *entity) t->class->driver (d); t->class->area (&tw, &th); + fits_width = t->class->fits_width (d->width); + fits_length = t->class->fits_length (d->length); + if (!fits_width || !fits_length) + { + int tl, tr, tt, tb; + tl = fits_width ? hl : 0; + tr = fits_width ? hr : 0; + tt = fits_length ? ht : 0; + tb = fits_length ? hb : 0; + t->class->set_headers (tl, tr, tt, tb); + t->class->driver (d); + t->class->area (&tw, &th); + } if (!(flags & SOMF_NO_SPACING) && d->cp_y != 0) d->cp_y += d->font_height; @@ -175,6 +189,8 @@ output_entity (struct outp_driver *driver, struct som_entity *entity) render_simple (); else render_segments (); + + t->class->set_headers (hl, hr, ht, hb); } /* Render the table into multiple columns. */ diff --git a/src/som.h b/src/som.h index f5780edd..9d195c94 100644 --- a/src/som.h +++ b/src/som.h @@ -36,6 +36,8 @@ desired, and in fact almost every operation performed by som may be overridden in a table class. */ +#include "bool.h" + enum som_type { SOM_TABLE, @@ -91,10 +93,13 @@ struct som_table_class void (*join) (int *(column[2]), int *(row[2])); /* ? */ void (*cumulate) (int cumtype, int start, int *end, int max, int *actual); void (*flags) (unsigned *); + bool (*fits_width) (int width); + bool (*fits_length) (int length); /* Set columns and rows. */ void (*set_width) (int column, int width); /* ? */ void (*set_height) (int row, int height); /* ? */ + void (*set_headers) (int l, int r, int t, int b); /* Rendering. */ void (*title) (int x, int y); diff --git a/src/tab.c b/src/tab.c index 9f6a9c35..fdcf0013 100644 --- a/src/tab.c +++ b/src/tab.c @@ -1135,6 +1135,45 @@ tabi_flags (unsigned *flags) *flags = t->flags; } +/* Returns true if the table will fit in the given page WIDTH, + false otherwise. */ +static bool +tabi_fits_width (int width) +{ + int i; + + for (i = t->l; i < t->nc - t->r; i++) + if (t->wl + t->wr + t->w[i] > width) + return false; + + return true; +} + +/* Returns true if the table will fit in the given page LENGTH, + false otherwise. */ +static bool +tabi_fits_length (int length) +{ + int i; + + for (i = t->t; i < t->nr - t->b; i++) + if (t->ht + t->hb + t->h[i] > length) + return false; + + return true; +} + +/* Sets the number of header rows/columns on the left, right, top, + and bottom sides to HL, HR, HT, and HB, respectively. */ +static void +tabi_set_headers (int hl, int hr, int ht, int hb) +{ + t->l = hl; + t->r = hr; + t->t = ht; + t->b = hb; +} + /* Render title for current table, with major index X and minor index Y. Y may be zero, or X and Y may be zero, but X should be nonzero if Y is nonzero. */ @@ -1235,9 +1274,12 @@ struct som_table_class tab_table_class = NULL, tabi_cumulate, tabi_flags, + tabi_fits_width, + tabi_fits_length, NULL, NULL, + tabi_set_headers, tabi_title, tabi_render, -- 2.30.2