File: docLayoutExternalItem.c

package info (click to toggle)
ted 2.11-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 11,064 kB
  • ctags: 13,935
  • sloc: ansic: 120,446; makefile: 7,469; sh: 253
file content (325 lines) | stat: -rw-r--r-- 9,038 bytes parent folder | download
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/************************************************************************/
/*									*/
/*  Geometry calculations about external items.				*/
/*									*/
/************************************************************************/

#   include	"tedConfig.h"

#   include	<stddef.h>
#   include	<stdio.h>
#   include	<stdlib.h>
#   include	<limits.h>
#   define	y0	math_y0
#   define	y1	math_y1
#   include	<math.h>
#   undef	y0
#   undef	y1

#   include	"docLayout.h"

#   include	<appDebugon.h>

/************************************************************************/
/*									*/
/*  Determine the box around a header or a footer.			*/
/*									*/
/************************************************************************/

int docGetExternalItemBox(	DocumentRectangle *		dr,
				const BufferItem *		bodySectBi,
				const ExternalItem *		ei,
				int				justUsed,
				int				page,
				BufferDocument *		bd,
				AppDrawingData *		add )
    {
    const DocumentProperties *	dp;
    const SectionProperties *	sp;
    const DocumentGeometry *	dgRef;

    double			xfac= add->addMagnifiedPixelsPerTwip;

    const BufferItem *		externSectBi= ei->eiItem;

    DocumentRectangle		drBox;

    int				pageTopPixels;

    if  ( ! externSectBi )
	{ XDEB(externSectBi); return -1;	}

    pageTopPixels= page* add->addPageStepPixels;

    switch( externSectBi->biInExternalItem )
	{
	case DOCinSECT_HEADER:
	case DOCinFIRST_HEADER:
	case DOCinLEFT_HEADER:
	case DOCinRIGHT_HEADER:
	case DOCinSECT_FOOTER:
	case DOCinFIRST_FOOTER:
	case DOCinLEFT_FOOTER:
	case DOCinRIGHT_FOOTER:

	    sp= &(bodySectBi->biSectProperties);
	    dgRef= &(sp->spDocumentGeometry);

	    drBox.drX0= TWIPStoPIXELS( xfac, dgRef->dgLeftMarginTwips );
	    drBox.drX1= TWIPStoPIXELS( xfac, dgRef->dgPageWideTwips-
						dgRef->dgRightMarginTwips );

	    if  ( justUsed )
		{
		drBox.drY0= pageTopPixels+
				TWIPStoPIXELS( xfac, ei->eiY0UsedTwips );
		drBox.drY1= pageTopPixels+
				TWIPStoPIXELS( xfac, ei->eiY1UsedTwips );
		}
	    else{
		drBox.drY0= pageTopPixels+
				TWIPStoPIXELS( xfac, ei->eiY0ReservedTwips );
		drBox.drY1= pageTopPixels+
				TWIPStoPIXELS( xfac, ei->eiY1ReservedTwips );
		}

	    *dr= drBox; return 0;

	case DOCinFOOTNOTE:
	case DOCinENDNOTE:

	    if  ( page != ei->eiPageFormattedFor )
		{ LLDEB(page,ei->eiPageFormattedFor);	}

	    sp= &(bodySectBi->biSectProperties);
	    dgRef= &(sp->spDocumentGeometry);

	    drBox.drX0= TWIPStoPIXELS( xfac, dgRef->dgLeftMarginTwips );
	    drBox.drX1= TWIPStoPIXELS( xfac, dgRef->dgPageWideTwips-
						dgRef->dgRightMarginTwips );

	    drBox.drY0= pageTopPixels+
				TWIPStoPIXELS( xfac, ei->eiY0UsedTwips );
	    drBox.drY1= pageTopPixels+
				TWIPStoPIXELS( xfac, ei->eiY1UsedTwips );

	    *dr= drBox; return 0;

	case DOCinFTNSEP:
	case DOCinFTNSEPC:
	case DOCinFTNCN:
	case DOCinAFTNSEP:
	case DOCinAFTNSEPC:
	case DOCinAFTNCN:

	    if  ( page != ei->eiPageFormattedFor )
		{ LLDEB(page,ei->eiPageFormattedFor);	}

	    dp= &(bd->bdProperties);
	    dgRef= &(dp->dpGeometry);

	    drBox.drX0= TWIPStoPIXELS( xfac, dgRef->dgLeftMarginTwips );
	    drBox.drX1= TWIPStoPIXELS( xfac, dgRef->dgPageWideTwips-
						dgRef->dgRightMarginTwips );

	    drBox.drY0= pageTopPixels+
				TWIPStoPIXELS( xfac, ei->eiY0UsedTwips );
	    drBox.drY1= pageTopPixels+
				TWIPStoPIXELS( xfac, ei->eiY1UsedTwips );

	    *dr= drBox; return 0;

	default:
	    LDEB(externSectBi->biInExternalItem);
	    return -1;
	}
    }

