1 /************************************************************************/
2 /*									*/
3 /*  Document Layout and Printing related functionality.			*/
4 /*									*/
5 /************************************************************************/
6 
7 #   ifndef	DOC_LAYOUT_H
8 #   define	DOC_LAYOUT_H
9 
10 #   include	<docBuf.h>
11 #   include	<docEditRange.h>
12 #   include	<utilIndexMapping.h>
13 #   include	"docParticuleData.h"
14 #   include	<docStripFrame.h>
15 #   include	"docStripLayoutJob.h"
16 #   include	"docLayoutDocumentTree.h"
17 #   include	<docBlockFrame.h>
18 #   include	"layoutContext.h"
19 #   include	"docSelectionGeometry.h"
20 
21 /************************************************************************/
22 
23 #   define	includeRectangleY( dr1, dr2 ) \
24 		{ \
25 		if  ( (dr1)->drY0 > (dr2)->drY0 )  \
26 		    { (dr1)->drY0=  (dr2)->drY0; } \
27 		if  ( (dr1)->drY1 < (dr2)->drY1 )  \
28 		    { (dr1)->drY1=  (dr2)->drY1; } \
29 		}
30 
31 /************************************************************************/
32 /*									*/
33 /*  Reasons why the formatter stops.					*/
34 /*									*/
35 /************************************************************************/
36 
37 typedef enum FormatterResult
38     {
39     FORMATstopREADY= 0,
40     FORMATstopFRAME_FULL,
41     FORMATstopNEXT_FRAME,
42     FORMATstopBLOCK_FULL,
43 
44     FORMATstopCOLUMN_BREAK,
45     FORMATstopPAGE_BREAK,
46 
47     FORMATstopPARTIAL,
48 
49     FORMATstop_COUNT
50     } FormatterResult;
51 
52 /************************************************************************/
53 /*									*/
54 /*  Pass through information for a layout job.				*/
55 /*									*/
56 /************************************************************************/
57 
58 struct LayoutJob;
59 
60 typedef int (*LAYOUT_SCREEN_LINE)(
61 				const struct TextLine *		tl,
62 				const struct BufferItem *	paraNode,
63 				const LayoutContext *		lc,
64 				const ParagraphFrame *		ffPixels,
65 				ParticuleData *			pd );
66 
67 typedef int (*START_SCREEN_PARAGRAPH)(
68 				struct BufferItem *		node,
69 				const ParagraphFrame *		pf,
70 				const LayoutContext *		lc );
71 
72 /************************************************************************/
73 /*									*/
74 /*  A Layout Job.							*/
75 /*									*/
76 /*  A)	The rectangle that is to be redrawn on the screen. Coordinates	*/
77 /*	are in pixels, but relative to the document as a whole. ( Not	*/
78 /*	dependent on the position of the scrollbars. ) In non		*/
79 /*	interactive layout jobs this is a NULL pointer.			*/
80 /*  B)	Drawing data for font information, scaling from wips to pixels	*/
81 /*	etc.								*/
82 /*  C)	The document as a whole.					*/
83 /*  D)	The Node in the document tree that initiated the layout job.	*/
84 /*									*/
85 /*  E)	The current position on paper of the layout job.		*/
86 /*									*/
87 /*  F)	Indirection for screen calculations when laying out the		*/
88 /*	document.							*/
89 /*									*/
90 /************************************************************************/
91 
92 typedef struct LayoutJob
93     {
94     DocumentRectangle *		ljChangedRectanglePixels;	/*  A	*/
95     struct BufferItem *		ljChangedNode;			/*  D	*/
96     LayoutContext		ljContext;
97     int				ljReachedDocumentBottom;
98 
99     int				ljBalancePage;
100     int				ljBalanceY1;
101 
102     const struct BufferItem *	ljBodySectNode;
103 
104     START_SCREEN_PARAGRAPH	ljStartScreenParagraph;		/*  F	*/
105     LAYOUT_SCREEN_LINE		ljLayoutScreenLine;		/*  F	*/
106     } LayoutJob;
107 
108 /************************************************************************/
109 /*									*/
110 /*  Routine declarations.						*/
111 /*									*/
112 /************************************************************************/
113 
114 extern void docInitLayoutJob(		LayoutJob *	lj );
115 extern void docCleanLayoutJob(		LayoutJob *	lj );
116 
117 extern int docLayoutLineBox(	struct TextLine *		tl,
118 				struct BufferItem *		node,
119 				int				part,
120 				const LayoutContext *		lc,
121 				ParticuleData *			pd,
122 				const ParagraphFrame *		pf );
123 
124 extern int docLayoutParagraphLineExtents(
125 				int *				pFontSize,
126 				const LayoutContext *		lc,
127 				struct BufferItem *		node );
128 
129 extern int docLayoutNodeAndParents(	struct BufferItem *	node,
130 					LayoutJob *		lj );
131 
132 extern int docAdjustParaLayout(		struct BufferItem *	node,
133 					int			afterReplace,
134 					int			stroffFrom,
135 					int			stroffShift,
136 					int			stroffUpto,
137 					LayoutJob *		lj );
138 
139 extern void docLayoutColumnTop(	LayoutPosition *		lpTop,
140 				BlockFrame *			bf,
141 				struct BufferItem *		bodySectNode,
142 				const LayoutJob *		lj );
143 
144 extern int docLayoutDocumentTree( DocumentTree *	ei,
145 				DocumentRectangle *	drChanged,
146 				int			page,
147 				int			column,
148 				int			y0Twips,
149 				const struct BufferItem *	bodySectNode,
150 				const LayoutContext *	lc,
151 				INIT_LAYOUT_EXTERNAL	initLayoutExternal,
152 				int			adjustDocument );
153 
154 extern int docLayoutStripChildren(
155 				int *				pStopCode,
156 				ParagraphLayoutJob *		plj,
157 				BlockFrame *			bf,
158 				const LayoutJob *		lj,
159 				struct BufferItem *		cellNode );
160 
161 extern int docLayoutStackedStrip( struct BufferItem *		cellNode,
162 				BlockFrame *			bf,
163 				const LayoutJob *		lj,
164 				ParagraphLayoutJob *		plj );
165 
166 extern void docLayoutToNextColumn(	LayoutPosition *		lpTop,
167 					BlockFrame *			bf,
168 					struct BufferItem *		node,
169 					const LayoutJob *		lj );
170 
171 extern int docLayoutRowNode(	int *			pStopCode,
172 				LayoutPosition *	lpBelow,
173 				const LayoutPosition *	lpTop,
174 				struct BufferItem *	rowBi,
175 				BlockFrame *		bf,
176 				int			stayInThisColumn,
177 				const LayoutJob *	lj );
178 
179 extern void docCommitStripLayout(
180 				int *				pAdvanced,
181 				int				advanceAnyway,
182 				ParagraphLayoutJob *		plj,
183 				int				page,
184 				int				column,
185 				const struct BufferItem *	cellNode );
186 
187 extern void docFindStripLayoutOrigin(
188 				ParagraphLayoutJob *		plj,
189 				int				page,
190 				int				column,
191 				const struct BufferItem *	cellNode );
192 
193 extern void docLayoutBlockFrame( BlockFrame *			bf,
194 				struct BufferItem *		node,
195 				const LayoutJob *		lj,
196 				int				page,
197 				int				column );
198 
199 extern int docLayoutFootnotesForColumn(	LayoutPosition *	lpBelowNotes,
200 					const LayoutPosition *	lpBelowText,
201 					const BlockFrame *	refBf,
202 					int			belowText,
203 					const LayoutJob *	refLj );
204 
205 extern int docLayoutCollectParaFootnoteHeight(
206 			NotesReservation *		nr,
207 			int				referringPage,
208 			int				referringColumn,
209 			BufferDocument *		bd,
210 			const struct BufferItem *	bodySectNode,
211 			const struct BufferItem *	paraNode,
212 			int				partFrom,
213 			int				partUpto );
214 
215 extern int docCollectFootnotesFromColumn(
216 			BlockFrame *			bf,
217 			const DocumentPosition *	dpHere,
218 			int				partHere,
219 			BufferDocument *		bd,
220 			int				referringPage,
221 			int				referringColumn );
222 
223 extern int docNoteSeparatorRectangle(
224 				DocumentRectangle *		drExtern,
225 				DocumentTree **			pEiNoteSep,
226 				int *				pY0Twips,
227 				const struct DocumentNote *	dnFirstNote,
228 				int				treeType,
229 				const LayoutContext *		lc );
230 
231 extern int docGetBoxAroundTree(
232 				DocumentRectangle *		dr,
233 				const struct BufferItem *	bodySectNode,
234 				const DocumentTree *		ei,
235 				int				justUsed,
236 				int				page,
237 				int				column,
238 				const LayoutContext *		lc );
239 
240 extern int docTreePrelayout(		DocumentTree *		ei,
241 					const struct BufferItem *	bodySectNode,
242 					LayoutJob *		lj );
243 
244 extern int docLayoutNodeImplementation(	LayoutPosition *	lpBelow,
245 					const LayoutPosition *	lpTop,
246 					struct BufferItem *	node,
247 					BlockFrame *		bf,
248 					LayoutJob *		lj );
249 
250 extern int docSectHeaderFooterPrelayout(	struct BufferItem *	sectNode,
251 						LayoutJob *	lj );
252 
253 extern int docLayoutEndnotesForSection(	LayoutPosition *	lpBelow,
254 					const LayoutPosition *	lpTop,
255 					int			sect,
256 					BlockFrame *		bf,
257 					LayoutJob *		lj );
258 
259 extern int docLayoutEndnotesForDocument(	LayoutPosition *	lpBelow,
260 						const LayoutPosition *	lpTop,
261 						BlockFrame *		bf,
262 						LayoutJob *		lj );
263 
264 extern int docLayoutParaLines(	int *				pStopCode,
265 				int				isRedo,
266 				const ParagraphFrame *		pf,
267 				LayoutPosition *		lpHere,
268 				int *				pLine,
269 				BlockFrame *			bf,
270 				const LayoutJob *		lj,
271 				struct BufferItem *		paraNode,
272 				int				part );
273 
274 extern int docLayoutSectChildren(	LayoutPosition *	lpBelow,
275 					const LayoutPosition *	lpTop,
276 					struct BufferItem *	sectNode,
277 					int			from,
278 					BlockFrame *		bf,
279 					LayoutJob *		lj );
280 
281 extern int docLayoutSectNode(	LayoutPosition *		lpBelow,
282 				const LayoutPosition *		lpTop,
283 				struct BufferItem *		sectNode,
284 				BlockFrame *			bf,
285 				LayoutJob *			lj );
286 
287 extern int docLayoutTableSlice( LayoutPosition *	lpBelow,
288 				const LayoutPosition *	lpTop,
289 				struct BufferItem *	parentNode,
290 				int			from,
291 				int			upto,
292 				BlockFrame *		bf,
293 				LayoutJob *		lj );
294 
295 extern void docResetExternalTreeLayout(	BufferDocument *	bd );
296 
297 extern void docDrawingShapeInvalidateTextLayout(
298 				struct DrawingShape *		ds );
299 
300 extern void docShapePageY(	LayoutPosition *	lpShapeTop,
301 				LayoutPosition *	lpBelowShape,
302 				BlockFrame *		bfShape,
303 				const struct DrawingShape *	ds,
304 				const struct BufferItem *	paraNode,
305 				const LayoutPosition *	lpLineTop,
306 				const BlockFrame *	bf );
307 
308 extern void docShapePageRectangle(
309 				LayoutPosition *	lpShapeTop,
310 				LayoutPosition *	lpBelowShape,
311 				int *			pX0,
312 				int *			pX1,
313 				const struct DrawingShape *	ds,
314 				const struct BufferItem *	paraNode,
315 				const LayoutPosition *	lpLineTop,
316 				const ParagraphFrame *	pfRef,
317 				const BlockFrame *	bfRef,
318 				int			xChar );
319 
320 extern int docShapeCheckTextLayout(
321 			struct DrawingShape *		ds,
322 			const DocumentRectangle *	drTwips,
323 			DocumentRectangle *		drChanged,
324 			const struct BufferItem *	bodySectNode,
325 			int				page,
326 			int				column,
327 			const LayoutContext *		lc,
328 			INIT_LAYOUT_EXTERNAL		initLayoutExternal );
329 
330 extern int docLayoutInvalidateRange(	DocumentSelection *	dsLayout,
331 					BufferDocument *	bd,
332 					const DocumentTree *	ei,
333 					EditRange *		er );
334 
335 extern void docRedoParaStripLayout(
336 				const LayoutJob *		lj,
337 				BlockFrame *			bf,
338 				const LayoutPosition *		lpFrom,
339 				struct BufferItem *		cellNode,
340 				int				paraFrom,
341 				int				paraUpto );
342 
343 extern int docCheckPageOfSelectedTree(
344 				int *			pChanged,
345 				struct BufferItem **	pBodySectNode,
346 				DocumentRectangle *	drChanged,
347 				DocumentTree *		selRootEi,
348 				const LayoutContext *	lc,
349 				INIT_LAYOUT_EXTERNAL	initLayoutExternal );
350 
351 extern int docSectNotesPrelayout(
352 				int				sect,
353 				const struct BufferItem *	bodySectNode,
354 				LayoutJob *			lj );
355 
356 extern void docLayoutSetNodeBottom(	int *			pChanged,
357 					struct BufferItem *	node,
358 					const LayoutPosition *	lp,
359 					const LayoutContext *	lc,
360 					DocumentRectangle *	drChanged );
361 
362 extern void docLayoutSetBottomPosition(
363 				int *				pChanged,
364 				LayoutPosition *		lpBelow,
365 				const LayoutPosition *		lp,
366 				const LayoutContext *		lc,
367 				DocumentRectangle *		drChanged );
368 
369 extern int docLayoutGetInitialFrame(	BlockFrame *		bf,
370 					const LayoutJob *	lj,
371 					const LayoutPosition *	lpHere,
372 					struct BufferItem *	node );
373 
374 extern void docLayoutStartNodeLayout(	struct BufferItem *	node,
375 					const LayoutJob *	lj,
376 					const LayoutPosition *	lpHere );
377 
378 extern void docLayoutFinishNodeLayout(	int *			pChanged,
379 					struct BufferItem *	node,
380 					const LayoutJob *	lj,
381 					const LayoutPosition *	lpHere );
382 
383 extern int docLayoutFinishSectNode(
384 				LayoutPosition *		lpBelow,
385 				const LayoutPosition *		lpTop,
386 				struct BufferItem *		sectNode,
387 				BlockFrame *			bf,
388 				LayoutJob *			lj );
389 
390 extern void docLayoutCalculateParaTopInset(
391 				const BufferDocument *		bd,
392 				struct BufferItem *		paraNode );
393 
394 extern void docLayoutCalculateParaBottomInset(
395 				const BufferDocument *		bd,
396 				struct BufferItem *		paraNode );
397 
398 extern const AfmFontInfo * docLayoutGetAfi(
399 			int *				pTextAttrNr,
400 			TextAttribute *			ta,
401 			unsigned char *			pLineFlags,
402 			const LayoutContext *		lc,
403 			const struct BufferItem *	paraNode,
404 			int				part );
405 
406 extern int docLayoutFontAscDesc( const struct BufferItem *	paraNode,
407 				TextAttribute *			ta,
408 				DocumentRectangle *		drAscDesc,
409 				int *				pBorder,
410 				const LayoutContext *		lc,
411 				int				part );
412 
413 extern int docLayoutStringExtents(	int *			pWidth,
414 					int *			pDecWidth,
415 					DocumentRectangle *	dr,
416 					const TextAttribute *	ta,
417 					int			sizeTwips,
418 					const BufferDocument *	bd,
419 					const AfmFontInfo *	afi,
420 					const char *		printString,
421 					int			len );
422 
423 extern int docLayoutInlineObject( TextAttribute *		ta,
424 				BufferDocument *		bd,
425 				const struct BufferItem *	paraNode,
426 				int				part,
427 				InsertedObject *		io,
428 				DocumentRectangle *		drWord,
429 				int *				pWordBorder,
430 				int *				pX1,
431 				int				x0 );
432 
433 extern void docLayoutCalculateAfterRowTopInset(	struct BufferItem *	belowBi,
434 						const BufferDocument *	bd );
435 
436 extern int docLayoutStartParagraph(
437 			const LayoutJob *		lj,
438 			int *				pStopCode,
439 			struct BufferItem *		paraNode,
440 			const BlockFrame *		bf,
441 			ParagraphLayoutPosition *	plp );
442 
443 extern void docLayoutFinishFrame(
444 			const FrameProperties *		fp,
445 			BlockFrame *			bfTextFrame,
446 			const BlockFrame *		bfFlow,
447 			const LayoutJob *		lj,
448 			const ParagraphLayoutPosition *	plpFlow,
449 			struct BufferItem *		cellNode,
450 			int				paraFrom,
451 			int				paraUpto );
452 
453 extern int docLayoutParagraphInStrip(
454 			int *				pStopCode,
455 			ParagraphLayoutPosition *	plp,
456 			BlockFrame *			bf,
457 			const LayoutJob *		lj,
458 			int				cellTopInset,
459 			struct BufferItem *		paraNode );
460 
461 extern int docLayoutRowInStrip(
462 			int *				pStopCode,
463 			ParagraphLayoutPosition *	plp,
464 			BlockFrame *			bf,
465 			const LayoutJob *		lj,
466 			int				cellTopInset,
467 			struct BufferItem *		paraNode );
468 
469 extern int docAdjustParentLayout(	const LayoutPosition *	lpTop,
470 					struct BufferItem *	node,
471 					BlockFrame *		bf,
472 					LayoutJob *		lj );
473 
474 extern int docLayoutCellNode(	LayoutPosition *	lpBelow,
475 				const LayoutPosition *	lpTop,
476 				struct BufferItem *	cellNode,
477 				int			from,
478 				BlockFrame *		bf,
479 				LayoutJob *		lj );
480 
481 extern void docRowLayoutRowspanAdmin(
482 				struct BufferItem *		cellNode,
483 				const struct BufferItem *	rowBi,
484 				const struct BufferItem *	nextRowBi,
485 				int				nextRow,
486 				const CellProperties *		cp,
487 				int				l,
488 				int				r,
489 				ParagraphLayoutJob *		plj );
490 
491 extern void docCellStripFrame(	struct BufferItem *		cellNode,
492 				const BlockFrame *		bf,
493 				ParagraphLayoutJob *		plj );
494 
495 extern void docGetPixelRect(	DocumentRectangle *		drPixels,
496 				const LayoutContext *		lc,
497 				const DocumentRectangle *	drTwips,
498 				int				page );
499 
500 extern void docGetPixelRectForPos(
501 				DocumentRectangle *		drPixels,
502 				const LayoutContext *		lc,
503 				int				x0Twips,
504 				int				x1Twips,
505 				const LayoutPosition *		lpTop,
506 				const LayoutPosition *		lpBottom );
507 
508 extern void docGetPageRectPixels(
509 				DocumentRectangle *		drPixels,
510 				const LayoutContext *		lc,
511 				int				page );
512 
513 extern void docGetPixelRectangleForPages(
514 				DocumentRectangle *		drPixels,
515 				const LayoutContext *		lc,
516 				int				page0,
517 				int				page1 );
518 
519 extern void docPixelRectangleForPositions(
520 				DocumentRectangle *		drPixels,
521 				const PositionGeometry *	pgB,
522 				const PositionGeometry *	pgE,
523 				const LayoutContext *		lc );
524 
525 extern int docLayoutScapsScreenFont(	const LayoutContext *	lc,
526 					const TextAttribute *	ta );
527 
528 extern void docNodeRectangle(	DocumentRectangle *	drPixels,
529 				struct BufferItem *	node,
530 				const LayoutContext *	lc,
531 				const BlockOrigin *	bo );
532 
533 extern int docGetFirstSectionOnPage(	BufferDocument *	bd,
534 					int			page );
535 
536 extern int docFindHeaderFooterForY(	DocumentTree **		pTree,
537 					struct BufferItem **	pSelSectNode,
538 					int *			pColumn,
539 					const LayoutContext *	lc,
540 					struct BufferItem *	bodySectNode,
541 					BufferDocument *	bd,
542 					int			page,
543 					int			docY );
544 
545 extern void docPageRectsPixels(	DocumentRectangle *	drOutside,
546 				DocumentRectangle *	drInside,
547 				double			xfac,
548 				const struct BufferItem *	bodySectNode,
549 				const BufferDocument *	bd );
550 
551 extern int docSectColumnsAreBalanced(
552 				const struct BufferItem *	sectNode );
553 
554 extern int docAdjustLayoutToChangedTree(
555 				LayoutPosition *		lpHere,
556 				struct BufferItem *		node,
557 				LayoutJob *			lj );
558 
559 extern void docLayoutAdjustFrame(	BlockFrame *			bf,
560 					const struct BufferItem *	node );
561 
562 #   endif	/*  DOC_LAYOUT_H  */
563