File: pap.c

package info (click to toggle)
abiword 0.7.7-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 20,604 kB
  • ctags: 18,358
  • sloc: cpp: 88,791; ansic: 66,296; sh: 7,777; makefile: 3,397; xml: 687; perl: 361; awk: 273; sed: 36; csh: 28
file content (356 lines) | stat: -rw-r--r-- 7,771 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#include <stdlib.h>
#include <stdio.h>
#include "wv.h"

/*
To apply a UPX.papx to a UPE.pap, set UPE.pap.istd equal to UPX.papx.istd, and 
then apply the UPX.papx.grpprl to UPE.pap.
*/
void wvAddPAPXFromBucket(PAP *apap,UPXF *upxf,STSH *stsh,FILE *data)
	{
	U8 *pointer;
	U16 i=0;
	U16 sprm;
	apap->istd = upxf->upx.papx.istd;
	if (upxf->cbUPX <= 2)
		return;
	wvTrace(("no is %d\n",upxf->cbUPX));
#ifdef SPRMTEST
	fprintf(stderr,"\n");
	while (i < upxf->cbUPX-2)
		{
		fprintf(stderr,"%x (%d) ",*(upxf->upx.papx.grpprl+i),*(upxf->upx.papx.grpprl+i));
		i++;
		}
	fprintf(stderr,"\n");
	i=0;
#endif
	/*
	while (i < upxf->cbUPX-2)	
	*/
	while (i < upxf->cbUPX-4)	/* the end of the list is at -2, but there has to be a full sprm of
								 len 2 as well*/
		{
		sprm = bread_16ubit(upxf->upx.papx.grpprl+i,&i);
#ifdef SPRMTEST
		wvError(("sprm is %x\n",sprm));
#endif
		pointer = upxf->upx.papx.grpprl+i;
		if (i < upxf->cbUPX-2)
			wvApplySprmFromBucket(WORD8,sprm,apap,NULL,NULL,stsh,pointer,&i,data);
		}
	}

void wvAddPAPXFromBucket6(PAP *apap,UPXF *upxf,STSH *stsh)
	{
	U8 *pointer;
	U16 i=0;
	U16 sprm;
	U8 sprm8;
	apap->istd = upxf->upx.papx.istd;
	if (upxf->cbUPX <= 2)
		return;
	wvTrace(("no is %d\n",upxf->cbUPX));

#ifdef SPRMTEST
	fprintf(stderr,"\n");
	while (i < upxf->cbUPX-2)
		{
		fprintf(stderr,"%x (%d) ",*(upxf->upx.papx.grpprl+i),*(upxf->upx.papx.grpprl+i));
		i++;
		}
	fprintf(stderr,"\n");
	i=0;
#endif

	while (i < upxf->cbUPX-3)	/* the end of the list is at -2, but there has to be a full sprm of
								 len 1 as well*/
		{
		sprm8 = bgetc(upxf->upx.papx.grpprl+i,&i);
#ifdef SPRMTEST
		wvError(("pap word 6 sprm is %x (%d)\n",sprm8,sprm8));
#endif
		sprm = (U16)wvGetrgsprmWord6(sprm8);
#ifdef SPRMTEST
		wvError(("pap word 6 sprm is converted to %x\n",sprm));
#endif
		pointer = upxf->upx.papx.grpprl+i;
		/* hmm, maybe im wrong here, but there appears to be corrupt 
		 * word 6 sprm lists being stored in the file
		 */
		if (i < upxf->cbUPX-2)
			wvApplySprmFromBucket(WORD6,sprm,apap,NULL,NULL,stsh,pointer,&i,NULL);
		}
	}