/************************************************************************/
/*									*/
/*  Do a preliminary layout of an external item.			*/
/*  Inside the external item, geometry is correct. Some items are	*/
/*  however used in different positions and here we just calculate the	*/
/*  layout in order to use the size of the item in geometry		*/
/*  calculations about the document as a whole.				*/
/*									*/
/*  1)  Remove the bottom of the page master frame. This is the routine	*/
/*	that calculates it for future use.				*/
/*									*/
/************************************************************************/

int docExternalItemPrelayout(		ExternalItem *			ei,
					const DocumentGeometry *	dgRef,
					LayoutJob *			lj )
    {
    LayoutJob			headerLj;
    LayoutPosition		headerLp;

    int				high;
    int				y1;

    BlockFrame			bf;

    ei->eiPageFormattedFor= -1;

    if  ( ! ei->eiItem )
	{ return 0;	}

    headerLp.lpPage= ei->eiItem->biTopPosition.lpPage;
    headerLp.lpColumn= 0;
    headerLp.lpPageYTwips= dgRef->dgHeaderPositionTwips;
    headerLp.lpAtTopOfColumn= 1; /* not really */

    headerLj= *lj;
    headerLj.ljChangedRectanglePixels= (DocumentRectangle *)0;
    headerLj.ljAdd= lj->ljAdd;
    headerLj.ljBd= lj->ljBd;
    headerLj.ljChangedItem= lj->ljChangedItem;
    headerLj.ljPosition= headerLp;

    docBlockFrameTwips( &bf, ei->eiItem, lj->ljBd,
					headerLp.lpPage, headerLp.lpColumn );
    /*  1  */
    bf.bfY1Twips= dgRef->dgPageHighTwips;

    if  ( docLayoutItemImplementation( ei->eiItem, &bf, &headerLj ) )
	{ LDEB(1); return -1;	}

    y1= ei->eiItem->biBelowPosition.lpPageYTwips;

    switch( ei->eiItem->biInExternalItem )
	{
	case DOCinSECT_HEADER:
	case DOCinFIRST_HEADER:
	case DOCinLEFT_HEADER:
	case DOCinRIGHT_HEADER:

	    ei->eiY0UsedTwips= dgRef->dgHeaderPositionTwips;
	    ei->eiY1UsedTwips= y1;
	    ei->eiY0ReservedTwips= ei->eiY0UsedTwips;
	    if  ( y1 > dgRef->dgTopMarginTwips )
		{ ei->eiY1ReservedTwips= y1;				}
	    else{ ei->eiY1ReservedTwips= dgRef->dgTopMarginTwips;	}
	    break;

	case DOCinSECT_FOOTER:
	case DOCinFIRST_FOOTER:
	case DOCinLEFT_FOOTER:
	case DOCinRIGHT_FOOTER:

	    high= y1- dgRef->dgHeaderPositionTwips;
	    ei->eiY1UsedTwips= dgRef->dgPageHighTwips-
					    dgRef->dgFooterPositionTwips;
	    ei->eiY0UsedTwips= ei->eiY1UsedTwips- high;

	    ei->eiY1ReservedTwips= ei->eiY1UsedTwips;

	    if  ( ei->eiY0UsedTwips >
			dgRef->dgPageHighTwips- dgRef->dgBottomMarginTwips )
		{
		ei->eiY0ReservedTwips= dgRef->dgPageHighTwips-
						dgRef->dgBottomMarginTwips;
		}
	    else{
		ei->eiY0ReservedTwips= ei->eiY0UsedTwips;
		}
	    break;

	case DOCinFOOTNOTE:
	case DOCinENDNOTE:

	    /*  temporarily, will be placed later on */
	    ei->eiY0UsedTwips= dgRef->dgHeaderPositionTwips;
	    ei->eiY1UsedTwips= y1;
	    break;

	case DOCinFTNSEP:
	case DOCinFTNSEPC:
	case DOCinFTNCN:
	case DOCinAFTNSEP:
	case DOCinAFTNSEPC:
	case DOCinAFTNCN:

	    /*  temporarily */
	    ei->eiY0UsedTwips= dgRef->dgHeaderPositionTwips;
	    ei->eiY1UsedTwips= y1;
	    break;

	default:
	    LDEB(ei->eiItem->biInExternalItem); return -1;
	}

    return 0;
    }

