1 /************************************************************************/
2 /*									*/
3 /*  Read the list table of a document.					*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"docRtfConfig.h"
8 
9 #   include	<string.h>
10 #   include	<stdio.h>
11 #   include	<ctype.h>
12 
13 #   include	<appDebugon.h>
14 
15 #   include	"docRtfWriterImpl.h"
16 #   include	<docListLevel.h>
17 #   include	<docDocumentList.h>
18 
19 /************************************************************************/
20 /*									*/
21 /*  Write a list level to rtf.						*/
22 /*									*/
23 /************************************************************************/
24 
docRtfWriteListLevel(RtfWriter * rwc,const ListLevel * ll)25 void docRtfWriteListLevel(	RtfWriter *		rwc,
26 				const ListLevel *	ll )
27     {
28     MemoryBuffer		mbtext;
29     MemoryBuffer		mbnumbers;
30 
31     utilInitMemoryBuffer( &mbtext );
32     utilInitMemoryBuffer( &mbnumbers );
33 
34     docRtfWriteDestinationBegin( rwc, "listlevel" );
35 
36     docRtfWriteArgTag( rwc, "levelnfc", ll->llNumberStyle );
37     docRtfWriteArgTag( rwc, "levelnfcn", ll->llNumberStyle );
38     docRtfWriteArgTag( rwc, "leveljc", ll->llJustification );
39     docRtfWriteArgTag( rwc, "leveljcn", ll->llJustification );
40 
41     docRtfWriteArgTag( rwc, "levelfollow", ll->llFollow );
42     docRtfWriteArgTag( rwc, "levelstartat", ll->llStartAt );
43 
44     if  ( ll->llPrevToDigits )
45 	{ docRtfWriteTag( rwc, "levellegal" );	}
46     if  ( ll->llNoRestart )
47 	{ docRtfWriteTag( rwc, "levelnorestart" );	}
48 
49     if  ( ll->llFromOld )
50 	{ docRtfWriteTag( rwc, "levelold" );	}
51     if  ( ll->llUsePrevText )
52 	{ docRtfWriteTag( rwc, "levelprev" );	}
53     if  ( ll->llUsePrevSpace )
54 	{ docRtfWriteTag( rwc, "levelprevspace" );	}
55 
56     if  ( ll->llIndent != 0 )
57 	{ docRtfWriteArgTag( rwc, "levelindent", ll->llIndent ); }
58     if  ( ll->llSpace != 0 )
59 	{ docRtfWriteArgTag( rwc, "levelspace", ll->llSpace ); }
60 
61     if  ( docListLevelToRtfStrings( &mbtext, &mbnumbers, ll ) )
62 	{ LDEB(1);	}
63     else{
64 	int			size= 0;
65 	const unsigned char *	bytes;
66 
67 	bytes= utilMemoryBufferGetBytes( &size, &mbtext );
68 	if  ( size > 0 )
69 	    {
70 	    const int	addSemicolon= 1;
71 	    char	tag[50];
72 
73 	    strcpy( tag, "leveltext" );
74 
75 	    if  ( ll->llTemplateID < -5 || ll->llTemplateID > -1 )
76 		{
77 		sprintf( tag, "leveltext\\leveltemplateid%ld",
78 						    ll->llTemplateID );
79 		}
80 
81 	    docRtfWriteDocEncodedStringDestination( rwc, tag,
82 					(char *)bytes, size, addSemicolon );
83 	    }
84 
85 	bytes= utilMemoryBufferGetBytes( &size, &mbnumbers );
86 	if  ( size > 0 )
87 	    {
88 	    docRtfWriteRawBytesDestination( rwc, "levelnumbers",
89 							(char *)bytes, size );
90 	    }
91 	}
92 
93     if  ( ll->llPictureNumber >= 0 )
94 	{ docRtfWriteArgTag( rwc, "levelpicture", ll->llPictureNumber ); }
95 
96     docRtfSaveTextAttribute( rwc, &(ll->llTextAttributeMask),
97 						    &(ll->llTextAttribute) );
98 
99     if  ( ! utilPropMaskIsEmpty( &(ll->llParaPropertyMask) ) )
100 	{
101 	ParagraphProperties	pp;
102 
103 	docInitParagraphProperties( &pp );
104 
105 	/* HACK */
106 	pp.ppTabStopListNumber= ll->llTabStopListNumber;
107 	pp.ppLeftIndentTwips= ll->llLeftIndentTwips;
108 	pp.ppFirstIndentTwips= ll->llFirstIndentTwips;
109 	pp.ppTabStopListNumber= ll->llTabStopListNumber;
110 
111 	docRtfSaveParagraphProperties( rwc, &(ll->llParaPropertyMask), &pp );
112 	}
113 
114     docRtfWriteDestinationEnd( rwc );
115 
116     utilCleanMemoryBuffer( &mbtext );
117     utilCleanMemoryBuffer( &mbnumbers );
118 
119     return;
120     }
121 
122 /************************************************************************/
123 /*									*/
124 /*  Write a list to rtf.						*/
125 /*									*/
126 /************************************************************************/
127 
docRtfWriteListProps(RtfWriter * rw,const DocumentList * dl)128 int docRtfWriteListProps(	RtfWriter *		rw,
129 				const DocumentList *	dl )
130     {
131     const ListLevel *	ll;
132     int			lev;
133 
134     if  ( dl->dlListTemplateID != -1 )
135 	{ docRtfWriteArgTag( rw, "listtemplateid", dl->dlListTemplateID ); }
136 
137     docRtfWriteAltTag( rw, "listhybrid", "listsimple", dl->dlListHybrid );
138 
139     if  ( dl->dlLevelCount > 0 )
140 	{ docRtfWriteNextLine( rw );	}
141 
142     ll= dl->dlLevels;
143     for ( lev= 0; lev < dl->dlLevelCount; ll++, lev++ )
144 	{
145 	docRtfWriteListLevel( rw, ll );
146 	docRtfWriteNextLine( rw );
147 	}
148 
149     if  ( dl->dlListID != -1 )
150 	{ docRtfWriteArgTag( rw, "listid", dl->dlListID );	}
151 
152     {
153     const int		addSemicolon= 1;
154 
155     docRtfWriteDocEncodedStringDestination( rw, "listname",
156 			    (const char *)dl->dlListName.mbBytes,
157 			    dl->dlListName.mbSize, addSemicolon );
158     }
159 
160     if  ( dl->dlListStyleID != -1 )
161 	{ docRtfWriteArgTag( rw, "liststyleid", dl->dlListStyleID ); }
162 
163     return 0;
164     }
165 
166 /************************************************************************/
167 /*									*/
168 /*  Write a listtable to rtf.						*/
169 /*									*/
170 /************************************************************************/
171 
docRtfWriteListTable(RtfWriter * rw,const DocumentListTable * dlt)172 void docRtfWriteListTable(	RtfWriter *			rw,
173 				const DocumentListTable *	dlt )
174     {
175     int				i;
176     const DocumentList *	dl= dlt->dltLists;
177 
178     docRtfWriteDestinationBegin( rw, "*\\listtable" );
179     docRtfWriteNextLine( rw );
180 
181     for ( i= 0; i < dlt->dltListCount; dl++, i++ )
182 	{
183 	docRtfWriteDestinationBegin( rw, "list" );
184 
185 	docRtfWriteListProps( rw, dl );
186 
187 	docRtfWriteDestinationEnd( rw );
188 	if  ( i+ 1 < dlt->dltListCount )
189 	    { docRtfWriteNextLine( rw );	}
190 	}
191 
192     docRtfWriteDestinationEnd( rw );
193     docRtfWriteNextLine( rw );
194 
195     return;
196     }
197 
198