diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/word2x/shrink_width.cc |
Initial commit
Diffstat (limited to 'support/word2x/shrink_width.cc')
-rw-r--r-- | support/word2x/shrink_width.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/support/word2x/shrink_width.cc b/support/word2x/shrink_width.cc new file mode 100644 index 0000000000..70a020eb8c --- /dev/null +++ b/support/word2x/shrink_width.cc @@ -0,0 +1,35 @@ + +/* $Id: shrink_width.cc,v 1.1 1997/03/31 23:12:33 dps Exp $ */ +/* O(n^2) table width reduction algorithm, n is small in almost all cases */ +static void shrink_widths(int ncols, struct rdata *cols, int mtw) +{ + int i, j, tw, maxw; + + for (tw=0, i=0; i<ncols; i++) + tw+=cols[i].w.width; + + mtw-=ncols; // Take account of column seperators + + /* Simply reduce the maximum width column width by one until + enougn has been trimed */ + while (tw>mtw) + { + maxw=0; j=-1; + for (i=0; i<ncols; i++) + { + if (maxw<cols[i].w.width && cols[i].w.align!=ALIGN_DP) + { + j=i; + maxw=cols[i].w.width; + } + } + + if (j==-1) + { + fprintf(stderr, "Can not shrink overwidth table\n"); + continue; + } + cols[j].w.width--; + tw--; + } +} |