File: docLayout.h

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 (495 lines) | stat: -rw-r--r-- 14,298 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
/************************************************************************/
/*									*/
/*  Document Layout and Printing related functionality.			*/
/*									*/
/************************************************************************/

#   ifndef	DOC_LAYOUT_H
#   define	DOC_LAYOUT_H

#   include	<psFont.h>
#   include	"docBuf.h"
#   include	"utilPs.h"

#   include	<appDraw.h>

/************************************************************************/
/*									*/
/*  Pixel position on a page						*/
/*									*/
/************************************************************************/

# define LP_YPIXELS( add, lp ) \
	    ( (add)->addPageStepPixels* (lp)->lpPage+ \
	      TWIPStoPIXELS( (add)->addMagnifiedPixelsPerTwip, \
						    (lp)->lpPageYTwips ) )

/**/

# define BI_TOP_PIXELS( add, bi ) \
			LP_YPIXELS( add, &((bi)->biTopPosition) )

# define BI_BELOW_PIXELS( add, bi ) \
			LP_YPIXELS( add, &((bi)->biBelowPosition) )

/**/

# define PG_TOP_PIXELS( add, pg ) \
			LP_YPIXELS( add, &((pg)->pgTopPosition) )

/**/

# define TL_TOP_PIXELS( add, tl ) LP_YPIXELS( add, &((tl)->tlTopPosition) )

# define TL_BASE_PIXELS( add, tl ) \
	    ( (add)->addPageStepPixels* (tl)->tlTopPosition.lpPage+ \
	      TWIPStoPIXELS( (add)->addMagnifiedPixelsPerTwip, \
		(tl)->tlTopPosition.lpPageYTwips+ (tl)->tlLineAscentTwips ) )

# define TL_BELOW_PIXELS( add, tl ) \
	    ( (add)->addPageStepPixels* (tl)->tlTopPosition.lpPage+ \
	      TWIPStoPIXELS( (add)->addMagnifiedPixelsPerTwip, \
		(tl)->tlTopPosition.lpPageYTwips+ (tl)->tlLineSpacingTwips ) )

/************************************************************************/
/*									*/
/*  The frame in which a series of successive lines in a paragraph is	*/
/*  is formatted. The frame lies on one page, and when the text has to	*/
/*  flow around an illustration, the formatter is called with different	*/
/*  frames for the text above the illustration, at the side of the	*/
/*  illustration and below the illustration.				*/
/*									*/
/*  Coordinates are absolute coordinates on the page or on the window.	*/
/*  [On the window they are shifted by the scrollbars.]			*/
/*									*/
/************************************************************************/

typedef struct ParagraphFrame
    {
    int		pfX0GeometryTwips;
    int		pfX0TextLinesTwips;
    int		pfX0FirstLineTwips;

    int		pfX1GeometryTwips;
    int		pfX1TextLinesTwips;

    int		pfPageY1Twips;

    int		pfX0TextLinesPixels;
    int		pfX0FirstLinePixels;
    int		pfX1TextLinesPixels;

    int		pfX0Pixels;
    int		pfX1Pixels;

    int		pfPageHigh;
    int		pfStripHigh;
    int		pfHasBottom;
    } ParagraphFrame;

/************************************************************************/
/*									*/
/*  Frame in which the regular text on a page is formatted. This is	*/
/*  either the page or a (newspaper style) column on the page. The	*/
/*  page headers and footers get their own block frame. The same	*/
/*  for the footnotes and endnotes. The space for footnotes is however	*/
/*  subtracted from the block frame for the page.			*/
/*									*/
/*  NOTE that table columns are not implemented with a block frame.	*/
/*									*/
/************************************************************************/

typedef struct NotesReservation
    {
    int		nrFirstFootnote;
    int		nrFootnoteCount;

    int		nrFtnsepHeight;
    int		nrFootnoteHeight;
    } NotesReservation;

typedef struct BlockFrame
    {
    int			bfX0Twips;
    int			bfX1Twips;
    int			bfY0Twips;
    int			bfY1Twips;

    NotesReservation	bfNotesReservation;
    } BlockFrame;