void wvInitPAPFromIstd(PAP *apap,U16 istdBase,STSH *stsh)
	{
	if (istdBase == istdNil)
		wvInitPAP(apap);
	else 
		{
		if (istdBase >= stsh->Stshi.cstd)
			{
			wvError(("ISTD out of bounds, requested %d of %d\n",istdBase,stsh->Stshi.cstd));
			wvInitPAP(apap);	/*it can't hurt to try and start with a blank istd*/
			return;
			}
		else
			{
			if (stsh->std[istdBase].cupx==0)	/*empty slot in the array, i don't think this should happen*/
				{
				wvTrace(("Empty style slot used (chp)\n"));
				wvInitPAP(apap);
				}
			else
				wvCopyPAP(apap,&(stsh->std[istdBase].grupe[0].apap));
			}
		}
	}

void wvCopyPAP(PAP *dest,PAP *src)
	{
	memcpy(dest,src,sizeof(PAP));
	}


void wvInitPAP(PAP *item)
	{
	int i;
	item->istd = 0;
	item->jc  = 0;
	item->fKeep  = 0;
	item->fKeepFollow  = 0;
	item->fPageBreakBefore = 0;
	item->fBrLnAbove = 0;
	item->fBrLnBelow = 0;
	item->fUnused = 0;
	item->pcVert = 0;
	item->pcHorz =0;
	item->brcp = 0;
	item->brcl = 0;
	item->reserved1 = 0;
	item->ilvl = 0;
	item->fNoLnn = 0;
	item->ilfo = 0;
	item->nLvlAnm = 0;
	item->reserved2 = 0;
	item->fSideBySide = 0;
	item->reserved3 = 0;
	item->fNoAutoHyph = 0;
	item->fWidowControl = 0;
	item->dxaRight = 0;
	item->dxaLeft = 0;
	item->dxaLeft1 = 0;

	wvInitLSPD(&item->lspd);

	item->dyaBefore = 0;
	item->dyaAfter = 0;

	wvInitPHE(&item->phe,0);

	item->fCrLf = 0;
	item->fUsePgsuSettings = 0;
	item->fAdjustRight = 0;
	item->reserved4 = 0;
	item->fKinsoku = 0;
	item->fWordWrap = 0;
	item->fOverflowPunct = 0;
	item->fTopLinePunct = 0;
	item->fAutoSpaceDE = 0;
	item->fAtuoSpaceDN = 0;
	item->wAlignFont = 0;
	item->fVertical = 0;
	item->fBackward = 0;
	item->fRotateFont = 0;
	item->reserved5 = 0;
	item->reserved6 = 0;
	item->fInTable = 0;
	item->fTtp = 0;
	item->wr = 0;
	item->fLocked = 0;

	wvInitTAP(&item->ptap);

	item->dxaAbs = 0;
	item->dyaAbs = 0;
	item->dxaWidth = 0;

	wvInitBRC(&item->brcTop);
	wvInitBRC(&item->brcLeft);
	wvInitBRC(&item->brcBottom);
	wvInitBRC(&item->brcRight);
	wvInitBRC(&item->brcBetween);
	wvInitBRC(&item->brcBar);

	item->dxaFromText = 0;
	item->dyaFromText = 0;
	item->dyaHeight = 0;
	item->fMinHeight = 0;

	wvInitSHD(&item->shd);
	wvInitDCS(&item->dcs);
	item->lvl = 0;
	item->fNumRMIns = 0;
	wvInitANLD(&item->anld);
	item->fPropRMark  = 0;
	item->ibstPropRMark  = 0;
	wvInitDTTM(&item->dttmPropRMark);
	wvInitNUMRM(&item->numrm);	
	item->itbdMac = 0;
	for (i=0;i<itbdMax;i++)
		item->rgdxaTab[i] = 0;
	for (i=0;i<itbdMax;i++)
		wvInitTBD(&item->rgtbd[i]);
	}

/*
1) Having found the index i of the FC in an FKP that marks the character stored
in the file immediately after the paragraph's paragraph mark, 

1 is done in Simple mode through wvGetSimpleParaBounds which places this index
in fcLim by default

2) it is necessary to use the word offset stored in the first byte of the 
fkp.rgbx[i - 1] to find the PAPX for the paragraph. 

3) Using papx.istd to index into the properties stored for the style sheet , 

4) the paragraph properties of the style are copied to a local PAP. 

5) Then the grpprl stored in the PAPX is applied to the local PAP, 

6) and papx.istd along with fkp.rgbx.phe are moved into the local PAP. 

7) The process thus far has created a PAP that describes what the paragraph properties 
of the paragraph were at the last full save.
*/

