1 /************************************************************************/
2 /* */
3 /* Read the the list override table of a document. */
4 /* */
5 /************************************************************************/
6
7 # include "docRtfConfig.h"
8
9 # include <stdio.h>
10 # include <ctype.h>
11
12 # include "docRtfWriterImpl.h"
13 # include "docRtfReaderImpl.h"
14
15 # include <docListAdmin.h>
16
17 # include <appDebugon.h>
18
docRtfRememberListOverrideLevelProperty(const RtfControlWord * rcw,int arg,RtfReader * rrc)19 int docRtfRememberListOverrideLevelProperty(
20 const RtfControlWord * rcw,
21 int arg,
22 RtfReader * rrc )
23 {
24 ListOverrideLevel * lol= &(rrc->rrcListOverrideLevel);
25
26 switch( rcw->rcwID )
27 {
28 case LOLpropSTARTAT:
29 lol->lolOverrideStartAt= arg != 0;
30 break;
31
32 case LOLpropFORMAT:
33 lol->lolOverrideFormat= arg != 0;
34 break;
35
36 /* LOLpropLEVEL */
37
38 default:
39 SDEB(rcw->rcwWord);
40 break;
41 }
42
43 return 0;
44 }
45
docRtfRememberListOverrideProperty(const RtfControlWord * rcw,int arg,RtfReader * rrc)46 int docRtfRememberListOverrideProperty(
47 const RtfControlWord * rcw,
48 int arg,
49 RtfReader * rrc )
50 {
51 ListOverride * lo= &(rrc->rrcListOverride);
52
53 if ( docSetListOverrideProperty( lo, rcw->rcwID, arg ) )
54 { SDEB(rcw->rcwWord); }
55
56 return 0;
57 }
58
docRtfListOverrideLevelLevel(const RtfControlWord * rcw,int arg,RtfReader * rrc)59 static int docRtfListOverrideLevelLevel( const RtfControlWord * rcw,
60 int arg,
61 RtfReader * rrc )
62 {
63 const int copyIds= 1;
64 const int * const fontMap= (const int *)0;
65 const int * const colorMap= (const int *)0;
66 const int * const rulerMap= (const int *)0;
67
68 if ( docRtfReadListLevelGroup( rcw, rrc ) )
69 { SLDEB(rcw->rcwWord,arg); return -1; }
70
71 if ( docCopyDocumentListLevel( &(rrc->rrcListOverrideLevel.lolListLevel),
72 &(rrc->rrcDocumentListLevel),
73 copyIds, fontMap, colorMap, rulerMap ) )
74 { LDEB(1); return -1; }
75
76 docCleanDocumentListLevel( &(rrc->rrcDocumentListLevel) );
77 docInitDocumentListLevel( &(rrc->rrcDocumentListLevel) );
78
79 return 0;
80 }
81
82 static RtfControlWord docRtfListOverrideLevelGroups[]=
83 {
84 RTF_DEST_XX( "listlevel", LOLpropLEVEL, docRtfListOverrideLevelLevel ),
85
86 { (char *)0, 0, 0 }
87 };
88
docRtfListOverrideLevel(const RtfControlWord * rcw,int arg,RtfReader * rrc)89 static int docRtfListOverrideLevel( const RtfControlWord * rcw,
90 int arg,
91 RtfReader * rrc )
92 {
93 const int * const fontMap= (const int *)0;
94 const int * const colorMap= (const int *)0;
95 const int * const rulerMap= (const int *)0;
96
97 docCleanListOverrideLevel( &(rrc->rrcListOverrideLevel) );
98 docInitListOverrideLevel( &(rrc->rrcListOverrideLevel) );
99
100 if ( docRtfReadGroup( rcw, 0, 0, rrc,
101 docRtfListOverrideLevelGroups,
102 docRtfRefuseText, (RtfCommitGroup)0 ) )
103 { SLDEB(rcw->rcwWord,arg); return -1; }
104
105 if ( docListOverrideAddLevel( &(rrc->rrcListOverride),
106 &(rrc->rrcListOverrideLevel),
107 fontMap, colorMap, rulerMap ) )
108 { LDEB(1); return -1; }
109
110 docCleanListOverrideLevel( &(rrc->rrcListOverrideLevel) );
111 docInitListOverrideLevel( &(rrc->rrcListOverrideLevel) );
112
113 return 0;
114 }
115
116 static RtfControlWord docRtfListOverrideGroups[]=
117 {
118 RTF_DEST_XX( "lfolevel", DLpropLEVELS, docRtfListOverrideLevel ),
119
120 { (char *)0, 0, 0 }
121 };
122
docRtfListOverride(const RtfControlWord * rcw,int arg,RtfReader * rrc)123 static int docRtfListOverride( const RtfControlWord * rcw,
124 int arg,
125 RtfReader * rrc )
126 {
127 const int * const fontMap= (const int *)0;
128 const int * const colorMap= (const int *)0;
129 const int * const rulerMap= (const int *)0;
130
131 DocumentProperties * dp= &(rrc->rrDocument->bdProperties);
132
133 docCleanListOverride( &(rrc->rrcListOverride) );
134 docInitListOverride( &(rrc->rrcListOverride) );
135
136 if ( docRtfReadGroup( rcw, 0, 0, rrc,
137 docRtfListOverrideGroups,
138 docRtfRefuseText, (RtfCommitGroup)0 ) )
139 { SLDEB(rcw->rcwWord,arg); return -1; }
140
141 if ( docListOverrideTableSetOverride(
142 &(dp->dpListAdmin->laListOverrideTable),
143 &(rrc->rrcListOverride),
144 fontMap, colorMap, rulerMap ) < 0 )
145 { LDEB(1); return -1; }
146
147 docCleanListOverride( &(rrc->rrcListOverride) );
148 docInitListOverride( &(rrc->rrcListOverride) );
149
150 return 0;
151 }
152
153 static RtfControlWord docRtfListtableGroups[]=
154 {
155 RTF_DEST_XX( "listoverride", DPpropLISTTABLE, docRtfListOverride ),
156
157 { (char *)0, 0, 0 }
158 };
159
160 /************************************************************************/
161 /* */
162 /* Read the list override table of a document. */
163 /* */
164 /* 1) Read the overrides in the table. */
165 /* 2) Allocate memory to manage the paragraphs in the lists in the */
166 /* body. Allocation for the trees in external items is done */
167 /* lazily. */
168 /* */
169 /************************************************************************/
170
docRtfListOverrideTable(const RtfControlWord * rcw,int arg,RtfReader * rrc)171 int docRtfListOverrideTable( const RtfControlWord * rcw,
172 int arg,
173 RtfReader * rrc )
174 {
175 BufferDocument * bd= rrc->rrDocument;
176 DocumentTree * dt= &(rrc->rrDocument->bdBody);
177 DocumentProperties * dp= &(bd->bdProperties);
178
179 /* 1 */
180 if ( docRtfReadGroup( rcw, 0, 0, rrc,
181 docRtfListtableGroups,
182 docRtfIgnoreText, (RtfCommitGroup)0 ) )
183 { SLDEB(rcw->rcwWord,arg); return -1; }
184
185 /* 2 */
186 if ( docClaimListNumberTrees( &(dt->dtListNumberTrees),
187 dp->dpListAdmin->laListOverrideTable.lotOverrideCount ) )
188 { LDEB(1); return -1; }
189
190 return 0;
191 }
192
193 /************************************************************************/
194 /* */
195 /* Write a list override table to rtf. */
196 /* */
197 /************************************************************************/
198
docRtfWriteListOverrideLevels(RtfWriter * rwc,const ListOverride * lo)199 static void docRtfWriteListOverrideLevels(
200 RtfWriter * rwc,
201 const ListOverride * lo )
202 {
203 const ListOverrideLevel * lol;
204 int lev;
205
206 docRtfWriteNextLine( rwc );
207
208 lol= lo->loLevels;
209 for ( lev= 0; lev < lo->loLevelCount; lol++, lev++ )
210 {
211 docRtfWriteDestinationBegin( rwc, "lfolevel" );
212
213 if ( lol->lolOverrideStartAt && ! lol->lolOverrideFormat )
214 {
215 docRtfWriteArgTag( rwc, "listoverridestartat\\levelstartat",
216 lol->lolListLevel.llStartAt );
217 }
218
219 if ( lol->lolOverrideFormat )
220 {
221 docRtfWriteTag( rwc, "listoverrideformat" );
222
223 docRtfWriteListLevel( rwc, &(lol->lolListLevel) );
224 }
225
226 docRtfWriteDestinationEnd( rwc );
227 docRtfWriteNextLine( rwc );
228 }
229 return;
230 }
231
232 /************************************************************************/
233 /* */
234 /* Write the list override table for a document. */
235 /* */
236 /************************************************************************/
237
docRtfWriteListOverrideTable(RtfWriter * rwc,const ListOverrideTable * lot)238 void docRtfWriteListOverrideTable( RtfWriter * rwc,
239 const ListOverrideTable * lot )
240 {
241 int ov;
242 const ListOverride * lo;
243 int overrideCount;
244
245 docRtfWriteDestinationBegin( rwc, "*\\listoverridetable" );
246 docRtfWriteNextLine( rwc );
247
248 overrideCount= lot->lotOverrideCount;
249 while( lot->lotOverrideCount > 0 &&
250 lot->lotOverrides[overrideCount- 1].loIndex < 0 )
251 { overrideCount--; }
252
253 lo= lot->lotOverrides;
254 for ( ov= 0; ov < overrideCount; lo++, ov++ )
255 {
256 if ( lo->loIndex < 1 )
257 { continue; }
258
259 docRtfWriteDestinationBegin( rwc, "listoverride" );
260
261 if ( lo->loListID != -1 )
262 { docRtfWriteArgTag( rwc, "listid", lo->loListID ); }
263
264 docRtfWriteArgTag( rwc, "listoverridecount", lo->loOverrideCount );
265
266 if ( lo->loLevelCount > 0 )
267 { docRtfWriteListOverrideLevels( rwc, lo ); }
268
269 docRtfWriteArgTag( rwc, "ls", lo->loIndex );
270
271 docRtfWriteDestinationEnd( rwc );
272 if ( ov+ 1 < overrideCount )
273 { docRtfWriteNextLine( rwc ); }
274 }
275
276 docRtfWriteDestinationEnd( rwc );
277 docRtfWriteNextLine( rwc );
278
279 return;
280 }
281
282