#   define	BF_HAS_FOOTNOTES( bf ) \
		    ((bf)->bfNotesReservation.nrFirstFootnote >= 0)

/************************************************************************/
/*									*/
/*  Additional information for the layout of a line of text. Some of	*/
/*  the sfields are used for scratch in the process.			*/
/*									*/
/************************************************************************/

typedef struct ParticuleData
    {
    int			pdX0;
    int			pdWidth;
    int			pdDecWidth;
    int			pdVisibleWidth;
    int			pdTabNumber;
    int			pdTabKind;
    int			pdTabPosition;
    const AfmFontInfo *	pdAfi;

    int			pdVisiblePixels;
    int			pdWhiteUnits;
    int			pdCorrectBy;
    } ParticuleData;

/************************************************************************/
/*									*/
/*  Pass through information for a layout job.				*/
/*									*/
/************************************************************************/

typedef int (*LAYOUT_SCREEN_LINE)( TextLine *			tl,
				const BufferItem *		bi,
				int				part,
				int				accepted,
				AppDrawingData *		add,
				const ParagraphFrame *		ffPixels,
				ParticuleData *			pd );

typedef int (*START_PARAGRAPH)(	BufferItem *			bi,
				AppDrawingData *		add,
				const DocumentProperties *	dp );

typedef void (*SCREEN_FRAME)(	ParagraphFrame *		pf,
				const AppDrawingData *		add,
				const BufferItem *		bi );

typedef int (*START_SCREEN_PARAGRAPH)(
				BufferItem *			bi,
				AppDrawingData *		add,
				BufferDocument *		bd );

typedef int (*START_ROW)(	BufferItem *			rowBi,
				AppDrawingData *		add,
				BufferDocument *		bd );

typedef struct ScreenLayout
    {
    START_ROW			slStartRow;
    START_SCREEN_PARAGRAPH	slStartParagraph;
    SCREEN_FRAME		slScreenFrame;
    LAYOUT_SCREEN_LINE		slLayoutLine;
    } ScreenLayout;

/************************************************************************/
/*									*/
/*  A Layout Job.							*/
/*									*/
/*  A)	The rectangle that is to be redrawn on the screen. Coordinates	*/
/*	are in pixels, but relative to the document as a whole. ( Not	*/
/*	dependent on the position of the scrollbars. ) In non		*/
/*	interactive layout jobs this is a NULL pointer.			*/
/*  B)	Drawing data for font information, scaling from wips to pixels	*/
/*	etc.								*/
/*  C)	The document as a whole.					*/
/*  D)	The Node in the document tree that initiated the layout job.	*/
/*									*/
/*  E)	The current position on paper of the layout job.		*/
/*									*/
/*  F)	Indirection for screen calculations when laying out the		*/
/*	document.							*/
/*  G)	Indirection for screen calculations when just placing the lines	*/
/*	in the document again.						*/
/*									*/
/************************************************************************/

typedef struct LayoutJob
    {
    DocumentRectangle *		ljChangedRectanglePixels;	/*  A	*/
    AppDrawingData *		ljAdd;				/*  B	*/
    BufferDocument *		ljBd;				/*  C	*/
    BufferItem *		ljChangedItem;			/*  D	*/

    LayoutPosition		ljPosition;			/*  E	*/

    ScreenLayout		ljLayoutScreen;			/*  F	*/
    ScreenLayout		ljPlaceScreen;			/*  G	*/
    } LayoutJob;

/************************************************************************/
/*									*/
/*  For formatting a series of paragraphs. ( Inside a Cell or just	*/
/*  below eachother )							*/
/*									*/
/************************************************************************/

typedef struct ParagraphStripPosition
    {
    int			pspPara;
    int			pspPart;
    int			pspLine;
    } ParagraphStripPosition;

typedef struct ParagraphLayoutPosition
    {
    ParagraphStripPosition	plpProgress;
    LayoutPosition		plpPos;
    ParagraphFrame		plpFormattingFrame;
    } ParagraphLayoutPosition;