int wvAssembleSimplePAP(version ver,PAP *apap,U32 fc,PAPX_FKP *fkp,STSH *stsh,FILE *data)
	{
	PAPX *papx;
	int index;
	UPXF upxf;
	int ret=0;
#ifdef SPRMTEST
	int i;
#endif
	/*index is the i in the text above*/
	index = wvGetIndexFCInFKP_PAPX(fkp,fc);
	
	wvTrace(("index is %d, using %d\n",index,index-1));
	papx = &(fkp->grppapx[index-1]);
	
	if (papx)
		{
		wvTrace(("istd index is %d\n",papx->istd));
		wvInitPAPFromIstd(apap,papx->istd,stsh);
		}
	else
		wvInitPAPFromIstd(apap,istdNil,stsh);

	if ((papx) && (papx->cb > 2))
		{
		ret=1;
#ifdef SPRMTEST
		fprintf(stderr,"cbUPX is %d\n",papx->cb);
		for (i=0;i<papx->cb-2;i++)
			fprintf(stderr,"%x ",papx->grpprl[i]);
		fprintf(stderr,"\n");
#endif
		upxf.cbUPX = papx->cb;
		upxf.upx.papx.istd = papx->istd;
		upxf.upx.papx.grpprl = papx->grpprl;
		if (ver == WORD8)
			wvAddPAPXFromBucket(apap,&upxf,stsh,data);
		else
			wvAddPAPXFromBucket6(apap,&upxf,stsh);
		}

	if (papx)
		apap->istd = papx->istd;
	
	wvCopyPHE(&apap->phe,&(fkp->rgbx[index-1].phe),apap->fTtp);
	return(ret);
	}

void wvReleasePAPX(PAPX *item)
	{
	item->cb=0;
	item->istd=0;
	wvFree(item->grpprl);
	item->grpprl=NULL;
	}

void wvInitPAPX(PAPX *item)
	{
	item->cb=0;
	item->istd=0;
	item->grpprl=NULL;
	}

void wvGetPAPX(version ver,PAPX *item,U8 *page,U16 *pos)
	{
	U16 cw,i;
	cw = bgetc(&(page[*pos]),pos);
	if ( (cw == 0) && (ver == WORD8) )	/* only do this for word 97 */
		{
		wvTrace(("cw was pad %d\n",cw));
		cw = bgetc(&(page[*pos]),pos);
		wvTrace(("cw was %d\n",cw));
		}
	item->cb=cw*2;
	item->istd = bread_16ubit(&(page[*pos]),pos);
	wvTrace(("papx istd is %x\n",item->istd));
	wvTrace(("no of bytes is %d\n",item->cb));
	if (item->cb > 2)
		{
		item->grpprl = (U8 *)malloc(item->cb-2);
		memcpy(item->grpprl,&(page[*pos]),(item->cb)-2);
		}
	else
		item->grpprl = NULL;
	}


int isPAPConform(PAP *current,PAP *previous)
	{
	if ((current) && (previous))
		if (wvEqualBRC(&current->brcLeft,&previous->brcLeft))
			if (wvEqualBRC(&current->brcRight,&previous->brcRight))
				if (current->dxaWidth == previous->dxaWidth)
					if (current->fInTable == previous->fInTable)
						return(1);
	return(0);
	}




void wvCopyConformPAP(PAP *dest,PAP *src)
	{
	if (src)
		{
#ifdef PURIFY
		wvInitPAP(dest);
#endif
		dest->brcLeft = src->brcLeft;
		dest->brcRight = src->brcRight;
		dest->dxaWidth = src->dxaWidth;
		dest->fInTable = src->fInTable;
		}
	else
		wvInitPAP(dest);
	}