summaryrefslogtreecommitdiff
path: root/support/word2x/shrink_width.cc
blob: 70a020eb8c1dc8fd7e7ea7879b5163f96ae44c87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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--;
    }
}