typedef struct ParagraphLayoutJob
    {
    int				pljParaUpto;

    ParagraphLayoutPosition	pljPos;
    ParagraphLayoutPosition	pljPos0;

    int				pljStopWhenSame;
    int				pljPageToFinish;
    int				pljColumnToFinish;
    } ParagraphLayoutJob;

struct ParagraphLayoutContext;

typedef int (*LAYOUT_LINES)(
			ParagraphLayoutPosition *		plp,
			BlockFrame *				bf,
			const struct ParagraphLayoutContext *	plc,
			BufferItem *				bi );

typedef void (*ADJUST_BOTTOM)(		int *			pChanged,
					BufferItem *		bi,
					const LayoutPosition *	lp,
					AppDrawingData *	add,
					DocumentRectangle *	drChanged );

typedef struct ParagraphLayoutContext
    {
    DocumentRectangle *		plcChangedRectanglePixels;
    AppDrawingData *		plcAdd;
    BufferDocument *		plcBd;

    ScreenLayout		plcScreenLayout;
    START_PARAGRAPH		plcStartParagraph;
    LAYOUT_LINES		plcLayoutLines;
    ADJUST_BOTTOM		plcAdjustBottom;
    } ParagraphLayoutContext;

typedef int (*LAYOUT_EXTERNAL)( int *				pY1Twips,
				ExternalItem *			ei,
				int				page,
				int				y0Twips,
				BufferDocument *		bd,
				AppDrawingData *		add,
				DocumentRectangle *		drChanged );

/************************************************************************/
/*									*/
/*  Routine declarations.						*/
/*									*/
/************************************************************************/

extern void docPsInitLayoutJob(		LayoutJob *	lj );
extern void docPsCleanLayoutJob(	LayoutJob *	lj );

extern int docLayoutLineBox(	TextLine *			tl,
				const BufferItem *		bi,
				int				part,
				int				tabInterval,
				const DocumentFontList *	dfl,
				AppPhysicalFontList *		apfl,
				const TextParticule *		tp,
				ParticuleData *			pd,
				const ParagraphFrame *		pf );

extern AfmFontInfo * docPsPrintGetAfi(
				int *				pEncoding,
				const AppPhysicalFontList *	apfl,
				int				physf );

extern int docPsClaimParticuleData(	const BufferItem *	bi,
					ParticuleData **	pData );

extern int docPsParagraphLineExtents(	const AppPhysicalFontList *	apfl,
					BufferItem *			bi );

extern int docPsPrintGetItemFonts(
				PostScriptFaceList *		psfl,
				const BufferItem *		bi,
				DocumentFontList *		dfl,
				const AppPhysicalFontList *	apfl );

extern int docPsPrintDocument(
			FILE *				f,
			const char *			title,
			const char *			applicationName,
			const char *			applicationReference,
			AppDrawingData *		add,
			BufferDocument *		bd,
			const PrintGeometry *		pg,
			int				firstPage,
			int				lastPage,
			LAYOUT_EXTERNAL			layoutExternal,
			DOC_CLOSE_OBJECT		closeObject );

extern int docLayoutItemAndParents(	BufferItem *		bi,
					LayoutJob *		lj );

extern int docPsAdjustParaLayout(	BufferItem *		bi,
					int			line,
					int			stroffShift,
					int			upto,
					LayoutJob *		lj );

extern void docLayoutSectColumnTop(
				BufferItem *			bodySectBi,
				BufferDocument *		bd,
				LayoutPosition *		lpTop,
				BlockFrame *			bf );

extern int docPsListObjectFonts(	PostScriptFaceList *	psfl,
					const InsertedObject *	io,
					const char *		afmDirectory,
					const char *		prefix );

extern int docLayoutExternalItem( ExternalItem *		ei,
				DocumentRectangle *		drChanged,
				int				pageNumber,
				int				y0Twips,
				BufferDocument *		bd,
				const BufferItem *		sectBi,
				AppDrawingData *		add,
				LAYOUT_EXTERNAL			layoutExternal,
				DOC_CLOSE_OBJECT		closeObject );

extern int docLayoutParagraphsInStrip(
				ParagraphLayoutJob *		plj,
				BlockFrame *			bf,
				const ParagraphLayoutContext *	plc,
				BufferItem *			cellBi,
				int				paraUpto,
				int				bottomTwips,
				int				stripHigh );

