bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / filter / ww1 / w1class.cxx
blob4c93211d129047b817833b30efc5a77cd4ac50d9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <string.h>
22 #include <rtl/strbuf.hxx>
23 #include <rtl/ustring.hxx>
24 #include <tools/stream.hxx>
25 #include <w1class.hxx>
28 #ifdef DUMP
29 static const sal_Char* pUnknown = "?";
30 #define DUMPNAME(s) s
31 #else
32 #define DUMPNAME(s) 0
33 #endif
35 Ww1SingleSprm* Ww1Sprm::aTab[ 256 ];
36 Ww1SingleSprm* Ww1Sprm::pSingleSprm = 0;
40 /////////////////////////////////////////////////////////////////// Fib
41 Ww1Fib::Ww1Fib( SvStream& _rStream )
42 : rStream(_rStream)
44 bOK = 0 == rStream.Seek(0) &&
45 rStream.Read( &aFib, sizeof( aFib )) == sizeof( aFib );
48 ///////////////////////////////////////////////////////////// PlainText
50 Ww1PlainText::Ww1PlainText(Ww1Fib& rWwFib, sal_uLong nFilePos, sal_uLong nCountBytes)
51 : rFib(rWwFib), ulFilePos(nFilePos), ulCountBytes(nCountBytes),
52 ulSeek(0), bOK(true)
56 sal_Unicode Ww1PlainText::operator [] ( sal_uLong ulOffset )
58 OSL_ENSURE( ulOffset<Count(), "Ww1PlainText" );
59 sal_Unicode cRet;
60 sal_Char cRead;
61 if( rFib.GetStream().Seek( ulFilePos + ulOffset ) == ulFilePos+ulOffset &&
62 rFib.GetStream().Read( &cRead, sizeof( cRead ) ) == sizeof( cRead ) )
64 cRet = OUString(&cRead, 1, RTL_TEXTENCODING_MS_1252).toChar();
66 else
67 cRet = ' ';
68 return cRet;
71 String Ww1PlainText::GetText( sal_uLong ulOffset, sal_uLong nLen ) const
73 OSL_ENSURE(ulOffset+nLen<Count(), "Ww1PlainText");
75 sal_Size nPos = ulFilePos+ulOffset;
77 bool bSeekOk = rFib.GetStream().Seek(nPos) == nPos;
78 return bSeekOk ?
79 read_uInt8s_ToOUString(rFib.GetStream(), nLen, RTL_TEXTENCODING_MS_1252) :
80 OUString();
83 ///////////////////////////////////////////////////////////////// Style
84 Ww1Style::Ww1Style()
85 : pPapx(0), pParent(0), stcBase(0), stcNext(0), bUsed(false)
89 Ww1Style::~Ww1Style()
91 delete pPapx;
94 void Ww1Style::SetDefaults(sal_uInt8 stc)
96 if( 222 == stc )
98 stcBase = 222;
99 stcNext = 222;
100 aChpx.hpsSet(20);
104 sal_uInt16 Ww1Style::ReadName( sal_uInt8*&p, sal_uInt16& rnCountBytes, sal_uInt16 stc )
106 sal_uInt8 nCountBytes = SVBT8ToByte(p);
107 p++;
108 rnCountBytes--;
109 if( !nCountBytes ) // default
111 static const sal_Char* const names[] =
113 "W1 Null", //222
114 "W1 Annotation reference", //223
115 "W1 Annotation text", //224
116 "W1 Table of contents 8", //225
117 "W1 Table of contents 7", //226
118 "W1 Table of contents 6", //227
119 "W1 Table of contents 5", //228
120 "W1 Table of contents 4", //229
121 "W1 Table of contents 3", //230
122 "W1 Table of contents 2", //231
123 "W1 Table of contents 1", //232
124 "W1 Index 7", //233
125 "W1 Index 6", //234
126 "W1 Index 5", //235
127 "W1 Index 4", //236
128 "W1 Index 3", //237
129 "W1 Index 2", //238
130 "W1 Index 1", //239
131 "W1 Line number", //240
132 "W1 Index heading", //241
133 "W1 Footer", //242
134 "W1 Header", //243
135 "W1 Footnote reference", //244
136 "W1 Footnote text", //245
137 "W1 Heading 9", //246
138 "W1 Heading 8", //247
139 "W1 Heading 7", //248
140 "W1 Heading 6", //249
141 "W1 Heading 5", //250
142 "W1 Heading 4", //251
143 "W1 Heading 3", //252
144 "W1 Heading 2", //253
145 "W1 Heading 1", //254
146 "W1 Normal indent" //255
147 };//256
149 const sal_Char* pStr;
150 size_t nSize(stc);
151 if (!nSize)
152 pStr = "W1 Normal";
153 else if (nSize - 222 >= SAL_N_ELEMENTS(names))
154 pStr = "?";
155 else
156 pStr = names[nSize-222];
157 SetName(String(pStr, RTL_TEXTENCODING_MS_1252));
159 else if( 255 > nCountBytes ) // unused
161 SetName( String( (sal_Char*)p, nCountBytes, RTL_TEXTENCODING_MS_1252 ));
162 p += nCountBytes;
163 OSL_ENSURE(rnCountBytes>=nCountBytes, "Ww1Style");
164 rnCountBytes = rnCountBytes - nCountBytes;
166 return 0;
169 sal_uInt16 Ww1Style::ReadChpx( sal_uInt8*&p, sal_uInt16& rnCountBytes )
171 sal_uInt16 nCountBytes = SVBT8ToByte(p);
172 p++;
173 rnCountBytes--;
174 if (nCountBytes != 255 // unused
175 && nCountBytes != 0) // default
177 if (nCountBytes > sizeof(aChpx))
178 nCountBytes = sizeof(aChpx);
179 memcpy( &aChpx, p, nCountBytes );
180 p += nCountBytes;
181 OSL_ENSURE(rnCountBytes>=nCountBytes, "Ww1Style");
182 rnCountBytes = rnCountBytes - nCountBytes;
184 return 0;
187 sal_uInt16 Ww1Style::ReadPapx(sal_uInt8*&p, sal_uInt16& rnCountBytes)
189 sal_uInt16 nCountBytes = SVBT8ToByte(p);
190 p++;
191 rnCountBytes--;
192 if (nCountBytes != 255)
194 pPapx = new Ww1SprmPapx(p, nCountBytes);
195 p += nCountBytes;
196 OSL_ENSURE(rnCountBytes>=nCountBytes, "Ww1Style");
197 rnCountBytes = rnCountBytes - nCountBytes;
199 else
200 pPapx = new Ww1SprmPapx(p, 0);
201 return 0;
204 sal_uInt16 Ww1Style::ReadEstcp(sal_uInt8*&p, sal_uInt16& rnCountBytes)
206 stcNext = SVBT8ToByte(p);
207 p++;
208 rnCountBytes--;
209 stcBase = SVBT8ToByte(p);
210 p++;
211 OSL_ENSURE(rnCountBytes>0, "Ww1Style");
212 rnCountBytes--;
213 return 0;
216 //////////////////////////////////////////////////////////// StyleSheet
217 Ww1StyleSheet::Ww1StyleSheet(Ww1Fib& _rFib)
218 : cstcStd(0),
219 rFib(_rFib),
220 bOK(sal_False)
222 sal_uInt16 cbStshf = rFib.GetFIB().cbStshfGet();
223 OSL_ENSURE(cbStshf>=17, "Ww1StyleSheet");
224 for (sal_uInt16 stc=0;stc<Count();stc++)
226 aStyles[stc].SetParent(this);
227 aStyles[stc].SetDefaults((sal_uInt8)stc);
229 sal_uInt8* del = NULL;
230 if (rFib.GetStream().Seek(rFib.GetFIB().fcStshfGet())
231 == (sal_uLong)rFib.GetFIB().fcStshfGet()
232 && (del = new sal_uInt8[cbStshf]) != NULL
233 && rFib.GetStream().Read(del, cbStshf) == (sal_uLong)cbStshf)
235 sal_uInt8* p = del;
236 cstcStd = SVBT16ToShort(p);
237 p += sizeof(SVBT16);
238 cbStshf -= sizeof(SVBT16);
239 ReadNames(p, cbStshf);
240 ReadChpx(p, cbStshf);
241 ReadPapx(p, cbStshf);
242 ReadEstcp(p, cbStshf);
243 OSL_ENSURE(cbStshf==0, "Ww1StyleSheet");
244 bOK = cbStshf == 0;
246 delete [] del;
249 sal_uInt16 Ww1StyleSheet::ReadNames( sal_uInt8*& p, sal_uInt16& rnCountBytes )
251 sal_uInt16 nCountBytes = SVBT16ToShort(p);
252 p += sizeof(SVBT16);
253 OSL_ENSURE(rnCountBytes>=nCountBytes, "Ww1StyleSheet");
254 rnCountBytes = rnCountBytes - nCountBytes;
255 nCountBytes = nCountBytes - sizeof(SVBT16);
256 sal_uInt16 stcp = 0;
257 while (nCountBytes > 0)
259 sal_uInt16 stc = (stcp - cstcStd) & 255;
260 aStyles[stc].ReadName(p, nCountBytes, stc);
261 stcp++;
263 OSL_ENSURE(nCountBytes==0, "Ww1StyleSheet");
264 return 0;
267 sal_uInt16 Ww1StyleSheet::ReadChpx(sal_uInt8*& p, sal_uInt16& rnCountBytes)
269 sal_uInt16 nCountBytes = SVBT16ToShort(p);
270 p += sizeof(SVBT16);
271 OSL_ENSURE(rnCountBytes>=nCountBytes, "Ww1StyleSheet");
272 rnCountBytes = rnCountBytes - nCountBytes;
273 nCountBytes = nCountBytes - sizeof(SVBT16);
274 sal_uInt16 stcp = 0;
275 while (nCountBytes > 0)
277 sal_uInt16 stc = (stcp - cstcStd) & 255;
278 aStyles[stc].ReadChpx(p, nCountBytes);
279 stcp++;
281 OSL_ENSURE(nCountBytes == 0, "Ww1StyleSheet");
282 return 0;
285 sal_uInt16 Ww1StyleSheet::ReadPapx(sal_uInt8*& p, sal_uInt16& rnCountBytes)
287 sal_uInt16 nCountBytes = SVBT16ToShort(p);
288 p += sizeof(SVBT16);
289 OSL_ENSURE(rnCountBytes>=nCountBytes, "Ww1StyleSheet");
290 rnCountBytes = rnCountBytes - nCountBytes;
291 nCountBytes = nCountBytes - sizeof(SVBT16);
292 sal_uInt16 stcp = 0;
293 while (nCountBytes > 0)
295 sal_uInt16 stc = (stcp - cstcStd) & 255;
296 aStyles[stc].ReadPapx(p, nCountBytes);
297 stcp++;
299 OSL_ENSURE(nCountBytes == 0, "Ww1StyleSheet");
300 return 0;
303 sal_uInt16 Ww1StyleSheet::ReadEstcp(sal_uInt8*& p, sal_uInt16& rnCountBytes)
305 sal_uInt16 iMac = SVBT16ToShort(p);
306 p += sizeof(SVBT16);
307 OSL_ENSURE(rnCountBytes>=sizeof(SVBT16), "Ww1StyleSheet");
308 rnCountBytes -= sizeof(SVBT16);
309 for (sal_uInt16 stcp=0;stcp<iMac;stcp++)
311 sal_uInt16 stc = (stcp - cstcStd) & 255;
312 aStyles[stc].ReadEstcp(p, rnCountBytes);
314 OSL_ENSURE(rnCountBytes==0, "Ww1StyleSheet");
315 return 0;
318 ///////////////////////////////////////////////////////////////// Fonts
320 Ww1Fonts::Ww1Fonts(Ww1Fib& rInFib, sal_uLong nFieldFlgs)
321 : pFontA(0), rFib(rInFib), nFieldFlags(nFieldFlgs), nMax(0), bOK(false)
323 if(rFib.GetFIB().cbSttbfffnGet() > 2 ) // ueberhaupt fonts?
325 SVBT16 nCountBytes;
326 OSL_ENSURE(rFib.GetFIB().cbSttbfffnGet() > sizeof(nCountBytes), "Ww1Fonts");
327 if (rFib.GetStream().Seek(rFib.GetFIB().fcSttbfffnGet())
328 == (sal_uLong)rFib.GetFIB().fcSttbfffnGet())
329 if (rFib.GetStream().Read(nCountBytes, sizeof(nCountBytes))
330 == sizeof(nCountBytes)) // Laenge steht hier nochmal
332 OSL_ENSURE(SVBT16ToShort(nCountBytes)
333 == rFib.GetFIB().cbSttbfffnGet(), "redundant-size missmatch");
334 // hoffentlich sind sie immer gleich
335 W1_FFN* pA = (W1_FFN*)new char[rFib.GetFIB().cbSttbfffnGet()
336 - sizeof(nCountBytes)]; // Alloziere Font-Array
337 //~ Ww1: new-NULL
338 if (rFib.GetStream().Read(pA, rFib.GetFIB().cbSttbfffnGet()
339 - sizeof(nCountBytes)) == (sal_uLong)rFib.GetFIB().cbSttbfffnGet()
340 - sizeof(nCountBytes)) // lese alle Fonts
341 {} //nothing
343 long nLeft = rFib.GetFIB().cbSttbfffnGet()
344 - sizeof(nCountBytes); // Zaehle, wieviele Fonts enthalten
345 W1_FFN* p = pA;
346 while (1)
348 sal_uInt16 nNextSiz;
349 nNextSiz = p->cbFfnM1Get() + 1;
350 if(nNextSiz > nLeft)
351 break;
352 nMax++;
353 nLeft -= nNextSiz;
354 if(nLeft < 1) // naechste Laenge muss gelesen werden koennen
355 break;
356 p = (W1_FFN *)(((char*)p) + nNextSiz);
358 if (nMax)
360 pFontA = new W1_FFN*[nMax]; // alloziere Index-Array
361 //~ Ww1: new-NULL
362 pFontA[0] = pA; // fuelle Index-Array
363 sal_uInt16 i;
364 for(i=1, p=pA; i<nMax; i++)
366 p = (W1_FFN*)(((char*)p) + p->cbFfnM1Get() + 1);
367 pFontA[i] = p;
370 else
371 pFontA = 0; // Keine Eintraege -> kein Array
374 bOK = sal_True;
377 W1_FFN* Ww1Fonts::GetFFN(sal_uInt16 nNum)
379 W1_FFN* pRet = NULL;
380 if (pFontA)
381 if (nNum < nMax)
382 pRet = pFontA[nNum];
383 return pRet;
386 /////////////////////////////////////////////////////////////////// DOP
387 Ww1Dop::Ww1Dop(Ww1Fib& _rFib)
388 : rFib(_rFib)
390 long nRead;
391 memset(&aDop, 0, sizeof(aDop)); // set defaults
392 if(rFib.GetFIB().cbDopGet() >= sizeof(aDop))
393 nRead = sizeof(aDop);
394 else
395 nRead = rFib.GetFIB().cbDopGet();
396 bOK = rFib.GetStream().Seek(rFib.GetFIB().fcDopGet()) ==
397 (sal_uLong)rFib.GetFIB().fcDopGet() &&
398 rFib.GetStream().Read(&aDop, nRead) == (sal_uLong)nRead;
401 /////////////////////////////////////////////////////////////// Picture
402 Ww1Picture::Ww1Picture(SvStream& rStream, sal_uLong ulFilePos)
403 : bOK(false), pPic(0)
405 ulFilePos &= 0xffffff; //~ ww1: warum auch immer - im highbyte steht eine 5?!?!
406 SVBT32 lcb;
407 if (rStream.Seek(ulFilePos) == (sal_uLong)ulFilePos)
408 if (rStream.Read(&lcb, sizeof(lcb)) == (sal_uLong)sizeof(lcb))
409 if (sizeof(int)>=4 || SVBT32ToUInt32(lcb) < 0x8000) //~ mdt: 64K & 16bit
410 if ((pPic = (W1_PIC*)(new sal_uInt8[SVBT32ToUInt32(lcb)])) != NULL)
411 if (rStream.Seek(ulFilePos) == (sal_uLong)ulFilePos)
412 if (rStream.Read(pPic, SVBT32ToUInt32(lcb)) == (sal_uLong)SVBT32ToUInt32(lcb))
414 OSL_ENSURE(pPic->cbHeaderGet()==sizeof(*pPic)-sizeof(pPic->rgb), "Ww1Picture");
415 bOK = true;
419 ////////////////////////////////////////////////////////////////// Sprm
420 Ww1Sprm::Ww1Sprm(sal_uInt8* x, sal_uInt16 _nCountBytes)
421 : p(NULL),
422 nCountBytes(_nCountBytes),
423 bOK(sal_False),
424 pArr(NULL),
425 count(0)
427 if (nCountBytes == 0)
428 bOK = sal_True;
429 else
430 if ((p = new sal_uInt8[nCountBytes]) != NULL)
432 memcpy(p, x, nCountBytes);
433 if (ReCalc())
434 bOK = sal_True;
438 Ww1Sprm::Ww1Sprm(SvStream& rStream, sal_uLong ulFilePos)
439 : p(NULL),
440 nCountBytes(0),
441 bOK(sal_False),
442 pArr(NULL),
443 count(0)
445 SVBT8 x;
446 ByteToSVBT8(0, x);
447 if (rStream.Seek(ulFilePos) == (sal_uLong)ulFilePos)
448 if (rStream.Read(&x, sizeof(x)) == (sal_uLong)sizeof(x))
449 if ((nCountBytes = SVBT8ToByte(x)) == 255
450 || !nCountBytes
451 || (p = new sal_uInt8[nCountBytes]) != NULL)
452 if (nCountBytes == 255
453 || !nCountBytes
454 || rStream.Read(p, nCountBytes) == (sal_uLong)nCountBytes)
455 if (ReCalc())
456 bOK = sal_True;
459 Ww1Sprm::~Ww1Sprm()
461 delete[] pArr;
462 delete[] p;
465 sal_uInt16 Ww1SingleSprm::Size(sal_uInt8* /*pSprm*/)
467 return nCountBytes;
470 Ww1SingleSprm::~Ww1SingleSprm()
474 sal_uInt16 Ww1SingleSprmTab::Size(sal_uInt8* pSprm) // Doc 24/25, Fastsave-Sprm
476 OSL_ENSURE(nCountBytes==0, "Ww1SingleSprmTab");
477 sal_uInt16 nRet = sizeof(SVBT8);
478 sal_uInt16 nSize = SVBT8ToByte(pSprm);
479 if (nSize != 255)
480 nRet = nRet + nSize;
481 else
483 sal_uInt16 nDel = SVBT8ToByte(pSprm+1) * 4;
484 sal_uInt16 nIns = SVBT8ToByte(pSprm + 3 + nDel) * 3;
485 nRet += nDel + nIns;
487 OSL_ENSURE(nRet <= 354, "Ww1SingleSprmTab");
488 if (nRet > 354)
489 nRet = 0;
490 return nRet;
493 sal_uInt16 Ww1SingleSprmByteSized::Size(sal_uInt8* pSprm)
495 sal_uInt16 nRet;
496 nRet = SVBT8ToByte(pSprm);
497 nRet += sizeof(SVBT8); // var. l. byte-size
498 nRet = nRet + nCountBytes;
499 return nRet;
502 sal_uInt16 Ww1SingleSprmWordSized::Size(sal_uInt8* pSprm)
504 sal_uInt16 nRet;
505 nRet = SVBT16ToShort(pSprm);
506 nRet += sizeof(SVBT16); // var. l. word-size
507 nRet = nRet + nCountBytes;
508 return nRet;
511 static sal_uInt8 nLast = 0;
512 static sal_uInt8 nCurrent = 0;
513 sal_uInt16 Ww1Sprm::GetSize(sal_uInt8 nId, sal_uInt8* pSprm)
515 sal_uInt16 nL = 0;
516 nL = GetTab(nId).Size(pSprm);
517 nLast = nCurrent;
518 nCurrent = nId;
519 return nL;
522 sal_Bool Ww1Sprm::Fill(sal_uInt16 index, sal_uInt8& nId, sal_uInt16& nL, sal_uInt8*& pSprm)
524 OSL_ENSURE(index < Count(), "Ww1Sprm");
525 pSprm = p + pArr[index];
526 nId = SVBT8ToByte(pSprm);
527 pSprm++;
528 nL = GetTab(nId).Size(pSprm);
529 return sal_True;
532 sal_Bool Ww1Sprm::ReCalc()
534 sal_Bool bRet = sal_True;
535 delete[] pArr;
536 pArr = NULL;
537 count = 0;
538 if (nCountBytes != 255) // not unused?
540 sal_uInt16 cbsik = nCountBytes;
541 sal_uInt8* psik = p;
542 while (cbsik > 0)
544 sal_uInt16 iLen = GetSizeBrutto(psik);
545 OSL_ENSURE(iLen<=cbsik, "Ww1Sprm");
546 if (iLen > cbsik)
547 cbsik = 0; // ignore the rest: we are wrong...
548 else
550 psik += iLen;
551 cbsik = cbsik - iLen;
552 count++;
555 if (bRet
556 && (pArr = new sal_uInt16[count]) != NULL)
558 cbsik = nCountBytes;
559 sal_uInt16 offset = 0;
560 sal_uInt16 current = 0;
561 psik = p;
562 while (current<count)
564 pArr[current++] = offset;
565 sal_uInt16 iLen = GetSizeBrutto(psik);
566 psik += iLen;
567 if (iLen > cbsik)
568 cbsik = 0;
569 else
570 cbsik = cbsik - iLen;
571 offset = offset + iLen;
575 else
576 count = 0;
578 return bRet;
581 void Ww1Sprm::DeinitTab()
583 for (size_t i=0; i < SAL_N_ELEMENTS(aTab); ++i)
584 delete aTab[i];
585 memset(aTab, 0, SAL_N_ELEMENTS(aTab));
586 delete pSingleSprm;
589 void Ww1Sprm::InitTab()
591 memset(aTab, 0, SAL_N_ELEMENTS(aTab));
592 pSingleSprm = new Ww1SingleSprm( 0, DUMPNAME(pUnknown));
594 aTab[ 2] = new Ww1SingleSprmByte(DUMPNAME("sprmPStc")); // 2 pap.istd (style code)
595 aTab[ 3] = new Ww1SingleSprmByteSized(0, DUMPNAME("sprmPIstdPermute")); // 3 pap.istd permutation
596 aTab[ 4] = new Ww1SingleSprmByte(DUMPNAME("sprmPIncLevel")); // 4 pap.istddifference
597 aTab[ 5] = new Ww1SingleSprmPJc(DUMPNAME("sprmPJc")); // 5 pap.jc (justification)
598 aTab[ 6] = new Ww1SingleSprmBool(DUMPNAME("sprmPFSideBySide")); // 6 pap.fSideBySide
599 aTab[ 7] = new Ww1SingleSprmPFKeep(DUMPNAME("sprmPFKeep")); // 7 pap.fKeep
600 aTab[ 8] = new Ww1SingleSprmPFKeepFollow(DUMPNAME("sprmPFKeepFollow")); // 8 pap.fKeepFollow
601 aTab[ 9] = new Ww1SingleSprmPPageBreakBefore(DUMPNAME("sprmPPageBreakBefore")); // 9 pap.fPageBreakBefore
602 aTab[ 10] = new Ww1SingleSprmByte(DUMPNAME("sprmPBrcl")); // 10 pap.brcl
603 aTab[ 11] = new Ww1SingleSprmByte(DUMPNAME("sprmPBrcp")); // 11 pap.brcp
604 aTab[ 12] = new Ww1SingleSprmByteSized(0, DUMPNAME("sprmPAnld")); // 12 pap.anld (ANLD structure)
605 aTab[ 13] = new Ww1SingleSprmByte(DUMPNAME("sprmPNLvlAnm")); // 13 pap.nLvlAnm nn
606 aTab[ 14] = new Ww1SingleSprmBool(DUMPNAME("sprmPFNoLineNumb")); // 14 ap.fNoLnn
607 aTab[ 15] = new Ww1SingleSprmPChgTabsPapx(DUMPNAME("sprmPChgTabsPapx")); // 15 pap.itbdMac, ...
608 aTab[ 16] = new Ww1SingleSprmPDxaRight(DUMPNAME("sprmPDxaRight")); // 16 pap.dxaRight
609 aTab[ 17] = new Ww1SingleSprmPDxaLeft(DUMPNAME("sprmPDxaLeft")); // 17 pap.dxaLeft
610 aTab[ 18] = new Ww1SingleSprmWord(DUMPNAME("sprmPNest")); // 18 pap.dxaNest
611 aTab[ 19] = new Ww1SingleSprmPDxaLeft1(DUMPNAME("sprmPDxaLeft1")); // 19 pap.dxaLeft1
612 aTab[ 20] = new Ww1SingleSprmPDyaLine(DUMPNAME("sprmPDyaLine")); // 20 pap.lspd an LSPD
613 aTab[ 21] = new Ww1SingleSprmPDyaBefore(DUMPNAME("sprmPDyaBefore")); // 21 pap.dyaBefore
614 aTab[ 22] = new Ww1SingleSprmPDyaAfter(DUMPNAME("sprmPDyaAfter")); // 22 pap.dyaAfter
615 aTab[ 23] = new Ww1SingleSprmTab(0, DUMPNAME(pUnknown)); // 23 pap.itbdMac, pap.rgdxaTab
616 aTab[ 24] = new Ww1SingleSprmPFInTable(DUMPNAME("sprmPFInTable")); // 24 pap.fInTable
617 aTab[ 25] = new Ww1SingleSprmPTtp(DUMPNAME("sprmPTtp")); // 25 pap.fTtp
618 aTab[ 26] = new Ww1SingleSprmPDxaAbs(DUMPNAME("sprmPDxaAbs")); // 26 pap.dxaAbs
619 aTab[ 27] = new Ww1SingleSprmPDyaAbs(DUMPNAME("sprmPDyaAbs")); // 27 pap.dyaAbs
620 aTab[ 28] = new Ww1SingleSprmPDxaWidth(DUMPNAME("sprmPDxaWidth")); // 28 pap.dxaWidth
621 aTab[ 29] = new Ww1SingleSprmPpc(DUMPNAME("sprmPPc")); // 29 pap.pcHorz, pap.pcVert
622 aTab[ 30] = new Ww1SingleSprmPBrc10(BRC_TOP, DUMPNAME("sprmPBrcTop10")); // 30 pap.brcTop BRC10
623 aTab[ 31] = new Ww1SingleSprmPBrc10(BRC_LEFT, DUMPNAME("sprmPBrcLeft10")); // 31 pap.brcLeft BRC10
624 aTab[ 32] = new Ww1SingleSprmPBrc10(BRC_BOTTOM, DUMPNAME("sprmPBrcBottom10")); // 32 pap.brcBottom BRC10
625 aTab[ 33] = new Ww1SingleSprmPBrc10(BRC_RIGHT, DUMPNAME("sprmPBrcRight10")); // 33 pap.brcRight BRC10
626 aTab[ 34] = new Ww1SingleSprmWord(DUMPNAME("sprmPBrcBetween10")); // 34 pap.brcBetween BRC10
627 aTab[ 35] = new Ww1SingleSprmPBrc10(BRC_LEFT, DUMPNAME("sprmPBrcBar10")); // 35 pap.brcBar BRC10
628 aTab[ 36] = new Ww1SingleSprmPFromText(DUMPNAME("sprmPFromText10")); // 36 pap.dxaFromText dxa
629 aTab[ 37] = new Ww1SingleSprmByte(DUMPNAME("sprmPWr")); // 37 pap.wr wr
630 aTab[ 38] = new Ww1SingleSprmWord(DUMPNAME("sprmPBrcTop")); // 38 pap.brcTop BRC
631 aTab[ 39] = new Ww1SingleSprmWord(DUMPNAME("sprmPBrcLeft")); // 39 pap.brcLeft BRC
632 aTab[ 40] = new Ww1SingleSprmWord(DUMPNAME("sprmPBrcBottom")); // 40 pap.brcBottom BRC
633 aTab[ 41] = new Ww1SingleSprmWord(DUMPNAME("sprmPBrcRight")); // 41 pap.brcRight BRC
634 aTab[ 42] = new Ww1SingleSprmWord(DUMPNAME("sprmPBrcBetween")); // 42 pap.brcBetween BRC
635 aTab[ 43] = new Ww1SingleSprmWord(DUMPNAME("sprmPBrcBar")); // 43 pap.brcBar BRC word
636 aTab[ 44] = new Ww1SingleSprmBool(DUMPNAME("sprmPFNoAutoHyph")); // 44 pap.fNoAutoHyph
637 aTab[ 45] = new Ww1SingleSprmWord(DUMPNAME("sprmPWHeightAbs")); // 45 pap.wHeightAbs w
638 aTab[ 46] = new Ww1SingleSprmWord(DUMPNAME("sprmPDcs")); // 46 pap.dcs DCS
639 aTab[ 47] = new Ww1SingleSprmWord(DUMPNAME("sprmPShd")); // 47 pap.shd SHD
640 aTab[ 48] = new Ww1SingleSprmWord(DUMPNAME("sprmPDyaFromText")); // 48 pap.dyaFromText dya
641 aTab[ 49] = new Ww1SingleSprmWord(DUMPNAME("sprmPDxaFromText")); // 49 pap.dxaFromText dxa
642 aTab[ 50] = new Ww1SingleSprmBool(DUMPNAME("sprmPFLocked")); // 50 pap.fLocked 0 or 1 byte
643 aTab[ 51] = new Ww1SingleSprmBool(DUMPNAME("sprmPFWidowControl")); // 51 pap.fWidowControl 0 or 1 byte
645 aTab[ 57] = new Ww1SingleSprmByteSized(0, DUMPNAME("sprmCDefault")); // 57 whole CHP (see below) none variable length
646 aTab[ 58] = new Ww1SingleSprm(0, DUMPNAME("sprmCPlain")); // 58 whole CHP (see below) none 0
648 aTab[ 60] = new Ww1SingleSprm4State(DUMPNAME("sprmCFBold")); // 60 chp.fBold 0,1, 128, or 129 (see below) byte
649 aTab[ 61] = new Ww1SingleSprm4State(DUMPNAME("sprmCFItalic")); // 61 chp.fItalic 0,1, 128, or 129 (see below) byte
650 aTab[ 62] = new Ww1SingleSprm4State(DUMPNAME("sprmCFStrike")); // 62 chp.fStrike 0,1, 128, or 129 (see below) byte
651 aTab[ 63] = new Ww1SingleSprm4State(DUMPNAME("sprmCFOutline")); // 63 chp.fOutline 0,1, 128, or 129 (see below) byte
652 aTab[ 64] = new Ww1SingleSprm4State(DUMPNAME("sprmCFShadow")); // 64 chp.fShadow 0,1, 128, or 129 (see below) byte
653 aTab[ 65] = new Ww1SingleSprm4State(DUMPNAME("sprmCFSmallCaps")); // 65 chp.fSmallCaps 0,1, 128, or 129 (see below) byte
654 aTab[ 66] = new Ww1SingleSprm4State(DUMPNAME("sprmCFCaps")); // 66 chp.fCaps 0,1, 128, or 129 (see below) byte
655 aTab[ 67] = new Ww1SingleSprm4State(DUMPNAME("sprmCFVanish")); // 67 chp.fVanish 0,1, 128, or 129 (see below) byte
656 aTab[ 68] = new Ww1SingleSprmWord(DUMPNAME("sprmCFtc")); // 68 chp.ftc ftc word
657 aTab[ 69] = new Ww1SingleSprmByte(DUMPNAME("sprmCKul")); // 69 chp.kul kul byte
658 aTab[ 70] = new Ww1SingleSprm(3, DUMPNAME("sprmCSizePos")); // 70 chp.hps, chp.hpsPos (see below) 3 bytes
659 aTab[ 71] = new Ww1SingleSprmWord(DUMPNAME("sprmCDxaSpace")); // 71 chp.dxaSpace dxa word
660 aTab[ 72] = new Ww1SingleSprmWord(DUMPNAME("//")); // 72 //
661 aTab[ 73] = new Ww1SingleSprmByte(DUMPNAME("sprmCIco")); // 73 chp.ico ico byte
662 aTab[ 74] = new Ww1SingleSprmByte(DUMPNAME("sprmCHps")); // 74 chp.hps hps !byte!
663 aTab[ 75] = new Ww1SingleSprmByte(DUMPNAME("sprmCHpsInc")); // 75 chp.hps (see below) byte
664 aTab[ 76] = new Ww1SingleSprmWord(DUMPNAME("sprmCHpsPos")); // 76 chp.hpsPos hps !word!
665 aTab[ 77] = new Ww1SingleSprmByte(DUMPNAME("sprmCHpsPosAdj")); // 77 chp.hpsPos hps (see below) byte
666 aTab[ 78] = new Ww1SingleSprmByteSized(0, DUMPNAME(pUnknown)); // 78 ?chp.fBold, chp.fItalic, chp.fSmallCaps, ...
668 aTab[ 94] = new Ww1SingleSprmByte(DUMPNAME("sprmPicBrcl")); // 94 pic.brcl brcl (see PIC structure definition) byte
669 aTab[ 95] = new Ww1SingleSprmByteSized(0, DUMPNAME("sprmPicScale")); // 95 pic.mx, pic.my, pic.dxaCropleft,
671 aTab[117] = new Ww1SingleSprmByte(DUMPNAME("sprmSBkc")); // 117 sep.bkc bkc byte
672 aTab[118] = new Ww1SingleSprmBool(DUMPNAME("sprmSFTitlePage")); // 118 sep.fTitlePage 0 or 1 byte
673 aTab[119] = new Ww1SingleSprmSColumns(DUMPNAME("sprmSCcolumns")); // 119 sep.ccolM1 # of cols - 1 word
674 aTab[120] = new Ww1SingleSprmWord(DUMPNAME("sprmSDxaColumns")); // 120 sep.dxaColumns dxa word
676 aTab[122] = new Ww1SingleSprmByte(DUMPNAME("sprmSNfcPgn")); // 122 sep.nfcPgn nfc byte
678 aTab[125] = new Ww1SingleSprmBool(DUMPNAME("sprmSFPgnRestart")); // 125 sep.fPgnRestart 0 or 1 byte
679 aTab[126] = new Ww1SingleSprmBool(DUMPNAME("sprmSFEndnote")); // 126 sep.fEndnote 0 or 1 byte
680 aTab[127] = new Ww1SingleSprmByte(DUMPNAME("sprmSLnc")); // 127 sep.lnc lnc byte
681 aTab[128] = new Ww1SingleSprmSGprfIhdt(DUMPNAME("sprmSGprfIhdt")); // 128 sep.grpfIhdt grpfihdt (see Headers and Footers topic) byte
682 aTab[129] = new Ww1SingleSprmWord(DUMPNAME("sprmSNLnnMod")); // 129 sep.nLnnMod non-neg int. word
683 aTab[130] = new Ww1SingleSprmWord(DUMPNAME("sprmSDxaLnn")); // 130 sep.dxaLnn dxa word
684 aTab[131] = new Ww1SingleSprmWord(DUMPNAME("sprmSDyaHdrTop")); // 131 sep.dyaHdrTop dya word
685 aTab[132] = new Ww1SingleSprmWord(DUMPNAME("sprmSDyaHdrBottom")); // 132 sep.dyaHdrBottom dya word
686 aTab[133] = new Ww1SingleSprmBool(DUMPNAME("sprmSLBetween")); // 133 sep.fLBetween 0 or 1 byte
687 aTab[134] = new Ww1SingleSprmByte(DUMPNAME("sprmSVjc")); // 134 sep.vjc vjc byte
688 aTab[135] = new Ww1SingleSprmWord(DUMPNAME("sprmSLnnMin")); // 135 sep.lnnMin lnn word
689 aTab[136] = new Ww1SingleSprmWord(DUMPNAME("sprmSPgnStart")); // 136 sep.pgnStart pgn word
691 aTab[146] = new Ww1SingleSprmWord(DUMPNAME("sprmTJc")); // 146 tap.jc jc word (low order byte is significant)
692 aTab[147] = new Ww1SingleSprmWord(DUMPNAME("sprmTDxaLeft")); // 147 tap.rgdxaCenter (see below) dxa word
693 aTab[148] = new Ww1SingleSprmWord(DUMPNAME("sprmTDxaGapHalf")); // 148 tap.dxaGapHalf, tap.rgdxaCenter (see below) dxa word
695 aTab[152] = new Ww1SingleSprmTDefTable10(DUMPNAME("sprmTDefTable10")); // 152 tap.rgdxaCenter, tap.rgtc complex (see below) variable length
696 aTab[153] = new Ww1SingleSprmWord(DUMPNAME("sprmTDyaRowHeight")); // 153 tap.dyaRowHeight dya word
698 aTab[158] = new Ww1SingleSprm(4, DUMPNAME("sprmTInsert")); // 158 tap.rgdxaCenter,tap.rgtc complex (see below) 4 bytes
699 aTab[159] = new Ww1SingleSprmWord(DUMPNAME("sprmTDelete")); // 159 tap.rgdxaCenter, tap.rgtc complex (see below) word
700 aTab[160] = new Ww1SingleSprm(4, DUMPNAME("sprmTDxaCol")); // 160 tap.rgdxaCenter complex (see below) 4 bytes
701 aTab[161] = new Ww1SingleSprmWord(DUMPNAME("sprmTMerge")); // 161 tap.fFirstMerged, tap.fMerged complex (see below) word
702 aTab[162] = new Ww1SingleSprmWord(DUMPNAME("sprmTSplit")); // 162 tap.fFirstMerged, tap.fMerged complex (see below) word
703 aTab[163] = new Ww1SingleSprm(5, DUMPNAME("sprmTSetBrc10")); // 163 tap.rgtc[].rgbrc complex (see below) 5 bytes
706 ////////////////////////////////////////////////////////////// SprmPapx
707 Ww1SprmPapx::Ww1SprmPapx(sal_uInt8* pByte, sal_uInt16 nSize) :
708 Ww1Sprm(Sprm(pByte, nSize), SprmSize(pByte, nSize))
710 memset(&aPapx, 0, sizeof(aPapx));
711 memcpy(&aPapx, pByte, nSize<sizeof(aPapx)?nSize:sizeof(aPapx));
714 sal_uInt16 Ww1SprmPapx::SprmSize(sal_uInt8*, sal_uInt16 nSize)
716 sal_uInt16 nRet = 0;
717 if (nSize >= sizeof(W1_PAPX))
718 nRet = nSize - ( sizeof(W1_PAPX) - 1 ); // im W1_PAPX ist das
719 // 1. SprmByte enthalten
720 return nRet;
723 sal_uInt8* Ww1SprmPapx::Sprm(sal_uInt8* pByte, sal_uInt16 nSize)
725 sal_uInt8* pRet = NULL;
726 if (nSize >= sizeof(W1_PAPX))
727 pRet = ((W1_PAPX*)(pByte))->grpprlGet();
728 return pRet;
731 /////////////////////////////////////////////////////////////////// Plc
732 Ww1Plc::Ww1Plc(Ww1Fib& rInFib, sal_uLong ulFilePos, sal_uInt16 nInCountBytes,
733 sal_uInt16 nInItemSize)
734 : p(0), nCountBytes(nInCountBytes), iMac(0), nItemSize(nInItemSize),
735 bOK(false), rFib(rInFib)
737 if (!nCountBytes)
738 bOK = true;
739 else
741 if (rFib.GetStream().Seek(ulFilePos) == (sal_uLong)ulFilePos)
743 if ((p = new sal_uInt8[nCountBytes]) != NULL)
745 if (rFib.GetStream().Read(p, nCountBytes) == (sal_uLong)nCountBytes)
747 bOK = true;
748 iMac = (nCountBytes -
749 sizeof(SVBT32)) / (sizeof(SVBT32) + nItemSize);
750 OSL_ENSURE(iMac * ((sal_uInt16)sizeof(sal_uLong) + nItemSize) +
751 (sal_uInt16)sizeof(SVBT32) == nCountBytes, "Ww1Plc");
758 Ww1Plc::~Ww1Plc()
760 delete p;
763 void Ww1Plc::Seek(sal_uLong ulSeek, sal_uInt16& nIndex)
765 if (iMac)
766 for (;nIndex <= iMac && Where(nIndex) < ulSeek;nIndex++)
770 sal_uLong Ww1Plc::Where(sal_uInt16 nIndex)
772 sal_uLong ulRet = 0xffffffff;
773 OSL_ENSURE(nIndex <= iMac, "index out of bounds");
774 if (iMac && nIndex <= iMac)
775 ulRet = SVBT32ToUInt32(p + sizeof(SVBT32) * nIndex);
776 return ulRet;
779 sal_uInt8* Ww1Plc::GetData(sal_uInt16 nIndex)
781 sal_uInt8* pRet = NULL;
782 OSL_ENSURE(nIndex < iMac, "index out of bounds");
783 if (nIndex < iMac)
784 pRet = p + (iMac + 1) * sizeof(SVBT32) +
785 nIndex * nItemSize; // Pointer auf Inhalts-Array
786 return pRet;
789 ///////////////////////////////////////////////////////////// PlcBookmarks
790 // class Ww1StringList liest im Ctor eine Anzahl von P-Strings aus dem Stream
791 // in den Speicher und patcht sie zu C-Strings um.
792 // Die Anzahl wird in nMax zurueckgeliefert.
793 // im Index 0 stehen alle Strings nacheinander, ab Index 1 werden
794 // die einzelnen Strings referenziert.
795 Ww1StringList::Ww1StringList( SvStream& rSt, sal_uLong nFc, sal_uInt16 nCb )
796 : pIdxA(0), nMax(0)
798 if( nCb > 2 ) // ueberhaupt Eintraege ?
800 SVBT16 nCountBytes;
801 OSL_ENSURE(nCb > sizeof(nCountBytes), "Ww1StringList");
802 if (rSt.Seek(nFc) == (sal_uLong)nFc)
803 if (rSt.Read(nCountBytes, sizeof(nCountBytes))
804 == sizeof(nCountBytes)) // Laenge steht hier nochmal
806 OSL_ENSURE(SVBT16ToShort(nCountBytes)
807 == nCb, "redundant-size missmatch");
808 // hoffentlich sind sie immer gleich
809 sal_Char* pA = new sal_Char[nCb - sizeof(nCountBytes) + 1];
810 // Alloziere PString-Array
811 //~ Ww1: new-NULL
812 if (rSt.Read(pA, nCb - sizeof(nCountBytes))
813 == (sal_uLong)nCb - sizeof(nCountBytes)) // lese alle
814 {}// do nothing
815 // Zaehle, wieviele Fonts enthalten
816 long nLeft = nCb - sizeof(nCountBytes);
817 sal_Char* p = pA;
818 while (1)
820 sal_uInt16 nNextSiz;
821 nNextSiz = *p + 1;
822 if(nNextSiz > nLeft)
823 break;
824 nMax++;
825 nLeft -= nNextSiz;
826 if(nLeft < 1) // naechste Laenge muss gelesen werden koennen
827 break;
828 p = p + nNextSiz;
830 if (nMax)
832 pIdxA = new sal_Char*[nMax+1]; // alloziere Index-Array
833 pIdxA[0] = pA; // Index 0 : alles
834 // ab Index 1 C-Strings
835 pIdxA[1] = pA + 1; // fuelle Index-Array
836 sal_uInt16 i = 2;
837 p = pA;
838 sal_uInt8 nL = *p;
839 while(1)
841 p += nL + 1; // Neues Laengen-Byte
842 nL = *p; // merke Laenge
843 *p = '\0'; // mach C-String draus
844 if( i > nMax )
845 break;
846 pIdxA[i] = p + 1; // Ptr auf C-String
847 i++;
850 else
851 pIdxA = 0; // Keine Eintraege -> kein Array
855 const String Ww1StringList::GetStr( sal_uInt16 nNum ) const
857 String sRet;
858 if( nNum <= nMax )
859 sRet = String( pIdxA[ nNum+1 ], RTL_TEXTENCODING_MS_1252 );
860 return sRet;
863 Ww1Bookmarks::Ww1Bookmarks(Ww1Fib& rInFib)
864 : aNames(rInFib), rFib(rInFib), nIsEnd(0)
866 pPos[0] = new Ww1PlcBookmarkPos(rFib, rFib.GetFIB().fcPlcfbkfGet(),
867 rFib.GetFIB().cbPlcfbkfGet(), sal_False);
868 nPlcIdx[0] = 0;
869 pPos[1] = new Ww1PlcBookmarkPos(rFib, rFib.GetFIB().fcPlcfbklGet(),
870 rFib.GetFIB().cbPlcfbklGet(), sal_True);
871 nPlcIdx[1] = 0;
872 bOK = !aNames.GetError() && !pPos[0]->GetError() && !pPos[1]->GetError();
875 // Der Operator ++ hat eine Tuecke: Wenn 2 Bookmarks aneinandergrenzen, dann
876 // sollte erst das Ende des ersten und dann der Anfang des 2. erreicht werden.
877 // Liegen jedoch 2 Bookmarks der Laenge 0 aufeinander, *muss* von jedem Bookmark
878 // erst der Anfang und dann das Ende gefunden werden.
879 // Der Fall: ][
880 // [...]
881 // ][
882 // ist noch nicht geloest, dabei muesste ich in den Anfangs- und Endindices
883 // vor- und zurueckspringen, wobei ein weiterer Index oder ein Bitfeld
884 // oder etwas aehnliches zum Merken der bereits abgearbeiteten Bookmarks
885 // noetig wird.
886 void Ww1Bookmarks::operator++()
888 if( bOK )
890 nPlcIdx[nIsEnd]++;
892 sal_uLong l0 = pPos[0]->Where(nPlcIdx[0]);
893 sal_uLong l1 = pPos[1]->Where(nPlcIdx[1]);
894 if( l0 < l1 )
895 nIsEnd = 0;
896 else if( l1 < l0 )
897 nIsEnd = 1;
898 else
899 nIsEnd = ( nIsEnd ) ? 0 : 1;
903 long Ww1Bookmarks::GetHandle() const
905 if( bOK )
907 if( nIsEnd )
908 return nPlcIdx[1];
910 const sal_uInt8* p = pPos[0]->GetData( nPlcIdx[0] );
911 if( p )
912 return SVBT16ToShort( p );
914 return LONG_MAX;
917 long Ww1Bookmarks::Len() const
919 if( nIsEnd )
921 OSL_ENSURE( sal_False, "Falscher Aufruf (1) von Ww1Bookmarks::Len()" );
922 return 0;
924 sal_uInt16 nEndIdx = SVBT16ToShort(pPos[0]->GetData(nPlcIdx[0]));
925 return pPos[1]->Where(nEndIdx) - pPos[0]->Where(nPlcIdx[0]);
928 const String Ww1Bookmarks::GetName() const
930 if( nIsEnd )
931 return OUString("???");
932 return aNames.GetStr( nPlcIdx[0] );
935 /////////////////////////////////////////////////////////////////// Fkp
936 Ww1Fkp::Ww1Fkp(SvStream& rStream, sal_uLong ulFilePos, sal_uInt16 _nItemSize) :
937 nItemSize(_nItemSize),
938 bOK(sal_False)
940 if (rStream.Seek(ulFilePos) == (sal_uLong)ulFilePos)
941 if (rStream.Read(aFkp, sizeof(aFkp)) == sizeof(aFkp))
942 bOK = sal_True;
945 sal_uLong Ww1Fkp::Where(sal_uInt16 nIndex)
947 sal_uLong lRet = 0xffffffff;
948 OSL_ENSURE(nIndex<=Count(), "index out of bounds");
949 if (nIndex<=Count())
950 lRet = SVBT32ToUInt32(aFkp+nIndex*sizeof(SVBT32));
951 return lRet;
954 sal_uInt8* Ww1Fkp::GetData(sal_uInt16 nIndex)
956 sal_uInt8* pRet = NULL;
957 OSL_ENSURE(nIndex<=Count(), "index out of bounds");
958 if (nIndex<=Count())
959 pRet = aFkp + (Count()+1) * sizeof(SVBT32) +
960 nIndex * nItemSize; // beginn der strukturen
961 return pRet;
964 //////////////////////////////////////////////////////////////// FkpPap
965 sal_Bool Ww1FkpPap::Fill(sal_uInt16 nIndex, sal_uInt8*& p, sal_uInt16& rnCountBytes)
967 OSL_ENSURE( nIndex < Count(), "Ww1FkpPap::Fill() Index out of Range" );
968 sal_uInt16 nOffset = SVBT8ToByte(GetData(nIndex)) * 2;
969 if (nOffset)
971 OSL_ENSURE(nOffset>(sal_uInt16)(Count()*sizeof(SVBT32)), "calc error");
972 rnCountBytes = SVBT8ToByte(aFkp+nOffset) * 2;
973 nOffset += sizeof(SVBT8);
974 if( nOffset + rnCountBytes < 511 ) // SH: Assert schlug 1 zu frueh zu
975 rnCountBytes++; // SH: Ich weiss nicht genau,
976 // ob das letzte Byte des PAPX
977 // genutzt wird, aber so vergessen
978 // wir keins und sind trotzdem
979 // auf der sicheren Seite
980 OSL_ENSURE(nOffset+rnCountBytes <= 511, "calc error");
981 p = aFkp + nOffset;
983 else
985 p = NULL;
986 rnCountBytes = 0;
988 return sal_True;
991 //////////////////////////////////////////////////////////////// FkpChp
992 sal_Bool Ww1FkpChp::Fill(sal_uInt16 nIndex, W1_CHP& aChp)
994 OSL_ENSURE( nIndex < Count(), "Ww1FkpChp::Fill() Index out of Range" );
995 memset(&aChp, 0, sizeof(aChp)); // Default, da verkuerzt gespeichert
996 sal_uInt16 nOffset = GetData(nIndex)[0] * 2;
997 if (nOffset)
999 OSL_ENSURE(nOffset>(sal_uInt16)(Count()*sizeof(SVBT32)), "calc error");
1000 sal_uInt16 nCountBytes = aFkp[nOffset];
1001 nOffset += sizeof(SVBT8);
1002 OSL_ENSURE(nCountBytes <= 511-nOffset, "calc error");
1003 OSL_ENSURE(nCountBytes <= sizeof(aChp), "calc error");
1004 memcpy(&aChp, aFkp+nOffset, nCountBytes);
1006 return sal_True;
1009 ///////////////////////////////////////////////////////////////// Assoc
1010 Ww1Assoc::Ww1Assoc(Ww1Fib& _rFib)
1011 : rFib(_rFib), pBuffer(NULL), bOK(sal_False)
1013 sal_uInt16 cb = rFib.GetFIB().cbSttbfAssocGet();
1014 sal_uInt16 i;
1016 for ( i = 0; i < MaxFields; i++ )
1017 pStrTbl[i] = NULL;
1018 if ((pBuffer = new sal_Char[cb]) != NULL
1019 && rFib.GetStream().Seek(rFib.GetFIB().fcSttbfAssocGet()) ==
1020 rFib.GetFIB().fcSttbfAssocGet()
1021 && rFib.GetStream().Read(pBuffer, cb) == cb)
1023 sal_uInt16 j;
1024 OSL_ENSURE( cb == SVBT16ToShort( *(SVBT16*)pBuffer ), "size missmatch");
1025 for (i=0,j=sizeof(SVBT16);j<cb && i<Criteria1;i++)
1027 pStrTbl[i] = pBuffer+j;
1028 j += (*pBuffer + j) + 1;
1030 bOK = sal_True;
1034 String Ww1Assoc::GetStr(sal_uInt16 code)
1036 OStringBuffer sRet;
1037 OSL_ENSURE(code<MaxFields, "out of range");
1038 if (pStrTbl[code] != NULL)
1039 for( sal_uInt16 i=0;i<pStrTbl[code][0];i++ )
1040 sRet.append(pStrTbl[code][i+1]);
1041 return OStringToOUString(sRet.makeStringAndClear(),
1042 RTL_TEXTENCODING_MS_1252);
1045 /////////////////////////////////////////////////////////////////// Pap
1046 Ww1Pap::Ww1Pap(Ww1Fib& _rFib)
1047 : Ww1PlcPap(_rFib), nPlcIndex(0), nPushedPlcIndex(0xffff), nFkpIndex(0),
1048 nPushedFkpIndex(0xffff), ulOffset(0), pPap(0)
1052 void Ww1Pap::Seek(sal_uLong ulSeek)
1054 while (ulSeek > Where())
1055 ++(*this);
1058 // SH: Where hat einen Parameter mitbekommen, der sagt, ob bei Neuanlegen eines
1059 // Fkps der zugehoerige Index auf 0 gesetzt werden soll
1060 // ( darf fuer Push/Pop nicht passieren )
1061 // Ein eleganterer Weg faellt mir auf die Schnelle nicht ein
1062 sal_uLong Ww1Pap::Where( sal_Bool bSetIndex )
1064 sal_uLong ulRet = 0xffffffff;
1065 if (pPap == NULL)
1066 if (nPlcIndex < Count())
1068 pPap = new Ww1FkpPap(rFib.GetStream(),
1069 SVBT16ToShort(GetData(nPlcIndex)) << 9);
1070 if( bSetIndex )
1071 nFkpIndex = 0;
1073 if (pPap != NULL)
1074 if (nFkpIndex <= pPap->Count())
1075 ulRet = pPap->Where(nFkpIndex) - rFib.GetFIB().fcMinGet();
1076 return ulRet;
1079 void Ww1Pap::operator++()
1081 if (pPap != NULL)
1082 if (++nFkpIndex > pPap->Count())
1084 delete pPap;
1085 pPap = NULL;
1086 nPlcIndex++;
1090 // SH: FindSprm sucht in grpprl nach Sprm nId
1091 // Rueckgabe: Pointer oder 0
1092 sal_Bool Ww1Pap::FindSprm(sal_uInt16 nId, sal_uInt8* pStart, sal_uInt8* pEnd)
1094 Ww1Sprm aSprm( pStart, static_cast< sal_uInt16 >(pEnd-pStart) );
1095 sal_uInt16 nC = aSprm.Count();
1096 sal_uInt16 i;
1097 sal_uInt8 nI;
1098 sal_uInt16 nLen;
1099 sal_uInt8 *pData;
1100 for( i = 0; i < nC; i++ ){
1101 aSprm.Fill( i, nI, nLen, pData );
1102 if( nI == nId )
1103 return sal_True;
1105 return sal_False;
1108 sal_Bool Ww1Pap::HasId0(sal_uInt16 nId)
1110 sal_Bool bRet = sal_False;
1111 UpdateIdx();
1113 if( !pPap ){
1114 OSL_ENSURE( sal_False, "Ww1Pap::HasId():: kann kein pPap erzeugen" );
1115 return sal_False;
1118 sal_uInt8* pByte;
1119 sal_uInt16 n;
1120 if( pPap->Fill(nFkpIndex, pByte, n) ){
1121 sal_uInt8* p2 = ((W1_PAPX*)(pByte))->grpprlGet(); // SH: Offset fehlte
1122 bRet = FindSprm( nId, p2, pByte + n );
1124 return bRet;
1127 sal_Bool Ww1Pap::HasId(sal_uInt16 nId)
1129 sal_uInt16 nPushedPlcIndex2 = nPlcIndex;
1130 sal_uInt16 nPushedFkpIndex2 = nFkpIndex;
1131 sal_Bool bRet = HasId0( nId );
1132 if (nPlcIndex != nPushedPlcIndex2)
1134 delete pPap;
1135 pPap = NULL;
1137 nPlcIndex = nPushedPlcIndex2;
1138 nFkpIndex = nPushedFkpIndex2;
1139 Where( sal_False );
1140 return bRet;
1143 /////////////////////////////////////////////////////////////////// Chp
1144 Ww1Chp::Ww1Chp(Ww1Fib& _rFib)
1145 : Ww1PlcChp(_rFib), nPlcIndex(0), nPushedPlcIndex(0xffff), nFkpIndex(0),
1146 nPushedFkpIndex(0xffff), ulOffset(0), pChp(0)
1150 void Ww1Chp::Seek(sal_uLong ulSeek)
1152 while (ulSeek > Where())
1153 ++(*this);
1156 // SH: Where hat einen Parameter mitbekommen, der sagt, ob bei Neuanlegen eines
1157 // Fkps der zugehoerige Index auf 0 gesetzt werden soll
1158 // ( darf fuer Push/Pop nicht passieren )
1159 // Ein eleganterer Weg faellt mir auf die Schnelle nicht ein
1160 sal_uLong Ww1Chp::Where( sal_Bool bSetIndex )
1162 sal_uLong ulRet = 0xffffffff;
1163 if (pChp == NULL)
1164 if (nPlcIndex < Count())
1166 pChp = new Ww1FkpChp(rFib.GetStream(),
1167 SVBT16ToShort(GetData(nPlcIndex)) << 9);
1168 if( bSetIndex )
1169 nFkpIndex = 0;
1171 if (pChp != NULL)
1172 if (nFkpIndex <= pChp->Count())
1173 ulRet = pChp->Where(nFkpIndex) -
1174 rFib.GetFIB().fcMinGet() - ulOffset;
1175 return ulRet;
1178 void Ww1Chp::operator++()
1180 if (pChp != NULL)
1181 if (++nFkpIndex > pChp->Count())
1183 delete pChp;
1184 pChp = NULL;
1185 nPlcIndex++;
1189 ////////////////////////////////////////////////////////////// Manager
1190 Ww1Manager::Ww1Manager(SvStream& rStrm, sal_uLong nFieldFlgs)
1191 : bOK(sal_False), bInTtp(false), bInStyle(false), bStopAll(false), aFib(rStrm),
1192 aDop(aFib), aFonts(aFib, nFieldFlgs), aDoc(aFib), pDoc(&aDoc),
1193 ulDocSeek(0), pSeek(&ulDocSeek), aFld(aFib), pFld(&aFld), aChp(aFib),
1194 aPap(aFib), aFtn(aFib), aBooks(aFib),
1195 aSep(aFib, aDop.GetDOP().grpfIhdtGet())
1197 bOK = !aFib.GetError()
1198 && !aFib.GetFIB().fComplexGet()
1199 && !aDoc.GetError()
1200 && !aSep.GetError()
1201 && !aPap.GetError()
1202 && !aChp.GetError()
1203 && !aFld.GetError()
1204 && !aFtn.GetError()
1205 && !aBooks.GetError();
1208 sal_Bool Ww1Manager::HasInTable()
1210 return aPap.HasId(24); // Ww1SingleSprmPFInTable
1213 sal_Bool Ww1Manager::HasTtp()
1215 return aPap.HasId(25); // Ww1SingleSprmPTtp
1218 sal_Bool Ww1Manager::HasPPc()
1220 return aPap.HasId(29); // Ww1SingleSprmPPc
1223 sal_Bool Ww1Manager::HasPDxaAbs()
1225 return aPap.HasId(26); // Ww1SingleSprmPDxaAbs
1228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */