1 /************************************************************************/
2 /*									*/
3 /*  Manage paragraph properties.					*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"docBaseConfig.h"
8 
9 #   include	<appDebugon.h>
10 
11 #   include	"docParaProperties.h"
12 #   include	"docPropVal.h"
13 #   include	"docListDepth.h"
14 
15 /************************************************************************/
16 /*									*/
17 /*  Manage paragraph properties.					*/
18 /*									*/
19 /************************************************************************/
20 
docCleanParagraphProperties(ParagraphProperties * pp)21 void docCleanParagraphProperties(	ParagraphProperties *	pp )
22     {
23     }
24 
docInitParagraphProperties(ParagraphProperties * pp)25 void docInitParagraphProperties(	ParagraphProperties *	pp )
26     {
27     pp->ppTabStopListNumber= 0;
28 
29     pp->ppFirstIndentTwips= 0;
30     pp->ppLeftIndentTwips= 0;
31     pp->ppRightIndentTwips= 0;
32 
33     pp->ppSpaceBeforeTwips= 0;
34     pp->ppSpaceAfterTwips= 0;
35     pp->ppLineSpacingTwips= 0;
36 
37     pp->ppStyle= 0;
38     pp->ppListOverride= 0;
39 
40     pp->ppTopBorderNumber= 0;
41     pp->ppLeftBorderNumber= 0;
42     pp->ppRightBorderNumber= 0;
43     pp->ppBottomBorderNumber= 0;
44     pp->ppBetweenBorderNumber= 0;
45     pp->ppBarNumber= 0;
46 
47     pp->ppShadingNumber= 0;
48     pp->ppFrameNumber= 0;
49 
50     pp->ppOutlineLevel= PPoutlineBODYTEXT;
51     pp->ppListLevel= 0;
52 
53     pp->ppAlignment= DOCthaLEFT;
54 
55     pp->ppBreakKind= DOCibkNONE;
56     pp->ppTableNesting= 0;
57     pp->ppLineSpacingIsMultiple= 0;
58 
59     pp->ppKeepOnPage= 0;
60     pp->ppKeepWithNext= 0;
61     pp->ppWidowControl= 0;
62     pp->ppHyphenateParagraph= 0;
63     pp->ppRToL= 0;
64 
65     return;
66     }
67 
68 /************************************************************************/
69 
70 static const int DocParaIntProps[]=
71 {
72     PPpropSTYLE,
73     PPpropTABLE_NESTING,
74     PPpropFIRST_INDENT,
75     PPpropLEFT_INDENT,
76     PPpropRIGHT_INDENT,
77     PPpropALIGNMENT,
78 
79     PPpropBREAK_KIND,
80     PPpropWIDCTLPAR,
81     PPpropKEEPN,
82     PPpropKEEP,
83     PPpropSPACE_BEFORE,
84     PPpropSPACE_AFTER,
85     PPpropLINE_SPACING_DIST,
86     PPpropLINE_SPACING_MULT,
87 
88     PPpropOUTLINELEVEL,
89     PPpropLISTLEVEL,
90     PPpropHYPHPAR,
91     PPpropRTOL,
92 };
93 
94 static const int DocParaIntPropCount= sizeof(DocParaIntProps)/sizeof(int);
95 
96 static const int DocParaBorderProps[]=
97 {
98     PPpropTOP_BORDER,
99     PPpropBOTTOM_BORDER,
100     PPpropLEFT_BORDER,
101     PPpropRIGHT_BORDER,
102     PPpropBETWEEN_BORDER,
103     PPpropBAR_BORDER,
104 };
105 
106 static const int DocParaBorderPropCount= sizeof(DocParaBorderProps)/sizeof(int);
107 
108 /************************************************************************/
109 /*									*/
110 /*  Change paragraph properties and tell what has been changed.		*/
111 /*									*/
112 /************************************************************************/
113 
docCopyParagraphProperties(ParagraphProperties * ppTo,const ParagraphProperties * ppFrom)114 int docCopyParagraphProperties(	ParagraphProperties *		ppTo,
115 				const ParagraphProperties *	ppFrom )
116     {
117     PropertyMask	ppSetMask;
118 
119     utilPropMaskFill( &ppSetMask, PPprop_FULL_COUNT );
120 
121     return docUpdParaProperties( (PropertyMask *)0, ppTo, &ppSetMask, ppFrom,
122 					    (const DocumentAttributeMap *)0 );
123     }
124 
docUpdParaProperties(PropertyMask * pDoneMask,ParagraphProperties * ppTo,const PropertyMask * ppSetMask,const ParagraphProperties * ppFrom,const DocumentAttributeMap * dam)125 int docUpdParaProperties(	PropertyMask *			pDoneMask,
126 				ParagraphProperties *		ppTo,
127 				const PropertyMask *		ppSetMask,
128 				const ParagraphProperties *	ppFrom,
129 				const DocumentAttributeMap *	dam )
130     {
131     PropertyMask		ppDoneMask;
132     int				p;
133 
134     utilPropMaskClear( &ppDoneMask );
135 
136     for ( p= 0; p < DocParaIntPropCount; p++ )
137 	{
138 	const int	prop= DocParaIntProps[p];
139 
140 	if  ( PROPmaskISSET( ppSetMask, prop ) )
141 	    {
142 	    int		from= docGetParaProperty( ppFrom, prop );
143 	    int		to= docGetParaProperty( ppTo, prop );
144 
145 	    if  ( to != from )
146 		{
147 		if  ( docSetParaProperty( ppTo, prop, from ) )
148 		    { LLDEB(prop,from);	}
149 		else{ PROPmaskADD( &ppDoneMask, prop );	}
150 		}
151 	    }
152 	}
153 
154     if  ( PROPmaskISSET( ppSetMask, PPpropLISTOVERRIDE ) )
155 	{
156 	int		listStyle= ppFrom->ppListOverride;
157 
158 	if  ( dam && dam->damListStyleMap )
159 	    { listStyle= dam->damListStyleMap[listStyle];	}
160 
161 	if  ( ppTo->ppListOverride != listStyle )
162 	    {
163 	    ppTo->ppListOverride= listStyle;
164 	    PROPmaskADD( &ppDoneMask, PPpropLISTOVERRIDE );
165 	    }
166 	}
167 
168     if  ( PROPmaskISSET( ppSetMask, PPpropTAB_STOPS ) )
169 	{
170 	int	fromNumber= ppFrom->ppTabStopListNumber;
171 
172 	if  ( fromNumber >= 0 && dam && dam->damRulerMap )
173 	    { fromNumber= dam->damRulerMap[fromNumber];	}
174 
175 	if  ( ppTo->ppTabStopListNumber != fromNumber )
176 	    {
177 	    ppTo->ppTabStopListNumber= fromNumber;
178 	    PROPmaskADD( &ppDoneMask, PPpropTAB_STOPS );
179 	    }
180 	}
181 
182     for ( p= 0; p < DocParaBorderPropCount; p++ )
183 	{
184 	const int	prop= DocParaBorderProps[p];
185 
186 	if  ( PROPmaskISSET( ppSetMask, prop ) )
187 	    {
188 	    int		from= docGetParaProperty( ppFrom, prop );
189 	    int		to= docGetParaProperty( ppTo, prop );
190 
191 	    if  ( from >= 0 && dam && dam->damBorderMap )
192 		{ from= dam->damBorderMap[from];	}
193 
194 	    if  ( to != from )
195 		{
196 		if  ( docSetParaProperty( ppTo, prop, from ) )
197 		    { LLDEB(prop,from);	}
198 		else{ PROPmaskADD( &ppDoneMask, prop );	}
199 		}
200 	    }
201 	}
202 
203     if  ( PROPmaskISSET( ppSetMask, PPpropSHADING ) )
204 	{
205 	int	fromNumber= ppFrom->ppShadingNumber;
206 
207 	if  ( fromNumber >= 0 && dam && dam->damShadingMap )
208 	    { fromNumber= dam->damShadingMap[fromNumber];	}
209 
210 	if  ( ppTo->ppShadingNumber != fromNumber )
211 	    {
212 	    ppTo->ppShadingNumber= fromNumber;
213 	    PROPmaskADD( &ppDoneMask, PPpropSHADING );
214 	    }
215 	}
216 
217     if  ( PROPmaskISSET( ppSetMask, PPpropFRAME ) )
218 	{
219 	int	fromNumber= ppFrom->ppFrameNumber;
220 
221 	if  ( fromNumber >= 0 && dam && dam->damFrameMap )
222 	    { fromNumber= dam->damFrameMap[fromNumber];	}
223 
224 	if  ( ppTo->ppFrameNumber != fromNumber )
225 	    {
226 	    ppTo->ppFrameNumber= fromNumber;
227 	    PROPmaskADD( &ppDoneMask, PPpropFRAME );
228 	    }
229 	}
230 
231     if  ( pDoneMask )
232 	{ utilPropMaskOr( pDoneMask, pDoneMask, &ppDoneMask );	}
233 
234     return 0;
235     }
236 
237 /************************************************************************/
238 /*									*/
239 /*  Compare paragraph properties.					*/
240 /*									*/
241 /************************************************************************/
242 
docParaPropertyDifference(PropertyMask * pDifMask,const ParagraphProperties * ppTo,const PropertyMask * ppCmpMask,const ParagraphProperties * ppFrom)243 void docParaPropertyDifference(	PropertyMask *			pDifMask,
244 				const ParagraphProperties *	ppTo,
245 				const PropertyMask *		ppCmpMask,
246 				const ParagraphProperties *	ppFrom )
247     {
248     PropertyMask		ppDifMask;
249     int				p;
250 
251     const DocumentAttributeMap *	dam= (const DocumentAttributeMap *)0;
252 
253     utilPropMaskClear( &ppDifMask );
254 
255     for ( p= 0; p < DocParaIntPropCount; p++ )
256 	{
257 	const int	prop= DocParaIntProps[p];
258 
259 	if  ( PROPmaskISSET( ppCmpMask, prop ) )
260 	    {
261 	    int		from= docGetParaProperty( ppFrom, prop );
262 	    int		to= docGetParaProperty( ppTo, prop );
263 
264 	    if  ( to != from )
265 		{ PROPmaskADD( &ppDifMask, prop );	}
266 	    }
267 	}
268 
269     if  ( PROPmaskISSET( ppCmpMask, PPpropLISTOVERRIDE ) )
270 	{
271 	int		listStyle= ppFrom->ppListOverride;
272 
273 	if  ( dam && dam->damListStyleMap )
274 	    { listStyle= dam->damListStyleMap[listStyle];	}
275 
276 	if  ( ppTo->ppListOverride != listStyle )
277 	    { PROPmaskADD( &ppDifMask, PPpropLISTOVERRIDE );	}
278 	}
279 
280     if  ( PROPmaskISSET( ppCmpMask, PPpropTAB_STOPS ) )
281 	{
282 	int	fromNumber= ppFrom->ppTabStopListNumber;
283 
284 	if  ( fromNumber >= 0 && dam && dam->damRulerMap )
285 	    { fromNumber= dam->damRulerMap[fromNumber];	}
286 
287 	if  ( ppTo->ppTabStopListNumber != fromNumber )
288 	    { PROPmaskADD( &ppDifMask, PPpropTAB_STOPS );	}
289 	}
290 
291     for ( p= 0; p < DocParaBorderPropCount; p++ )
292 	{
293 	const int	prop= DocParaBorderProps[p];
294 
295 	if  ( PROPmaskISSET( ppCmpMask, prop ) )
296 	    {
297 	    int		from= docGetParaProperty( ppFrom, prop );
298 	    int		to= docGetParaProperty( ppTo, prop );
299 
300 	    if  ( from >= 0 && dam && dam->damBorderMap )
301 		{ from= dam->damBorderMap[from];	}
302 
303 	    if  ( to != from )
304 		{ PROPmaskADD( &ppDifMask, prop );	}
305 	    }
306 	}
307 
308     if  ( PROPmaskISSET( ppCmpMask, PPpropSHADING ) )
309 	{
310 	int	fromNumber= ppFrom->ppShadingNumber;
311 
312 	if  ( fromNumber >= 0 && dam && dam->damShadingMap )
313 	    { fromNumber= dam->damShadingMap[fromNumber];	}
314 
315 	if  ( ppTo->ppShadingNumber != fromNumber )
316 	    { PROPmaskADD( &ppDifMask, PPpropSHADING );	}
317 	}
318 
319     if  ( PROPmaskISSET( ppCmpMask, PPpropFRAME ) )
320 	{
321 	int	fromNumber= ppFrom->ppFrameNumber;
322 
323 	if  ( fromNumber >= 0 && dam && dam->damFrameMap )
324 	    { fromNumber= dam->damFrameMap[fromNumber];	}
325 
326 	if  ( ppTo->ppFrameNumber != fromNumber )
327 	    { PROPmaskADD( &ppDifMask, PPpropFRAME );	}
328 	}
329 
330     *pDifMask= ppDifMask;
331     return;
332     }
333 
docSetParaProperty(ParagraphProperties * pp,int prop,int arg)334 int docSetParaProperty(		ParagraphProperties *	pp,
335 				int			prop,
336 				int			arg )
337     {
338     switch( prop )
339 	{
340 	case PPpropSTYLE:
341 	    pp->ppStyle= arg;
342 	    break;
343 
344 	case PPpropLISTOVERRIDE:
345 	    pp->ppListOverride= arg;
346 	    break;
347 
348 	case PPprop_IN_TABLE:  /* intbl */
349 	    if  ( arg == 0 )
350 		{ pp->ppTableNesting= 0;	}
351 	    else{
352 		if  ( pp->ppTableNesting == 0 )
353 		    { pp->ppTableNesting= 1;	}
354 		}
355 	    break;
356 
357 	case PPpropTABLE_NESTING:  /* itap */
358 	    pp->ppTableNesting= arg;
359 	    break;
360 
361 	case PPpropLEFT_INDENT:
362 	    pp->ppLeftIndentTwips= arg;
363 	    break;
364 
365 	case PPpropFIRST_INDENT:
366 	    pp->ppFirstIndentTwips= arg;
367 	    break;
368 
369 	case PPpropRIGHT_INDENT:
370 	    pp->ppRightIndentTwips= arg;
371 	    break;
372 
373 	case PPpropALIGNMENT:
374 	    pp->ppAlignment= arg;
375 	    break;
376 
377 	case PPpropTAB_STOPS:
378 	    LDEB(prop);
379 	    return 0;
380 
381 	case PPpropBREAK_KIND:
382 	    pp->ppBreakKind= arg;
383 	    break;
384 
385 	case PPpropWIDCTLPAR:
386 	    pp->ppWidowControl= arg;
387 	    break;
388 
389 	case PPpropKEEP:
390 	    pp->ppKeepOnPage= arg != 0;
391 	    break;
392 
393 	case PPpropKEEPN:
394 	    pp->ppKeepWithNext= arg != 0;
395 	    break;
396 
397 	case PPpropSPACE_BEFORE:
398 	    pp->ppSpaceBeforeTwips= arg;
399 	    break;
400 
401 	case PPpropSPACE_AFTER:
402 	    pp->ppSpaceAfterTwips= arg;
403 	    break;
404 
405 	case PPpropLINE_SPACING_DIST:
406 	    pp->ppLineSpacingTwips= arg;
407 	    break;
408 
409 	case PPpropLINE_SPACING_MULT:
410 	    pp->ppLineSpacingIsMultiple= ( arg != 0 );
411 	    break;
412 
413 	case PPpropTOP_BORDER:
414 	    pp->ppTopBorderNumber= arg;
415 	    break;
416 
417 	case PPpropBOTTOM_BORDER:
418 	    pp->ppBottomBorderNumber= arg;
419 	    break;
420 
421 	case PPpropLEFT_BORDER:
422 	    pp->ppLeftBorderNumber= arg;
423 	    break;
424 
425 	case PPpropRIGHT_BORDER:
426 	    pp->ppRightBorderNumber= arg;
427 	    break;
428 
429 	case PPprop_BOX_BORDER:
430 	    pp->ppTopBorderNumber= arg;
431 	    pp->ppBottomBorderNumber= arg;
432 	    pp->ppLeftBorderNumber= arg;
433 	    pp->ppRightBorderNumber= arg;
434 	    break;
435 
436 	case PPpropBETWEEN_BORDER:
437 	    pp->ppBetweenBorderNumber= arg;
438 	    break;
439 
440 	case PPpropBAR_BORDER:
441 	    pp->ppBarNumber= arg;
442 	    break;
443 
444 	case PPpropOUTLINELEVEL:
445 	    if  ( arg >= 0 && arg <= PPoutlineBODYTEXT )
446 		{ pp->ppOutlineLevel= arg;			}
447 	    else{ pp->ppOutlineLevel= PPoutlineBODYTEXT;	}
448 	    break;
449 
450 	case PPpropLISTLEVEL:
451 	    if  ( arg > 0 && arg < 10 )
452 		{ pp->ppListLevel= arg;	}
453 	    else{ pp->ppListLevel= 0;	}
454 	    break;
455 
456 	case PPpropHYPHPAR:
457 	    pp->ppHyphenateParagraph= arg != 0;
458 	    break;
459 
460 	case PPpropRTOL:
461 	    pp->ppRToL= arg != 0;
462 	    break;
463 
464 	case PPprop_LISB:
465 	case PPprop_LISA:
466 	    break;
467 
468 	case PPprop_IGNORED:
469 	    break;
470 
471 	default:
472 	    LDEB(prop); return -1;
473 	}
474 
475     return 0;
476     }
477 
docGetParaProperty(const ParagraphProperties * pp,int prop)478 int docGetParaProperty(		const ParagraphProperties *	pp,
479 				int				prop )
480     {
481     switch( prop )
482 	{
483 	case PPpropSTYLE:
484 	    return pp->ppStyle;
485 
486 	case PPpropLISTOVERRIDE:
487 	    return pp->ppListOverride;
488 
489 	case PPprop_IN_TABLE:  /* intbl */
490 	    return ( pp->ppTableNesting > 0 );
491 
492 	case PPpropTABLE_NESTING:  /* itap */
493 	    return pp->ppTableNesting;
494 
495 	case PPpropLEFT_INDENT:
496 	    return pp->ppLeftIndentTwips;
497 
498 	case PPpropFIRST_INDENT:
499 	    return pp->ppFirstIndentTwips;
500 
501 	case PPpropRIGHT_INDENT:
502 	    return pp->ppRightIndentTwips;
503 
504 	case PPpropALIGNMENT:
505 	    return pp->ppAlignment;
506 
507 	case PPpropTAB_STOPS:
508 	    LDEB(prop); return -1;
509 
510 	case PPpropBREAK_KIND:
511 	    return pp->ppBreakKind;
512 
513 	case PPpropWIDCTLPAR:
514 	    return pp->ppWidowControl;
515 
516 	case PPpropKEEP:
517 	    return pp->ppKeepOnPage;
518 
519 	case PPpropKEEPN:
520 	    return pp->ppKeepWithNext;
521 
522 	case PPpropSPACE_BEFORE:
523 	    return pp->ppSpaceBeforeTwips;
524 
525 	case PPpropSPACE_AFTER:
526 	    return pp->ppSpaceAfterTwips;
527 
528 	case PPpropLINE_SPACING_DIST:
529 	    return pp->ppLineSpacingTwips;
530 
531 	case PPpropLINE_SPACING_MULT:
532 	    return pp->ppLineSpacingIsMultiple;
533 
534 	case PPpropTOP_BORDER:
535 	    return pp->ppTopBorderNumber;
536 
537 	case PPpropBOTTOM_BORDER:
538 	    return pp->ppBottomBorderNumber;
539 
540 	case PPpropLEFT_BORDER:
541 	    return pp->ppLeftBorderNumber;
542 
543 	case PPpropRIGHT_BORDER:
544 	    return pp->ppRightBorderNumber;
545 
546 	case PPprop_BOX_BORDER:
547 	    LDEB(prop); return -1;
548 
549 	case PPpropBETWEEN_BORDER:
550 	    return pp->ppBetweenBorderNumber;
551 
552 	case PPpropBAR_BORDER:
553 	    return pp->ppBarNumber;
554 
555 	case PPpropOUTLINELEVEL:
556 	    return pp->ppOutlineLevel;
557 
558 	case PPpropLISTLEVEL:
559 	    return pp->ppListLevel;
560 
561 	case PPpropHYPHPAR:
562 	    return pp->ppHyphenateParagraph;
563 
564 	case PPpropRTOL:
565 	    return pp->ppRToL;
566 
567 	case PPprop_LISB:
568 	case PPprop_LISA:
569 	case PPprop_IGNORED:
570 	    LDEB(prop); return -1;
571 
572 	default:
573 	    LDEB(prop); return -1;
574 	}
575     }
576 
577