/************************************************************************/
/*									*/
/*  Do the preliminary layout of the headers and footers of a section	*/
/*									*/
/************************************************************************/

int docSectHeaderFooterPrelayout(	BufferItem *	sectBi,
					LayoutJob *	lj )
    {
    const SectionProperties *	sp= &(sectBi->biSectProperties);
    const DocumentGeometry *	dgSect= &(sp->spDocumentGeometry);


    sectBi->biSectHeader.eiY0ReservedTwips=
    sectBi->biSectFirstPageHeader.eiY0ReservedTwips=
    sectBi->biSectLeftPageHeader.eiY0ReservedTwips=
    sectBi->biSectRightPageHeader.eiY0ReservedTwips=
					dgSect->dgHeaderPositionTwips;

    sectBi->biSectHeader.eiY1ReservedTwips=
    sectBi->biSectFirstPageHeader.eiY1ReservedTwips=
    sectBi->biSectLeftPageHeader.eiY1ReservedTwips=
    sectBi->biSectRightPageHeader.eiY1ReservedTwips=
					dgSect->dgTopMarginTwips;

    if  ( docExternalItemPrelayout( &(sectBi->biSectHeader), dgSect, lj ) )
	{ LDEB(1); return -1;	}

    if  ( docExternalItemPrelayout( &(sectBi->biSectFirstPageHeader),
							    dgSect, lj ) )
	{ LDEB(1); return -1;	}

    if  ( docExternalItemPrelayout( &(sectBi->biSectLeftPageHeader),
							    dgSect, lj ) )
	{ LDEB(1); return -1;	}

    if  ( docExternalItemPrelayout( &(sectBi->biSectRightPageHeader),
							    dgSect, lj ) )
	{ LDEB(1); return -1;	}

    /**/

    sectBi->biSectFooter.eiY0ReservedTwips=
    sectBi->biSectFirstPageFooter.eiY0ReservedTwips=
    sectBi->biSectLeftPageFooter.eiY0ReservedTwips=
    sectBi->biSectRightPageFooter.eiY0ReservedTwips=
		dgSect->dgPageHighTwips- dgSect->dgBottomMarginTwips;

    sectBi->biSectFooter.eiY1ReservedTwips=
    sectBi->biSectFirstPageFooter.eiY1ReservedTwips=
    sectBi->biSectLeftPageFooter.eiY1ReservedTwips=
    sectBi->biSectRightPageFooter.eiY1ReservedTwips=
		dgSect->dgPageHighTwips- dgSect->dgFooterPositionTwips;

    if  ( docExternalItemPrelayout( &(sectBi->biSectFooter), dgSect, lj ) )
	{ LDEB(1); return -1;	}

    if  ( docExternalItemPrelayout( &(sectBi->biSectFirstPageFooter),
							    dgSect, lj ) )
	{ LDEB(1); return -1;	}

    if  ( docExternalItemPrelayout( &(sectBi->biSectLeftPageFooter),
							    dgSect, lj ) )
	{ LDEB(1); return -1;	}

    if  ( docExternalItemPrelayout( &(sectBi->biSectRightPageFooter),
							    dgSect, lj ) )
	{ LDEB(1); return -1;	}

    return 0;
    }