extern int docLayoutParagraphs(	const ParagraphLayoutContext *	plc,
				BufferItem *			cellBi,
				BlockFrame *			bf,
				LayoutJob *			lj,
				ParagraphLayoutJob *		plj );

extern void docPsInitParagraphLayoutJob( ParagraphLayoutJob *	plj );

extern void docLayoutToNextColumn(	BufferItem *			bi,
					BufferDocument *		bd,
					LayoutPosition *		lpTop,
					BlockFrame *			bf );

extern void docPsBeginParagraphLayoutProgress(	ParagraphLayoutJob *	plj,
						int			para,
						int			line,
						int			part,
						int			pUpto,
						const LayoutPosition *	lp );

extern int docLayoutRowItem(	BufferItem *			rowBi,
				BlockFrame *			bf,
				LayoutJob *			lj,
				const ParagraphLayoutContext *	plc );

extern void docPsLayoutPushBottomDown(	LayoutPosition *	lpRowBottom,
					const LayoutPosition *	lpColBottom );

extern void docParagraphFrameTwips(
				ParagraphFrame *		pf,
				const BlockFrame *		bf,
				int				bottom,
				int				stripHigh,
				BufferItem *			bi );

extern void docPsAdvanceParagraphLayout(
				int *				pAdvanced,
				ParagraphStripPosition *	psp0,
				const ParagraphStripPosition *	psp00,
				const ParagraphStripPosition *	psp1,
				int				page,
				const BufferItem *		cellBi );

extern void docParagraphStripFrame(
				const ScreenLayout *		sl,
				BufferItem *			cellBi,
				AppDrawingData *		add,
				int				bottomTwips,
				int				stripHigh,
				const BlockFrame *		bf,
				ParagraphLayoutJob *		plj );

extern void docBlockFrameTwips( BlockFrame *			bf,
				BufferItem *			bi,
				const BufferDocument *		bd,
				int				page,
				int				column );

extern void docLayoutInitBlockFrame(	BlockFrame *		bf );
extern void docInitNotesReservation(	NotesReservation *      nr );

extern void docLayoutReserveNoteHeight(
				ParagraphFrame *		pf,
				BlockFrame *			bf,
				const NotesReservation *	nrLine );

extern int docLayoutFootnotesForColumn(	const BlockFrame *	refBf,
					const LayoutPosition *	lpBelowText,
					const LayoutJob *	refLj );

extern int docLayoutCollectParaFootnoteHeight(
					NotesReservation *	nr,
					int			referringPage,
					int			referringColumn,
					BufferDocument *	bd,
					const BufferItem *	paraBi,
					int			partFrom,
					int			partUpto );

extern int docCollectFootnotesForColumn(
				BlockFrame *			bf,
				const DocumentPosition *	dpHere,
				const LayoutJob *		refLj );

extern int docNoteSeparatorRectangle(	DocumentRectangle *	drExtern,
					ExternalItem **		pEiNoteSep,
					int *			pY0Twips,
					BufferDocument *	bd,
					const DocumentNote *	dnFirstNote,
					int			extItKind,
					const AppDrawingData *	add );

extern int docGetExternalItemBox(
				DocumentRectangle *		dr,
				const BufferItem *		bodySectBi,
				const ExternalItem *		ei,
				int				justUsed,
				int				page,
				BufferDocument *		bd,
				AppDrawingData *		add );

extern int docExternalItemPrelayout(	ExternalItem *			ei,
					const DocumentGeometry *	dgRef,
					LayoutJob *			lj );

extern int docLayoutItemImplementation(	BufferItem *		bi,
					BlockFrame *		bf,
					LayoutJob *		lj );

extern int docSectHeaderFooterPrelayout(	BufferItem *	sectBi,
						LayoutJob *	lj );

extern int docLayoutEndnotesForSection(	int			sect,
					BlockFrame *		bf,
					LayoutJob *		lj );

extern int docLayoutEndnotesForDocument(	BlockFrame *		bf,
						LayoutJob *		lj );

#   endif	/*  DOC_LAYOUT_H  */