File: docTableRectangle.c

package info (click to toggle)
ted 2.16-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,944 kB
  • ctags: 20,273
  • sloc: ansic: 167,980; makefile: 12,518; sh: 263
file content (192 lines) | stat: -rw-r--r-- 4,287 bytes parent folder | download | duplicates (2)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/************************************************************************/
/*									*/
/*  Book keeping on TableRectangle's					*/
/*									*/
/*  The colspan and rowspan fields are managed in a halfhearted way:	*/
/*  You need the table to do a correct administration. So their value	*/
/*  is the responsibility of the caller.				*/
/*									*/
/************************************************************************/

#   include	"tedConfig.h"

#   include	<stdlib.h>
#   include	<string.h>
#   include	<stdio.h>

#   include	<appDebugon.h>

#   include	"docBuf.h"

/************************************************************************/
/*									*/
/*  Initialise a Table Rectangle.					*/
/*									*/
/************************************************************************/

void docInitTableRectangle(	TableRectangle *	tr )
    {
    tr->trCol0= -1;
    tr->trCol1= -1;
    tr->trCol11= -1;

    tr->trRow00= -1;
    tr->trRow0= -1;
    tr->trRow1= -1;
    tr->trRow11= -1;

    tr->trCellRowspan= 0;
    tr->trCellColspan= 0;

    return;
    }

/************************************************************************/
/*									*/
/*  Intersect two TableRectangles.					*/
/*									*/
/************************************************************************/

int docIntersectTableRectangle(	TableRectangle *		tr,
				const TableRectangle *		tr1,
				const TableRectangle *		tr2 )
    {
    TableRectangle	res= *tr1;

    if  ( tr1->trRow00 != tr2->trRow00 )
	{ LLDEB(tr1->trRow00,tr2->trRow00); return 0;	}
    if  ( tr1->trRow11 != tr2->trRow11 )
	{ LLDEB(tr1->trRow11,tr2->trRow11); return 0;	}
    if  ( tr1->trCol11 != tr2->trCol11 )
	{ LLDEB(tr1->trCol11,tr2->trCol11); return 0;	}

    if  ( tr1->trCol1 < tr2->trCol0 )
	{ return 0;	}

    if  ( tr2->trCol1 < tr1->trCol0 )
	{ return 0;	}

    if  ( tr1->trRow1 < tr2->trRow0 )
	{ return 0;	}

    if  ( tr2->trRow1 < tr1->trRow0 )
	{ return 0;	}

    if  ( ! tr )
	{ return 1;	}

    if  ( tr1->trCol0 < tr2->trCol0 )
	{ res.trCol0= tr2->trCol0;	}
    else{ res.trCol0= tr1->trCol0;	}

    if  ( tr1->trRow0 < tr2->trRow0 )
	{ res.trRow0= tr2->trRow0;	}
    else{ res.trRow0= tr1->trRow0;	}

    if  ( tr1->trCol1 < tr2->trCol1 )
	{ res.trCol1= tr1->trCol1;	}
    else{ res.trCol1= tr2->trCol1;	}

    if  ( tr1->trRow1 < tr2->trRow1 )
	{ res.trRow1= tr1->trRow1;	}
    else{ res.trRow1= tr2->trRow1;	}

    res.trCellRowspan= 0;
    res.trCellColspan= 0;

    *tr= res; return 1;
    }

void docExpandTableRectangleToWholeTable(	TableRectangle *	tr )
    {
    tr->trRow0= tr->trRow00;
    tr->trRow1= tr->trRow11;
    tr->trCol0= 0;
    tr->trCol1= tr->trCol11;

    if  ( tr->trRow0 != tr->trRow1	||
	  tr->trCol0 != tr->trCol1	)
	{
	tr->trCellRowspan= 0;
	tr->trCellColspan= 0;
	}

    return;
    }

void docExpandTableRectangleToWholeRows(	TableRectangle *	tr )
    {
    tr->trCol0= 0;
    tr->trCol1= tr->trCol11;

    if  ( tr->trRow0 != tr->trRow1	||
	  tr->trCol0 != tr->trCol1	)
	{
	tr->trCellRowspan= 0;
	tr->trCellColspan= 0;
	}

    return;
    }

void docExpandTableRectangleToWholeColumns(	TableRectangle *	tr )
    {
    tr->trRow0= tr->trRow00;
    tr->trRow1= tr->trRow11;

    if  ( tr->trRow0 != tr->trRow1	||
	  tr->trCol0 != tr->trCol1	)
	{
	tr->trCellRowspan= 0;
	tr->trCellColspan= 0;
	}

    return;
    }

int docShiftTableRectangleByRows(	TableRectangle *	tr,
					int			rows )
    {
    TableRectangle	trShifted;
    TableRectangle	trTable;

    trShifted= *tr;
    trTable= *tr;

    trShifted.trRow0 += rows;
    trShifted.trRow1 += rows;

    docExpandTableRectangleToWholeTable( &trTable );

    if  ( ! docIntersectTableRectangle( &trShifted, &trShifted, &trTable ) )
	{ return -1;	}

    tr->trCellRowspan= 0;
    tr->trCellColspan= 0;

    *tr= trShifted; return 0;
    }

int docShiftTableRectangleByColumns(	TableRectangle *	tr,
					int			columns )
    {
    TableRectangle	trShifted;
    TableRectangle	trTable;

    trShifted= *tr;
    trTable= *tr;

    trShifted.trCol0 += columns;
    trShifted.trCol1 += columns;

    docExpandTableRectangleToWholeTable( &trTable );

    if  ( ! docIntersectTableRectangle( &trShifted, &trShifted, &trTable ) )
	{ return -1;	}

    tr->trCellRowspan= 0;
    tr->trCellColspan= 0;

    *tr= trShifted; return 0;
    }