summaryrefslogtreecommitdiffstats
path: root/binfilter/bf_sw/source/core/sw3io/sw_sw3page.cxx
blob: 6af46dd6eef1e8a7f0be643c0dce55ddd8672b56 (plain)
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */


#ifdef _MSC_VER
#pragma hdrstop
#endif

#include <bf_svtools/bf_solar.h>

#include "swerror.h"

#include <horiornt.hxx>

#include "doc.hxx"

#include <tools/tenccvt.hxx>

#include <osl/diagnose.h>

#include <fmtcol.hxx>

#include <fmthdft.hxx>
#include <fmtpdsc.hxx>
#include <hints.hxx>
#include "sw3imp.hxx"
#include "pagedesc.hxx"
#include "poolfmt.hxx"
namespace binfilter {


////////////////////////////////////////////////////////////////////////////

// Fussnoten-Info einlesen

/*N*/ void Sw3IoImp::InPageFtnInfo( SwPageFtnInfo& rFtn )
/*N*/ {
/*N*/   INT32 nHeight, nTopDist, nBottomDist, nNum, nDenom;
/*N*/   INT16 nAdjust, nPenWidth;
/*N*/   Color aPenColor;
/*N*/   BYTE cType = Peek();
/*N*/   if( cType == SWG_FOOTINFO || cType == SWG_PAGEFOOTINFO )
/*N*/   {
/*N*/       OpenRec( cType );
/*N*/       *pStrm >> nHeight
/*N*/              >> nTopDist
/*N*/              >> nBottomDist
/*N*/              >> nAdjust
/*N*/              >> nNum >> nDenom
/*N*/              >> nPenWidth
/*N*/              >> aPenColor;
/*N*/       CloseRec( cType );
/*N*/       rFtn.SetHeight( (SwTwips) nHeight );
/*N*/       rFtn.SetTopDist( (SwTwips) nTopDist );
/*N*/       rFtn.SetBottomDist( (SwTwips) nBottomDist );
/*N*/       rFtn.SetAdj( (SwFtnAdj) nAdjust );
/*N*/       Fraction f( nNum, nDenom );
/*N*/       rFtn.SetWidth( f );
/*N*/       rFtn.SetLineColor( aPenColor );
/*N*/       rFtn.SetLineWidth( nPenWidth );
/*N*/   }
/*N*/   else
/*N*/       Error();
/*N*/ }

/*N*/ void Sw3IoImp::InPageDescs()
/*N*/ {
/*N*/   if( Peek() != SWG_STRINGPOOL )
/*N*/   {
/*N*/       InHeader( TRUE );
/*N*/       if( !Good() )
/*N*/           return;
/*N*/   }
/*N*/   else
/*N*/       nVersion = SWG_FRSTVERSION;
/*N*/   // Der Stream koennte auch leer sein, falls eine leere Textbaustein-
/*N*/   // datei eingelesen wird.
/*N*/   if( Peek() == SWG_STRINGPOOL )
/*N*/   {
/*N*/       InStringPool( SWG_STRINGPOOL, aStringPool );
/*N*/
/*N*/       while( SWG_FIELDTYPE == Peek() )
/*N*/           InFieldType();
/*N*/
/*N*/       if( SWG_BOOKMARKS == Peek() )
/*N*/           InBookmarks();
/*N*/
/*N*/       if( SWG_REDLINES == Peek() )
                InRedlines(); //SW50.SDW
/*N*/
/*N*/       // ggfs. dem Numberformatter lesen
/*N*/       if( SWG_NUMBERFORMATTER == Peek() )
/*N*/           InNumberFormatter();
/*N*/
/*N*/       OpenRec( SWG_PAGEDESCS );
/*N*/       OpenFlagRec();
/*N*/       USHORT nDesc;
/*N*/       *pStrm >> nDesc;
/*N*/       CloseFlagRec();
/*N*/       if( nDesc > 0 )
/*N*/       {
/*N*/           USHORT* pFollows = new USHORT[ nDesc ];
/*N*/           SwPageDesc** pDescs = new SwPageDesc*[ nDesc ];
                USHORT i=0;
/*N*/           for( i = 0; i < nDesc; i++ )
/*N*/               pDescs[ i ] = InPageDesc( pFollows[ i ] );
/*N*/           // Follows aufloesen
/*N*/           for( i = 0; i < nDesc; i++ )
/*N*/           {
/*N*/               USHORT nFollow = pFollows[ i ];
/*N*/               SwPageDesc* pDesc = pDescs[ i ];
/*N*/               if( pDesc && nFollow < IDX_SPEC_VALUE )
/*N*/                   pDesc->SetFollow( FindPageDesc( nFollow ) );
/*N*/           }
/*N*/             delete []pDescs;
/*N*/             delete []pFollows;
/*N*/       }
/*N*/       else if( nDesc )
/*N*/           Error();
/*N*/
/*N*/ #ifdef TEST_HUGE_DOCS
/*N*/       if( SWG_TESTHUGEDOCS == Peek() )
/*N*/           InHugeRecord();
/*N*/ #endif
/*N*/
/*N*/       CloseRec( SWG_PAGEDESCS );
/*N*/
/*N*/       // Aufraeumen, wenn Seitenvorlagen geladen wurden
/*N*/       if( bPageDescs )
/*N*/       {
/*?*/           SwDBData aOldData(pDoc->_GetDBDesc());
/*?*/
/*?*/           // fuer Versionen ohne mehrfache Datenbanken wird jetzt der
/*?*/           // Datenbankname gelesen.
/*?*/           // if( !nRes && nVersion < SWG_MULTIDB )
/*?*/           if( !nRes &&
/*?*/               !IsVersion( SWG_MULTIDB, SWG_EXPORT31, SWG_DESKTOP40 ) )
                    SetDBName();
/*?*/           Cleanup();
/*?*/
/*?*/           pDoc->ChgDBData( aOldData );
/*N*/       }
/*N*/       else if( bOrganizer )
/*N*/       {
/*N*/           //JP 18.08.98: Bug 55115 - PageDescAttribute mit ihren Vorlagen
/*N*/           //              verbinden
/*?*/           ConnectPageDescAttrs();
/*?*/           if( osl_getThreadTextEncoding() != eSrcSet )
/*?*/               ChangeFontItemCharSet();
/*?*/
/*?*/           // Temporaere Namenserweiterungen entfernen
/*?*/           aStringPool.RemoveExtensions( *pDoc );
/*?*/           ConvertFmtsToStarSymbol();
/*N*/       }
/*N*/       // TODO: unicode: is this required really?
/*N*/       eSrcSet = GetSOLoadTextEncoding( osl_getThreadTextEncoding() );
/*N*/   }
/*N*/ }

void Sw3IoImp::SetDBName()
{
    SvStream* pOld = pStrm;
    pContents->Seek( 0L );
    pContents->SetBufferSize( SW3_BSR_CONTENTS );
    pStrm = pContents;

    // Erstmal den Header lesen
    BYTE cLen, cSet;
    INT8 nLCompatVer, nDummy8;
    USHORT nLVersion, nLFileFlags;
    INT32 nDummy32;
    sal_Char cHdrSign[ 8 ];

    Reset2();
    OutputMode( FALSE );

    if( pStrm->Read( cHdrSign, 7 ) != 7 || !CheckHeader(cHdrSign) )
    {
        Error( ERR_SW6_NOWRITER_FILE );
        return;
    }
    *pStrm >> cLen;

    // nRecSizesPos braucht hier nicht gelesen zu werden, da die Methode
    // nicht fuer eine 5.0 ff aufgerufen wird.
    ULONG nOld = pStrm->Tell();
    *pStrm >> nLVersion >> nLFileFlags >> nDummy32 >> nDummy32 >> nDummy32
           >> nDummy8 >> nDummy8 >> nDummy8 >> nLCompatVer;
    if( nLCompatVer > SWG_CVERSION )
    {
        Error( ERR_SWG_NEW_VERSION );
        return;
    }
    if( nLFileFlags & SWGF_BAD_FILE )
    {
        Error( ERR_SWG_READ_ERROR );
        return;
    }

    pStrm->Read( cPasswd, 16L );
    *pStrm >> cSet >> nDummy8 >> nDummy32 >> nDummy32;
    if( nLFileFlags & SWGF_BLOCKNAME )
    {
        BYTE cBuf[ 64 ];
        if( pStrm->Read( cBuf, 64 ) != 64 )
            pStrm->SetError( SVSTREAM_FILEFORMAT_ERROR );
    }

    ULONG nNew = pStrm->Tell();
    nOld += cLen;
    if( nOld != nNew )
        pStrm->Seek( nOld );

    BOOL bDone = FALSE;

    // Normales Lesen?
    while( !bDone )
    {
        BYTE cType = Peek();
        if( !Good() || pStrm->IsEof() )
            bDone = TRUE;
        else switch( cType )
        {
            case SWG_EOF:
                bDone = TRUE;
                break;

            case SWG_DBNAME:
            {
                String sDBName;
                OpenRec( SWG_DBNAME );

                rtl::OString s8 = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(*pStrm);
                rtl_TextEncoding eEnc = GetSOLoadTextEncoding(
                                (rtl_TextEncoding)cSet );
                sDBName = ConvertStringNoDbDelim( s8, eEnc );
                SwDBData aData;
                aData.sDataSource = sDBName.GetToken(0, DB_DELIM);
                aData.sCommand = sDBName.GetToken(1, DB_DELIM);
                pDoc->ChgDBData( aData );

                ULONG nSaveWarn = nWarn;
                CloseRec( SWG_DBNAME );
                nWarn = nSaveWarn;
            }
            break;

            default:
                SkipRec();
        }
    }

    pStrm = pOld;
    CheckIoError( pContents );
    pContents->SetBufferSize( 0 );
}

// Seitenvorlage einlesen

/*N*/ SwPageDesc* Sw3IoImp::InPageDesc( USHORT& nFollow )
/*N*/ {
/*N*/   OpenRec( SWG_PAGEDESC );
/*N*/   short nUsedOn;
/*N*/   // 0x10 - Landscape mode
/*N*/   BYTE cFlags = OpenFlagRec();
/*N*/   USHORT nIdx = 0, nPoolId = 0;
/*N*/   USHORT nRegCollIdx = IDX_NO_VALUE;
/*N*/   BYTE nNumType;
/*N*/   *pStrm >> nIdx >> nFollow >> nPoolId >> nNumType >> nUsedOn;
/*N*/   if( IsVersion( SWG_REGISTER, SWG_EXPORT31, SWG_DESKTOP40 ) )
/*N*/       *pStrm >> nRegCollIdx;
/*N*/   CloseFlagRec();
/*N*/   if( nRes )
/*N*/       return NULL;
/*N*/
/*N*/   const String& rName = aStringPool.Find( nIdx );
/*N*/   SwPageDesc* pDesc = NULL;
/*N*/   // Gibt es diese Vorlage bereits?
/*N*/   BOOL bPresent = FALSE;
/*N*/   USHORT nPos=0;
/*N*/   if( bInsert )
/*N*/   {
/*?*/       USHORT nArrLen = pDoc->GetPageDescCnt();
/*?*/       for( nPos = 0; nPos < nArrLen; nPos++ )
/*?*/       {
/*?*/           pDesc = &pDoc->_GetPageDesc( nPos );
/*?*/           if( pDesc->GetName() == rName )
/*?*/           {
/*?*/               bPresent = TRUE; break;
/*?*/           }
/*?*/       }
/*?*/       if( bPresent && bAdditive )
/*?*/       {
/*?*/           // Nur hinzufuegen: lass die Vorlage in Ruhe!
/*?*/           // Dabei geht nichts verloren, also nWarn retten
/*?*/           ULONG nWarnSave = nWarn;
/*?*/           CloseRec( SWG_PAGEDESC );
/*?*/           nWarn = nWarnSave;
/*?*/           return NULL;
/*N*/       }
/*N*/   }
/*N*/   if( bPresent )
/*N*/       // Ueberplaetten im Insert Mode: wir brauchen eine Kopie
/*?*/       pDesc = new SwPageDesc( *pDesc );
/*N*/   else
/*N*/   {
/*N*/       // Sonst bauen wir uns eine
/*N*/       if( nPoolId != IDX_NO_VALUE )
/*N*/       {
/*N*/           // Fehlerfall: unbekannte Poolvorlage -> neu anlegen
/*N*/           if( RES_POOLPAGE_BEGIN > nPoolId ||  nPoolId >= RES_POOLPAGE_END )
/*N*/           {
/*?*/               OSL_ENSURE( !this, "ungueltige Id" );
/*?*/               nPoolId = IDX_NO_VALUE;
/*N*/           }
/*N*/       }
/*N*/
/*N*/       if( nPoolId != IDX_NO_VALUE )
/*N*/           pDesc = pDoc->GetPageDescFromPool( nPoolId );
/*N*/       else
/*N*/           pDesc = &pDoc->_GetPageDesc( pDoc->MakePageDesc( rName ) );
/*N*/   }
/*N*/
/*N*/   SvxNumberType aType;
/*N*/   aType.SetNumberingType(nNumType);
/*N*/   pDesc->SetNumType( aType );
/*N*/   pDesc->WriteUseOn( UseOnPage( nUsedOn ) );
/*N*/   pDesc->SetLandscape( BOOL( ( cFlags & 0x10 ) != 0 ) );
/*N*/   if( nPoolId != IDX_NO_VALUE )
/*N*/       pDesc->SetPoolFmtId( nPoolId );
/*N*/
/*N*/   if( nRegCollIdx != IDX_NO_VALUE )
/*N*/       pDesc->SetRegisterFmtColl( FindTxtColl( nRegCollIdx ) );
/*N*/
/*N*/   pDesc->ResetAllMasterAttr();
/*N*/   pDesc->ResetAllLeftAttr();
/*N*/   // Header und Footer sind Shared-Formate
/*N*/   nGblFlags |= SW3F_SHAREDFMT;
/*N*/   short nAttrSet = 0;
/*N*/   while( BytesLeft() )
/*N*/   {
/*N*/       BYTE cType = Peek();
/*N*/       switch( cType )
/*N*/       {
/*N*/           case SWG_FOOTINFO:
/*N*/           case SWG_PAGEFOOTINFO:
/*N*/               InPageFtnInfo( pDesc->GetFtnInfo() ); break;
/*N*/           case SWG_ATTRSET:
/*N*/               switch( ++nAttrSet )
/*N*/               {
/*N*/                   case 1: InAttrSet( (SwAttrSet&) pDesc->GetMaster().GetAttrSet() );
/*N*/                           break;
/*N*/                   case 2: InAttrSet( (SwAttrSet&) pDesc->GetLeft().GetAttrSet() );
/*N*/                           break;
/*?*/                   default: Error(); OpenRec( cType ); CloseRec( cType );
/*N*/               } break;
/*N*/           default:
/*?*/               SkipRec();
/*N*/       }
/*N*/   }
/*N*/   CloseRec( SWG_PAGEDESC );
/*N*/   // Hdr/Ftr-Formate umsetzen:
/*N*/   if( pDesc->IsHeaderShared() )
/*N*/   {
/*N*/       const SwFmtHeader& rFmtM = pDesc->GetMaster().GetHeader();
/*N*/       pDesc->GetLeft().SetAttr( rFmtM );
/*N*/   }
/*N*/   if( pDesc->IsFooterShared() )
/*N*/   {
/*N*/       const SwFmtFooter& rFmtM = pDesc->GetMaster().GetFooter();
/*N*/       pDesc->GetLeft().SetAttr( rFmtM );
/*N*/   }
/*N*/   nGblFlags &= ~SW3F_SHAREDFMT;
/*N*/
/*N*/   if( bPresent )
/*N*/   {
/*N*/       // Kopie uebernehmen
/*?*/       pDoc->ChgPageDesc( nPos, *pDesc );
/*?*/       delete pDesc;
/*?*/       pDesc = &pDoc->_GetPageDesc( nPos );
/*N*/   }
/*N*/
/*N*/   return pDesc;
/*N*/ }

// PageDesc-Attribute koennen in einer Absatzvorlage vorkommen; diese
// werden vor den Seitenvorlagen eingelesen, so dass eine Vorwaerts-
// Referenz entsteht. Die Einleseroutine legt den Stringpool-Index
// des Vorlagennamens im Attribut ab. Nach dem Einlesen muss die Vorlage
// dann noch verbunden werden.

// Aufloesen aller Seitenbeschreibungs-Attribute
// Die Attribute werden aus dem Pool entnommen und die
// korrekten Seitenvorlagen werden eingetragen.

/*N*/ void Sw3IoImp::ConnectPageDescAttrs()
/*N*/ {
/*N*/   SfxItemPool& rPool = pDoc->GetAttrPool();
/*N*/   USHORT nArrLen = rPool.GetItemCount( RES_PAGEDESC );
/*N*/   for( USHORT n = 0; n < nArrLen; n++ )
/*N*/   {
/*N*/       SwFmtPageDesc* pAttr =
/*N*/           (SwFmtPageDesc*) rPool.GetItem( RES_PAGEDESC, n );
/*N*/       if( pAttr && pAttr->GetDescNameIdx() != IDX_NO_VALUE )
/*N*/       {
/*N*/           SwPageDesc* pDesc = FindPageDesc( pAttr->GetDescNameIdx() );
/*N*/           pAttr->SetDescNameIdx( IDX_NO_VALUE );
/*N*/           OSL_ENSURE( pDesc, "Unbekannte Seitenvorlage fuer PageDesc-Attribut" );
/*N*/           if( pDesc )
/*N*/           {
/*N*/               pDesc->Add( pAttr );
/*N*/               if( bInsert && pAttr->GetDefinedIn() )
/*N*/               {
/*N*/                   // dann sollte das Layout auch etwas davon mitbekommen.
/*N*/                   if( pAttr->GetDefinedIn()->ISA( SwTxtFmtColl ) )
/*N*/                   {
/*N*/                       const SwTxtFmtColl *pColl =
/*N*/                           static_cast< const SwTxtFmtColl * >( pAttr->GetDefinedIn() );
/*N*/                       SwAttrSet aChgSet( *pColl->GetAttrSet().GetPool(), RES_PAGEDESC, RES_PAGEDESC );
/*N*/                       aChgSet.Put( *pAttr );
/*N*/                       SwAttrSetChg aOld( pColl->GetAttrSet(), aChgSet );
/*N*/                       SwAttrSetChg aNew( pColl->GetAttrSet(), aChgSet );
/*N*/
/*N*/                       const_cast < SwTxtFmtColl *>( pColl )->Modify( &aOld, &aNew );
/*N*/
/*N*/                   }
/*N*/                   else
/*N*/                   {
/*?*/                   ((SwModify*)pAttr->GetDefinedIn())->SwModify::Modify( pAttr, pAttr );
/*N*/                   }
/*N*/               }
/*N*/           }
/*N*/       }
/*N*/   }
/*N*/ }



}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */