1 /************************************************************************/
2 /*									*/
3 /*  Buffer administration routines.					*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"docBaseConfig.h"
8 
9 #   include	<utilPalette.h>
10 #   include	<utilPropMask.h>
11 #   include	<appUnit.h>
12 #   include	<appDebugon.h>
13 
14 #   include	"docDocumentProperties.h"
15 
16 /************************************************************************/
17 /*									*/
18 /*   Translate document property numbers to notes property numbers.	*/
19 /*									*/
20 /************************************************************************/
21 
22 const int DOCdocNOTE_PROP_MAP[FEPprop_COUNT]=
23 {
24     DPpropFOOTNOTE_STARTNR,
25     DPpropFOOTNOTE_JUSTIFICATION,
26     DPpropFOOTNOTE_PLACEMENT,
27     DPpropFOOTNOTE_RESTART,
28     DPpropFOOTNOTE_STYLE,
29 
30     DPpropENDNOTE_STARTNR,
31     DPpropENDNOTE_JUSTIFICATION,
32     DPpropENDNOTE_PLACEMENT,
33     DPpropENDNOTE_RESTART,
34     DPpropENDNOTE_STYLE,
35 };
36 
37 const int * const DOCdocFOOTNOTE_PROP_MAP= DOCdocNOTE_PROP_MAP;
38 const int * const DOCdocENDNOTE_PROP_MAP= DOCdocNOTE_PROP_MAP+ NOTESprop_COUNT;
39 
docFillDocFootnoteMask(PropertyMask * dpMask)40 void docFillDocFootnoteMask(	PropertyMask *	dpMask )
41     {
42     PROPmaskADD( dpMask, DPpropFOOTNOTE_PLACEMENT );
43     PROPmaskADD( dpMask, DPpropFOOTNOTE_JUSTIFICATION );
44     PROPmaskADD( dpMask, DPpropFOOTNOTE_RESTART );
45     PROPmaskADD( dpMask, DPpropFOOTNOTE_STYLE );
46     PROPmaskADD( dpMask, DPpropFOOTNOTE_STARTNR );
47     }
48 
docFillDocEndnoteMask(PropertyMask * dpMask)49 void docFillDocEndnoteMask(	PropertyMask *	dpMask )
50     {
51     PROPmaskADD( dpMask, DPpropENDNOTE_PLACEMENT );
52     PROPmaskADD( dpMask, DPpropENDNOTE_JUSTIFICATION );
53     PROPmaskADD( dpMask, DPpropENDNOTE_RESTART );
54     PROPmaskADD( dpMask, DPpropENDNOTE_STYLE );
55     PROPmaskADD( dpMask, DPpropENDNOTE_STARTNR );
56     }
57 
58 /************************************************************************/
59 /*									*/
60 /*  Fill a mask with notes properties that are relevant for the		*/
61 /*  document.								*/
62 /*  I.E: Set those document properties that are a note property.	*/
63 /*									*/
64 /************************************************************************/
65 
docFillDocNotesMask(PropertyMask * dpMask)66 void docFillDocNotesMask(	PropertyMask *	dpMask )
67     {
68     docFillDocFootnoteMask( dpMask );
69     docFillDocEndnoteMask( dpMask );
70     }
71 
72 static const int DOC_IntProperties[] =
73 {
74     DGpropPAGE_WIDTH,
75     DGpropPAGE_HEIGHT,
76     DGpropLEFT_MARGIN,
77     DGpropRIGHT_MARGIN,
78     DGpropTOP_MARGIN,
79     DGpropBOTTOM_MARGIN,
80     /* no DGpropHEADER_POSITION, */
81     /* no DGpropFOOTER_POSITION, */
82     DGpropGUTTER,
83     DGpropMARGMIR,
84 
85     DPpropSTART_PAGE,
86 
87     DPpropFACING_PAGES,
88     DPpropGUTTER_HORIZONTAL,
89     DPpropWIDOWCTRL,
90     DPpropTWO_ON_ONE,
91     DPpropDOCTEMP,
92     DPpropRTOL,
93 
94     DPpropNOTETYPES,	/*  \fetN	*/
95 
96     DPpropFOOTNOTE_STARTNR,
97     DPpropFOOTNOTE_JUSTIFICATION,
98     DPpropFOOTNOTE_PLACEMENT,
99     DPpropFOOTNOTE_RESTART,
100     DPpropFOOTNOTE_STYLE,
101 
102     DPpropENDNOTE_STARTNR,
103     DPpropENDNOTE_JUSTIFICATION,
104     DPpropENDNOTE_PLACEMENT,
105     DPpropENDNOTE_RESTART,
106     DPpropENDNOTE_STYLE,
107 
108     DPpropDEFTAB,
109     DPpropDOC_CHARSET,
110     DPpropANSICPG,
111     DPpropDEFLANG,
112 
113     DPpropDEFF,
114     DPpropSTSHFDBCH,
115     DPpropSTSHFLOCH,
116     DPpropSTSHFHICH,
117     DPpropSTSHFBI,
118 };
119 
120 static const int DOC_IntPropertyCount= sizeof(DOC_IntProperties)/sizeof(int);
121 
122 static const int DOC_TextProperties[] =
123 {
124     DPpropGENERATOR,
125     DPpropTITLE,
126     DPpropSUBJECT,
127     DPpropKEYWORDS,
128     DPpropDOCCOMM,
129     DPpropAUTHOR,
130     DPpropCOMPANY,
131     DPpropHLINKBASE,
132 };
133 
134 static const int DOC_TextPropertyCount= sizeof(DOC_TextProperties)/sizeof(int);
135 
136 static const int DOC_TimeProperties[] =
137 {
138     DPpropCREATIM,
139     DPpropREVTIM,
140     DPpropPRINTIM,
141 };
142 
143 static const int DOC_TimePropertyCount= sizeof(DOC_TimeProperties)/sizeof(int);
144 
145 static const int DOC_BorderProperties[] =
146 {
147     DPpropTOP_BORDER,
148     DPpropBOTTOM_BORDER,
149     DPpropLEFT_BORDER,
150     DPpropRIGHT_BORDER,
151     DPpropHEAD_BORDER,
152     DPpropFOOT_BORDER,
153 };
154 
155 static const int DOC_BorderPropertyCount= sizeof(DOC_BorderProperties)/sizeof(int);
156 
157 /************************************************************************/
158 /*									*/
159 /*  Initialise Document Properties.					*/
160 /*									*/
161 /************************************************************************/
162 
docInitDocumentProperties(DocumentProperties * dp)163 void docInitDocumentProperties(	DocumentProperties *	dp )
164     {
165     dp->dpContainsTables= 0;
166     dp->dpTabIntervalTwips= 720;
167     dp->dpDefaultColor= 0;
168     dp->dpDocumentCharset= DOCcharsetANSI;
169     dp->dpAnsiCodepage= -1;
170     dp->dpDefaultLanguage= -1;
171 
172     dp->dpDefaultFont= -1;
173     dp->dpDefaultFontDbch= -1;
174     dp->dpDefaultFontLoch= -1;
175     dp->dpDefaultFontHich= -1;
176     dp->dpDefaultFontBi= -1;
177 
178     dp->dpStartPageNumber= 1;
179     dp->dpFootEndNoteType= DPfetFOOT_ONLY;
180 
181     docInitFootEndNotesProperties( &(dp->dpNotesProps) );
182 
183     dp->dpHasFacingPages= 0;
184     dp->dpGutterHorizontal= 0;
185     dp->dpWidowControl= 0;
186     dp->dpTwoOnOne= 0;
187     dp->dpIsDocumentTemplate= 0;
188     dp->dpRToL= 0;
189 
190     utilInitDocumentGeometry( &(dp->dpGeometry) );
191 
192     dp->dpFontList= (struct DocumentFontList *)0;
193     dp->dpListAdmin= (struct ListAdmin *)0;
194     dp->dpColorPalette= (struct ColorPalette *)0;
195 
196     utilInitMemoryBuffer( &(dp->dpGeneratorRead) );
197     utilInitMemoryBuffer( &(dp->dpGeneratorWrite) );
198     utilInitMemoryBuffer( &(dp->dpTitle) );
199     utilInitMemoryBuffer( &(dp->dpSubject) );
200     utilInitMemoryBuffer( &(dp->dpKeywords) );
201     utilInitMemoryBuffer( &(dp->dpDoccomm) );
202     utilInitMemoryBuffer( &(dp->dpAuthor) );
203     utilInitMemoryBuffer( &(dp->dpCompany) );
204     utilInitMemoryBuffer( &(dp->dpHlinkbase) );
205     utilInitMemoryBuffer( &(dp->dpFilename) );
206 
207     dp->dpTopBorderNumber= 0;
208     dp->dpLeftBorderNumber= 0;
209     dp->dpRightBorderNumber= 0;
210     dp->dpBottomBorderNumber= 0;
211     dp->dpHeadBorderNumber= 0;
212     dp->dpFootBorderNumber= 0;
213 
214     utilInvalidateTime( &(dp->dpCreatim) );
215     utilInvalidateTime( &(dp->dpRevtim) );
216     utilInvalidateTime( &(dp->dpPrintim) );
217 
218     dp->dpHasOpenEnd= 0;
219     }
220 
docCleanDocumentProperties(DocumentProperties * dp)221 void docCleanDocumentProperties(	DocumentProperties *	dp )
222     {
223     /* Owned by the document:
224     dp->dpFontList
225     dp->dpListAdmin
226     dp->dpColorPalette
227     */
228 
229     utilInvalidateTime( &(dp->dpCreatim) );
230     utilInvalidateTime( &(dp->dpRevtim) );
231     utilInvalidateTime( &(dp->dpPrintim) );
232 
233     utilCleanMemoryBuffer( &(dp->dpGeneratorRead ) );
234     utilCleanMemoryBuffer( &(dp->dpGeneratorWrite ) );
235     utilCleanMemoryBuffer( &(dp->dpTitle ) );
236     utilCleanMemoryBuffer( &(dp->dpSubject ) );
237     utilCleanMemoryBuffer( &(dp->dpKeywords ) );
238     utilCleanMemoryBuffer( &(dp->dpDoccomm ) );
239     utilCleanMemoryBuffer( &(dp->dpAuthor ) );
240     utilCleanMemoryBuffer( &(dp->dpCompany ) );
241     utilCleanMemoryBuffer( &(dp->dpHlinkbase ) );
242     utilCleanMemoryBuffer( &(dp->dpFilename ) );
243 
244     return;
245     }
246 
247 /************************************************************************/
248 /*									*/
249 /*  Copy document properties.						*/
250 /*									*/
251 /************************************************************************/
252 
docCopyDocumentProperties(DocumentProperties * to,const DocumentProperties * from)253 int docCopyDocumentProperties(	DocumentProperties *		to,
254 				const DocumentProperties *	from )
255     {
256     PropertyMask	dpSetMask;
257 
258     int			rval =0;
259 
260     const DocumentAttributeMap * const dam0= (const DocumentAttributeMap *)0;
261 
262     utilPropMaskClear( &dpSetMask );
263     utilPropMaskFill( &dpSetMask, DPprop_COUNT );
264 
265     PROPmaskUNSET( &dpSetMask, DPpropFONTTABLE );
266     PROPmaskUNSET( &dpSetMask, DPpropCOLORTABLE );
267     PROPmaskUNSET( &dpSetMask, DPpropSTYLESHEET );
268     PROPmaskUNSET( &dpSetMask, DPpropLISTTABLE );
269     PROPmaskUNSET( &dpSetMask, DPpropLISTOVERRIDETABLE );
270 
271     PROPmaskUNSET( &dpSetMask, DPpropGENERATOR );
272     PROPmaskUNSET( &dpSetMask, DPpropTITLE );
273     PROPmaskUNSET( &dpSetMask, DPpropSUBJECT );
274     PROPmaskUNSET( &dpSetMask, DPpropKEYWORDS );
275     PROPmaskUNSET( &dpSetMask, DPpropDOCCOMM );
276     PROPmaskUNSET( &dpSetMask, DPpropAUTHOR );
277     PROPmaskUNSET( &dpSetMask, DPpropCOMPANY );
278     PROPmaskUNSET( &dpSetMask, DPpropHLINKBASE );
279 
280     PROPmaskUNSET( &dpSetMask, DPpropCREATIM );
281     PROPmaskUNSET( &dpSetMask, DPpropREVTIM );
282     PROPmaskUNSET( &dpSetMask, DPpropPRINTIM );
283 
284     if  ( docUpdDocumentProperties( (PropertyMask *)0,
285 					    to, &dpSetMask, from, dam0 ) )
286 	{ LDEB(1); return -1;	}
287 
288     if  ( to->dpFontList != from->dpFontList			&&
289 	  docCopyFontList( to->dpFontList, from->dpFontList )	)
290 	{ LDEB(1); rval= -1; goto ready;	}
291 
292     if  ( to->dpListAdmin != from->dpListAdmin			&&
293 	  docCopyListAdmin( to->dpListAdmin, from->dpListAdmin ) )
294 	{ LDEB(1); rval= -1; goto ready;	}
295 
296     if  ( to->dpColorPalette != from->dpColorPalette			&&
297 	  utilCopyColorPalette( to->dpColorPalette, from->dpColorPalette ) )
298 	{ LDEB(1); rval= -1; goto ready;	}
299 
300     if  ( utilCopyMemoryBuffer( &(to->dpGeneratorRead),
301 						&(from->dpGeneratorRead) ) )
302 	{ LDEB(1); rval= -1; goto ready;	}
303 
304     if  ( utilCopyMemoryBuffer( &(to->dpGeneratorWrite),
305 						&(from->dpGeneratorWrite) ) )
306 	{ LDEB(1); rval= -1; goto ready;	}
307 
308     if  ( utilCopyMemoryBuffer( &(to->dpTitle), &(from->dpTitle) ) )
309 	{ LDEB(1); rval= -1; goto ready;	}
310 
311     if  ( utilCopyMemoryBuffer( &(to->dpSubject), &(from->dpSubject) ) )
312 	{ LDEB(1); rval= -1; goto ready;	}
313 
314     if  ( utilCopyMemoryBuffer( &(to->dpKeywords), &(from->dpKeywords) ) )
315 	{ LDEB(1); rval= -1; goto ready;	}
316 
317     if  ( utilCopyMemoryBuffer( &(to->dpDoccomm), &(from->dpDoccomm) ) )
318 	{ LDEB(1); rval= -1; goto ready;	}
319 
320     if  ( utilCopyMemoryBuffer( &(to->dpAuthor), &(from->dpAuthor) ) )
321 	{ LDEB(1); rval= -1; goto ready;	}
322 
323     if  ( utilCopyMemoryBuffer( &(to->dpCompany), &(from->dpCompany) ) )
324 	{ LDEB(1); rval= -1; goto ready;	}
325 
326     if  ( utilCopyMemoryBuffer( &(to->dpHlinkbase), &(from->dpHlinkbase) ) )
327 	{ LDEB(1); rval= -1; goto ready;	}
328 
329     if  ( utilCopyMemoryBuffer( &(to->dpFilename), &(from->dpFilename) ) )
330 	{ LDEB(1); rval= -1; goto ready;	}
331 
332   ready:
333 
334     return rval;
335     }
336 
337 /************************************************************************/
338 /*									*/
339 /*  Set the file name in the document properties.			*/
340 /*									*/
341 /************************************************************************/
342 
docPropertiesSetFilename(DocumentProperties * dp,const MemoryBuffer * filename)343 int docPropertiesSetFilename(	DocumentProperties *	dp,
344 				const MemoryBuffer *	filename )
345     {
346     if  ( filename )
347 	{
348 	if  ( utilCopyMemoryBuffer( &(dp->dpFilename), filename ) )
349 	    { LDEB(1); return -1;	}
350 	}
351     else{ utilEmptyMemoryBuffer( &(dp->dpFilename) );	}
352 
353     return 0;
354     }
355 
356 /************************************************************************/
357 /*									*/
358 /*  Change document properties and tell what has been changed.		*/
359 /*									*/
360 /************************************************************************/
361 
docUpdDocumentProperties(PropertyMask * pDoneMask,DocumentProperties * dpTo,const PropertyMask * dpSetMask,const DocumentProperties * dpFrom,const DocumentAttributeMap * dam)362 int docUpdDocumentProperties(	PropertyMask *			pDoneMask,
363 				DocumentProperties *		dpTo,
364 				const PropertyMask *		dpSetMask,
365 				const DocumentProperties *	dpFrom,
366 				const DocumentAttributeMap *	dam )
367     {
368     int			i;
369 
370     PropertyMask	doneMask;
371 
372     utilPropMaskClear( &doneMask );
373 
374     for ( i= 0; i < DOC_IntPropertyCount; i++ )
375 	{
376 	int	prop= DOC_IntProperties[i];
377 
378 	if  ( PROPmaskISSET( dpSetMask, prop ) )
379 	    {
380 	    int		from= docGetDocumentProperty( dpFrom, prop );
381 	    int		to= docGetDocumentProperty( dpTo, prop );
382 
383 	    if  ( to != from )
384 		{
385 		if  ( docSetDocumentProperty( dpTo, prop, from ) )
386 		    { LLDEB(prop,from); return -1;	}
387 
388 		PROPmaskADD( &doneMask, prop );
389 		}
390 	    }
391 	}
392 
393     for ( i= 0; i < DOC_TextPropertyCount; i++ )
394 	{
395 	int	prop= DOC_TextProperties[i];
396 
397 	if  ( PROPmaskISSET( dpSetMask, prop ) )
398 	    {
399 	    const MemoryBuffer *	from;
400 	    MemoryBuffer *		to;
401 
402 	    from= docGetDocumentPropertyBuffer(
403 					(DocumentProperties *)dpFrom, prop );
404 	    to= docGetDocumentPropertyBuffer( dpTo, prop );
405 
406 	    if  ( ! utilEqualMemoryBuffer( to, from ) )
407 		{
408 		if  ( utilCopyMemoryBuffer( to, from ) )
409 		    { LDEB(prop); return -1;	}
410 
411 		PROPmaskADD( &doneMask, prop );
412 		}
413 	    }
414 	}
415 
416     for ( i= 0; i < DOC_BorderPropertyCount; i++ )
417 	{
418 	int	prop= DOC_BorderProperties[i];
419 
420 	if  ( PROPmaskISSET( dpSetMask, prop ) )
421 	    {
422 	    int		from= docGetDocumentProperty( dpFrom, prop );
423 	    int		to= docGetDocumentProperty( dpTo, prop );
424 
425 	    if  ( from >= 0 && dam && dam->damBorderMap )
426 		{ from= dam->damBorderMap[from];	}
427 
428 	    if  ( to != from )
429 		{
430 		if  ( docSetDocumentProperty( dpTo, prop, from ) )
431 		    { LLDEB(prop,from); return -1;	}
432 
433 		PROPmaskADD( &doneMask, prop );
434 		}
435 	    }
436 	}
437 
438     for ( i= 0; i < DOC_TimePropertyCount; i++ )
439 	{
440 	int	prop= DOC_TimeProperties[i];
441 
442 	if  ( PROPmaskISSET( dpSetMask, prop ) )
443 	    {
444 	    struct tm *	from= docGetDocumentPropertyTime(
445 					(DocumentProperties *)dpFrom, prop );
446 	    struct tm *	to= docGetDocumentPropertyTime( dpTo, prop );
447 
448 	    /* tm_isdst makes this necessary: */
449 
450 	    if  ( to->tm_sec != from->tm_sec )
451 		{ to->tm_sec = from->tm_sec; PROPmaskADD( &doneMask, prop ); }
452 	    if  ( to->tm_min != from->tm_min )
453 		{ to->tm_min = from->tm_min; PROPmaskADD( &doneMask, prop ); }
454 	    if  ( to->tm_hour != from->tm_hour )
455 		{ to->tm_hour = from->tm_hour; PROPmaskADD( &doneMask, prop ); }
456 	    if  ( to->tm_mday != from->tm_mday )
457 		{ to->tm_mday = from->tm_mday; PROPmaskADD( &doneMask, prop ); }
458 	    if  ( to->tm_mon != from->tm_mon )
459 		{ to->tm_mon = from->tm_mon; PROPmaskADD( &doneMask, prop ); }
460 	    if  ( to->tm_year != from->tm_year )
461 		{ to->tm_year = from->tm_year; PROPmaskADD( &doneMask, prop ); }
462 	    }
463 	}
464 
465     if  ( pDoneMask )
466 	{ utilPropMaskOr( pDoneMask, pDoneMask, &doneMask );	}
467 
468     return 0;
469     }
470 
docDocumentPropertyDifference(PropertyMask * pDifMask,const DocumentProperties * dp1,const PropertyMask * cmpMask,const DocumentProperties * dp2)471 void docDocumentPropertyDifference(
472 				PropertyMask *			pDifMask,
473 				const DocumentProperties *	dp1,
474 				const PropertyMask *		cmpMask,
475 				const DocumentProperties *	dp2 )
476     {
477     int			i;
478 
479     PropertyMask	dpDifMask;
480 
481     utilPropMaskClear( &dpDifMask );
482 
483     for ( i= 0; i < DOC_IntPropertyCount; i++ )
484 	{
485 	int	prop= DOC_IntProperties[i];
486 
487 	if  ( PROPmaskISSET( cmpMask, prop ) )
488 	    {
489 	    int		from= docGetDocumentProperty( dp1, prop );
490 	    int		to= docGetDocumentProperty( dp2, prop );
491 
492 	    if  ( to != from )
493 		{ PROPmaskADD( &dpDifMask, prop );	}
494 	    }
495 	}
496 
497     for ( i= 0; i < DOC_TextPropertyCount; i++ )
498 	{
499 	int	prop= DOC_TextProperties[i];
500 
501 	if  ( PROPmaskISSET( cmpMask, prop ) )
502 	    {
503 	    const MemoryBuffer *	from;
504 	    MemoryBuffer *		to;
505 
506 	    from= docGetDocumentPropertyBuffer(
507 					(DocumentProperties *)dp1, prop );
508 	    to= docGetDocumentPropertyBuffer(
509 					(DocumentProperties *)dp2, prop );
510 
511 	    if  ( ! utilEqualMemoryBuffer( to, from ) )
512 		{ PROPmaskADD( &dpDifMask, prop );	}
513 	    }
514 	}
515 
516     for ( i= 0; i < DOC_BorderPropertyCount; i++ )
517 	{
518 	int	prop= DOC_BorderProperties[i];
519 
520 	if  ( PROPmaskISSET( cmpMask, prop ) )
521 	    {
522 	    int		from= docGetDocumentProperty( dp1, prop );
523 	    int		to= docGetDocumentProperty( dp2, prop );
524 
525 	    if  ( to != from )
526 		{ PROPmaskADD( &dpDifMask, prop );	}
527 	    }
528 	}
529 
530     for ( i= 0; i < DOC_TimePropertyCount; i++ )
531 	{
532 	int	prop= DOC_TimeProperties[i];
533 
534 	if  ( PROPmaskISSET( cmpMask, prop ) )
535 	    {
536 	    struct tm *	from= docGetDocumentPropertyTime(
537 					(DocumentProperties *)dp1, prop );
538 	    struct tm *	to= docGetDocumentPropertyTime(
539 					(DocumentProperties *)dp2, prop );
540 
541 	    if  ( mktime( to ) != mktime( from ) )
542 		{ PROPmaskADD( &dpDifMask, prop );	}
543 	    }
544 	}
545 
546     *pDifMask= dpDifMask;
547     return;
548     }
549 
550 /************************************************************************/
551 /*									*/
552 /*  Allocate a color.							*/
553 /*									*/
554 /************************************************************************/
555 
docAllocateDocumentColor(DocumentProperties * dp,const RGB8Color * rgb8)556 int docAllocateDocumentColor(		DocumentProperties *	dp,
557 					const RGB8Color *	rgb8 )
558     {
559     const int			avoidZero= 1;
560     const int			maxColors= 256;
561     int				color;
562 
563     color= utilPaletteInsertColor( dp->dpColorPalette,
564 						avoidZero, maxColors, rgb8 );
565     if  ( color < 0 )
566 	{ LDEB(color); return -1;	}
567 
568     return color;
569     }
570 
docSetDocumentProperty(DocumentProperties * dp,int prop,int arg)571 int docSetDocumentProperty(	DocumentProperties *	dp,
572 				int			prop,
573 				int			arg )
574     {
575     switch( prop )
576 	{
577 	case DGpropLEFT_MARGIN:
578 	    dp->dpGeometry.dgLeftMarginTwips= arg;
579 	    return 0;
580 	case DGpropTOP_MARGIN:
581 	    dp->dpGeometry.dgTopMarginTwips= arg;
582 	    return 0;
583 	case DGpropRIGHT_MARGIN:
584 	    dp->dpGeometry.dgRightMarginTwips= arg;
585 	    return 0;
586 	case DGpropBOTTOM_MARGIN:
587 	    dp->dpGeometry.dgBottomMarginTwips= arg;
588 	    return 0;
589 	case DGpropPAGE_WIDTH:
590 	    dp->dpGeometry.dgPageWideTwips= arg;
591 	    return 0;
592 	case DGpropPAGE_HEIGHT:
593 	    dp->dpGeometry.dgPageHighTwips= arg;
594 	    return 0;
595 	case DGpropGUTTER:
596 	    dp->dpGeometry.dgGutterTwips= arg;
597 	    return 0;
598 	case DGpropMARGMIR:
599 	    dp->dpGeometry.dgMirrorMargins= arg != 0;
600 	    return 0;
601 
602 	case DPpropFACING_PAGES:
603 	    dp->dpHasFacingPages= arg != 0;
604 	    return 0;
605 	case DPpropGUTTER_HORIZONTAL:
606 	    dp->dpGutterHorizontal= arg != 0;
607 	    return 0;
608 	case DPpropWIDOWCTRL:
609 	    dp->dpWidowControl= arg != 0;
610 	    return 0;
611 	case DPpropTWO_ON_ONE:
612 	    dp->dpTwoOnOne= arg != 0;
613 	    return 0;
614 	case DPpropDOCTEMP:
615 	    dp->dpIsDocumentTemplate= arg != 0;
616 	    return 0;
617 	case DPpropRTOL:
618 	    dp->dpRToL= arg != 0;
619 	    return 0;
620 
621 	case DPpropSTART_PAGE:
622 	    dp->dpStartPageNumber= arg;
623 	    return 0;
624 	case DPpropDEFTAB:
625 	    dp->dpTabIntervalTwips= arg;
626 	    return 0;
627 
628 	case DPpropDEFF:
629 	    dp->dpDefaultFont= arg;
630 	    return 0;
631 	case DPpropSTSHFDBCH:
632 	    dp->dpDefaultFontDbch= arg;
633 	    return 0;
634 	case DPpropSTSHFLOCH:
635 	    dp->dpDefaultFontLoch= arg;
636 	    return 0;
637 	case DPpropSTSHFHICH:
638 	    dp->dpDefaultFontHich= arg;
639 	    return 0;
640 	case DPpropSTSHFBI:
641 	    dp->dpDefaultFontBi= arg;
642 	    return 0;
643 
644 	case DPpropNOTETYPES:
645 	    if  ( arg < 0 || arg > 2 )
646 		{ LDEB(arg); return -1;	}
647 	    dp->dpFootEndNoteType= arg;
648 	    return 0;
649 
650 	/* FOOTNOTE */
651 	case DPpropFOOTNOTE_STARTNR:
652 	    docSetNotesProperty( &(dp->dpNotesProps.fepFootnotesProps),
653 						NOTESpropSTARTNR, arg );
654 	    return 0;
655 	case DPpropFOOTNOTE_JUSTIFICATION:
656 	    docSetNotesProperty( &(dp->dpNotesProps.fepFootnotesProps),
657 						NOTESpropJUSTIFICATION, arg );
658 	    return 0;
659 	case DPpropFOOTNOTE_PLACEMENT:
660 	    docSetNotesProperty( &(dp->dpNotesProps.fepFootnotesProps),
661 						NOTESpropPLACEMENT, arg );
662 	    return 0;
663 	case DPpropFOOTNOTE_RESTART:
664 	    docSetNotesProperty( &(dp->dpNotesProps.fepFootnotesProps),
665 						NOTESpropRESTART, arg );
666 	    return 0;
667 	case DPpropFOOTNOTE_STYLE:
668 	    docSetNotesProperty( &(dp->dpNotesProps.fepFootnotesProps),
669 						NOTESpropSTYLE, arg );
670 	    return 0;
671 
672 	/* ENDNOTE */
673 	case DPpropENDNOTE_STARTNR:
674 	    docSetNotesProperty( &(dp->dpNotesProps.fepEndnotesProps),
675 						NOTESpropSTARTNR, arg );
676 	    return 0;
677 	case DPpropENDNOTE_JUSTIFICATION:
678 	    docSetNotesProperty( &(dp->dpNotesProps.fepEndnotesProps),
679 						NOTESpropJUSTIFICATION, arg );
680 	    return 0;
681 	case DPpropENDNOTE_PLACEMENT:
682 	    docSetNotesProperty( &(dp->dpNotesProps.fepEndnotesProps),
683 						NOTESpropPLACEMENT, arg );
684 	    return 0;
685 	case DPpropENDNOTE_RESTART:
686 	    docSetNotesProperty( &(dp->dpNotesProps.fepEndnotesProps),
687 						NOTESpropRESTART, arg );
688 	    return 0;
689 	case DPpropENDNOTE_STYLE:
690 	    docSetNotesProperty( &(dp->dpNotesProps.fepEndnotesProps),
691 						NOTESpropSTYLE, arg );
692 	    return 0;
693 
694 	case DPpropDOC_CHARSET:
695 	    dp->dpDocumentCharset= arg;
696 	    return 0;
697 
698 	case DPpropANSICPG:
699 	    dp->dpAnsiCodepage= arg;
700 	    return 0;
701 
702 	case DPpropDEFLANG:
703 	    dp->dpDefaultLanguage= arg;
704 	    return 0;
705 
706 	case DPpropTOP_BORDER:
707 	    dp->dpTopBorderNumber= arg;
708 	    return 0;
709 	case DPpropBOTTOM_BORDER:
710 	    dp->dpBottomBorderNumber= arg;
711 	    return 0;
712 	case DPpropLEFT_BORDER:
713 	    dp->dpLeftBorderNumber= arg;
714 	    return 0;
715 	case DPpropRIGHT_BORDER:
716 	    dp->dpRightBorderNumber= arg;
717 	    return 0;
718 	case DPpropHEAD_BORDER:
719 	    dp->dpHeadBorderNumber= arg;
720 	    return 0;
721 	case DPpropFOOT_BORDER:
722 	    dp->dpFootBorderNumber= arg;
723 	    return 0;
724 	default:
725 	    LDEB(prop); return -1;
726 	}
727     }
728 
docGetDocumentProperty(const DocumentProperties * dp,int prop)729 int docGetDocumentProperty(	const DocumentProperties *	dp,
730 				int				prop )
731     {
732     switch( prop )
733 	{
734 	case DGpropPAGE_WIDTH:
735 	    return dp->dpGeometry.dgPageWideTwips;
736 	case DGpropPAGE_HEIGHT:
737 	    return dp->dpGeometry.dgPageHighTwips;
738 	case DGpropLEFT_MARGIN:
739 	    return dp->dpGeometry.dgLeftMarginTwips;
740 	case DGpropRIGHT_MARGIN:
741 	    return dp->dpGeometry.dgRightMarginTwips;
742 	case DGpropTOP_MARGIN:
743 	    return dp->dpGeometry.dgTopMarginTwips;
744 	case DGpropBOTTOM_MARGIN:
745 	    return dp->dpGeometry.dgBottomMarginTwips;
746 	/* NO DGpropHEADER_POSITION: */
747 	/* NO DGpropFOOTER_POSITION: */
748 	case DGpropGUTTER:
749 	    return dp->dpGeometry.dgGutterTwips;
750 	case DGpropMARGMIR:
751 	    return dp->dpGeometry.dgMirrorMargins;
752 
753 	case DPpropSTART_PAGE:
754 	    return dp->dpStartPageNumber;
755 
756 	case DPpropFACING_PAGES:
757 	    return dp->dpHasFacingPages;
758 	case DPpropGUTTER_HORIZONTAL:
759 	    return dp->dpGutterHorizontal;
760 	case DPpropWIDOWCTRL:
761 	    return dp->dpWidowControl;
762 	case DPpropTWO_ON_ONE:
763 	    return dp->dpTwoOnOne;
764 	case DPpropDOCTEMP:
765 	    return dp->dpIsDocumentTemplate;
766 	case DPpropRTOL:
767 	    return dp->dpRToL;
768 
769 	case DPpropNOTETYPES:
770 	    return dp->dpFootEndNoteType;
771 
772 	/* FOOTNOTE */
773 	case DPpropFOOTNOTE_STARTNR:
774 	    return docGetNotesProperty( &(dp->dpNotesProps.fepFootnotesProps),
775 						NOTESpropSTARTNR );
776 	case DPpropFOOTNOTE_JUSTIFICATION:
777 	    return docGetNotesProperty( &(dp->dpNotesProps.fepFootnotesProps),
778 						NOTESpropJUSTIFICATION );
779 	case DPpropFOOTNOTE_PLACEMENT:
780 	    return docGetNotesProperty( &(dp->dpNotesProps.fepFootnotesProps),
781 						NOTESpropPLACEMENT );
782 	case DPpropFOOTNOTE_RESTART:
783 	    return docGetNotesProperty( &(dp->dpNotesProps.fepFootnotesProps),
784 						NOTESpropRESTART );
785 	case DPpropFOOTNOTE_STYLE:
786 	    return docGetNotesProperty( &(dp->dpNotesProps.fepFootnotesProps),
787 						NOTESpropSTYLE );
788 
789 	/* ENDNOTE */
790 	case DPpropENDNOTE_STARTNR:
791 	    return docGetNotesProperty( &(dp->dpNotesProps.fepEndnotesProps),
792 						NOTESpropSTARTNR );
793 	case DPpropENDNOTE_JUSTIFICATION:
794 	    return docGetNotesProperty( &(dp->dpNotesProps.fepEndnotesProps),
795 						NOTESpropJUSTIFICATION );
796 	case DPpropENDNOTE_PLACEMENT:
797 	    return docGetNotesProperty( &(dp->dpNotesProps.fepEndnotesProps),
798 						NOTESpropPLACEMENT );
799 	case DPpropENDNOTE_RESTART:
800 	    return docGetNotesProperty( &(dp->dpNotesProps.fepEndnotesProps),
801 						NOTESpropRESTART );
802 	case DPpropENDNOTE_STYLE:
803 	    return docGetNotesProperty( &(dp->dpNotesProps.fepEndnotesProps),
804 						NOTESpropSTYLE );
805 
806 	case DPpropDEFTAB:
807 	    return dp->dpTabIntervalTwips;
808 	case DPpropDOC_CHARSET:
809 	    return dp->dpDocumentCharset;
810 	case DPpropANSICPG:
811 	    return dp->dpAnsiCodepage;
812 	case DPpropDEFLANG:
813 	    return dp->dpDefaultLanguage;
814 
815 	case DPpropDEFF:
816 	    return dp->dpDefaultFont;
817 	case DPpropSTSHFDBCH:
818 	    return dp->dpDefaultFontDbch;
819 	case DPpropSTSHFLOCH:
820 	    return dp->dpDefaultFontLoch;
821 	case DPpropSTSHFHICH:
822 	    return dp->dpDefaultFontHich;
823 	case DPpropSTSHFBI:
824 	    return dp->dpDefaultFontBi;
825 
826 	case DPpropTOP_BORDER:
827 	    return dp->dpTopBorderNumber;
828 	case DPpropBOTTOM_BORDER:
829 	    return dp->dpBottomBorderNumber;
830 	case DPpropLEFT_BORDER:
831 	    return dp->dpLeftBorderNumber;
832 	case DPpropRIGHT_BORDER:
833 	    return dp->dpRightBorderNumber;
834 	case DPpropHEAD_BORDER:
835 	    return dp->dpHeadBorderNumber;
836 	case DPpropFOOT_BORDER:
837 	    return dp->dpFootBorderNumber;
838 	default:
839 	    LDEB(prop); return -1;
840 	}
841     }
842 
docSetDocumentPropertyString(DocumentProperties * dp,int prop,const char * val,int vallen)843 int docSetDocumentPropertyString(	DocumentProperties *	dp,
844 					int			prop,
845 					const char *		val,
846 					int			vallen )
847     {
848     switch( prop )
849 	{
850 	case DPpropGENERATOR:
851 	    return utilMemoryBufferSetBytes( &(dp->dpGeneratorRead),
852 					(const unsigned char *)val, vallen );
853 	case DPpropTITLE:
854 	    return utilMemoryBufferSetBytes( &(dp->dpTitle),
855 					(const unsigned char *)val, vallen );
856 	case DPpropSUBJECT:
857 	    return utilMemoryBufferSetBytes( &(dp->dpSubject),
858 					(const unsigned char *)val, vallen );
859 	case DPpropKEYWORDS:
860 	    return utilMemoryBufferSetBytes( &(dp->dpKeywords),
861 					(const unsigned char *)val, vallen );
862 	case DPpropDOCCOMM:
863 	    return utilMemoryBufferSetBytes( &(dp->dpDoccomm),
864 					(const unsigned char *)val, vallen );
865 	case DPpropAUTHOR:
866 	    return utilMemoryBufferSetBytes( &(dp->dpAuthor),
867 					(const unsigned char *)val, vallen );
868 	case DPpropCOMPANY:
869 	    return utilMemoryBufferSetBytes( &(dp->dpCompany),
870 					(const unsigned char *)val, vallen );
871 	case DPpropHLINKBASE:
872 	    return utilMemoryBufferSetBytes( &(dp->dpHlinkbase),
873 					(const unsigned char *)val, vallen );
874 
875 	default:
876 	    LDEB(prop); return -1;
877 	}
878     }
879 
docGetDocumentPropertyBuffer(DocumentProperties * dp,int prop)880 MemoryBuffer * docGetDocumentPropertyBuffer(
881 					DocumentProperties *	dp,
882 					int			prop )
883     {
884     switch( prop )
885 	{
886 	case DPpropGENERATOR:
887 	    return &(dp->dpGeneratorRead);
888 	case DPpropTITLE:
889 	    return &(dp->dpTitle);
890 	case DPpropSUBJECT:
891 	    return &(dp->dpSubject);
892 	case DPpropKEYWORDS:
893 	    return &(dp->dpKeywords);
894 	case DPpropDOCCOMM:
895 	    return &(dp->dpDoccomm);
896 	case DPpropAUTHOR:
897 	    return &(dp->dpAuthor);
898 	case DPpropCOMPANY:
899 	    return &(dp->dpCompany);
900 	case DPpropHLINKBASE:
901 	    return &(dp->dpHlinkbase);
902 
903 	default:
904 	    LDEB(prop); return (MemoryBuffer *)0;
905 	}
906     }
907 
docGetDocumentPropertyTime(DocumentProperties * dp,int prop)908 struct tm * docGetDocumentPropertyTime(	DocumentProperties *	dp,
909 					int			prop )
910     {
911     switch( prop )
912 	{
913 	case DPpropCREATIM:
914 	    return &(dp->dpCreatim);
915 
916 	case DPpropREVTIM:
917 	    return &(dp->dpRevtim);
918 
919 	case DPpropPRINTIM:
920 	    return &(dp->dpPrintim);
921 
922 	default:
923 	    LDEB(prop); return (struct tm *)0;
924 	}
925     }
926 
docSetDocumentPropertyTime(DocumentProperties * dp,int prop,const struct tm * val)927 int docSetDocumentPropertyTime(		DocumentProperties *	dp,
928 					int			prop,
929 					const struct tm *	val )
930     {
931     switch( prop )
932 	{
933 	case DPpropCREATIM:
934 	    dp->dpCreatim= *val;
935 	    return 0;
936 
937 	case DPpropREVTIM:
938 	    dp->dpRevtim= *val;
939 	    return 0;
940 
941 	case DPpropPRINTIM:
942 	    dp->dpPrintim= *val;
943 	    return 0;
944 
945 	default:
946 	    LDEB(prop); return -1;
947 	}
948 
949     }
950