LCOV - code coverage report
Current view: top level - libreoffice/sw/source/filter/ww8 - ww8graf.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 618 1331 46.4 %
Date: 2012-12-17 Functions: 31 56 55.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <comphelper/string.hxx>
      21             : #include <svl/urihelper.hxx>
      22             : #include <hintids.hxx>
      23             : #include <osl/endian.h>
      24             : #include <svx/fmglob.hxx>
      25             : #include <svx/sdtaitm.hxx>
      26             : #include <editeng/lrspitem.hxx>
      27             : #include <editeng/udlnitem.hxx>
      28             : #include <svx/xlineit.hxx>
      29             : #include <svx/xfillit.hxx>
      30             : #include <svx/svdmodel.hxx>
      31             : #include <svx/svdocapt.hxx>
      32             : #include <svx/sxctitm.hxx>
      33             : #include <editeng/editeng.hxx>
      34             : #include <svx/svdpage.hxx>
      35             : #include <svx/svdopath.hxx>
      36             : #include <svx/svdocirc.hxx>
      37             : #include <editeng/outlobj.hxx>
      38             : #include <svx/svdogrp.hxx>
      39             : #include <svx/svdograf.hxx>
      40             : #include <svx/svdoole2.hxx>
      41             : #include <editeng/colritem.hxx>
      42             : #include <editeng/fhgtitem.hxx>
      43             : #include <editeng/postitem.hxx>
      44             : #include <editeng/adjitem.hxx>
      45             : #include <editeng/wghtitem.hxx>
      46             : #include <editeng/crsditem.hxx>
      47             : #include <editeng/cntritem.hxx>
      48             : #include <editeng/shdditem.hxx>
      49             : #include <editeng/fontitem.hxx>
      50             : #include <editeng/ulspitem.hxx>
      51             : #include <svx/svdoattr.hxx>
      52             : #include <editeng/brshitem.hxx>
      53             : #include <svx/rectenum.hxx>
      54             : #include <editeng/opaqitem.hxx>
      55             : #include <editeng/shaditem.hxx>
      56             : #include <editeng/boxitem.hxx>
      57             : #include <editeng/outliner.hxx>
      58             : #include <editeng/frmdiritem.hxx>
      59             : #include <svx/xfltrit.hxx>
      60             : #include <filter/msfilter/msdffimp.hxx>
      61             : #include <grfatr.hxx>           // class SwCropGrf
      62             : #include <fmtornt.hxx>
      63             : #include <fmtcntnt.hxx>
      64             : #include <frmfmt.hxx>
      65             : #include <fmtanchr.hxx>
      66             : #include <pam.hxx>
      67             : #include <doc.hxx>
      68             : #include <docary.hxx>
      69             : #include <ndgrf.hxx>
      70             : #include <ndtxt.hxx>
      71             : #include <dcontact.hxx>
      72             : #include <docsh.hxx>
      73             : #include <mdiexp.hxx>           // Progress
      74             : #include <fmtcnct.hxx>
      75             : #include "ww8struc.hxx"
      76             : #include "ww8scan.hxx"
      77             : #include "ww8par.hxx"           // class SwWWImplReader
      78             : #include "ww8par2.hxx"          // SwWW8StyInf
      79             : #include "ww8graf.hxx"
      80             : #include <fmtinfmt.hxx>
      81             : #include <editeng/eeitem.hxx>
      82             : #include <editeng/flditem.hxx>
      83             : // #i18732#
      84             : #include <fmtfollowtextflow.hxx>
      85             : #include "writerhelper.hxx"
      86             : #include "writerwordglue.hxx"
      87             : #include <basegfx/point/b2dpoint.hxx>
      88             : #include <basegfx/polygon/b2dpolygon.hxx>
      89             : #include <editeng/editobj.hxx>
      90             : #include <boost/scoped_ptr.hpp>
      91             : #include <math.h>
      92             : 
      93             : using ::editeng::SvxBorderLine;
      94             : using namespace ::com::sun::star;
      95             : using namespace sw::types;
      96             : using namespace sw::util;
      97             : 
      98             : // Hilfsroutinen
      99             : 
     100           0 : Color WW8TransCol(SVBT32 nWC)
     101             : {
     102             : #if 1               // 1 = Vordefinierte Farben benutzen, 0 = ignorieren
     103             : 
     104             :     // Farbtabelle zum Umrechnen RGB-Werte in vordefinierte Farben
     105             :     // ( Damit bei der Writer-UI die Farbnamen stimmen )
     106             :     // Die Tabelle int im *3er-System* aufgeteilt. Die Grauwerte fehlen,
     107             :     // da sie nicht ins 3er-System passen ( 4 Werte: sw, ws, 2 * grau )
     108             :     static ColorData eColA[] = {                    //  B G R  B G R  B G R
     109             :         COL_BLACK, COL_RED, COL_LIGHTRED,           //  0 0 0, 0 0 1, 0 0 2
     110             :         COL_GREEN, COL_BROWN, COL_BLACK,            //  0 1 0, 0 1 1, 0 1 2
     111             :         COL_LIGHTGREEN, COL_BLACK, COL_YELLOW,      //  0 2 0, 0 2 1, 0 2 2
     112             :         COL_BLUE, COL_MAGENTA, COL_BLACK,           //  1 0 0, 1 0 1, 1 0 2
     113             :         COL_CYAN, COL_LIGHTGRAY, COL_BLACK,         //  1 1 0, 1 1 1, 1 1 2
     114             :         COL_BLACK, COL_BLACK, COL_BLACK,            //  1 2 0, 1 2 1, 1 2 2
     115             :         COL_LIGHTBLUE, COL_BLACK, COL_LIGHTMAGENTA, //  2 0 0, 2 0 1, 2 0 2
     116             :         COL_BLACK, COL_BLACK, COL_BLACK,            //  2 1 0, 2 1 1, 2 1 2
     117             :         COL_LIGHTCYAN, COL_BLACK, COL_WHITE };      //  2 2 0, 2 2 1, 2 2 2
     118             : 
     119             :     // In nWC[3] steht ein Byte, dass in der WW-Doku nicht beschrieben ist.
     120             :     // Die Bedeutung ist anscheinend folgende: Bei 0 ist es eine normale
     121             :     // Farbe, dessen RGB-Wert in nWC[0..2] steht. stehen in nWC[3] die
     122             :     // Werte 0x1, 0x7d oder 0x83, dann ist es ein Grauwert, dessen
     123             :     // Schwarzanteil in 1/2 % in nWC[0] steht.
     124             :     // Ich vermute, dass es auf Bit0 in nWV[3] ankommt, ob es RGB oder Grau ist.
     125             : 
     126           0 :     if( !( nWC[3] & 0x1 ) &&                        // keine Spezial-Farbe (grau)
     127           0 :         (    ( nWC[0] == 0 ||  nWC[0]== 0x80 || nWC[0] == 0xff )    // R-Anteil
     128           0 :           && ( nWC[1] == 0 ||  nWC[1]== 0x80 || nWC[1] == 0xff )    // G-Anteil
     129           0 :           && ( nWC[2] == 0 ||  nWC[2]== 0x80 || nWC[2] == 0xff ) ) ){// B-Anteil
     130           0 :         int nIdx = 0;       // und nun: Idx-Berechnung im 3er-System
     131           0 :         for (int i = 2; i >= 0; i--)
     132             :         {
     133           0 :             nIdx *= 3;
     134           0 :             if (nWC[i])
     135           0 :                 nIdx += ((nWC[i] == 0xff) ? 2 : 1);
     136             :         }
     137           0 :         if (eColA[nIdx] != COL_BLACK)
     138           0 :             return Color(eColA[nIdx]);  // Standard-Color
     139             :     }
     140             : #endif
     141             : 
     142           0 :     if (nWC[3] & 0x1)
     143             :     {
     144             :         //Special colour gray
     145           0 :         sal_uInt8 u = (sal_uInt8)( (sal_uLong)( 200 - nWC[0] ) * 256 / 200 );
     146           0 :         return Color(u, u, u);
     147             :     }
     148             : 
     149             :     // User-Color
     150           0 :     return Color(nWC[0], nWC[1], nWC[2]);
     151             : }
     152             : 
     153          26 : void wwFrameNamer::SetUniqueGraphName(SwFrmFmt *pFrmFmt, const rtl::OUString &rFixed)
     154             : {
     155          26 :     if (mbIsDisabled || rFixed.isEmpty())
     156          26 :         return;
     157           0 :     rtl::OUStringBuffer aName(msSeed);
     158           0 :     aName.append(++mnImportedGraphicsCount);
     159           0 :     aName.append(": ");
     160           0 :     aName.append(rFixed);
     161           0 :     pFrmFmt->SetName(aName.makeStringAndClear());
     162             : }
     163             : 
     164             : // ReadGrafStart liest die ObjektDaten ein und erzeugt falls noetig einen Anker
     165           0 : bool SwWW8ImplReader::ReadGrafStart(void* pData, short nDataSiz,
     166             :     WW8_DPHEAD* pHd, const WW8_DO* pDo, SfxAllItemSet &rSet)
     167             : {
     168           0 :     if (SVBT16ToShort(pHd->cb) < sizeof(WW8_DPHEAD) + nDataSiz)
     169             :     {
     170             :         OSL_ENSURE( !this, "+Grafik-Element: Size ?" );
     171           0 :         pStrm->SeekRel(SVBT16ToShort(pHd->cb) - sizeof(WW8_DPHEAD));
     172           0 :         return false;
     173             :     }
     174             : 
     175           0 :     bool bCouldRead = checkRead(*pStrm, pData, nDataSiz);
     176             :     OSL_ENSURE(bCouldRead, "Short Graphic header");
     177           0 :     if (!bCouldRead)
     178           0 :         return false;
     179             : 
     180           0 :     RndStdIds eAnchor = (SVBT8ToByte(pDo->by) < 2) ? FLY_AT_PAGE : FLY_AT_PARA;
     181           0 :     rSet.Put(SwFmtAnchor(eAnchor));
     182             : 
     183           0 :     nDrawXOfs2 = nDrawXOfs;
     184           0 :     nDrawYOfs2 = nDrawYOfs;
     185             : 
     186           0 :     if (eAnchor == FLY_AT_PARA)
     187             :     {
     188           0 :         if( SVBT8ToByte( pDo->bx ) == 1 )       // Pos: echt links
     189           0 :             nDrawXOfs2 = static_cast< short >(nDrawXOfs2 - maSectionManager.GetPageLeft());
     190           0 :         if( nInTable )                          // Obj in Table
     191           0 :             nDrawXOfs2 = nDrawXOfs2 - GetTableLeft();       // -> siehe Kommentar
     192             :                                                 // bei GetTableLeft()
     193             :     }
     194             :     else
     195             :     {
     196           0 :         if( SVBT8ToByte( pDo->bx ) != 1 )
     197           0 :             nDrawXOfs2 = static_cast< short >(nDrawXOfs2 + maSectionManager.GetPageLeft());
     198             :     }
     199             : 
     200           0 :     return true;
     201             : }
     202             : 
     203             : // SetStdAttr() setzt die Attribute, die jedes Objekt hat
     204             : 
     205           0 : static void SetStdAttr( SfxItemSet& rSet, WW8_DP_LINETYPE& rL,
     206             :                         WW8_DP_SHADOW& rSh )
     207             : {
     208           0 :     if( SVBT16ToShort( rL.lnps ) == 5 ){            // unsichtbar
     209           0 :         rSet.Put( XLineStyleItem( XLINE_NONE ) );
     210             :     }else{                                          // sichtbar
     211           0 :         Color aCol( WW8TransCol( rL.lnpc ) );           // LinienFarbe
     212           0 :         rSet.Put( XLineColorItem( aEmptyStr, aCol ) );
     213           0 :         rSet.Put( XLineWidthItem( SVBT16ToShort( rL.lnpw ) ) );
     214             :                                                     // LinienDicke
     215           0 :         if( SVBT16ToShort( rL.lnps ) >= 1
     216           0 :             && SVBT16ToShort(rL.lnps ) <= 4 ){      // LinienStil
     217           0 :             rSet.Put( XLineStyleItem( XLINE_DASH ) );
     218           0 :             sal_Int16 nLen = SVBT16ToShort( rL.lnpw );
     219           0 :             XDash aD( XDASH_RECT, 1, 2 * nLen, 1, 5 * nLen, 5 * nLen );
     220           0 :             switch( SVBT16ToShort( rL.lnps ) ){
     221           0 :             case 1: aD.SetDots( 0 );            // Dash
     222           0 :                     aD.SetDashLen( 6 * nLen );
     223           0 :                     aD.SetDistance( 4 * nLen );
     224           0 :                     break;
     225           0 :             case 2: aD.SetDashes( 0 ); break;   // Dot
     226           0 :             case 3: break;                      // Dash Dot
     227           0 :             case 4: aD.SetDots( 2 ); break;     // Dash Dot Dot
     228             :             }
     229           0 :             rSet.Put( XLineDashItem( aEmptyStr, aD ) );
     230             :         }else{
     231           0 :             rSet.Put( XLineStyleItem( XLINE_SOLID ) );  // noetig fuer TextBox
     232             :         }
     233             :     }
     234           0 :     if( SVBT16ToShort( rSh.shdwpi ) ){                  // Schatten
     235           0 :         rSet.Put(SdrShadowItem(true));
     236           0 :         rSet.Put( SdrShadowXDistItem( SVBT16ToShort( rSh.xaOffset ) ) );
     237           0 :         rSet.Put( SdrShadowYDistItem( SVBT16ToShort( rSh.yaOffset ) ) );
     238             :     }
     239           0 : }
     240             : 
     241             : // SetFill setzt Fuellattribute wie Vordergrund- und Hintergrund-Farbe
     242             : // und Muster durch Reduktion auf eine Farbe.
     243             : // SetFill() setzt z.Zt kein Muster, da Sdr das nur sehr umstaendlich kann
     244             : // und die Sdr-Schraffur ( XDash ) noch nicht fertig ist.
     245             : // Statt dessen wird eine Mischfarbe gewaehlt, die auf den entsprechenden
     246             : // Farbton zwischen den Farben liegt.
     247             : 
     248           0 : static void SetFill( SfxItemSet& rSet, WW8_DP_FILL& rFill )
     249             : {
     250             :     static sal_uInt8 nPatA[] =
     251             :     {
     252             :              0,  0,  5, 10, 20, 25, 30, 40, 50, 60, 70, 75, 80,
     253             :             90, 50, 50, 50, 50, 50, 50, 33, 33, 33, 33, 33, 33
     254             :     };
     255           0 :     sal_uInt16 nPat = SVBT16ToShort(rFill.flpp);
     256             : 
     257           0 :     if (nPat == 0) // transparent
     258           0 :         rSet.Put(XFillStyleItem(XFILL_NONE));
     259             :     else
     260             :     {
     261           0 :         rSet.Put(XFillStyleItem(XFILL_SOLID));  // necessary for textbox
     262           0 :         if (nPat <= 1 || ((sizeof(nPatA)/sizeof(nPatA[0])) <= nPat))
     263             :         {
     264             :             // Solid Background or unknown
     265           0 :             rSet.Put(XFillColorItem(aEmptyStr, WW8TransCol(rFill.dlpcBg)));
     266             :         }
     267             :         else
     268             :         {                                      // Brush -> Farbmischung
     269           0 :             Color aB( WW8TransCol( rFill.dlpcBg ) );
     270           0 :             Color aF( WW8TransCol( rFill.dlpcFg ) );
     271           0 :             aB.SetRed( (sal_uInt8)( ( (sal_uLong)aF.GetRed() * nPatA[nPat]
     272           0 :                         + (sal_uLong)aB.GetRed() * ( 100 - nPatA[nPat] ) ) / 100 ) );
     273           0 :             aB.SetGreen( (sal_uInt8)( ( (sal_uLong)aF.GetGreen() * nPatA[nPat]
     274           0 :                         + (sal_uLong)aB.GetGreen() * ( 100 - nPatA[nPat] ) ) / 100 ) );
     275           0 :             aB.SetBlue( (sal_uInt8)( ( (sal_uLong)aF.GetBlue() * nPatA[nPat]
     276           0 :                         + (sal_uLong)aB.GetBlue() * ( 100 - nPatA[nPat] ) ) / 100 ) );
     277           0 :             rSet.Put( XFillColorItem( aEmptyStr, aB ) );
     278             :         }
     279             :     }
     280           0 : }
     281             : 
     282           0 : static void SetLineEndAttr( SfxItemSet& rSet, WW8_DP_LINEEND& rLe,
     283             :                             WW8_DP_LINETYPE& rLt )
     284             : {
     285           0 :     sal_uInt16 aSB = SVBT16ToShort( rLe.aStartBits );
     286           0 :     if( aSB & 0x3 )
     287             :     {
     288           0 :         ::basegfx::B2DPolygon aPolygon;
     289           0 :         aPolygon.append(::basegfx::B2DPoint(0.0, 330.0));
     290           0 :         aPolygon.append(::basegfx::B2DPoint(100.0, 0.0));
     291           0 :         aPolygon.append(::basegfx::B2DPoint(200.0, 330.0));
     292           0 :         aPolygon.setClosed(true);
     293           0 :         rSet.Put( XLineEndItem( aEmptyStr, ::basegfx::B2DPolyPolygon(aPolygon) ) );
     294           0 :         sal_uInt16 nSiz = SVBT16ToShort( rLt.lnpw )
     295           0 :                         * ( ( aSB >> 2 & 0x3 ) + ( aSB >> 4 & 0x3 ) );
     296           0 :         if( nSiz < 220 ) nSiz = 220;
     297           0 :         rSet.Put(XLineEndWidthItem(nSiz));
     298           0 :         rSet.Put(XLineEndCenterItem(false));
     299             :     }
     300             : 
     301           0 :     sal_uInt16 aEB = SVBT16ToShort( rLe.aEndBits );
     302           0 :     if( aEB & 0x3 ){
     303           0 :         ::basegfx::B2DPolygon aPolygon;
     304           0 :         aPolygon.append(::basegfx::B2DPoint(0.0, 330.0));
     305           0 :         aPolygon.append(::basegfx::B2DPoint(100.0, 0.0));
     306           0 :         aPolygon.append(::basegfx::B2DPoint(200.0, 330.0));
     307           0 :         aPolygon.setClosed(true);
     308           0 :         rSet.Put( XLineStartItem( aEmptyStr, ::basegfx::B2DPolyPolygon(aPolygon) ) );
     309           0 :         sal_uInt16 nSiz = SVBT16ToShort( rLt.lnpw )
     310           0 :                         * ( ( aEB >> 2 & 0x3 ) + ( aEB >> 4 & 0x3 ) );
     311           0 :         if( nSiz < 220 ) nSiz = 220;
     312           0 :         rSet.Put(XLineStartWidthItem(nSiz));
     313           0 :         rSet.Put(XLineStartCenterItem(false));
     314             :     }
     315           0 : }
     316             : 
     317             : // Ab hier folgen die Routinen fuer die einzelnen Objekte
     318           0 : SdrObject* SwWW8ImplReader::ReadLine( WW8_DPHEAD* pHd, const WW8_DO* pDo,
     319             :     SfxAllItemSet &rSet)
     320             : {
     321             :     WW8_DP_LINE aLine;
     322             : 
     323           0 :     if( !ReadGrafStart( (void*)&aLine, sizeof( aLine ), pHd, pDo, rSet ) )
     324           0 :         return 0;
     325             : 
     326           0 :     Point aP[2];
     327             :     {
     328           0 :         Point& rP0 = aP[0];
     329           0 :         Point& rP1 = aP[1];
     330             : 
     331           0 :         rP0.X() = (sal_Int16)SVBT16ToShort( pHd->xa ) + nDrawXOfs2;
     332           0 :         rP0.Y() = (sal_Int16)SVBT16ToShort( pHd->ya ) + nDrawYOfs2;
     333           0 :         rP1 = rP0;
     334           0 :         rP0.X() += (sal_Int16)SVBT16ToShort( aLine.xaStart );
     335           0 :         rP0.Y() += (sal_Int16)SVBT16ToShort( aLine.yaStart );
     336           0 :         rP1.X() += (sal_Int16)SVBT16ToShort( aLine.xaEnd );
     337           0 :         rP1.Y() += (sal_Int16)SVBT16ToShort( aLine.yaEnd );
     338             :     }
     339             : 
     340           0 :     ::basegfx::B2DPolygon aPolygon;
     341           0 :     aPolygon.append(::basegfx::B2DPoint(aP[0].X(), aP[0].Y()));
     342           0 :     aPolygon.append(::basegfx::B2DPoint(aP[1].X(), aP[1].Y()));
     343           0 :     SdrObject* pObj = new SdrPathObj(OBJ_LINE, ::basegfx::B2DPolyPolygon(aPolygon));
     344             : 
     345           0 :     SetStdAttr( rSet, aLine.aLnt, aLine.aShd );
     346           0 :     SetLineEndAttr( rSet, aLine.aEpp, aLine.aLnt );
     347             : 
     348           0 :     return pObj;
     349             : }
     350             : 
     351           0 : SdrObject* SwWW8ImplReader::ReadRect( WW8_DPHEAD* pHd, const WW8_DO* pDo,
     352             :     SfxAllItemSet &rSet)
     353             : {
     354             :     WW8_DP_RECT aRect;
     355             : 
     356           0 :     if( !ReadGrafStart( (void*)&aRect, sizeof( aRect ), pHd, pDo, rSet ) )
     357           0 :         return 0;
     358             : 
     359           0 :     Point aP0( (sal_Int16)SVBT16ToShort( pHd->xa ) + nDrawXOfs2,
     360           0 :                (sal_Int16)SVBT16ToShort( pHd->ya ) + nDrawYOfs2 );
     361           0 :     Point aP1( aP0 );
     362           0 :     aP1.X() += (sal_Int16)SVBT16ToShort( pHd->dxa );
     363           0 :     aP1.Y() += (sal_Int16)SVBT16ToShort( pHd->dya );
     364             : 
     365           0 :     SdrObject* pObj = new SdrRectObj( Rectangle( aP0, aP1 ) );
     366             : 
     367           0 :     SetStdAttr( rSet, aRect.aLnt, aRect.aShd );
     368           0 :     SetFill( rSet, aRect.aFill );
     369             : 
     370           0 :     return pObj;
     371             : }
     372             : 
     373           0 : SdrObject* SwWW8ImplReader::ReadElipse( WW8_DPHEAD* pHd, const WW8_DO* pDo,
     374             :     SfxAllItemSet &rSet)
     375             : {
     376             :     WW8_DP_ELIPSE aElipse;
     377             : 
     378           0 :     if( !ReadGrafStart( (void*)&aElipse, sizeof( aElipse ), pHd, pDo, rSet ) )
     379           0 :         return 0;
     380             : 
     381           0 :     Point aP0( (sal_Int16)SVBT16ToShort( pHd->xa ) + nDrawXOfs2,
     382           0 :                (sal_Int16)SVBT16ToShort( pHd->ya ) + nDrawYOfs2 );
     383           0 :     Point aP1( aP0 );
     384           0 :     aP1.X() += (sal_Int16)SVBT16ToShort( pHd->dxa );
     385           0 :     aP1.Y() += (sal_Int16)SVBT16ToShort( pHd->dya );
     386             : 
     387           0 :     SdrObject* pObj = new SdrCircObj( OBJ_CIRC, Rectangle( aP0, aP1 ) );
     388             : 
     389           0 :     SetStdAttr( rSet, aElipse.aLnt, aElipse.aShd );
     390           0 :     SetFill( rSet, aElipse.aFill );
     391             : 
     392           0 :     return pObj;
     393             : }
     394             : 
     395           0 : SdrObject* SwWW8ImplReader::ReadArc( WW8_DPHEAD* pHd, const WW8_DO* pDo,
     396             :     SfxAllItemSet &rSet)
     397             : {
     398             :     WW8_DP_ARC aArc;
     399             : 
     400           0 :     if( !ReadGrafStart( (void*)&aArc, sizeof( aArc ), pHd, pDo, rSet ) )
     401           0 :         return 0;
     402             : 
     403           0 :     Point aP0( (sal_Int16)SVBT16ToShort( pHd->xa ) + nDrawXOfs2,
     404           0 :                (sal_Int16)SVBT16ToShort( pHd->ya ) + nDrawYOfs2 );
     405           0 :     Point aP1( aP0 );
     406           0 :     aP1.X() += (sal_Int16)SVBT16ToShort( pHd->dxa ) * 2;
     407           0 :     aP1.Y() += (sal_Int16)SVBT16ToShort( pHd->dya ) * 2;
     408             : 
     409           0 :     short nA[] = { 2, 3, 1, 0 };
     410           0 :     short nW = nA[ ( ( SVBT8ToByte( aArc.fLeft ) & 1 ) << 1 )
     411           0 :                     + ( SVBT8ToByte( aArc.fUp ) & 1 ) ];
     412           0 :     if( !SVBT8ToByte( aArc.fLeft ) ){
     413           0 :         aP0.Y() -= (sal_Int16)SVBT16ToShort( pHd->dya );
     414           0 :         aP1.Y() -= (sal_Int16)SVBT16ToShort( pHd->dya );
     415             :     }
     416           0 :     if( SVBT8ToByte( aArc.fUp ) ){
     417           0 :         aP0.X() -= (sal_Int16)SVBT16ToShort( pHd->dxa );
     418           0 :         aP1.X() -= (sal_Int16)SVBT16ToShort( pHd->dxa );
     419             :     }
     420             : 
     421             :     SdrObject* pObj = new SdrCircObj( OBJ_SECT, Rectangle( aP0, aP1 ),
     422           0 :                                nW * 9000, ( ( nW + 1 ) & 3 ) * 9000 );
     423             : 
     424           0 :     SetStdAttr( rSet, aArc.aLnt, aArc.aShd );
     425           0 :     SetFill( rSet, aArc.aFill );
     426             : 
     427           0 :     return pObj;
     428             : }
     429             : 
     430           0 : SdrObject* SwWW8ImplReader::ReadPolyLine( WW8_DPHEAD* pHd, const WW8_DO* pDo,
     431             :     SfxAllItemSet &rSet)
     432             : {
     433             :     WW8_DP_POLYLINE aPoly;
     434             : 
     435           0 :     if( !ReadGrafStart( (void*)&aPoly, sizeof( aPoly ), pHd, pDo, rSet ) )
     436           0 :         return 0;
     437             : 
     438           0 :     sal_uInt16 nCount = SVBT16ToShort( aPoly.aBits1 ) >> 1 & 0x7fff;
     439           0 :     boost::scoped_array<SVBT16> xP(new SVBT16[nCount * 2]);
     440             : 
     441           0 :     bool bCouldRead = checkRead(*pStrm, xP.get(), nCount * 4);      // Punkte einlesen
     442             :     OSL_ENSURE(bCouldRead, "Short PolyLine header");
     443           0 :     if (!bCouldRead)
     444           0 :         return 0;
     445             : 
     446           0 :     Polygon aP( nCount );
     447           0 :     Point aPt;
     448           0 :     for (sal_uInt16 i=0; i<nCount; ++i)
     449             :     {
     450           0 :         aPt.X() = SVBT16ToShort( xP[i << 1] ) + nDrawXOfs2
     451           0 :                   + (sal_Int16)SVBT16ToShort( pHd->xa );
     452           0 :         aPt.Y() = SVBT16ToShort( xP[( i << 1 ) + 1] ) + nDrawYOfs2
     453           0 :                   + (sal_Int16)SVBT16ToShort( pHd->ya );
     454           0 :         aP[i] = aPt;
     455             :     }
     456           0 :     xP.reset();
     457             : 
     458           0 :     SdrObject* pObj = new SdrPathObj(( SVBT16ToShort( aPoly.aBits1 ) & 0x1 ) ? OBJ_POLY : OBJ_PLIN, ::basegfx::B2DPolyPolygon(aP.getB2DPolygon()));
     459           0 :     SetStdAttr( rSet, aPoly.aLnt, aPoly.aShd );
     460           0 :     SetFill( rSet, aPoly.aFill );
     461             : 
     462           0 :     return pObj;
     463             : }
     464             : 
     465         238 : ESelection SwWW8ImplReader::GetESelection( long nCpStart, long nCpEnd )
     466             : {
     467         238 :     sal_uInt16 nPCnt = mpDrawEditEngine->GetParagraphCount();
     468         238 :     sal_uInt16 nSP = 0;
     469         238 :     sal_uInt16 nEP = 0;
     470         714 :     while(      (nSP < nPCnt)
     471         238 :             &&  (nCpStart >= mpDrawEditEngine->GetTextLen( nSP ) + 1) )
     472             :     {
     473           0 :         nCpStart -= mpDrawEditEngine->GetTextLen( nSP ) + 1;
     474           0 :         nSP++;
     475             :     }
     476             :         // Beim Ende erst 1 Zeichen spaeter auf naechste Zeile umschalten,
     477             :         // da sonst Zeilenattribute immer eine Zeile zu weit reichen.
     478         714 :     while(      (nEP < nPCnt)
     479         238 :             &&  (nCpEnd > mpDrawEditEngine->GetTextLen( nEP ) + 1) )
     480             :     {
     481           0 :         nCpEnd -= mpDrawEditEngine->GetTextLen( nEP ) + 1;
     482           0 :         nEP++;
     483             :     }
     484         238 :     return ESelection( nSP, (sal_uInt16)nCpStart, nEP, (sal_uInt16)nCpEnd );
     485             : }
     486             : 
     487             : // InsertTxbxStyAttrs() setzt die Style-Attribute in den uebergebenen ItemSet.
     488             : // Es werden die SW-Styles genommen, die Import-WW-Styles sind zu diesem
     489             : // Zeitpunkt schon destruiert.
     490             : // Die SW-Styles werden per Tiefensuche, d.h. mit Parent-Styles nach den
     491             : // in aSrcTab angegebenen Attributen untersucht. Diese werden per Clone
     492             : // dupliziert, bei den Duplikaten werden die Which-IDs
     493             : // gemaess der Tabelle aDstTab umgesetzt, damit die EditEngine sie nicht
     494             : // ignoriert.
     495             : // Es werden hierbei sowohl Para- wie auch Zeichen-Attribute in den
     496             : // ItemSet gestopft.
     497         238 : void SwWW8ImplReader::InsertTxbxStyAttrs( SfxItemSet& rS, sal_uInt16 nColl )
     498             : {
     499         238 :     SwWW8StyInf * pStyInf = GetStyle(nColl);
     500         238 :     if( pStyInf != NULL && pStyInf->pFmt && pStyInf->bColl )
     501             :     {
     502             :         const SfxPoolItem* pItem;
     503       34034 :         for( sal_uInt16 i = POOLATTR_BEGIN; i < POOLATTR_END; i++ )
     504             :         {
     505             :             //If we are set in the source and not set in the destination
     506             :             //then add it in.
     507       33796 :             if ( SFX_ITEM_SET == pStyInf->pFmt->GetItemState(
     508       33796 :                 i, true, &pItem ) )
     509             :             {
     510        2902 :                 SfxItemPool *pEditPool = rS.GetPool();
     511        2902 :                 sal_uInt16 nWhich = i;
     512        2902 :                 sal_uInt16 nSlotId = rDoc.GetAttrPool().GetSlotId(nWhich);
     513        8230 :                 if (
     514             :                     nSlotId && nWhich != nSlotId &&
     515        2902 :                     0 != (nWhich = pEditPool->GetWhich(nSlotId)) &&
     516             :                     nWhich != nSlotId &&
     517        2426 :                     ( SFX_ITEM_SET != rS.GetItemState(nWhich, false) )
     518             :                    )
     519             :                 {
     520        2090 :                     SfxPoolItem* pCopy = pItem->Clone();
     521        2090 :                     pCopy->SetWhich( nWhich );
     522        2090 :                     rS.Put( *pCopy );
     523        2090 :                     delete pCopy;
     524             :                 }
     525             :             }
     526             :         }
     527             :     }
     528             : 
     529         238 : }
     530             : 
     531         116 : static void lcl_StripFields(String &rString, long &rNewStartCp)
     532             : {
     533         926 :     for(sal_uInt16 i=0; i < rString.Len(); i++)
     534             :     {
     535         810 :         if( 0x13 == rString.GetChar( i ) )
     536             :         {
     537           0 :             do
     538             :             {
     539           0 :                 rString.Erase( i, 1 );
     540           0 :                 rNewStartCp++;
     541             :             }
     542           0 :             while(              rString.Len()
     543           0 :                     && (   i  < rString.Len())
     544           0 :                     && (0x14 != rString.GetChar( i ) )
     545           0 :                     && (0x15 != rString.GetChar( i ) ) );
     546           0 :             if( rString.Len() )
     547             :             {
     548           0 :                 if( 0x14 == rString.GetChar( i ) )
     549             :                 {
     550           0 :                     rString.Erase( i, 1 );
     551           0 :                     rNewStartCp++;
     552           0 :                     do
     553             :                     {
     554           0 :                         i++;
     555             :                     }
     556           0 :                     while(              rString.Len()
     557           0 :                             && (   i  < rString.Len())
     558           0 :                             && (0x15 != rString.GetChar( i ) ) );
     559           0 :                     if( i < rString.Len() )
     560           0 :                         rString.Erase( i, 1 );
     561             :                 }
     562           0 :                 else if( 0x15 == rString.GetChar( i ) )
     563           0 :                     rString.Erase( i, 1 );
     564             :             }
     565             :         }
     566             :     }
     567         116 : }
     568             : 
     569           0 : class Chunk
     570             : {
     571             : private:
     572             :     String msURL;
     573             :     long mnStartPos; //0x13
     574             :     long mnEndPos;   //0x15
     575             : public:
     576           0 :     explicit Chunk(long nStart, const String &rURL)
     577           0 :         : msURL(rURL), mnStartPos(nStart), mnEndPos(0)  {}
     578           0 :     Chunk(const Chunk &rChunk)
     579             :         : msURL(rChunk.msURL), mnStartPos(rChunk.mnStartPos),
     580           0 :         mnEndPos(rChunk.mnEndPos) {}
     581             :     Chunk& operator=(const Chunk &rChunk)
     582             :     {
     583             :         msURL = rChunk.msURL;
     584             :         mnStartPos = rChunk.mnStartPos;
     585             :         mnEndPos = rChunk.mnEndPos;
     586             :         return *this;
     587             :     }
     588           0 :     void SetEndPos(long nEnd) { mnEndPos = nEnd; }
     589           0 :     long GetStartPos() const {return mnStartPos;}
     590           0 :     long GetEndPos() const {return mnEndPos;}
     591           0 :     const String &GetURL() const {return msURL;}
     592           0 :     void Adjust(xub_StrLen nAdjust)
     593             :     {
     594           0 :         mnStartPos-=nAdjust;
     595           0 :         mnEndPos-=nAdjust;
     596           0 :     }
     597             : };
     598             : 
     599             : // InsertAttrsAsDrawingAttrs() setzt zwischen StartCp und EndCp die Attribute.
     600             : // Dabei werden Style-Attribute als harte Attribute, Absatz- und Zeichen-
     601             : // attribute gesetzt.
     602         112 : void SwWW8ImplReader::InsertAttrsAsDrawingAttrs(long nStartCp, long nEndCp,
     603             :     ManTypes eType, bool bONLYnPicLocFc)
     604             : {
     605             :     /*
     606             :      Save and create new plcxman for this drawing object, of the type that
     607             :      will include the para end mark inside a paragraph property range, as
     608             :      drawing boxes have real paragraph marks as part of their text, while
     609             :      normal writer has seperate nodes for each paragraph and so has no actual
     610             :      paragraph mark as part of the paragraph text.
     611             :     */
     612         112 :     WW8ReaderSave aSave(this);
     613         112 :     pPlcxMan = new WW8PLCFMan(pSBase, eType, nStartCp, true);
     614             : 
     615         112 :     WW8_CP nStart = pPlcxMan->Where();
     616         112 :     WW8_CP nNext, nEnd, nStartReplace=0;
     617             : 
     618         112 :     bool bDoingSymbol = false;
     619         112 :     sal_Unicode cReplaceSymbol = cSymbol;
     620             : 
     621         112 :     SfxItemSet *pS = new SfxItemSet(mpDrawEditEngine->GetEmptyItemSet());
     622             :     WW8PLCFManResult aRes;
     623             : 
     624         112 :     std::deque<Chunk> aChunks;
     625             : 
     626             :     //Here store stack location
     627         112 :     size_t nCurrentCount = pCtrlStck->size();
     628        1528 :     while (nStart < nEndCp)
     629             :     {
     630             :         //nStart is the beginning of the attributes for this range, and
     631             :         //may be before the text itself. So watch out for that
     632        1304 :         WW8_CP nTxtStart = nStart;
     633        1304 :         if (nTxtStart < nStartCp)
     634         110 :             nTxtStart = nStartCp;
     635             :         // get position of next SPRM
     636        1304 :         bool bStartAttr = pPlcxMan->Get(&aRes);
     637        1304 :         nAktColl = pPlcxMan->GetColl();
     638        1304 :         if (aRes.nSprmId)
     639             :         {
     640        1160 :             if( bONLYnPicLocFc )
     641             :             {
     642           0 :                 if ( (68 == aRes.nSprmId) || (0x6A03 == aRes.nSprmId) )
     643             :                 {
     644             :                     Read_PicLoc(aRes.nSprmId, aRes.pMemPos +
     645           0 :                         mpSprmParser->DistanceToData(aRes.nSprmId), 4);
     646             :                      // Ok, that's what we were looking for.  Now let's get
     647             :                      // out of here!
     648           0 :                     break;
     649             :                 }
     650             :             }
     651        1160 :             else if ( aRes.nSprmId && (
     652             :                 (eFTN >  aRes.nSprmId) || (0x0800 <= aRes.nSprmId) ) )
     653             :             {
     654             :                 //Here place them onto our usual stack and we will pop them
     655             :                 //off and convert them later
     656        1160 :                 if (bStartAttr)
     657             :                 {
     658        1128 :                     ImportSprm(aRes.pMemPos, aRes.nSprmId);
     659        1128 :                     if (!bDoingSymbol && bSymbol == true)
     660             :                     {
     661           0 :                         bDoingSymbol = true;
     662           0 :                         nStartReplace = nTxtStart;
     663           0 :                         cReplaceSymbol = cSymbol;
     664             :                     }
     665             :                 }
     666             :                 else
     667             :                 {
     668          32 :                     EndSprm( aRes.nSprmId );
     669          32 :                     if (bSymbol == false && bDoingSymbol)
     670             :                     {
     671           0 :                         bDoingSymbol = false;
     672           0 :                         rtl::OUStringBuffer sTemp;
     673             :                         comphelper::string::padToLength(sTemp,
     674           0 :                             nTxtStart - nStartReplace, cReplaceSymbol);
     675             :                         mpDrawEditEngine->QuickInsertText(sTemp.makeStringAndClear(),
     676             :                             GetESelection(nStartReplace - nStartCp,
     677           0 :                             nTxtStart - nStartCp ) );
     678             :                     }
     679        1160 :                 }
     680             :             }
     681           0 :             else if (aRes.nSprmId == eFLD)
     682             :             {
     683           0 :                 if (bStartAttr)
     684             :                 {
     685           0 :                     size_t nCount = pCtrlStck->size();
     686           0 :                     if (maFieldStack.empty() && Read_Field(&aRes))
     687             :                     {
     688           0 :                         String sURL;
     689           0 :                         for (size_t nI = pCtrlStck->size(); nI > nCount; --nI)
     690             :                         {
     691           0 :                             const SfxPoolItem *pItem = ((*pCtrlStck)[nI-1]).pAttr;
     692           0 :                             sal_uInt16 nWhich = pItem->Which();
     693           0 :                             if (nWhich == RES_TXTATR_INETFMT)
     694             :                             {
     695             :                                 const SwFmtINetFmt *pURL =
     696           0 :                                     (const SwFmtINetFmt *)pItem;
     697           0 :                                 sURL = pURL->GetValue();
     698             :                             }
     699           0 :                             pCtrlStck->DeleteAndDestroy(nI-1);
     700             :                         }
     701           0 :                         aChunks.push_back(Chunk(nStart, sURL));
     702             :                     }
     703             :                 }
     704             :                 else
     705             :                 {
     706           0 :                     if (!maFieldStack.empty() && End_Field())
     707           0 :                         aChunks.back().SetEndPos(nStart+1);
     708             :                 }
     709             :             }
     710             :         }
     711             : 
     712        1304 :         pPlcxMan->advance();
     713        1304 :         nNext = pPlcxMan->Where();
     714             : 
     715        1304 :         if( (nNext != nStart) && !bONLYnPicLocFc )
     716             :         {
     717         238 :             nEnd = ( nNext < nEndCp ) ? nNext : nEndCp;
     718         238 :             SfxItemPool *pEditPool = pS->GetPool();
     719             : 
     720             :             //Here read current properties and convert them into pS
     721             :             //and put those attrs into the draw box if they can be converted
     722             :             //to draw attributes
     723         238 :             if (pCtrlStck->size() - nCurrentCount)
     724             :             {
     725         760 :                 for (size_t i = nCurrentCount; i < pCtrlStck->size(); ++i)
     726             :                 {
     727         632 :                     const SfxPoolItem *pItem = ((*pCtrlStck)[i]).pAttr;
     728         632 :                     sal_uInt16 nWhich = pItem->Which();
     729         632 :                     if( nWhich < RES_FLTRATTR_BEGIN ||
     730             :                         nWhich >= RES_FLTRATTR_END )
     731             :                     {
     732         632 :                         sal_uInt16 nSlotId = rDoc.GetAttrPool().GetSlotId(nWhich);
     733        1264 :                         if (
     734             :                             nSlotId && nWhich != nSlotId &&
     735         632 :                             0 != (nWhich = pEditPool->GetWhich(nSlotId)) &&
     736             :                             nWhich != nSlotId
     737             :                         )
     738             :                         {
     739         632 :                             SfxPoolItem* pCopy = pItem->Clone();
     740         632 :                             pCopy->SetWhich( nWhich );
     741         632 :                             pS->Put( *pCopy );
     742         632 :                             delete pCopy;
     743             :                         }
     744             :                     }
     745             :                 }
     746             :             }
     747             :             //Fill in the remainder from the style
     748         238 :             InsertTxbxStyAttrs(*pS, nAktColl);
     749             : 
     750         238 :             if( pS->Count() )
     751             :             {
     752             :                 mpDrawEditEngine->QuickSetAttribs( *pS,
     753         238 :                     GetESelection( nTxtStart - nStartCp, nEnd - nStartCp ) );
     754         238 :                 delete pS;
     755         238 :                 pS = new SfxItemSet(mpDrawEditEngine->GetEmptyItemSet());
     756             :             }
     757             :         }
     758        1304 :         nStart = nNext;
     759             :     }
     760         112 :     delete pS;
     761             : 
     762             :     //pop off as far as recorded location just in case there were some left
     763             :     //unclosed
     764         704 :     for (size_t nI = pCtrlStck->size(); nI > nCurrentCount; --nI)
     765         592 :         pCtrlStck->DeleteAndDestroy(nI-1);
     766             : 
     767             :     typedef std::deque<Chunk>::iterator myIter;
     768         112 :     myIter aEnd = aChunks.end();
     769         112 :     for (myIter aIter = aChunks.begin(); aIter != aEnd; ++aIter)
     770             :     {
     771           0 :         ESelection aSel(GetESelection(aIter->GetStartPos()-nStartCp,
     772           0 :             aIter->GetEndPos()-nStartCp));
     773           0 :         String aString(mpDrawEditEngine->GetText(aSel));
     774           0 :         xub_StrLen nOrigLen = aString.Len();
     775           0 :         long nDummy(0);
     776           0 :         lcl_StripFields(aString, nDummy);
     777             : 
     778             :         xub_StrLen nChanged;
     779           0 :         if (aIter->GetURL().Len())
     780             :         {
     781           0 :             SvxURLField aURL(aIter->GetURL(), aString,
     782           0 :                 SVXURLFORMAT_APPDEFAULT);
     783           0 :             mpDrawEditEngine->QuickInsertField(SvxFieldItem(aURL, EE_FEATURE_FIELD), aSel);
     784           0 :             nChanged = nOrigLen - 1;
     785             :         }
     786             :         else
     787             :         {
     788           0 :             mpDrawEditEngine->QuickInsertText(aString, aSel);
     789           0 :             nChanged = nOrigLen - aString.Len();
     790             :         }
     791           0 :         for (myIter aIter2 = aIter+1; aIter2 != aEnd; ++aIter2)
     792           0 :             aIter2->Adjust(nChanged);
     793           0 :         }
     794             : 
     795             :     /*
     796             :      Don't worry about the new pPlcxMan, the restorer removes it when
     797             :      replacing the current one with the old one.
     798             :     */
     799         112 :     aSave.Restore(this);
     800         112 : }
     801             : 
     802         118 : bool SwWW8ImplReader::GetTxbxTextSttEndCp(WW8_CP& rStartCp, WW8_CP& rEndCp,
     803             :     sal_uInt16 nTxBxS, sal_uInt16 nSequence)
     804             : {
     805             :     // rasch den TextBox-PLCF greifen
     806         118 :     WW8PLCFspecial* pT = pPlcxMan ? pPlcxMan->GetTxbx() : 0;
     807         118 :     if( !pT )
     808             :     {
     809             :         OSL_ENSURE( !this, "+Wo ist der Grafik-Text (1) ?" );
     810           0 :         return false;
     811             :     }
     812             : 
     813             :     // ggfs. zuerst die richtige TextBox-Story finden
     814         118 :     bool bCheckTextBoxStory = ( nTxBxS && pT->GetIMax() >= nTxBxS );
     815         118 :     if(  bCheckTextBoxStory )
     816         118 :         pT->SetIdx( nTxBxS-1 );
     817             : 
     818             :     // dann Start und Ende ermitteln
     819             :     void* pT0;
     820         118 :     if( !pT->Get( rStartCp, pT0 ) )
     821             :     {
     822             :         OSL_ENSURE( !this, "+Wo ist der Grafik-Text (2) ?" );
     823           0 :         return false;
     824             :     }
     825             : 
     826         118 :     if( bCheckTextBoxStory )
     827             :     {
     828         118 :         bool bReusable = (0 != SVBT16ToShort( ((WW8_TXBXS*)pT0)->fReusable ));
     829         236 :         while( bReusable )
     830             :         {
     831           0 :             pT->advance();
     832           0 :             if( !pT->Get( rStartCp, pT0 ) )
     833             :             {
     834             :                 OSL_ENSURE( !this, "+Wo ist der Grafik-Text (2-a) ?" );
     835           0 :                 return false;
     836             :             }
     837           0 :             bReusable = (0 != SVBT16ToShort( ((WW8_TXBXS*)pT0)->fReusable ));
     838             :         }
     839             :     }
     840         118 :     pT->advance();
     841         118 :     if( !pT->Get( rEndCp, pT0 ) )
     842             :     {
     843             :         OSL_ENSURE( !this, "+Wo ist der Grafik-Text (3) ?" );
     844           0 :         return false;
     845             :     }
     846             : 
     847             :     // jetzt ggfs. die passende Page in der Break-Table finden
     848         118 :     if( bCheckTextBoxStory )
     849             :     {
     850             :         // Sonderfall: gesamte(!) Kette soll ermittelt werden,
     851             :         //             dann sind wir hier schon fertig!
     852         118 :         if( USHRT_MAX > nSequence )
     853             :         {
     854         114 :             long nMinStartCp = rStartCp;
     855         114 :             long nMaxEndCp   = rEndCp;
     856             :             // rasch den TextBox-Break-Deskriptor-PLCF greifen
     857         114 :             pT = pPlcxMan->GetTxbxBkd();
     858         114 :             if (!pT) //It can occur on occasion, Caolan
     859           0 :                 return false;
     860             : 
     861             :             // den ersten Eintrag fuer diese TextBox-Story finden
     862         114 :             if( !pT->SeekPos( rStartCp ) )
     863             :             {
     864             :                 OSL_ENSURE( !this, "+Wo ist der Grafik-Text (4) ?" );
     865           0 :                 return false;
     866             :             }
     867             :             // ggfs. entsprechende Anzahl Eintraege weitergehen
     868         114 :             for (sal_uInt16 iSequence = 0; iSequence < nSequence; ++iSequence)
     869           0 :                 pT->advance();
     870             :             // dann die tatsaechlichen Start und Ende ermitteln
     871         114 :             if(    (!pT->Get( rStartCp, pT0 ))
     872             :                 || ( nMinStartCp > rStartCp  ) )
     873             :             {
     874             :                 OSL_ENSURE( !this, "+Wo ist der Grafik-Text (5) ?" );
     875           0 :                 return false;
     876             :             }
     877         114 :             if( rStartCp >= nMaxEndCp )
     878           0 :                 rEndCp = rStartCp;  // kein Error: leerer String!
     879             :             else
     880             :             {
     881         114 :                 pT->advance();
     882         114 :                 if ( (!pT->Get(rEndCp, pT0)) || (nMaxEndCp < rEndCp-1) )
     883             :                 {
     884             :                     OSL_ENSURE( !this, "+Wo ist der Grafik-Text (6) ?" );
     885           0 :                     return false;
     886             :                 }
     887         114 :                 rEndCp -= 1;
     888             :             }
     889             :         }
     890             :         else
     891           4 :             rEndCp -= 1;
     892             :     }
     893             :     else
     894           0 :         rEndCp -= 1;
     895         118 :     return true;
     896             : }
     897             : 
     898             : // TxbxText() holt aus WW-File den Text und gibt diesen und den Anfangs- und
     899             : // den um -2 (bzw. -1 bei Ver8) korrigierten End-Cp zurueck
     900         116 : bool SwWW8ImplReader::GetRangeAsDrawingString(String& rString, long nStartCp, long nEndCp, ManTypes eType)
     901             : {
     902         116 :     WW8_CP nOffset = pWwFib->GetBaseCp(eType);
     903             : 
     904         116 :     bool bOk = false;
     905             :     OSL_ENSURE(nStartCp <= nEndCp, "+Wo ist der Grafik-Text (7) ?");
     906         116 :     if (nStartCp == nEndCp)
     907           0 :         rString.Erase();      // leerer String: durchaus denkbar!
     908         116 :     else if (nStartCp < nEndCp)
     909             :     {
     910             :         // den Text einlesen: kann sich ueber mehrere Pieces erstrecken!!!
     911             :         sal_uInt16 nLen = pSBase->WW8ReadString(*pStrm, rString,
     912         116 :             nStartCp + nOffset, nEndCp - nStartCp, GetCurrentCharSet());
     913             :         OSL_ENSURE(nLen, "+Wo ist der Grafik-Text (8) ?");
     914         116 :         if (nLen)
     915             :         {
     916         116 :             bOk = true;
     917         116 :             if( 0x0d == rString.GetChar(nLen - 1) )
     918         116 :                 rString.Erase(nLen - 1);
     919             : 
     920         116 :             rString.SearchAndReplaceAll( 0xb, 0xa );
     921             :         }
     922             :     }
     923         116 :     return bOk;
     924             : }
     925             : 
     926           0 : OutlinerParaObject* SwWW8ImplReader::ImportAsOutliner(String &rString, WW8_CP nStartCp, WW8_CP nEndCp, ManTypes eType)
     927             : {
     928           0 :     OutlinerParaObject* pRet = 0;
     929             : 
     930           0 :     if (GetRangeAsDrawingString( rString, nStartCp, nEndCp, eType ))
     931             :     {
     932           0 :         if (!mpDrawEditEngine)
     933           0 :             mpDrawEditEngine = new EditEngine(0);
     934             : 
     935           0 :         mpDrawEditEngine->SetText(rString);
     936           0 :         InsertAttrsAsDrawingAttrs(nStartCp, nEndCp, eType);
     937             : 
     938             :         //Annotations typically begin with a (useless) 0x5
     939           0 :         if ((eType == MAN_AND) && mpDrawEditEngine->GetTextLen())
     940             :         {
     941           0 :             ESelection aFirstChar(0, 0, 0, 1);
     942           0 :             if (comphelper::string::equals(mpDrawEditEngine->GetText( aFirstChar ), 0x5))
     943           0 :                 mpDrawEditEngine->QuickDelete(aFirstChar);
     944             :         }
     945             : 
     946           0 :         EditTextObject* pTemporaryText = mpDrawEditEngine->CreateTextObject();
     947           0 :         pRet = new OutlinerParaObject(*pTemporaryText);
     948           0 :         pRet->SetOutlinerMode( OUTLINERMODE_TEXTOBJECT );
     949           0 :         delete pTemporaryText;
     950             : 
     951           0 :         mpDrawEditEngine->SetText( aEmptyStr );
     952           0 :         mpDrawEditEngine->SetParaAttribs(0, mpDrawEditEngine->GetEmptyItemSet());
     953             : 
     954             :         //Strip out fields, leaving the result
     955           0 :         long nDummy(0);
     956           0 :         lcl_StripFields(rString, nDummy);
     957             :         //Strip out word's special characters for the simple string
     958           0 :         rString = comphelper::string::remove(rString, 0x1);
     959           0 :         rString = comphelper::string::remove(rString, 0x5);
     960           0 :         rString = comphelper::string::remove(rString, 0x8);
     961           0 :         rString.SearchAndReplaceAllAscii("\007\007", rtl::OUString("\007\012"));
     962           0 :         rString.SearchAndReplaceAll(0x7, ' ');
     963             : 
     964             :     }
     965             : 
     966           0 :     return pRet;
     967             : }
     968             : 
     969             : // InsertTxbxText() fuegt fuer TextBoxen und CaptionBoxen den Text
     970             : // und die Attribute ein
     971         116 : SwFrmFmt* SwWW8ImplReader::InsertTxbxText(SdrTextObj* pTextObj,
     972             :     Size* pObjSiz, sal_uInt16 nTxBxS, sal_uInt16 nSequence, long nPosCp,
     973             :     SwFrmFmt* pOldFlyFmt, bool bMakeSdrGrafObj, bool& rbEraseTextObj,
     974             :     bool* pbTestTxbxContainsText, long* pnStartCp, long* pnEndCp,
     975             :     bool* pbContainsGraphics, SvxMSDffImportRec* pRecord)
     976             : {
     977         116 :     SwFrmFmt* pFlyFmt = 0;
     978         116 :     sal_uLong nOld = pStrm->Tell();
     979             : 
     980         116 :     ManTypes eType = pPlcxMan->GetManType() == MAN_HDFT ? MAN_TXBX_HDFT : MAN_TXBX;
     981             : 
     982         116 :     rbEraseTextObj = false;
     983             : 
     984         116 :     String aString;
     985             :     WW8_CP nStartCp, nEndCp;
     986         116 :     bool bContainsGraphics = false;
     987             :     bool bTextWasRead = GetTxbxTextSttEndCp( nStartCp, nEndCp, nTxBxS,
     988         116 :         nSequence ) && GetRangeAsDrawingString( aString, nStartCp, nEndCp, eType );
     989             : 
     990         116 :     if (!mpDrawEditEngine)
     991           8 :         mpDrawEditEngine = new EditEngine(0);
     992         116 :     if( pObjSiz )
     993         112 :         mpDrawEditEngine->SetPaperSize( *pObjSiz );
     994             : 
     995         116 :     String aOrigString(aString);
     996         116 :     if( bTextWasRead )
     997             :     {
     998         116 :         long nNewStartCp = nStartCp;
     999         116 :         lcl_StripFields(aString, nNewStartCp);
    1000             : 
    1001         116 :         if (1 != aString.Len())
    1002             :         {
    1003         136 :             if ( (STRING_NOTFOUND != aString.Search(0x1)) ||
    1004          68 :                 (STRING_NOTFOUND != aString.Search(0x8)) )
    1005             :             {
    1006           0 :                 bContainsGraphics = true;
    1007             :             }
    1008             :         }
    1009             :         else        // May be a single graphic or object
    1010             :         {
    1011          48 :             bool bDone = true;
    1012          48 :             switch( aString.GetChar(0) )
    1013             :             {
    1014             :                 case 0x1:
    1015           0 :                     if (!pbTestTxbxContainsText)
    1016             :                     {
    1017           0 :                         WW8ReaderSave aSave(this, nNewStartCp -1);
    1018           0 :                         bool bOldEmbeddObj = bEmbeddObj;
    1019             :                         //bEmbedd Ordinarily would have been set by field
    1020             :                         //parse, but this is impossible here so...
    1021           0 :                         bEmbeddObj = true;
    1022             : 
    1023             :                         // 1st look for OLE- or Graph-Indicator Sprms
    1024           0 :                         WW8PLCFx_Cp_FKP* pChp = pPlcxMan->GetChpPLCF();
    1025           0 :                         WW8PLCFxDesc aDesc;
    1026           0 :                         pChp->GetSprms( &aDesc );
    1027             :                         WW8SprmIter aSprmIter(aDesc.pMemPos, aDesc.nSprmsLen,
    1028           0 :                             *mpSprmParser);
    1029             : 
    1030           0 :                         const sal_uInt8* pParams = aSprmIter.GetAktParams();
    1031           0 :                         for( int nLoop = 0; nLoop < 2; ++nLoop )
    1032             :                         {
    1033           0 :                             while( aSprmIter.GetSprms()
    1034             :                                 && (0 != (pParams = aSprmIter.GetAktParams())) )
    1035             :                             {
    1036           0 :                                 sal_uInt16 nAktId = aSprmIter.GetAktId();
    1037           0 :                                 switch( nAktId )
    1038             :                                 {
    1039             :                                     case     75:
    1040             :                                     case    118:
    1041             :                                     case 0x080A:
    1042             :                                     case 0x0856:
    1043           0 :                                             Read_Obj(nAktId, pParams, 1);
    1044           0 :                                         break;
    1045             :                                     case     68:  // Read_Pic()
    1046             :                                     case 0x6A03:
    1047             :                                     case 0x680E:
    1048           0 :                                             Read_PicLoc(nAktId, pParams, 1);
    1049           0 :                                         break;
    1050             :                                 }
    1051           0 :                                 aSprmIter.advance();
    1052             :                             }
    1053             : 
    1054           0 :                             if( !nLoop )
    1055             :                             {
    1056           0 :                                 pChp->GetPCDSprms(  aDesc );
    1057             :                                 aSprmIter.SetSprms( aDesc.pMemPos,
    1058           0 :                                     aDesc.nSprmsLen );
    1059             :                             }
    1060             :                         }
    1061           0 :                         aSave.Restore(this);
    1062           0 :                         bEmbeddObj=bOldEmbeddObj;
    1063             : 
    1064             :                         // then import either an OLE of a Graphic
    1065           0 :                         if( bObj )
    1066             :                         {
    1067           0 :                             if( bMakeSdrGrafObj && pTextObj &&
    1068           0 :                                 pTextObj->GetUpGroup() )
    1069             :                             {
    1070             :                                 // SdrOleObj/SdrGrafObj anstatt des
    1071             :                                 // SdrTextObj in dessen Gruppe einsetzen
    1072             : 
    1073           0 :                                 Graphic aGraph;
    1074           0 :                                 SdrObject* pNew = ImportOleBase(aGraph);
    1075             : 
    1076           0 :                                 if( !pNew )
    1077             :                                 {
    1078           0 :                                     pNew = new SdrGrafObj;
    1079           0 :                                     ((SdrGrafObj*)pNew)->SetGraphic(aGraph);
    1080             :                                 }
    1081             : 
    1082           0 :                                 GrafikCtor();
    1083             : 
    1084           0 :                                 pNew->SetModel( pDrawModel );
    1085           0 :                                 pNew->SetLogicRect( pTextObj->GetCurrentBoundRect() );
    1086           0 :                                 pNew->SetLayer( pTextObj->GetLayer() );
    1087             : 
    1088           0 :                                 pTextObj->GetUpGroup()->GetSubList()->
    1089           0 :                                     ReplaceObject(pNew, pTextObj->GetOrdNum());
    1090             :                             }
    1091             :                             else
    1092           0 :                                 pFlyFmt = ImportOle();
    1093           0 :                             bObj = false;
    1094             :                         }
    1095             :                         else
    1096             :                         {
    1097             :                             InsertAttrsAsDrawingAttrs(nNewStartCp, nNewStartCp+1,
    1098           0 :                                 eType, true);
    1099             :                             pFlyFmt = ImportGraf(bMakeSdrGrafObj ? pTextObj : 0,
    1100           0 :                                 pOldFlyFmt);
    1101           0 :                         }
    1102             :                     }
    1103           0 :                     break;
    1104             :                 case 0x8:
    1105           0 :                     if ( (!pbTestTxbxContainsText) && (!bObj) )
    1106           0 :                         pFlyFmt = Read_GrafLayer( nPosCp );
    1107           0 :                     break;
    1108             :                 default:
    1109          48 :                     bDone = false;
    1110          48 :                     break;
    1111             :             }
    1112             : 
    1113          48 :             if( bDone )
    1114             :             {
    1115           0 :                 if( pFlyFmt )
    1116             :                 {
    1117           0 :                     if( pRecord )
    1118             :                     {
    1119           0 :                         SfxItemSet aFlySet( rDoc.GetAttrPool(),
    1120           0 :                             RES_FRMATR_BEGIN, RES_FRMATR_END-1 );
    1121             : 
    1122             :                         Rectangle aInnerDist(   pRecord->nDxTextLeft,
    1123             :                                                 pRecord->nDyTextTop,
    1124             :                                                 pRecord->nDxTextRight,
    1125           0 :                                                 pRecord->nDyTextBottom  );
    1126             :                         MatchSdrItemsIntoFlySet( pTextObj,
    1127             :                                                  aFlySet,
    1128             :                                                  pRecord->eLineStyle,
    1129             :                                                  pRecord->eLineDashing,
    1130             :                                                  pRecord->eShapeType,
    1131           0 :                                                  aInnerDist );
    1132             : 
    1133           0 :                         pFlyFmt->SetFmtAttr( aFlySet );
    1134             : 
    1135           0 :                         MapWrapIntoFlyFmt(pRecord, pFlyFmt);
    1136             :                     }
    1137             :                 }
    1138           0 :                 aString.Erase();
    1139           0 :                 rbEraseTextObj = (0 != pFlyFmt);
    1140             :             }
    1141             :         }
    1142             :     }
    1143             : 
    1144         116 :     if( pnStartCp )
    1145           4 :         *pnStartCp = nStartCp;
    1146         116 :     if( pnEndCp )
    1147           4 :         *pnEndCp = nEndCp;
    1148             : 
    1149         116 :     if( pbTestTxbxContainsText )
    1150           4 :         *pbTestTxbxContainsText = bTextWasRead && ! rbEraseTextObj;
    1151         112 :     else if( !rbEraseTextObj )
    1152             :     {
    1153         112 :         if( bTextWasRead )
    1154             :         {
    1155         112 :             mpDrawEditEngine->SetText(aOrigString);
    1156         112 :             InsertAttrsAsDrawingAttrs(nStartCp, nEndCp, eType);
    1157             :         }
    1158             : 
    1159         112 :         bool bVertical = pTextObj->IsVerticalWriting() ? true : false;
    1160         112 :         EditTextObject* pTemporaryText = mpDrawEditEngine->CreateTextObject();
    1161         112 :         OutlinerParaObject* pOp = new OutlinerParaObject(*pTemporaryText);
    1162         112 :         pOp->SetOutlinerMode( OUTLINERMODE_TEXTOBJECT );
    1163         112 :         pOp->SetVertical( bVertical );
    1164         112 :         delete pTemporaryText;
    1165         112 :         pTextObj->NbcSetOutlinerParaObject( pOp );
    1166         112 :         pTextObj->SetVerticalWriting(bVertical);
    1167             : 
    1168             :         // Fuer die naechste Textbox noch die alten Absatz-Attribute
    1169             :         // und Styles entfernen, sonst startet die naechste Box
    1170             :         // mit falschen Attributen.
    1171             :         // Vorgehen: Text loeschen = auf 1 Absatz reduzieren
    1172             :         // und an diesem Absatz die Absatzattribute und Styles loeschen
    1173             :         // (Empfehlung JOE)
    1174         112 :         mpDrawEditEngine->SetText( aEmptyStr );
    1175         112 :         mpDrawEditEngine->SetParaAttribs(0, mpDrawEditEngine->GetEmptyItemSet());
    1176             :     }
    1177             : 
    1178         116 :     pStrm->Seek( nOld );
    1179         116 :     if (pbContainsGraphics)
    1180           0 :         *pbContainsGraphics = bContainsGraphics;
    1181         116 :     return pFlyFmt;
    1182             : }
    1183             : 
    1184             : 
    1185           4 : bool SwWW8ImplReader::TxbxChainContainsRealText(sal_uInt16 nTxBxS, long& rStartCp,
    1186             :     long&  rEndCp)
    1187             : {
    1188             :     bool bErase, bContainsText;
    1189             :     InsertTxbxText( 0,0,nTxBxS,USHRT_MAX,0,0,0, bErase, &bContainsText,
    1190           4 :         &rStartCp, &rEndCp );
    1191           4 :     return bContainsText;
    1192             : }
    1193             : 
    1194             : 
    1195             : // TextBoxes only for Ver67 !!
    1196           0 : SdrObject* SwWW8ImplReader::ReadTxtBox( WW8_DPHEAD* pHd, const WW8_DO* pDo,
    1197             :     SfxAllItemSet &rSet)
    1198             : {
    1199             :     bool bDummy;
    1200             :     WW8_DP_TXTBOX aTxtB;
    1201             : 
    1202           0 :     if( !ReadGrafStart( (void*)&aTxtB, sizeof( aTxtB ), pHd, pDo, rSet ) )
    1203           0 :         return 0;
    1204             : 
    1205           0 :     Point aP0( (sal_Int16)SVBT16ToShort( pHd->xa ) + nDrawXOfs2,
    1206           0 :                (sal_Int16)SVBT16ToShort( pHd->ya ) + nDrawYOfs2 );
    1207           0 :     Point aP1( aP0 );
    1208           0 :     aP1.X() += (sal_Int16)SVBT16ToShort( pHd->dxa );
    1209           0 :     aP1.Y() += (sal_Int16)SVBT16ToShort( pHd->dya );
    1210             : 
    1211           0 :     SdrObject* pObj = new SdrRectObj( OBJ_TEXT, Rectangle( aP0, aP1 ) );
    1212           0 :     pObj->SetModel( pDrawModel );
    1213           0 :     pObj->NbcSetSnapRect(Rectangle(aP0, aP1));
    1214           0 :     Size aSize( (sal_Int16)SVBT16ToShort( pHd->dxa ) ,
    1215           0 :         (sal_Int16)SVBT16ToShort( pHd->dya ) );
    1216             : 
    1217             :     long nStartCpFly,nEndCpFly;
    1218             :     bool bContainsGraphics;
    1219           0 :     InsertTxbxText(PTR_CAST(SdrTextObj,pObj), &aSize, 0, 0, 0, 0, false,
    1220           0 :         bDummy,0,&nStartCpFly,&nEndCpFly,&bContainsGraphics);
    1221             : 
    1222           0 :     SetStdAttr( rSet, aTxtB.aLnt, aTxtB.aShd );
    1223           0 :     SetFill( rSet, aTxtB.aFill );
    1224             : 
    1225           0 :     rSet.Put( SdrTextFitToSizeTypeItem( SDRTEXTFIT_NONE ) );
    1226           0 :     rSet.Put( SdrTextAutoGrowWidthItem(false));
    1227           0 :     rSet.Put( SdrTextAutoGrowHeightItem(false));
    1228           0 :     rSet.Put( SdrTextLeftDistItem(  MIN_BORDER_DIST*2 ) );
    1229           0 :     rSet.Put( SdrTextRightDistItem( MIN_BORDER_DIST*2 ) );
    1230           0 :     rSet.Put( SdrTextUpperDistItem( MIN_BORDER_DIST ) );
    1231           0 :     rSet.Put( SdrTextLowerDistItem( MIN_BORDER_DIST ) );
    1232             : 
    1233           0 :     return pObj;
    1234             : }
    1235             : 
    1236           0 : SdrObject* SwWW8ImplReader::ReadCaptionBox( WW8_DPHEAD* pHd, const WW8_DO* pDo,
    1237             :     SfxAllItemSet &rSet)
    1238             : {
    1239             :     static SdrCaptionType aCaptA[] = { SDRCAPT_TYPE1, SDRCAPT_TYPE2,
    1240             :                                        SDRCAPT_TYPE3, SDRCAPT_TYPE4 };
    1241             : 
    1242             :     WW8_DP_CALLOUT_TXTBOX aCallB;
    1243             : 
    1244           0 :     if( !ReadGrafStart( (void*)&aCallB, sizeof( aCallB ), pHd, pDo, rSet ) )
    1245           0 :         return 0;
    1246             : 
    1247           0 :     sal_uInt16 nCount = SVBT16ToShort( aCallB.dpPolyLine.aBits1 ) >> 1 & 0x7fff;
    1248           0 :     boost::scoped_array<SVBT16> xP(new SVBT16[nCount * 2]);
    1249             : 
    1250           0 :     bool bCouldRead = checkRead(*pStrm, xP.get(), nCount * 4);      // Punkte einlesen
    1251             :     OSL_ENSURE(bCouldRead, "Short CaptionBox header");
    1252           0 :     if (!bCouldRead)
    1253           0 :         return 0;
    1254             : 
    1255           0 :     sal_uInt8 nTyp = (sal_uInt8)nCount - 1;
    1256           0 :     if( nTyp == 1 && SVBT16ToShort( xP[0] ) == SVBT16ToShort( xP[2] ) )
    1257           0 :         nTyp = 0;
    1258             : 
    1259           0 :     Point aP0( (sal_Int16)SVBT16ToShort( pHd->xa ) +
    1260           0 :                (sal_Int16)SVBT16ToShort( aCallB.dpheadTxbx.xa ) + nDrawXOfs2,
    1261           0 :                (sal_Int16)SVBT16ToShort( pHd->ya )
    1262           0 :                + (sal_Int16)SVBT16ToShort( aCallB.dpheadTxbx.ya ) + nDrawYOfs2 );
    1263           0 :     Point aP1( aP0 );
    1264           0 :     aP1.X() += (sal_Int16)SVBT16ToShort( aCallB.dpheadTxbx.dxa );
    1265           0 :     aP1.Y() += (sal_Int16)SVBT16ToShort( aCallB.dpheadTxbx.dya );
    1266           0 :     Point aP2( (sal_Int16)SVBT16ToShort( pHd->xa )
    1267           0 :                 + (sal_Int16)SVBT16ToShort( aCallB.dpheadPolyLine.xa )
    1268           0 :                 + nDrawXOfs2 + (sal_Int16)SVBT16ToShort( xP[0] ),
    1269           0 :                (sal_Int16)SVBT16ToShort( pHd->ya )
    1270           0 :                + (sal_Int16)SVBT16ToShort( aCallB.dpheadPolyLine.ya )
    1271           0 :                + nDrawYOfs2 + (sal_Int16)SVBT16ToShort( xP[1] ) );
    1272           0 :     xP.reset();
    1273             : 
    1274           0 :     SdrCaptionObj* pObj = new SdrCaptionObj( Rectangle( aP0, aP1 ), aP2 );
    1275           0 :     pObj->SetModel( pDrawModel );
    1276           0 :     pObj->NbcSetSnapRect(Rectangle(aP0, aP1));
    1277           0 :     Size aSize( (sal_Int16)SVBT16ToShort( aCallB.dpheadTxbx.dxa ),
    1278           0 :                            (sal_Int16)SVBT16ToShort(  aCallB.dpheadTxbx.dya ) );
    1279             :     bool bEraseThisObject;
    1280             : 
    1281           0 :     InsertTxbxText(pObj, &aSize, 0, 0, 0, 0, false, bEraseThisObject );
    1282             : 
    1283           0 :     if( SVBT16ToShort( aCallB.dptxbx.aLnt.lnps ) != 5 ) // Umrandung sichtbar ?
    1284           0 :         SetStdAttr( rSet, aCallB.dptxbx.aLnt, aCallB.dptxbx.aShd );
    1285             :     else                                                // nein -> Nimm Linie
    1286           0 :         SetStdAttr( rSet, aCallB.dpPolyLine.aLnt, aCallB.dptxbx.aShd );
    1287           0 :     SetFill( rSet, aCallB.dptxbx.aFill );
    1288           0 :     rSet.Put( SdrCaptionTypeItem( aCaptA[nTyp] ) );
    1289             : 
    1290           0 :     return pObj;
    1291             : }
    1292             : 
    1293             : 
    1294           0 : SdrObject *SwWW8ImplReader::ReadGroup( WW8_DPHEAD* pHd, const WW8_DO* pDo,
    1295             :     SfxAllItemSet &rSet)
    1296             : {
    1297             :     sal_Int16 nGrouped;
    1298             : 
    1299           0 :     if( !ReadGrafStart( (void*)&nGrouped, sizeof( nGrouped ), pHd, pDo, rSet ) )
    1300           0 :         return 0;
    1301             : 
    1302             : #ifdef OSL_BIGENDIAN
    1303             :     nGrouped = (sal_Int16)OSL_SWAPWORD( nGrouped );
    1304             : #endif
    1305             : 
    1306           0 :     nDrawXOfs = nDrawXOfs + (sal_Int16)SVBT16ToShort( pHd->xa );
    1307           0 :     nDrawYOfs = nDrawYOfs + (sal_Int16)SVBT16ToShort( pHd->ya );
    1308             : 
    1309           0 :     SdrObject* pObj = new SdrObjGroup;
    1310             : 
    1311           0 :     short nLeft = (sal_Int16)SVBT16ToShort( pHd->cb ) - sizeof( WW8_DPHEAD );
    1312           0 :     for (int i = 0; i < nGrouped; i++)
    1313             :     {
    1314           0 :         SfxAllItemSet aSet(pDrawModel->GetItemPool());
    1315           0 :         if (SdrObject *pObject = ReadGrafPrimitive(nLeft, pDo, aSet))
    1316             :         {
    1317             :             // first add and then set ItemSet
    1318           0 :             SdrObjList *pSubGroup = pObj->GetSubList();
    1319             :             OSL_ENSURE(pSubGroup, "Why no sublist available?");
    1320           0 :             if (pSubGroup)
    1321           0 :                 pSubGroup->InsertObject(pObject, 0);
    1322           0 :             pObject->SetMergedItemSetAndBroadcast(aSet);
    1323             :         }
    1324           0 :     }
    1325             : 
    1326           0 :     nDrawXOfs = nDrawXOfs - (sal_Int16)SVBT16ToShort( pHd->xa );
    1327           0 :     nDrawYOfs = nDrawYOfs - (sal_Int16)SVBT16ToShort( pHd->ya );
    1328             : 
    1329           0 :     return pObj;
    1330             : }
    1331             : 
    1332           0 : SdrObject* SwWW8ImplReader::ReadGrafPrimitive( short& rLeft, const WW8_DO* pDo,
    1333             :     SfxAllItemSet &rSet)
    1334             : {
    1335             :     //cmc: This whole archaic word 6 graphic import can probably be refactored
    1336             :     //into an object hierarachy with a little effort.
    1337           0 :     SdrObject *pRet=0;
    1338             :     WW8_DPHEAD aHd;                         // Lese Draw-Primitive-Header
    1339           0 :     bool bCouldRead = checkRead(*pStrm, &aHd, sizeof(WW8_DPHEAD));
    1340             :     OSL_ENSURE(bCouldRead, "Graphic Primitive header short read" );
    1341           0 :     if (!bCouldRead)
    1342             :     {
    1343           0 :         rLeft=0;
    1344           0 :         return pRet;
    1345             :     }
    1346             : 
    1347           0 :     if( rLeft >= SVBT16ToShort(aHd.cb) )    // Vorsichtsmassmahme
    1348             :     {
    1349           0 :         rSet.Put(SwFmtSurround(SURROUND_THROUGHT));
    1350           0 :         switch (SVBT16ToShort(aHd.dpk) & 0xff )
    1351             :         {
    1352             :             case 0:
    1353           0 :                 pRet = ReadGroup( &aHd, pDo, rSet );
    1354           0 :                 break;
    1355             :             case 1:
    1356           0 :                 pRet = ReadLine( &aHd, pDo, rSet );
    1357           0 :                 break;
    1358             :             case 2:
    1359           0 :                 pRet = ReadTxtBox( &aHd, pDo, rSet );
    1360           0 :                 break;
    1361             :             case 3:
    1362           0 :                 pRet = ReadRect( &aHd, pDo, rSet );
    1363           0 :                 break;
    1364             :             case 4:
    1365           0 :                 pRet = ReadElipse( &aHd, pDo, rSet );
    1366           0 :                 break;
    1367             :             case 5:
    1368           0 :                 pRet = ReadArc( &aHd, pDo, rSet );
    1369           0 :                 break;
    1370             :             case 6:
    1371           0 :                 pRet = ReadPolyLine( &aHd, pDo, rSet );
    1372           0 :                 break;
    1373             :             case 7:
    1374           0 :                 pRet = ReadCaptionBox( &aHd, pDo, rSet );
    1375           0 :                 break;
    1376             :             default:    // unbekannt
    1377           0 :                 pStrm->SeekRel(SVBT16ToShort(aHd.cb) - sizeof(WW8_DPHEAD));
    1378           0 :                 break;
    1379             :         }
    1380             :     }
    1381             :     else
    1382             :     {
    1383             :         OSL_ENSURE( !this, "+Grafik-Overlap" );
    1384             :     }
    1385           0 :     rLeft = rLeft - SVBT16ToShort( aHd.cb );
    1386           0 :     return pRet;
    1387             : }
    1388             : 
    1389           0 : void SwWW8ImplReader::ReadGrafLayer1( WW8PLCFspecial* pPF, long nGrafAnchorCp )
    1390             : {
    1391           0 :     pPF->SeekPos( nGrafAnchorCp );
    1392             :     WW8_FC nStartFc;
    1393             :     void* pF0;
    1394           0 :     if( !pPF->Get( nStartFc, pF0 ) )
    1395             :     {
    1396             :         OSL_ENSURE( !this, "+Wo ist die Grafik (2) ?" );
    1397             :         return;
    1398             :     }
    1399           0 :     WW8_FDOA* pF = (WW8_FDOA*)pF0;
    1400           0 :     if( !SVBT32ToUInt32( pF->fc ) )
    1401             :     {
    1402             :         OSL_ENSURE( !this, "+Wo ist die Grafik (3) ?" );
    1403             :         return;
    1404             :     }
    1405             : 
    1406           0 :     bool bCouldSeek = checkSeek(*pStrm, SVBT32ToUInt32(pF->fc));
    1407             :     OSL_ENSURE(bCouldSeek, "Invalid Graphic offset");
    1408           0 :     if (!bCouldSeek)
    1409             :         return;
    1410             : 
    1411             :     // Lese Draw-Header
    1412             :     WW8_DO aDo;
    1413           0 :     bool bCouldRead = checkRead(*pStrm, &aDo, sizeof(WW8_DO));
    1414             :     OSL_ENSURE(bCouldRead, "Short Graphic header");
    1415           0 :     if (!bCouldRead)
    1416             :         return;
    1417             : 
    1418           0 :     short nLeft = SVBT16ToShort( aDo.cb ) - sizeof( WW8_DO );
    1419           0 :     while (nLeft > static_cast<short>(sizeof(WW8_DPHEAD)))
    1420             :     {
    1421           0 :         SfxAllItemSet aSet( pDrawModel->GetItemPool() );
    1422           0 :         if (SdrObject *pObject = ReadGrafPrimitive( nLeft, &aDo, aSet ))
    1423             :         {
    1424           0 :             pWWZOrder->InsertDrawingObject(pObject, SVBT16ToShort(aDo.dhgt));
    1425           0 :             SwFrmFmt *pFrm = rDoc.Insert( *pPaM, *pObject, &aSet, NULL);
    1426           0 :             pObject->SetMergedItemSet(aSet);
    1427           0 :             pAnchorStck->AddAnchor(*pPaM->GetPoint(), pFrm);
    1428             :         }
    1429           0 :     }
    1430             : }
    1431             : 
    1432          60 : sal_Int32 SwMSDffManager::GetEscherLineMatch(MSO_LineStyle eStyle,
    1433             :     MSO_SPT eShapeType, sal_Int32 &rThick)
    1434             : {
    1435          60 :     sal_Int32 nOutsideThick = 0;
    1436             :     /*
    1437             :     Beachte: im Gegensatz zu den Winword-ueblichen Tabellen- und
    1438             :     Rahmen-Randbreiten-Angaben, bei denen jeweils aus der Staerke *einer*
    1439             :     Linie die Gesamt-Randbreite zu errechnen ist, liegen die aus dem ESCHER
    1440             :     stammenden Daten bereits als Gesamt-Breite [twips] vor!
    1441             : 
    1442             :     Der Winword default ist 15 tw. Wir nehmen hierfuer unsere 20 tw Linie.  (
    1443             :     0.75 pt uns 1.0 pt sehen sich auf dem Ausdruck naemlich aehnlicher als
    1444             :     etwas 0.75 pt und unsere 0.05 pt Haarlinie. ) Die Haarlinie setzen wir nur
    1445             :     bei Winword-Staerken bis zu maximal 0.5 pt ein.
    1446             :     */
    1447          60 :     switch( eStyle )
    1448             :     {
    1449             :     case mso_lineTriple:
    1450             :     case mso_lineSimple:
    1451          12 :         nOutsideThick = eShapeType != mso_sptTextBox ? rThick : rThick/2;
    1452          12 :         break;
    1453             :     case mso_lineDouble:
    1454           0 :         if (eShapeType == mso_sptTextBox)
    1455             :         {
    1456           0 :             nOutsideThick = rThick/6;
    1457           0 :             rThick = rThick*2/3;
    1458             :         }
    1459             :         else
    1460           0 :             nOutsideThick = rThick*2/3;
    1461           0 :         break;
    1462             :     case mso_lineThickThin:
    1463           0 :         if (eShapeType == mso_sptTextBox)
    1464             :         {
    1465           0 :             nOutsideThick = rThick*3/10;
    1466           0 :             rThick = rThick*4/5;
    1467             :         }
    1468             :         else
    1469           0 :             nOutsideThick = rThick*4/5;
    1470           0 :         break;
    1471             :     case mso_lineThinThick:
    1472             :         {
    1473           0 :         if (eShapeType == mso_sptTextBox)
    1474             :         {
    1475           0 :             nOutsideThick = rThick/10;
    1476           0 :             rThick = rThick*3/5;
    1477             :         }
    1478             :         else
    1479           0 :             nOutsideThick = rThick*3/5;
    1480             :         }
    1481           0 :         break;
    1482             :     default:
    1483          48 :         break;
    1484             :     }
    1485          60 :     return nOutsideThick;
    1486             : }
    1487             : 
    1488             : //Returns the thickness of the line outside the frame, the logic of
    1489             : //words positioning of borders around floating objects is that of a
    1490             : //disturbed mind.
    1491          60 : sal_Int32 SwWW8ImplReader::MatchSdrBoxIntoFlyBoxItem(const Color& rLineColor,
    1492             :     MSO_LineStyle eLineStyle, MSO_LineDashing eDashing, MSO_SPT eShapeType, sal_Int32 &rLineThick,
    1493             :     SvxBoxItem& rBox )
    1494             : {
    1495          60 :     sal_Int32 nOutsideThick = 0;
    1496          60 :     if( !rLineThick )
    1497           0 :         return nOutsideThick;
    1498             : 
    1499          60 :     ::editeng::SvxBorderStyle nIdx = table::BorderLineStyle::NONE;
    1500             : 
    1501          60 :     sal_Int32 nLineThick=rLineThick;
    1502             :     nOutsideThick = SwMSDffManager::GetEscherLineMatch(eLineStyle,
    1503          60 :         eShapeType, rLineThick);
    1504             : 
    1505             :     /*
    1506             :     Beachte: im Gegensatz zu den Winword-ueblichen Tabellen- und
    1507             :     Rahmen-Randbreiten-Angaben, bei denen jeweils aus der Staerke *einer*
    1508             :     Linie die Gesamt-Randbreite zu errechnen ist, liegen die aus dem ESCHER
    1509             :     stammenden Daten bereits als Gesamt-Breite [twips] vor!
    1510             : 
    1511             :     Der Winword default ist 15 tw. Wir nehmen hierfuer unsere 20 tw Linie.  (
    1512             :     0.75 pt uns 1.0 pt sehen sich auf dem Ausdruck naemlich aehnlicher als
    1513             :     etwas 0.75 pt und unsere 0.05 pt Haarlinie. ) Die Haarlinie setzen wir nur
    1514             :     bei Winword-Staerken bis zu maximal 0.5 pt ein.
    1515             :     */
    1516          60 :     switch( +eLineStyle )
    1517             :     {
    1518             :     // zuerst die Einzel-Linien
    1519             :     case mso_lineSimple:
    1520          12 :         nIdx = table::BorderLineStyle::SOLID;
    1521          12 :     break;
    1522             :     // dann die Doppel-Linien, fuer die wir feine Entsprechungen haben :-)))
    1523             :     case mso_lineDouble:
    1524           0 :         nIdx = table::BorderLineStyle::DOUBLE;
    1525           0 :     break;
    1526             :     case mso_lineThickThin:
    1527           0 :         nIdx = table::BorderLineStyle::THICKTHIN_SMALLGAP;
    1528           0 :     break;
    1529             :     case mso_lineThinThick:
    1530           0 :         nIdx = table::BorderLineStyle::THINTHICK_SMALLGAP;
    1531           0 :     break;
    1532             :     // We have no triple border, use double instead.
    1533             :     case mso_lineTriple:
    1534           0 :         nIdx = table::BorderLineStyle::DOUBLE;
    1535           0 :     break;
    1536             :     // no line style is set
    1537             :     case (MSO_LineStyle)USHRT_MAX:
    1538          48 :         break;
    1539             :     // erroneously not implemented line style is set
    1540             :     default:
    1541             :         OSL_ENSURE(!this, "eLineStyle is not (yet) implemented!");
    1542           0 :         break;
    1543             :     }
    1544             : 
    1545          60 :     switch( eDashing )
    1546             :     {
    1547             :         case mso_lineDashGEL:
    1548           0 :             nIdx = table::BorderLineStyle::DASHED;
    1549           0 :             break;
    1550             :         case mso_lineDotGEL:
    1551           0 :             nIdx = table::BorderLineStyle::DOTTED;
    1552           0 :             break;
    1553             :         default:
    1554          60 :             break;
    1555             :     }
    1556             : 
    1557          60 :     if (table::BorderLineStyle::NONE != nIdx)
    1558             :     {
    1559          12 :         SvxBorderLine aLine;
    1560          12 :         aLine.SetColor( rLineColor );
    1561             : 
    1562          12 :         aLine.SetWidth( nLineThick ); // No conversion here, nLineThick is already in twips
    1563          12 :         aLine.SetBorderLineStyle(nIdx);
    1564             : 
    1565          60 :         for(sal_uInt16 nLine = 0; nLine < 4; ++nLine)
    1566          48 :             rBox.SetLine(new SvxBorderLine( aLine ), nLine);
    1567             :     }
    1568             : 
    1569          60 :     return nOutsideThick;
    1570             : }
    1571             : 
    1572             : #define WW8ITEMVALUE(ItemSet,Id,Cast)  ((const Cast&)(ItemSet).Get(Id)).GetValue()
    1573             : 
    1574          60 : void SwWW8ImplReader::MatchSdrItemsIntoFlySet( SdrObject* pSdrObj,
    1575             :     SfxItemSet& rFlySet, MSO_LineStyle eLineStyle, MSO_LineDashing eDashing, MSO_SPT eShapeType,
    1576             :     Rectangle& rInnerDist )
    1577             : {
    1578             : /*
    1579             :     am Rahmen zu setzende Frame-Attribute
    1580             :     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1581             :     SwFmtFrmSize            falls noch nicht gesetzt, hier setzen
    1582             :     SvxLRSpaceItem          hier setzen
    1583             :     SvxULSpaceItem          hier setzen
    1584             :     SvxOpaqueItem           (Derzeit bei Rahmen nicht moeglich! khz 10.2.1999)
    1585             :     SwFmtSurround           bereits gesetzt
    1586             :     SwFmtVertOrient         bereits gesetzt
    1587             :     SwFmtHoriOrient         bereits gesetzt
    1588             :     SwFmtAnchor             bereits gesetzt
    1589             :     SvxBoxItem              hier setzen
    1590             :     SvxBrushItem            hier setzen
    1591             :     SvxShadowItem           hier setzen
    1592             : */
    1593             : 
    1594             :     // 1. GrafikObjekt des Docs?
    1595          60 :     GrafikCtor();
    1596             : 
    1597          60 :     const SfxItemSet& rOldSet = pSdrObj->GetMergedItemSet();
    1598             : 
    1599             :     // einige Items koennen direkt so uebernommen werden
    1600          60 :     const sal_uInt16 nDirectMatch = 2;
    1601             :     static RES_FRMATR const aDirectMatch[ nDirectMatch ] =
    1602             :     {
    1603             :         RES_LR_SPACE,   // Aussenabstand links/rechts: SvxLRSpaceItem
    1604             :         RES_UL_SPACE    // Aussenabstand Oben/unten:   SvxULSpaceItem
    1605             :     };
    1606             :     const SfxPoolItem* pPoolItem;
    1607         180 :     for(sal_uInt16 nItem = 0; nItem < nDirectMatch; ++nItem)
    1608         120 :         if( SFX_ITEM_SET == rOldSet.GetItemState(
    1609         120 :                     static_cast< sal_uInt16 >(aDirectMatch[ nItem ]), false, &pPoolItem) )
    1610             :         {
    1611           0 :             rFlySet.Put( *pPoolItem );
    1612             :         }
    1613             : 
    1614             : 
    1615             :     // jetzt die Umrandung berechnen und die Box bauen: Das Mass wird fuer die
    1616             :     // Rahmen-GROESSE benoetigt!
    1617          60 :     SvxBoxItem aBox(sw::util::ItemGet<SvxBoxItem>(rFlySet, RES_BOX));
    1618             :     // dashed oder solid wird zu solid
    1619             :     // WW-default: 0.75 pt = 15 twips
    1620          60 :     sal_Int32 nLineThick = 15, nOutside=0;
    1621             : 
    1622             :     // check if LineStyle is *really* set!
    1623             :     const SfxPoolItem* pItem;
    1624             : 
    1625          60 :     SfxItemState eState = rOldSet.GetItemState(XATTR_LINESTYLE,true,&pItem);
    1626          60 :     if( eState == SFX_ITEM_SET )
    1627             :     {
    1628             :         // Now, that we know there is a line style we will make use the
    1629             :         // parameter given to us when calling the method...  :-)
    1630             :         const Color aLineColor = static_cast< XLineColorItem const & >(
    1631          60 :             rOldSet.Get(XATTR_LINECOLOR)).GetColorValue();
    1632          60 :         nLineThick = WW8ITEMVALUE(rOldSet, XATTR_LINEWIDTH, XLineWidthItem);
    1633             : 
    1634          60 :         if( !nLineThick )
    1635          56 :             nLineThick = 1; // for Writer, zero is "no border", so set a minimal value
    1636             : 
    1637             :         nOutside = MatchSdrBoxIntoFlyBoxItem(aLineColor, eLineStyle,
    1638          60 :             eDashing, eShapeType, nLineThick, aBox);
    1639             :     }
    1640             : 
    1641          60 :     rInnerDist.Left()+=nLineThick;
    1642          60 :     rInnerDist.Top()+=nLineThick;
    1643          60 :     rInnerDist.Right()+=nLineThick;
    1644          60 :     rInnerDist.Bottom()+=nLineThick;
    1645             : 
    1646             :     const SvxBorderLine *pLine;
    1647          60 :     if (0 != (pLine = aBox.GetLine(BOX_LINE_LEFT)))
    1648             :     {
    1649          12 :         rInnerDist.Left() -= (pLine->GetScaledWidth());
    1650             :     }
    1651             : 
    1652          60 :     if (0 != (pLine = aBox.GetLine(BOX_LINE_TOP)))
    1653             :     {
    1654          12 :         rInnerDist.Top() -= (pLine->GetScaledWidth());
    1655             :     }
    1656             : 
    1657          60 :     if (0 != (pLine = aBox.GetLine(BOX_LINE_RIGHT)))
    1658             :     {
    1659          12 :         rInnerDist.Right() -= (pLine->GetScaledWidth());
    1660             :     }
    1661             : 
    1662          60 :     if (0 != (pLine = aBox.GetLine(BOX_LINE_BOTTOM)))
    1663             :     {
    1664          12 :         rInnerDist.Bottom() -= (pLine->GetScaledWidth());
    1665             :     }
    1666             : 
    1667             :     // set distances from box's border to text contained within the box
    1668          60 :     if( 0 < rInnerDist.Left() )
    1669          54 :         aBox.SetDistance( (sal_uInt16)rInnerDist.Left(), BOX_LINE_LEFT );
    1670          60 :     if( 0 < rInnerDist.Top() )
    1671          54 :         aBox.SetDistance( (sal_uInt16)rInnerDist.Top(), BOX_LINE_TOP );
    1672          60 :     if( 0 < rInnerDist.Right() )
    1673          60 :         aBox.SetDistance( (sal_uInt16)rInnerDist.Right(), BOX_LINE_RIGHT );
    1674          60 :     if( 0 < rInnerDist.Bottom() )
    1675          60 :         aBox.SetDistance( (sal_uInt16)rInnerDist.Bottom(), BOX_LINE_BOTTOM );
    1676             : 
    1677          60 :     bool bFixSize = !(WW8ITEMVALUE(rOldSet, SDRATTR_TEXT_AUTOGROWHEIGHT,
    1678          60 :         SdrTextAutoGrowHeightItem));
    1679             : 
    1680             :     // Size: SwFmtFrmSize
    1681          60 :     if( SFX_ITEM_SET != rFlySet.GetItemState(RES_FRM_SIZE, false) )
    1682             :     {
    1683           0 :         const Rectangle& rSnapRect = pSdrObj->GetSnapRect();
    1684             :         // if necessary adapt width and position of the framework: The
    1685             :         // recorded interior is to remain equally large despite thick edges.
    1686             :         rFlySet.Put( SwFmtFrmSize(bFixSize ? ATT_FIX_SIZE : ATT_VAR_SIZE,
    1687           0 :             rSnapRect.GetWidth()  + 2*nOutside,
    1688           0 :             rSnapRect.GetHeight() + 2*nOutside) );
    1689             :     }
    1690             :     else //If a size is set, adjust it to consider border thickness
    1691             :     {
    1692          60 :         SwFmtFrmSize aSize = (const SwFmtFrmSize &)(rFlySet.Get(RES_FRM_SIZE));
    1693             : 
    1694             :         SwFmtFrmSize aNewSize = SwFmtFrmSize(bFixSize ? ATT_FIX_SIZE : ATT_VAR_SIZE,
    1695          60 :             aSize.GetWidth()  + 2*nOutside,
    1696         120 :             aSize.GetHeight() + 2*nOutside);
    1697          60 :         aNewSize.SetWidthSizeType(aSize.GetWidthSizeType());
    1698          60 :         rFlySet.Put( aNewSize );
    1699             :     }
    1700             : 
    1701             :     //Sadly word puts escher borders outside the graphic, but orients the
    1702             :     //graphic in relation to the top left inside the border. We don't
    1703          60 :     if (nOutside)
    1704             :     {
    1705             :         SwFmtHoriOrient aHori = (const SwFmtHoriOrient &)(rFlySet.Get(
    1706          10 :             RES_HORI_ORIENT));
    1707          10 :         aHori.SetPos(MakeSafePositioningValue(aHori.GetPos()-nOutside));
    1708          10 :         rFlySet.Put(aHori);
    1709             : 
    1710             :         SwFmtVertOrient aVert = (const SwFmtVertOrient &)(rFlySet.Get(
    1711          10 :             RES_VERT_ORIENT));
    1712          10 :         aVert.SetPos(aVert.GetPos()-nOutside);
    1713          10 :         rFlySet.Put(aVert);
    1714             :     }
    1715             : 
    1716             :     // jetzt die Umrandung setzen
    1717          60 :     rFlySet.Put( aBox );
    1718             : 
    1719             :     // Schattenwurf der Box: SvxShadowItem
    1720          60 :     if( WW8ITEMVALUE(rOldSet, SDRATTR_SHADOW, SdrShadowItem) )
    1721             :     {
    1722           4 :         SvxShadowItem aShadow( RES_SHADOW );
    1723             : 
    1724             :         const Color aShdColor = static_cast< SdrShadowColorItem const & >(
    1725           4 :             rOldSet.Get(SDRATTR_SHADOWCOLOR)).GetColorValue();
    1726           4 :         const sal_Int32 nShdDistX = WW8ITEMVALUE(rOldSet, SDRATTR_SHADOWXDIST,
    1727             :             SdrShadowXDistItem);
    1728           4 :         const sal_Int32 nShdDistY = WW8ITEMVALUE(rOldSet, SDRATTR_SHADOWYDIST,
    1729             :             SdrShadowYDistItem);
    1730             : 
    1731           4 :         aShadow.SetColor( Color( aShdColor ) );
    1732             : 
    1733           4 :         aShadow.SetWidth(writer_cast<sal_uInt16>((Abs( nShdDistX) +
    1734           4 :             Abs( nShdDistY )) / 2 ));
    1735             : 
    1736             :         SvxShadowLocation eShdPosi;
    1737           4 :         if( 0 <= nShdDistX )
    1738             :         {
    1739           4 :             if( 0 <= nShdDistY )
    1740           4 :                 eShdPosi = SVX_SHADOW_BOTTOMRIGHT;
    1741             :             else
    1742           0 :                 eShdPosi = SVX_SHADOW_TOPRIGHT;
    1743             :         }
    1744             :         else
    1745             :         {
    1746           0 :             if( 0 <= nShdDistY )
    1747           0 :                 eShdPosi = SVX_SHADOW_BOTTOMLEFT;
    1748             :             else
    1749           0 :                 eShdPosi = SVX_SHADOW_TOPLEFT;
    1750             :         }
    1751           4 :         aShadow.SetLocation( eShdPosi );
    1752             : 
    1753           4 :         rFlySet.Put( aShadow );
    1754             :     }
    1755          60 :     Color Temp(COL_WHITE);
    1756          60 :     SvxBrushItem aBrushItem(Temp, RES_BACKGROUND);
    1757          60 :     bool bBrushItemOk = false;
    1758          60 :     sal_uInt8 nTrans = 0;
    1759             : 
    1760             :     //Seperate transparency
    1761          60 :     eState = rOldSet.GetItemState(XATTR_FILLTRANSPARENCE, true, &pItem);
    1762          60 :     if (eState == SFX_ITEM_SET)
    1763             :     {
    1764           0 :         sal_uInt16 nRes = WW8ITEMVALUE(rOldSet, XATTR_FILLTRANSPARENCE,
    1765             :             XFillTransparenceItem);
    1766           0 :         nTrans = sal_uInt8((nRes * 0xFE) / 100);
    1767           0 :         aBrushItem.GetColor().SetTransparency(nTrans);
    1768           0 :         bBrushItemOk = true;
    1769             :     }
    1770             : 
    1771             :     // Hintergrund: SvxBrushItem
    1772          60 :     eState = rOldSet.GetItemState(XATTR_FILLSTYLE, true, &pItem);
    1773          60 :     if (eState == SFX_ITEM_SET)
    1774             :     {
    1775          60 :         const XFillStyle eFill = ((const XFillStyleItem*)pItem)->GetValue();
    1776             : 
    1777          60 :         switch (eFill)
    1778             :         {
    1779             :             case XFILL_NONE:
    1780             :                 //Writer graphics don't have it yet
    1781          40 :                 if (eShapeType != mso_sptPictureFrame)
    1782             :                 {
    1783           0 :                     aBrushItem.GetColor().SetTransparency(0xFE);
    1784           0 :                     bBrushItemOk = true;
    1785             :                 }
    1786          40 :             break;
    1787             :             case XFILL_SOLID:
    1788             :             case XFILL_GRADIENT:
    1789             :                 {
    1790             :                     const Color aColor = static_cast< XFillColorItem const & >(
    1791          20 :                         rOldSet.Get(XATTR_FILLCOLOR)).GetColorValue();
    1792          20 :                     aBrushItem.SetColor(aColor);
    1793             : 
    1794          20 :                     if (bBrushItemOk) //has trans
    1795           0 :                         aBrushItem.GetColor().SetTransparency(nTrans);
    1796             : 
    1797          20 :                     bBrushItemOk = true;
    1798             :                 }
    1799          20 :             break;
    1800             :             //case XFILL_GRADIENT:
    1801             :             //break;
    1802             :             case XFILL_HATCH:
    1803           0 :             break;
    1804             :             case XFILL_BITMAP:
    1805             :                 {
    1806             :                     const Graphic aGraphic(
    1807             :                         static_cast< XFillBitmapItem const & >(
    1808           0 :                             rOldSet.Get(XATTR_FILLBITMAP)).
    1809           0 :                         GetBitmapValue().GetBitmap());
    1810           0 :                     bool bTile = WW8ITEMVALUE(rOldSet, XATTR_FILLBMP_TILE,
    1811           0 :                         SfxBoolItem) ? true: false;
    1812           0 :                     GraphicObject aGrfObj(aGraphic);
    1813             : 
    1814           0 :                     aBrushItem.SetGraphicObject(aGrfObj);
    1815             : 
    1816           0 :                     if (bBrushItemOk) //has trans
    1817             :                     {
    1818             :                         GraphicObject *pGraphicObject =
    1819             :                             const_cast<GraphicObject *>
    1820           0 :                             (aBrushItem.GetGraphicObject());
    1821           0 :                         GraphicAttr aAttr(pGraphicObject->GetAttr());
    1822           0 :                         aAttr.SetTransparency(nTrans);
    1823           0 :                         pGraphicObject->SetAttr(aAttr);
    1824             :                     }
    1825             : 
    1826           0 :                     aBrushItem.SetGraphicPos(bTile ? GPOS_TILED : GPOS_AREA);
    1827             : 
    1828           0 :                     bBrushItemOk = true;
    1829             :                 }
    1830           0 :             break;
    1831             :         }
    1832             :     }
    1833             : 
    1834          60 :     if (bBrushItemOk)
    1835          20 :         rFlySet.Put(aBrushItem, RES_BACKGROUND);
    1836          60 : }
    1837             : 
    1838         100 : void SwWW8ImplReader::AdjustLRWrapForWordMargins(
    1839             :     const SvxMSDffImportRec &rRecord, SvxLRSpaceItem &rLR)
    1840             : {
    1841         100 :     sal_uInt32 nXRelTo = SvxMSDffImportRec::RELTO_DEFAULT;
    1842         100 :     if ( rRecord.pXRelTo )
    1843             :     {
    1844          76 :         nXRelTo = *(rRecord.pXRelTo);
    1845             :     }
    1846             : 
    1847             :     // Left adjustments - if horizontally aligned to left of
    1848             :     // margin or column then remove the left wrapping
    1849         100 :     if (rRecord.nXAlign == 1)
    1850             :     {
    1851           2 :         if ((nXRelTo == 0) || (nXRelTo == 2))
    1852           0 :             rLR.SetLeft((sal_uInt16)0);
    1853             :     }
    1854             : 
    1855             :     // Right adjustments - if horizontally aligned to right of
    1856             :     // margin or column then remove the right wrapping
    1857         100 :     if (rRecord.nXAlign == 3)
    1858             :     {
    1859           0 :         if ((nXRelTo == 0) || (nXRelTo == 2))
    1860           0 :             rLR.SetRight((sal_uInt16)0);
    1861             :     }
    1862             : 
    1863             :     //Inside margin, remove left wrapping
    1864         100 :     if ((rRecord.nXAlign == 4) && (nXRelTo == 0))
    1865             :     {
    1866           0 :         rLR.SetLeft((sal_uInt16)0);
    1867             :     }
    1868             : 
    1869             :     //Outside margin, remove left wrapping
    1870         100 :     if ((rRecord.nXAlign == 5) && (nXRelTo == 0))
    1871             :     {
    1872           0 :         rLR.SetRight((sal_uInt16)0);
    1873             :     }
    1874         100 : }
    1875             : 
    1876             : 
    1877           0 : void SwWW8ImplReader::AdjustULWrapForWordMargins(
    1878             :     const SvxMSDffImportRec &rRecord, SvxULSpaceItem &rUL)
    1879             : {
    1880           0 :     sal_uInt32 nYRelTo = SvxMSDffImportRec::RELTO_DEFAULT;
    1881           0 :     if ( rRecord.pYRelTo )
    1882             :     {
    1883           0 :         nYRelTo = *(rRecord.pYRelTo);
    1884             :     }
    1885             : 
    1886             :     // Top adjustment - remove upper wrapping if aligned to page
    1887             :     // printable area or to page
    1888           0 :     if (rRecord.nYAlign == 1)
    1889             :     {
    1890           0 :         if ((nYRelTo == 0) || (nYRelTo == 1))
    1891           0 :             rUL.SetUpper((sal_uInt16)0);
    1892             :     }
    1893             : 
    1894             :     // Bottom adjustment - remove bottom wrapping if aligned to page or
    1895             :     // printable area or to page
    1896           0 :     if (rRecord.nYAlign == 3)
    1897             :     {
    1898           0 :         if ((nYRelTo == 0) || (nYRelTo == 1))
    1899           0 :             rUL.SetLower((sal_uInt16)0);
    1900             :     }
    1901             : 
    1902             :     //Remove top margin if aligned vertically inside margin
    1903           0 :     if ((rRecord.nYAlign == 4) && (nYRelTo == 0))
    1904           0 :         rUL.SetUpper((sal_uInt16)0);
    1905           0 : }
    1906             : 
    1907         104 : void SwWW8ImplReader::MapWrapIntoFlyFmt(SvxMSDffImportRec* pRecord,
    1908             :     SwFrmFmt* pFlyFmt)
    1909             : {
    1910         104 :     if (!pRecord || !pFlyFmt)
    1911         104 :         return;
    1912             : 
    1913         104 :     if (pRecord->nDxWrapDistLeft || pRecord->nDxWrapDistRight)
    1914             :     {
    1915         100 :         SvxLRSpaceItem aLR(writer_cast<sal_uInt16>(pRecord->nDxWrapDistLeft),
    1916         200 :             writer_cast<sal_uInt16>(pRecord->nDxWrapDistRight), 0, 0, RES_LR_SPACE);
    1917         100 :         AdjustLRWrapForWordMargins(*pRecord, aLR);
    1918         100 :         pFlyFmt->SetFmtAttr(aLR);
    1919             :     }
    1920         104 :     if (pRecord->nDyWrapDistTop || pRecord->nDyWrapDistBottom)
    1921             :     {
    1922           0 :         SvxULSpaceItem aUL(writer_cast<sal_uInt16>(pRecord->nDyWrapDistTop),
    1923           0 :             writer_cast<sal_uInt16>(pRecord->nDyWrapDistBottom), RES_UL_SPACE);
    1924           0 :         AdjustULWrapForWordMargins(*pRecord, aUL);
    1925           0 :         pFlyFmt->SetFmtAttr(aUL);
    1926             :     }
    1927             : 
    1928             :     //If we are contoured and have a custom polygon...
    1929         104 :     if (pRecord->pWrapPolygon && pFlyFmt->GetSurround().IsContour())
    1930             :     {
    1931           0 :         if (SwNoTxtNode *pNd = GetNoTxtNodeFromSwFrmFmt(*pFlyFmt))
    1932             :         {
    1933             : 
    1934             :             /*
    1935             :              Gather round children and hear of a tale that will raise the
    1936             :              hairs on the back of your neck this dark halloween night.
    1937             : 
    1938             :              There is a polygon in word that describes the wraping around
    1939             :              the graphic.
    1940             : 
    1941             :              Here are some sample values for the simplest case of a square
    1942             :              around some solid coloured graphics
    1943             : 
    1944             :                                 X       Y       Pixel size of graphic
    1945             :                 TopLeft         -54     21600   400x400
    1946             :                 Bottom Right    0       21546
    1947             : 
    1948             :                 TopLeft         -108    21600   200x200
    1949             :                 Bottom Right    0       21492
    1950             : 
    1951             :                 TopLeft         -216    21600   100x100
    1952             :                 Bottom Right    0       21384
    1953             : 
    1954             :                 TopLeft         -432    21600   50x50
    1955             :                 Bottom Right    0       21168
    1956             : 
    1957             :                 TopLeft         -76     21600   283x212
    1958             :                 Bottom Right    0       21498
    1959             : 
    1960             :              So given that the size of the values remains pretty much the
    1961             :              same despite the size of the graphic, we can tell that the
    1962             :              polygon is measured in units that are independant of the
    1963             :              graphic. But why does the left corner move a different value
    1964             :              to the left each time, and why does the bottom move upwards
    1965             :              each time, when the right and top remain at the same value ?
    1966             : 
    1967             :              I have no idea, but clearly once we calculate the values out
    1968             :              we see that the left margin is always a fixed realworld
    1969             :              distance from the true left and the polygon bottom is the same
    1970             :              fixed value from the bottom. i.e. 15twips.
    1971             : 
    1972             :              So here we take our word provided polygon, shift it to the
    1973             :              right by 15twips and rescale it widthwise to shrink the width
    1974             :              a little to fit the now moved right margin back to where it
    1975             :              was, and stretch the height a little to make the bottom move
    1976             :              down the missing 15twips then we get a polygon that matches
    1977             :              what I actually see in word
    1978             :             */
    1979             : 
    1980           0 :             PolyPolygon aPoly(*pRecord->pWrapPolygon);
    1981           0 :             const Size &rSize = pNd->GetTwipSize();
    1982             :             /*
    1983             :              Move to the left by 15twips, and rescale to
    1984             :              a) shrink right bound back to orig position
    1985             :              b) stretch bottom bound to where I think it should have been
    1986             :              in the first place
    1987             :             */
    1988           0 :             Fraction aMoveHack(ww::nWrap100Percent, rSize.Width());
    1989           0 :             aMoveHack *= Fraction(15, 1);
    1990           0 :             long nMove(aMoveHack);
    1991           0 :             aPoly.Move(nMove, 0);
    1992             : 
    1993           0 :             Fraction aHackX(ww::nWrap100Percent, ww::nWrap100Percent + nMove);
    1994           0 :             Fraction aHackY(ww::nWrap100Percent, ww::nWrap100Percent - nMove);
    1995           0 :             aPoly.Scale(aHackX, aHackY);
    1996             : 
    1997             :             //Turn polygon back into units that match the graphic's
    1998           0 :             const Size &rOrigSize = pNd->GetGraphic().GetPrefSize();
    1999           0 :             Fraction aMapPolyX(rOrigSize.Width(), ww::nWrap100Percent);
    2000           0 :             Fraction aMapPolyY(rOrigSize.Height(), ww::nWrap100Percent);
    2001           0 :             aPoly.Scale(aMapPolyX, aMapPolyY);
    2002             : 
    2003             :             // #i47277# - contour is already in unit of the
    2004             :             // graphic prefered unit. Thus, call method <SetContour(..)>
    2005           0 :             pNd->SetContour(&aPoly);
    2006             :         }
    2007             :     }
    2008             : }
    2009             : 
    2010             : void
    2011          50 : SwWW8ImplReader::SetAttributesAtGrfNode(SvxMSDffImportRec const*const pRecord,
    2012             :     SwFrmFmt *pFlyFmt, WW8_FSPA *pF )
    2013             : {
    2014          50 :     const SwNodeIndex* pIdx = pFlyFmt->GetCntnt(false).GetCntntIdx();
    2015             :     SwGrfNode* pGrfNd;
    2016          50 :     if( pIdx && 0 != (pGrfNd = rDoc.GetNodes()[pIdx->GetIndex() + 1]->GetGrfNode() ))
    2017             :     {
    2018          40 :         Size aSz(pGrfNd->GetTwipSize());
    2019             :         // use type <sal_uInt64> instead of sal_uLong to get correct results
    2020             :         // in the following calculations.
    2021          40 :         sal_uInt64 rHeight = aSz.Height();
    2022          40 :         sal_uInt64 rWidth  = aSz.Width();
    2023          40 :         if( !rWidth && pF)
    2024          22 :             rWidth  = pF->nXaRight  - pF->nXaLeft;
    2025          18 :         else if( !rHeight && pF)
    2026           0 :             rHeight = pF->nYaBottom - pF->nYaTop;
    2027             : 
    2028          40 :         if( pRecord->nCropFromTop || pRecord->nCropFromBottom ||
    2029             :             pRecord->nCropFromLeft || pRecord->nCropFromRight )
    2030             :         {
    2031           0 :             SwCropGrf aCrop;            // Cropping is stored in 'fixed floats'
    2032             :                                         // 16.16 (it est fraction times total
    2033           0 :             if( pRecord->nCropFromTop ) //        image width or height resp.)
    2034             :                 aCrop.SetTop( static_cast< sal_Int32 >(
    2035             :                 (   ( (pRecord->nCropFromTop    >> 16   ) * rHeight )
    2036           0 :                   + (((pRecord->nCropFromTop    & 0xffff) * rHeight ) >> 16) )));
    2037           0 :             if( pRecord->nCropFromBottom )
    2038             :                 aCrop.SetBottom( static_cast< sal_Int32 >(
    2039             :                 (   ( (pRecord->nCropFromBottom >> 16   ) * rHeight )
    2040           0 :                   + (((pRecord->nCropFromBottom & 0xffff) * rHeight ) >> 16) )));
    2041           0 :             if( pRecord->nCropFromLeft )
    2042             :                 aCrop.SetLeft( static_cast< sal_Int32 >(
    2043             :                 (   ( (pRecord->nCropFromLeft   >> 16   ) * rWidth  )
    2044           0 :                   + (((pRecord->nCropFromLeft   & 0xffff) * rWidth  ) >> 16) )));
    2045           0 :             if( pRecord->nCropFromRight )
    2046             :                 aCrop.SetRight( static_cast< sal_Int32 >(
    2047             :                 (   ( (pRecord->nCropFromRight  >> 16   ) * rWidth  )
    2048           0 :                   + (((pRecord->nCropFromRight  & 0xffff) * rWidth  ) >> 16) )));
    2049             : 
    2050           0 :             pGrfNd->SetAttr( aCrop );
    2051             :         }
    2052             : 
    2053          40 :         if (pRecord && pRecord->pObj)
    2054             :         {
    2055          40 :             const SfxItemSet& rOldSet = pRecord->pObj->GetMergedItemSet();
    2056             :             //contrast
    2057          40 :             if (WW8ITEMVALUE(rOldSet, SDRATTR_GRAFCONTRAST,
    2058             :                 SdrGrafContrastItem))
    2059             :             {
    2060             :                 SwContrastGrf aContrast(
    2061           0 :                     WW8ITEMVALUE(rOldSet,
    2062           0 :                     SDRATTR_GRAFCONTRAST, SdrGrafContrastItem));
    2063           0 :                 pGrfNd->SetAttr( aContrast );
    2064             :             }
    2065             : 
    2066             :             //luminance
    2067          40 :             if (WW8ITEMVALUE(rOldSet, SDRATTR_GRAFLUMINANCE,
    2068             :                 SdrGrafLuminanceItem))
    2069             :             {
    2070           0 :                 SwLuminanceGrf aLuminance(WW8ITEMVALUE(rOldSet,
    2071           0 :                     SDRATTR_GRAFLUMINANCE, SdrGrafLuminanceItem));
    2072           0 :                 pGrfNd->SetAttr( aLuminance );
    2073             :             }
    2074             :             //gamma
    2075          40 :             if (WW8ITEMVALUE(rOldSet, SDRATTR_GRAFGAMMA, SdrGrafGamma100Item))
    2076             :             {
    2077          40 :                 double fVal = WW8ITEMVALUE(rOldSet, SDRATTR_GRAFGAMMA,
    2078             :                     SdrGrafGamma100Item);
    2079          40 :                 pGrfNd->SetAttr(SwGammaGrf(fVal/100.));
    2080             :             }
    2081             : 
    2082             :             //drawmode
    2083          40 :             if (WW8ITEMVALUE(rOldSet, SDRATTR_GRAFMODE, SdrGrafModeItem))
    2084             :             {
    2085           0 :                 SwDrawModeGrf aDrawMode( static_cast< sal_uInt16 >(WW8ITEMVALUE(rOldSet,
    2086           0 :                     SDRATTR_GRAFMODE, SdrGrafModeItem)) );
    2087           0 :                 pGrfNd->SetAttr( aDrawMode );
    2088             :             }
    2089             :         }
    2090             :     }
    2091          50 : }
    2092             : 
    2093          88 : SdrObject* SwWW8ImplReader::CreateContactObject(SwFrmFmt* pFlyFmt)
    2094             : {
    2095          88 :     if (pFlyFmt)
    2096             :     {
    2097          88 :         SdrObject* pNewObject = mbNewDoc ? 0 : pFlyFmt->FindRealSdrObject();
    2098          88 :         if (!pNewObject)
    2099          88 :             pNewObject = pFlyFmt->FindSdrObject();
    2100          88 :         if (!pNewObject && pFlyFmt->ISA(SwFlyFrmFmt))
    2101             :         {
    2102             :             SwFlyDrawContact* pContactObject
    2103             :                 = new SwFlyDrawContact(static_cast<SwFlyFrmFmt*>(pFlyFmt),
    2104          54 :                 pDrawModel);
    2105          54 :             pNewObject = pContactObject->GetMaster();
    2106             :         }
    2107          88 :         return pNewObject;
    2108             :     }
    2109           0 :     return 0;
    2110             : }
    2111             : 
    2112             : // Miserable miserable hack to fudge word's graphic layout in RTL mode to ours.
    2113         120 : bool SwWW8ImplReader::MiserableRTLGraphicsHack(SwTwips &rLeft, SwTwips nWidth,
    2114             :     sal_Int16 eHoriOri, sal_Int16 eHoriRel)
    2115             : {
    2116         120 :     if (!IsRightToLeft())
    2117         104 :         return false;
    2118             :     return RTLGraphicsHack(rLeft, nWidth, eHoriOri, eHoriRel,
    2119          16 :             maSectionManager.GetPageLeft(),
    2120          16 :             maSectionManager.GetPageRight(),
    2121          48 :             maSectionManager.GetPageWidth());
    2122             : }
    2123             : 
    2124         110 : RndStdIds SwWW8ImplReader::ProcessEscherAlign(SvxMSDffImportRec* pRecord,
    2125             :     WW8_FSPA *pFSPA, SfxItemSet &rFlySet, bool /*bOrgObjectWasReplace*/)
    2126             : {
    2127             :     OSL_ENSURE(pRecord || pFSPA, "give me something! to work with for anchoring");
    2128         110 :     if (!pRecord && !pFSPA)
    2129           0 :         return FLY_AT_PAGE;
    2130             : 
    2131         110 :     SvxMSDffImportRec aRecordFromFSPA;
    2132         110 :     if (!pRecord)
    2133           0 :         pRecord = &aRecordFromFSPA;
    2134         110 :     if (!(pRecord->pXRelTo) && pFSPA)
    2135             :     {
    2136          98 :         pRecord->pXRelTo = new sal_uInt32;
    2137          98 :     *(pRecord->pXRelTo) = pFSPA->nbx;
    2138             :     }
    2139         110 :     if (!(pRecord->pYRelTo) && pFSPA)
    2140             :     {
    2141          98 :         pRecord->pYRelTo = new sal_uInt32;
    2142          98 :     *(pRecord->pYRelTo) = pFSPA->nby;
    2143             :     }
    2144             : 
    2145             :     // nXAlign - abs. Position, Left,  Centered,  Right,  Inside, Outside
    2146             :     // nYAlign - abs. Position, Top,   Centered,  Bottom, Inside, Outside
    2147             : 
    2148             :     // nXRelTo - Page printable area, Page,  Column,    Character
    2149             :     // nYRelTo - Page printable area, Page,  Paragraph, Line
    2150             : 
    2151         110 :     const sal_uInt32 nCntXAlign = 6;
    2152         110 :     const sal_uInt32 nCntYAlign = 6;
    2153             : 
    2154         110 :     const sal_uInt32 nCntRelTo  = 4;
    2155             : 
    2156         110 :     sal_uInt32 nXAlign = nCntXAlign > pRecord->nXAlign ? pRecord->nXAlign : 1;
    2157         110 :     sal_uInt32 nYAlign = nCntYAlign > pRecord->nYAlign ? pRecord->nYAlign : 1;
    2158             : 
    2159         110 :     if (pFSPA)
    2160             :     {
    2161             :         /*
    2162             :         #i15718# #i19008#
    2163             :         Strangely in this case the FSPA value seems to be considered before
    2164             :         the newer escher nXRelTo record.
    2165             :         */
    2166             :         // #i52565# - correct condition checking:
    2167             :         // first check, if <nXRelTo> and <nYRelTo> have default values.  This
    2168             :         // is a hint that these values aren't set by the escher import - see
    2169             :         // method <SwMSDffManager::ProcessObj(..)>. Then, check if for each
    2170             :         // values, if it differs from the one in the FSPA.
    2171         110 :         if ( *(pRecord->pXRelTo) == 2 && *(pRecord->pYRelTo) == 2 )
    2172             :         {
    2173             :             // if <nYRelTo> differs from <FSPA.nby> overwrite <nYRelTo>
    2174         102 :             if ( pFSPA->nby != *(pRecord->pYRelTo) )
    2175             :             {
    2176           0 :                 *(pRecord->pYRelTo) = pFSPA->nby;
    2177             :             }
    2178             :         }
    2179             :     }
    2180             : 
    2181         110 :     sal_uInt32 nXRelTo = nCntRelTo > *(pRecord->pXRelTo) ? *(pRecord->pXRelTo) : 1;
    2182         110 :     sal_uInt32 nYRelTo = nCntRelTo > *(pRecord->pYRelTo) ? *(pRecord->pYRelTo) : 1;
    2183             : 
    2184         110 :     RndStdIds eAnchor = IsInlineEscherHack() ? FLY_AS_CHAR : FLY_AT_CHAR; // #i43718#
    2185             : 
    2186         110 :     SwFmtAnchor aAnchor( eAnchor );
    2187         110 :     aAnchor.SetAnchor( pPaM->GetPoint() );
    2188         110 :     rFlySet.Put( aAnchor );
    2189             : 
    2190         110 :     if (pFSPA)
    2191             :     {
    2192             :         // #i18732#
    2193             :         //Given new layout where everything is changed to be anchored to
    2194             :         //character the following 4 tables may need to be changed.
    2195             : 
    2196             :         // horizontal Adjustment
    2197             :         static const sal_Int16 aHoriOriTab[ nCntXAlign ] =
    2198             :         {
    2199             :             text::HoriOrientation::NONE,     // From left position
    2200             :             text::HoriOrientation::LEFT,     // left
    2201             :             text::HoriOrientation::CENTER,   // centered
    2202             :             text::HoriOrientation::RIGHT,    // right
    2203             :             // #i36649#
    2204             :             // - inside -> text::HoriOrientation::LEFT and outside -> text::HoriOrientation::RIGHT
    2205             :             text::HoriOrientation::LEFT,   // inside
    2206             :             text::HoriOrientation::RIGHT   // outside
    2207             :         };
    2208             : 
    2209             : 
    2210             :         // generic vertical Adjustment
    2211             :         static const sal_Int16 aVertOriTab[ nCntYAlign ] =
    2212             :         {
    2213             :             text::VertOrientation::NONE,         // From Top position
    2214             :             text::VertOrientation::TOP,          // top
    2215             :             text::VertOrientation::CENTER,       // centered
    2216             :             text::VertOrientation::BOTTOM,       // bottom
    2217             :             text::VertOrientation::LINE_TOP,     // inside (obscure)
    2218             :             text::VertOrientation::LINE_BOTTOM   // outside (obscure)
    2219             :         };
    2220             : 
    2221             :         // #i22673# - to-line vertical alignment
    2222             :         static const sal_Int16 aToLineVertOriTab[ nCntYAlign ] =
    2223             :         {
    2224             :             text::VertOrientation::NONE,         // below
    2225             :             text::VertOrientation::LINE_BOTTOM,  // top
    2226             :             text::VertOrientation::LINE_CENTER,  // centered
    2227             :             text::VertOrientation::LINE_TOP,     // bottom
    2228             :             text::VertOrientation::LINE_BOTTOM,  // inside (obscure)
    2229             :             text::VertOrientation::LINE_TOP      // outside (obscure)
    2230             :         };
    2231             : 
    2232             :         // Adjustment is horizontally relative to...
    2233             :         static const sal_Int16 aHoriRelOriTab[nCntRelTo] =
    2234             :         {
    2235             :             text::RelOrientation::PAGE_PRINT_AREA,    // 0 is page textarea margin
    2236             :             text::RelOrientation::PAGE_FRAME,  // 1 is page margin
    2237             :             text::RelOrientation::FRAME,         // 2 is relative to column
    2238             :             text::RelOrientation::CHAR       // 3 is relative to character
    2239             :         };
    2240             : 
    2241             :         // Adjustment is vertically relative to...
    2242             :         // #i22673# - adjustment for new vertical alignment at top of line.
    2243             :         static const sal_Int16 aVertRelOriTab[nCntRelTo] =
    2244             :         {
    2245             :             text::RelOrientation::PAGE_PRINT_AREA, // 0 is page textarea margin
    2246             :             text::RelOrientation::PAGE_FRAME,   // 1 is page margin
    2247             :             text::RelOrientation::FRAME,          // 2 is relative to paragraph
    2248             :             text::RelOrientation::TEXT_LINE   // 3 is relative to line
    2249             :         };
    2250             : 
    2251         110 :         sal_Int16 eHoriOri = aHoriOriTab[ nXAlign ];
    2252         110 :         sal_Int16 eHoriRel = aHoriRelOriTab[  nXRelTo ];
    2253             : 
    2254             :         // #i36649# - adjustments for certain alignments
    2255         110 :         if ( eHoriOri == text::HoriOrientation::LEFT && eHoriRel == text::RelOrientation::PAGE_FRAME )
    2256             :         {
    2257             :             // convert 'left to page' to 'from left -<width> to page text area'
    2258           2 :             eHoriOri = text::HoriOrientation::NONE;
    2259           2 :             eHoriRel = text::RelOrientation::PAGE_PRINT_AREA;
    2260           2 :             const long nWidth = pFSPA->nXaRight - pFSPA->nXaLeft;
    2261           2 :             pFSPA->nXaLeft = -nWidth;
    2262           2 :             pFSPA->nXaRight = 0;
    2263             :         }
    2264         108 :         else if ( eHoriOri == text::HoriOrientation::RIGHT && eHoriRel == text::RelOrientation::PAGE_FRAME )
    2265             :         {
    2266             :             // convert 'right to page' to 'from left 0 to right page border'
    2267           0 :             eHoriOri = text::HoriOrientation::NONE;
    2268           0 :             eHoriRel = text::RelOrientation::PAGE_RIGHT;
    2269           0 :             const long nWidth = pFSPA->nXaRight - pFSPA->nXaLeft;
    2270           0 :             pFSPA->nXaLeft = 0;
    2271           0 :             pFSPA->nXaRight = nWidth;
    2272             :         }
    2273             : 
    2274             :         // #i24255# - position of floating screen objects in
    2275             :         // R2L layout are given in L2R layout, thus convert them of all
    2276             :         // floating screen objects, which are imported.
    2277             :         {
    2278             :             // Miserable miserable hack.
    2279         110 :             SwTwips nWidth = (pFSPA->nXaRight - pFSPA->nXaLeft);
    2280         110 :             SwTwips nLeft = pFSPA->nXaLeft;
    2281         110 :             if (MiserableRTLGraphicsHack(nLeft, nWidth, eHoriOri,
    2282         110 :                 eHoriRel))
    2283             :             {
    2284          10 :                 pFSPA->nXaLeft = nLeft;
    2285          10 :                 pFSPA->nXaRight = pFSPA->nXaLeft + nWidth;
    2286             :             }
    2287             :         }
    2288             : 
    2289             :         // if the object is anchored inside a table cell, is horizontal aligned
    2290             :         // at frame|character and has wrap through, but its attribute
    2291             :         // 'layout in table cell' isn't set, convert its horizontal alignment to page text area.
    2292             :         // #i84783# - use new method <IsObjectLayoutInTableCell()>
    2293         112 :         if ( nInTable &&
    2294             :              ( eHoriRel == text::RelOrientation::FRAME || eHoriRel == text::RelOrientation::CHAR ) &&
    2295             :              pFSPA->nwr == 3 &&
    2296           2 :              !IsObjectLayoutInTableCell( pRecord->nLayoutInTableCell ) )
    2297             :         {
    2298           2 :             eHoriRel = text::RelOrientation::PAGE_PRINT_AREA;
    2299             :         }
    2300             : 
    2301             :         SwFmtHoriOrient aHoriOri(MakeSafePositioningValue(pFSPA->nXaLeft),
    2302         110 :             eHoriOri, eHoriRel);
    2303         110 :         if( 4 <= nXAlign )
    2304           0 :             aHoriOri.SetPosToggle(true);
    2305         110 :         rFlySet.Put( aHoriOri );
    2306             : 
    2307             :         //Writer honours this wrap distance when aligned as "left" or "right",
    2308             :         //Word doesn't. Writer doesn't honour it when its "from left".
    2309         110 :         if (eHoriOri == text::HoriOrientation::LEFT)
    2310           0 :             pRecord->nDxWrapDistLeft=0;
    2311         110 :         else if (eHoriOri == text::HoriOrientation::RIGHT)
    2312           0 :             pRecord->nDxWrapDistRight=0;
    2313             : 
    2314             :         sal_Int16 eVertRel;
    2315         110 :         eVertRel = aVertRelOriTab[  nYRelTo ]; // #i18732#
    2316             :         // #i22673# - fill <eVertOri> in dependence of <eVertRel>
    2317             :         sal_Int16 eVertOri;
    2318         110 :         if ( eVertRel == text::RelOrientation::TEXT_LINE )
    2319             :         {
    2320           6 :             eVertOri = aToLineVertOriTab[ nYAlign ];
    2321             :         }
    2322             :         else
    2323             :         {
    2324         104 :             eVertOri = aVertOriTab[ nYAlign ];
    2325             :         }
    2326             : 
    2327             :         //Below line in word is a positive value, while in writer its
    2328             :         //negative
    2329         110 :         long nYPos = pFSPA->nYaTop;
    2330             :         // #i22673#
    2331         110 :         if ((eVertRel == text::RelOrientation::TEXT_LINE) && (eVertOri == text::VertOrientation::NONE))
    2332           6 :             nYPos = -nYPos;
    2333             : 
    2334             :         rFlySet.Put(SwFmtVertOrient(MakeSafePositioningValue(nYPos),
    2335         110 :             eVertOri, eVertRel));
    2336             :     }
    2337             : 
    2338         110 :     return eAnchor;
    2339             : }
    2340             : 
    2341             : // #i84783#
    2342           4 : bool SwWW8ImplReader::IsObjectLayoutInTableCell( const sal_uInt32 nLayoutInTableCell ) const
    2343             : {
    2344           4 :     bool bIsObjectLayoutInTableCell = false;
    2345             : 
    2346           4 :     if ( bVer8 )
    2347             :     {
    2348           4 :         const sal_uInt16 nWWVersion = pWwFib->nProduct & 0xE000;
    2349           4 :         switch ( nWWVersion )
    2350             :         {
    2351             :             case 0x0000: // version 8 aka Microsoft Word 97
    2352             :             {
    2353           0 :                 bIsObjectLayoutInTableCell = false;
    2354             :                 OSL_ENSURE( nLayoutInTableCell == 0xFFFFFFFF,
    2355             :                         "no explicit object attribute layout in table cell excepted." );
    2356             :             }
    2357           0 :             break;
    2358             :             case 0x2000: // version 9 aka Microsoft Word 2000
    2359             :             case 0x4000: // version 10 aka Microsoft Word 2002
    2360             :             case 0x6000: // version 11 aka Microsoft Word 2003
    2361             :             case 0x8000: // version 12 aka Microsoft Word 2007
    2362             :             {
    2363             :                 // #i98037#
    2364             :                 // adjustment of conditions needed after deeper analysis of
    2365             :                 // certain test cases.
    2366           0 :                 if ( nLayoutInTableCell == 0xFFFFFFFF || // no explicit attribute value given
    2367             :                      nLayoutInTableCell & 0x80008000 ||
    2368             :                      ( nLayoutInTableCell & 0x02000000 &&
    2369           0 :                        !(nLayoutInTableCell & 0x80000000 ) ) )
    2370             :                 {
    2371           0 :                     bIsObjectLayoutInTableCell = true;
    2372             :                 }
    2373             :                 else
    2374             :                 {
    2375           0 :                     bIsObjectLayoutInTableCell = false;
    2376             :                 }
    2377             :             }
    2378           0 :             break;
    2379             :             default:
    2380             :             {
    2381             :                 OSL_FAIL( "unknown version." );
    2382             :             }
    2383             :         }
    2384             :     }
    2385             : 
    2386           4 :     return bIsObjectLayoutInTableCell;
    2387             : }
    2388             : 
    2389         110 : SwFrmFmt* SwWW8ImplReader::Read_GrafLayer( long nGrafAnchorCp )
    2390             : {
    2391         110 :     if( nIniFlags & WW8FL_NO_GRAFLAYER )
    2392           0 :         return 0;
    2393             : 
    2394         110 :     ::SetProgressState(nProgress, mpDocShell);     // Update
    2395             : 
    2396         110 :     nDrawCpO = pWwFib->GetBaseCp(pPlcxMan->GetManType() == MAN_HDFT ? MAN_TXBX_HDFT : MAN_TXBX);
    2397             : 
    2398         110 :     GrafikCtor();
    2399             : 
    2400         110 :     WW8PLCFspecial* pPF = pPlcxMan->GetFdoa();
    2401         110 :     if( !pPF )
    2402             :     {
    2403             :         OSL_ENSURE( !this, "Where is the grapic (1) ?" );
    2404           0 :         return 0;
    2405             :     }
    2406             : 
    2407         110 :     if( bVer67 )
    2408             :     {
    2409           0 :         long nOldPos = pStrm->Tell();
    2410             : 
    2411           0 :         nDrawXOfs = nDrawYOfs = 0;
    2412           0 :         ReadGrafLayer1( pPF, nGrafAnchorCp );
    2413             : 
    2414           0 :         pStrm->Seek( nOldPos );
    2415           0 :         return 0;
    2416             :     }
    2417             : 
    2418             :     //Normal case of Word 8+ version stuff
    2419         110 :     pPF->SeekPos( nGrafAnchorCp );
    2420             : 
    2421             :     WW8_FC nStartFc;
    2422             :     void* pF0;
    2423         110 :     if( !pPF->Get( nStartFc, pF0 ) ){
    2424             :         OSL_ENSURE( !this, "+Wo ist die Grafik (2) ?" );
    2425           0 :         return 0;
    2426             :     }
    2427             : 
    2428         110 :     WW8_FSPA_SHADOW* pFS = (WW8_FSPA_SHADOW*)pF0;
    2429             :     WW8_FSPA*        pF;
    2430             : #ifdef __WW8_NEEDS_COPY
    2431             :     WW8_FSPA aFSFA;
    2432         110 :     pF = &aFSFA;
    2433         110 :     WW8FSPAShadowToReal( pFS, pF );
    2434             : #else
    2435             :     pF = (WW8_FSPA*)pFS;
    2436             : #endif // defined __WW8_NEEDS_COPY
    2437         110 :     if( !pF->nSpId )
    2438             :     {
    2439             :         OSL_ENSURE( !this, "+Wo ist die Grafik (3) ?" );
    2440           0 :         return 0;
    2441             :     }
    2442             : 
    2443         110 :     if (!pMSDffManager->GetModel())
    2444           0 :          pMSDffManager->SetModel(pDrawModel, 1440);
    2445             : 
    2446             : 
    2447         110 :     Rectangle aRect(pF->nXaLeft,  pF->nYaTop, pF->nXaRight, pF->nYaBottom);
    2448         110 :     SvxMSDffImportData aData( aRect );
    2449             : 
    2450             :     /*
    2451             :     #i20540#
    2452             :     The SdrOle2Obj will try and manage any ole objects it finds, causing all
    2453             :     sorts of trouble later on
    2454             :     */
    2455         110 :     SwDocShell* pPersist = rDoc.GetDocShell();
    2456         110 :     rDoc.SetDocShell(0);         //#i20540# Persist guard
    2457             : 
    2458         110 :     SdrObject* pObject = 0;
    2459         110 :     bool bOk = (pMSDffManager->GetShape(pF->nSpId, pObject, aData) && pObject);
    2460             : 
    2461         110 :     rDoc.SetDocShell(pPersist);  //#i20540# Persist guard
    2462             : 
    2463         110 :     if (!bOk)
    2464             :     {
    2465             :         OSL_ENSURE( !this, "Where is the Shape ?" );
    2466           0 :         return 0;
    2467             :     }
    2468             : 
    2469         110 :     bool bDone = false;
    2470         110 :     SdrObject* pOurNewObject = 0;
    2471         110 :     bool bReplaceable = false;
    2472             : 
    2473         110 :     switch (SdrObjKind(pObject->GetObjIdentifier()))
    2474             :     {
    2475             :         case OBJ_GRAF:
    2476          26 :             bReplaceable = true;
    2477          26 :             bDone = true;
    2478          26 :             break;
    2479             :         case OBJ_OLE2:
    2480           0 :             bReplaceable = true;
    2481           0 :             break;
    2482             :         default:
    2483          84 :             break;
    2484             : 
    2485             :     }
    2486             : 
    2487             :     // when in a header or footer word appears to treat all elements as wrap through
    2488             : 
    2489             :     // Umfluss-Modus ermitteln
    2490         110 :     SfxItemSet aFlySet(rDoc.GetAttrPool(), RES_FRMATR_BEGIN, RES_FRMATR_END-1);
    2491         110 :     SwSurround eSurround = SURROUND_PARALLEL;
    2492         110 :     bool bContour = false;
    2493         110 :     switch (pF->nwr)
    2494             :     {
    2495             :         case 0: //0 like 2, but doesn't require absolute object
    2496             :         case 2: //2 wrap around absolute object
    2497           4 :             eSurround = SURROUND_PARALLEL;
    2498           4 :             break;
    2499             :         case 1: //1 no text next to shape
    2500           0 :             eSurround = SURROUND_NONE;
    2501           0 :             break;
    2502             :         case 3: //3 wrap as if no object present
    2503         106 :             eSurround = SURROUND_THROUGHT;
    2504         106 :             break;
    2505             :         case 4: //4 wrap tightly around object
    2506             :         case 5: //5 wrap tightly, but allow holes
    2507           0 :             eSurround = SURROUND_PARALLEL;
    2508           0 :             bContour = true;
    2509           0 :             break;
    2510             :     }
    2511             : 
    2512             :     // bei Modus 2 oder 4 auch den Zusatzparameter beruecksichtigen
    2513         110 :     if ( (2 == pF->nwr) || (4 == pF->nwr) )
    2514             :     {
    2515           4 :         switch( pF->nwrk )
    2516             :         {
    2517             :             //0 wrap both sides
    2518             :             case 0:
    2519           4 :                 eSurround = SURROUND_PARALLEL;
    2520           4 :                 break;
    2521             :             //1 wrap only on left
    2522             :             case 1:
    2523           0 :                 eSurround = SURROUND_LEFT;
    2524           0 :                 break;
    2525             :             //2 wrap only on right
    2526             :             case 2:
    2527           0 :                 eSurround = SURROUND_RIGHT;
    2528           0 :                 break;
    2529             :             //3 wrap only on largest side
    2530             :             case 3:
    2531           0 :                 eSurround = SURROUND_IDEAL;
    2532           0 :                 break;
    2533             :         }
    2534             :     }
    2535             : 
    2536         110 :     SwFmtSurround aSur( eSurround );
    2537         110 :     aSur.SetContour( bContour );
    2538         110 :     aSur.SetOutside(true); // Winword kann nur Aussen-Konturen
    2539         110 :     aFlySet.Put( aSur );
    2540             : 
    2541             :     // eingelesenes Objekt (kann eine ganze Gruppe sein) jetzt korrekt
    2542             :     // positionieren usw.
    2543             : 
    2544             :     OSL_ENSURE(!((aData.size() != 1) && bReplaceable),
    2545             :         "Replaceable drawing with > 1 entries ?");
    2546             : 
    2547         110 :     if (aData.size() != 1)
    2548          28 :         bReplaceable = false;
    2549             : 
    2550         110 :     SvxMSDffImportRec* pRecord = 0;
    2551             :     /*
    2552             :         Get the record for top level object, so we can get the word anchoring
    2553             :         and wrapping information for it.
    2554             :     */
    2555         342 :     for (MSDffImportRecords::const_iterator it = aData.begin();
    2556         228 :             it != aData.end(); ++it) // MSVC2008 wants const_iterator here???
    2557             :     {
    2558         114 :         if (it->pObj == pObject)
    2559             :         {
    2560         110 :             pRecord = &const_cast<SvxMSDffImportRec&>(*it);
    2561         110 :             break;
    2562             :         }
    2563             :     }
    2564             : 
    2565             :     OSL_ENSURE(pRecord, "how did that happen?");
    2566         110 :     if (!pRecord)
    2567           0 :         return 0;
    2568             : 
    2569             :     const bool bLayoutInTableCell =
    2570         110 :         nInTable && IsObjectLayoutInTableCell( pRecord->nLayoutInTableCell );
    2571             : 
    2572             :     // #i18732# - Switch on 'follow text flow', if object is laid out
    2573             :     // inside table cell and its wrapping isn't 'SURROUND_THROUGH'
    2574         110 :     if (bLayoutInTableCell && eSurround != SURROUND_THROUGHT)
    2575             :     {
    2576           0 :         SwFmtFollowTextFlow aFollowTextFlow( sal_True );
    2577           0 :         aFlySet.Put( aFollowTextFlow );
    2578             :     }
    2579             : 
    2580             : 
    2581             :     //#i21847#
    2582             :     //Some shapes are set to *hidden*, don't import those ones.
    2583         110 :     if (pRecord->bHidden)
    2584           0 :         return 0;
    2585             : 
    2586             :     // If we are to be "below text" then we are not to be opaque
    2587             :     // #i14045# MM If we are in a header or footer then make the object transparent
    2588             :     // Not exactly like word but close enough for now
    2589             : 
    2590             :     // both flags <bBelowText> and <bDrawHell> have to be set to move object into the background.
    2591             :     // #i46794# - it reveals that value of flag <bBelowText> can be neglected.
    2592             :     const bool bMoveToBackgrd = pRecord->bDrawHell ||
    2593         110 :                                 ( ( bIsHeader || bIsFooter ) && pF->nwr == 3 );
    2594         110 :     if ( bMoveToBackgrd )
    2595           4 :         aFlySet.Put(SvxOpaqueItem(RES_OPAQUE,false));
    2596             : 
    2597         110 :     String aObjName = pObject->GetName();
    2598             : 
    2599         110 :     SwFrmFmt* pRetFrmFmt = 0;
    2600         110 :     if (bReplaceable)
    2601             :     {
    2602             :         //Single graphics or ole objects
    2603             :         pRetFrmFmt = ImportReplaceableDrawables(pObject, pOurNewObject, pRecord,
    2604          26 :             pF, aFlySet);
    2605             :     }
    2606             :     else
    2607             :     {
    2608             :         //Drawing objects, (e.g. ovals or drawing groups)
    2609          84 :         if (pF->bRcaSimple)
    2610             :         {
    2611           0 :             pF->nbx = WW8_FSPA::RelPageBorder;
    2612           0 :             pF->nby = WW8_FSPA::RelPageBorder;
    2613             :         }
    2614             : 
    2615             :         RndStdIds eAnchor = ProcessEscherAlign(pRecord, pF, aFlySet,
    2616          84 :             bReplaceable);
    2617             : 
    2618             :         // Should we, and is it possible to make this into a writer textbox
    2619          84 :         if ((!(nIniFlags1 & WW8FL_NO_FLY_FOR_TXBX)) && pRecord->bReplaceByFly)
    2620             :         {
    2621             :             pRetFrmFmt = ConvertDrawTextToFly(pObject, pOurNewObject, pRecord,
    2622           4 :                 eAnchor, pF, aFlySet);
    2623           4 :             if (pRetFrmFmt)
    2624           4 :                 bDone = true;
    2625             :         }
    2626             : 
    2627          84 :         if (!bDone)
    2628             :         {
    2629          80 :             sw::util::SetLayer aSetLayer(rDoc);
    2630          80 :             if ( bMoveToBackgrd )
    2631           0 :                 aSetLayer.SendObjectToHell(*pObject);
    2632             :             else
    2633          80 :                 aSetLayer.SendObjectToHeaven(*pObject);
    2634             : 
    2635          80 :             if (!IsInlineEscherHack())
    2636             :             {
    2637             :                 /* Need to make sure that the correct layer ordering is applied. */
    2638             :                 //  pass information, if object is in page header|footer to method.
    2639             :                 pWWZOrder->InsertEscherObject( pObject, pF->nSpId,
    2640          74 :                                                bIsHeader || bIsFooter );
    2641             :             }
    2642             :             else
    2643             :             {
    2644           6 :                 pWWZOrder->InsertTextLayerObject(pObject);
    2645             :             }
    2646             : 
    2647          80 :             pRetFrmFmt = rDoc.Insert(*pPaM, *pObject, &aFlySet, NULL);
    2648             : 
    2649             :             OSL_ENSURE(pRetFrmFmt->GetAnchor().GetAnchorId() ==
    2650             :                 eAnchor, "Not the anchor type requested!");
    2651             : 
    2652             :             /*
    2653             :                 Insert text if necessary into textboxes contained in groups.
    2654             :             */
    2655          80 :             if (!aData.empty())
    2656             :             {
    2657        1296 :                 for (MSDffImportRecords::const_iterator it = aData.begin();
    2658         864 :                         it != aData.end(); ++it)
    2659             :                 {
    2660         352 :                     pRecord = &const_cast<SvxMSDffImportRec&>(*it);
    2661         352 :                     if (pRecord->pObj && pRecord->aTextId.nTxBxS)
    2662             :                     { // #i52825# pRetFrmFmt can be NULL
    2663             :                         pRetFrmFmt = MungeTextIntoDrawBox(pRecord->pObj,
    2664         112 :                             pRecord, nGrafAnchorCp, pRetFrmFmt);
    2665             :                     }
    2666             :                 }
    2667             :             }
    2668             :         }
    2669             :     }
    2670             : 
    2671             :     // #i44344#, #i44681# - positioning attributes already set
    2672         110 :     if ( pRetFrmFmt /*#i52825# */ && pRetFrmFmt->ISA(SwDrawFrmFmt) )
    2673             :     {
    2674          80 :         static_cast<SwDrawFrmFmt*>(pRetFrmFmt)->PosAttrSet();
    2675             :     }
    2676         110 :     if (!IsInlineEscherHack())
    2677         104 :         MapWrapIntoFlyFmt(pRecord, pRetFrmFmt);
    2678             : 
    2679             :     // Set frame name with object name
    2680         110 :     if( pRetFrmFmt /*#i52825# */ && aObjName.Len() )
    2681           2 :         pRetFrmFmt->SetName( aObjName );
    2682         110 :     return AddAutoAnchor(pRetFrmFmt);
    2683             : }
    2684             : 
    2685         134 : SwFrmFmt *SwWW8ImplReader::AddAutoAnchor(SwFrmFmt *pFmt)
    2686             : {
    2687             :     /*
    2688             :      * anchored to character at the current position will move along the
    2689             :      * paragraph as text is added because we are at the insertion point.
    2690             :      *
    2691             :      * Leave to later and set the correct location then.
    2692             :      */
    2693         134 :     if ((pFmt) && (pFmt->GetAnchor().GetAnchorId() != FLY_AS_CHAR))
    2694             :     {
    2695         104 :         pAnchorStck->AddAnchor(*pPaM->GetPoint(), pFmt);
    2696             :     }
    2697         134 :     return pFmt;
    2698             : }
    2699             : 
    2700         112 : SwFrmFmt* SwWW8ImplReader::MungeTextIntoDrawBox(SdrObject* pTrueObject,
    2701             :     SvxMSDffImportRec *pRecord, long nGrafAnchorCp, SwFrmFmt* pRetFrmFmt)
    2702             : {
    2703             :     SdrTextObj* pSdrTextObj;
    2704             : 
    2705             :     // Pruefen, ob Gruppenobjekt (z.B. zwei Klammern) vorliegt
    2706         112 :     if (SdrObjGroup* pThisGroup = PTR_CAST(SdrObjGroup, pRecord->pObj))
    2707             :     {
    2708             :         // Gruppenobjekte haben keinen Text. Fuege ein Textobjekt in die
    2709             :         // Gruppe ein, um den Text zu halten.
    2710           0 :         pSdrTextObj = new SdrRectObj( OBJ_TEXT, pThisGroup->GetCurrentBoundRect());
    2711             : 
    2712           0 :         SfxItemSet aSet(pDrawModel->GetItemPool());
    2713           0 :         aSet.Put(XFillStyleItem(XFILL_NONE));
    2714           0 :         aSet.Put(XLineStyleItem(XLINE_NONE));
    2715           0 :         aSet.Put(SdrTextFitToSizeTypeItem( SDRTEXTFIT_NONE ));
    2716           0 :         aSet.Put(SdrTextAutoGrowHeightItem(false));
    2717           0 :         aSet.Put(SdrTextAutoGrowWidthItem(false));
    2718           0 :         pSdrTextObj->SetMergedItemSet(aSet);
    2719             : 
    2720           0 :         long nAngle = pRecord->nTextRotationAngle;
    2721           0 :         if ( nAngle )
    2722             :         {
    2723           0 :             double a = nAngle*nPi180;
    2724           0 :             pSdrTextObj->NbcRotate(pSdrTextObj->GetCurrentBoundRect().Center(), nAngle,
    2725           0 :                 sin(a), cos(a) );
    2726             :         }
    2727             : 
    2728           0 :         pSdrTextObj->NbcSetLayer( pThisGroup->GetLayer() );
    2729           0 :         pThisGroup->GetSubList()->NbcInsertObject(pSdrTextObj);
    2730             :     }
    2731             :     else
    2732         112 :         pSdrTextObj = PTR_CAST(SdrTextObj, pRecord->pObj);
    2733             : 
    2734         112 :     if( pSdrTextObj )
    2735             :     {
    2736         112 :         Size aObjSize(pSdrTextObj->GetSnapRect().GetWidth(),
    2737         224 :             pSdrTextObj->GetSnapRect().GetHeight());
    2738             : 
    2739             :         // Objekt ist Bestandteil einer Gruppe?
    2740         112 :         SdrObject* pGroupObject = pSdrTextObj->GetUpGroup();
    2741             : 
    2742         112 :         sal_uInt32 nOrdNum = pSdrTextObj->GetOrdNum();
    2743             :         bool bEraseThisObject;
    2744             :         InsertTxbxText( pSdrTextObj, &aObjSize, pRecord->aTextId.nTxBxS,
    2745             :             pRecord->aTextId.nSequence, nGrafAnchorCp, pRetFrmFmt,
    2746             :             (pSdrTextObj != pTrueObject) || (0 != pGroupObject),
    2747         112 :             bEraseThisObject, 0, 0, 0, 0, pRecord);
    2748             : 
    2749             :         // wurde dieses Objekt ersetzt ??
    2750         112 :         if (bEraseThisObject)
    2751             :         {
    2752           0 :             if( pGroupObject || (pSdrTextObj != pTrueObject) )
    2753             :             {
    2754             :                 // Objekt wurde bereits (in der Gruppe und) der Drawing-Page
    2755             :                 // durch ein neues SdrGrafObj ersetzt.
    2756             : 
    2757             :                 SdrObject* pNewObj = pGroupObject ?
    2758           0 :                     pGroupObject->GetSubList()->GetObj(nOrdNum) : pTrueObject;
    2759           0 :                 if (pSdrTextObj != pNewObj)
    2760             :                 {
    2761             :                     // Objekt in der Z-Order-Liste ersetzen
    2762           0 :                     pMSDffManager->ExchangeInShapeOrder(pSdrTextObj, 0,0, pNewObj);
    2763             :                     // Objekt jetzt noch loeschen
    2764           0 :                     SdrObject::Free( pRecord->pObj );
    2765             :                     // und das neue Objekt merken.
    2766           0 :                     pRecord->pObj = pNewObj;
    2767           0 :                 }
    2768             :             }
    2769             :             else
    2770             :             {
    2771             :                 // Objekt aus der Z-Order-Liste loeschen
    2772           0 :                 pMSDffManager->RemoveFromShapeOrder( pSdrTextObj );
    2773             :                 // Objekt aus der Drawing-Page rausnehmen
    2774           0 :                 if( pSdrTextObj->GetPage() )
    2775           0 :                     pDrawPg->RemoveObject( pSdrTextObj->GetOrdNum() );
    2776             :                 // und FrameFormat entfernen, da durch Grafik ersetzt (dies
    2777             :                 // loescht auch das Objekt)
    2778           0 :                 rDoc.DelFrmFmt( pRetFrmFmt );
    2779           0 :                 pRetFrmFmt = 0;
    2780             :                 // auch den Objektmerker loeschen
    2781           0 :                 pRecord->pObj = 0;
    2782             :             }
    2783             :         }
    2784             :         else
    2785             :         {
    2786             :             // ww8-default Randabstand einsetzen
    2787         112 :             SfxItemSet aItemSet(pDrawModel->GetItemPool(),
    2788         112 :                 SDRATTR_TEXT_LEFTDIST, SDRATTR_TEXT_LOWERDIST);
    2789         112 :             aItemSet.Put( SdrTextLeftDistItem( pRecord->nDxTextLeft ) );
    2790         112 :             aItemSet.Put( SdrTextRightDistItem( pRecord->nDxTextRight  ) );
    2791         112 :             aItemSet.Put( SdrTextUpperDistItem( pRecord->nDyTextTop    ) );
    2792         112 :             aItemSet.Put( SdrTextLowerDistItem( pRecord->nDyTextBottom ) );
    2793         112 :             pSdrTextObj->SetMergedItemSetAndBroadcast(aItemSet);
    2794             :         }
    2795             :     }
    2796         112 :     return pRetFrmFmt;
    2797             : }
    2798             : 
    2799           4 : SwFlyFrmFmt* SwWW8ImplReader::ConvertDrawTextToFly(SdrObject* &rpObject,
    2800             :     SdrObject* &rpOurNewObject, SvxMSDffImportRec* pRecord, RndStdIds eAnchor,
    2801             :     WW8_FSPA *pF, SfxItemSet &rFlySet)
    2802             : {
    2803           4 :     SwFlyFrmFmt* pRetFrmFmt = 0;
    2804             :     long nStartCp;
    2805             :     long nEndCp;
    2806             : 
    2807             :     // Check if this textbox chain contains text as conversion of an empty
    2808             :     // chain would not make sense.
    2809           4 :     if ( TxbxChainContainsRealText(pRecord->aTextId.nTxBxS,nStartCp,nEndCp) )
    2810             :     {
    2811             :         // The Text is not read into SdrTextObj!  Rather insert a frame and
    2812             :         // insert the text from nStartCp to nEndCp.
    2813             :         //
    2814             :         // More attributes can be used in a frame compared to the
    2815             :         // Edit-Enging, and it can contain field, OLEs or graphics...
    2816             :         Rectangle aInnerDist(pRecord->nDxTextLeft, pRecord->nDyTextTop,
    2817           4 :             pRecord->nDxTextRight, pRecord->nDyTextBottom);
    2818             : 
    2819           4 :         SwFmtFrmSize aFrmSize(ATT_FIX_SIZE, pF->nXaRight - pF->nXaLeft, pF->nYaBottom - pF->nYaTop);
    2820           4 :         aFrmSize.SetWidthSizeType(pRecord->bAutoWidth ? ATT_VAR_SIZE : ATT_FIX_SIZE);
    2821           4 :         rFlySet.Put(aFrmSize);
    2822             : 
    2823             :         MatchSdrItemsIntoFlySet( rpObject, rFlySet, pRecord->eLineStyle,
    2824           4 :             pRecord->eLineDashing, pRecord->eShapeType, aInnerDist );
    2825             : 
    2826             : 
    2827           4 :         SdrTextObj *pSdrTextObj = PTR_CAST(SdrTextObj, rpObject);
    2828           4 :         if (pSdrTextObj && pSdrTextObj->IsVerticalWriting())
    2829           0 :             rFlySet.Put(SvxFrameDirectionItem(FRMDIR_VERT_TOP_RIGHT, RES_FRAMEDIR));
    2830             : 
    2831           4 :         pRetFrmFmt = rDoc.MakeFlySection(eAnchor, pPaM->GetPoint(), &rFlySet);
    2832             :         OSL_ENSURE(pRetFrmFmt->GetAnchor().GetAnchorId() == eAnchor,
    2833             :             "Not the anchor type requested!");
    2834             : 
    2835             :         // if everything is OK, find pointer on new object and correct
    2836             :         // Z-order list (oder delete entry)
    2837           4 :         rpOurNewObject = CreateContactObject(pRetFrmFmt);
    2838             : 
    2839             :         // remove old object from the Z-Order list
    2840           4 :         pMSDffManager->RemoveFromShapeOrder( rpObject );
    2841             : 
    2842             :         // and delete the object
    2843           4 :         SdrObject::Free( rpObject );
    2844             :         /*
    2845             :             NB: only query pOrgShapeObject starting here!
    2846             :         */
    2847             : 
    2848           4 :         if (rpOurNewObject)
    2849             :         {
    2850             :             /*
    2851             :             We do not store our rpOutNewObject in the ShapeOrder because we
    2852             :             have a FrmFmt from which we can regenerate the contact object when
    2853             :             we need it. Because, we can have frames anchored to paragraphs in
    2854             :             header/footers and we can copy header/footers, if we do copy a
    2855             :             header/footer with a nonpage anchored frame in it then the contact
    2856             :             objects are invalidated. Under this condition the FrmFmt will be
    2857             :             updated to reflect this change and can be used to get a new
    2858             :             contact object, while a raw rpOutNewObject stored here becomes
    2859             :             deleted and useless.
    2860             :             */
    2861             :             pMSDffManager->StoreShapeOrder(pF->nSpId,
    2862             :                 (((sal_uLong)pRecord->aTextId.nTxBxS) << 16) +
    2863           4 :                 pRecord->aTextId.nSequence, 0, pRetFrmFmt);
    2864             : 
    2865             :             // The Kontakt object has to be inserted into the draw page, so
    2866             :             // SwWW8ImplReader::LoadDoc1() can determine the z-order.
    2867           4 :             if (!rpOurNewObject->IsInserted())
    2868             :             {
    2869             :                 // pass information, if object is in page header|footer to method.
    2870             :                 pWWZOrder->InsertEscherObject( rpOurNewObject, pF->nSpId,
    2871           4 :                                                bIsHeader || bIsFooter );
    2872             :             }
    2873             :         }
    2874             : 
    2875             :         // Box-0 receives the text for the whole chain!
    2876           4 :         if( !pRecord->aTextId.nSequence )
    2877             :         {
    2878             :             // save flags etc and reset them
    2879           4 :             WW8ReaderSave aSave( this );
    2880             : 
    2881           4 :             MoveInsideFly(pRetFrmFmt);
    2882             : 
    2883           4 :             SwNodeIndex aStart(pPaM->GetPoint()->nNode);
    2884             : 
    2885           4 :             pWWZOrder->InsideEscher(pF->nSpId);
    2886             : 
    2887             :             // read in the text
    2888           4 :             bTxbxFlySection = true;
    2889             :             bool bJoined = ReadText(nStartCp, (nEndCp-nStartCp),
    2890           4 :                 MAN_MAINTEXT == pPlcxMan->GetManType() ?
    2891           4 :                         MAN_TXBX : MAN_TXBX_HDFT);
    2892             : 
    2893           4 :             pWWZOrder->OutsideEscher();
    2894             : 
    2895           4 :             MoveOutsideFly(pRetFrmFmt, aSave.GetStartPos(),!bJoined);
    2896             : 
    2897           4 :             aSave.Restore( this );
    2898           4 :         }
    2899             :     }
    2900           4 :     return pRetFrmFmt;
    2901             : }
    2902             : 
    2903          50 : void MatchEscherMirrorIntoFlySet(const SvxMSDffImportRec &rRecord,
    2904             :     SfxItemSet &rFlySet)
    2905             : {
    2906          50 :     if (rRecord.bVFlip || rRecord.bHFlip)
    2907             :     {
    2908           0 :         MirrorGraph eType(RES_MIRROR_GRAPH_DONT);
    2909           0 :         if (rRecord.bVFlip && rRecord.bHFlip)
    2910           0 :             eType = RES_MIRROR_GRAPH_BOTH;
    2911           0 :         else if (rRecord.bVFlip)
    2912           0 :             eType = RES_MIRROR_GRAPH_HOR;
    2913             :         else
    2914           0 :             eType = RES_MIRROR_GRAPH_VERT;
    2915           0 :         rFlySet.Put( SwMirrorGrf(eType) );
    2916             :     }
    2917          50 : }
    2918             : 
    2919          26 : SwFlyFrmFmt* SwWW8ImplReader::ImportReplaceableDrawables( SdrObject* &rpObject,
    2920             :     SdrObject* &rpOurNewObject, SvxMSDffImportRec* pRecord, WW8_FSPA *pF,
    2921             :     SfxItemSet &rFlySet )
    2922             : {
    2923          26 :     SwFlyFrmFmt* pRetFrmFmt = 0;
    2924          26 :     long nWidthTw  = pF->nXaRight - pF->nXaLeft;
    2925          26 :     if (0 > nWidthTw)
    2926           0 :         nWidthTw = 0;
    2927          26 :     long nHeightTw = pF->nYaBottom - pF->nYaTop;
    2928          26 :     if (0 > nHeightTw)
    2929           0 :         nHeightTw = 0;
    2930             : 
    2931          26 :     ProcessEscherAlign(pRecord, pF, rFlySet, true);
    2932             : 
    2933          26 :     rFlySet.Put(SwFmtFrmSize(ATT_FIX_SIZE, nWidthTw, nHeightTw));
    2934             : 
    2935          26 :     SfxItemSet aGrSet(rDoc.GetAttrPool(), RES_GRFATR_BEGIN, RES_GRFATR_END-1);
    2936             : 
    2937          26 :     if (pRecord)
    2938             :     {
    2939             :         //Note that the escher inner distance only seems to be honoured in
    2940             :         //word for textboxes, not for graphics and ole objects.
    2941          26 :         Rectangle aInnerDist(0, 0, 0, 0);
    2942             : 
    2943             :         MatchSdrItemsIntoFlySet(rpObject, rFlySet, pRecord->eLineStyle,
    2944          26 :             pRecord->eLineDashing, pRecord->eShapeType, aInnerDist);
    2945             : 
    2946          26 :         MatchEscherMirrorIntoFlySet(*pRecord, aGrSet);
    2947             :     }
    2948             : 
    2949          26 :     String aObjectName(rpObject->GetName());
    2950          26 :     if (OBJ_OLE2 == SdrObjKind(rpObject->GetObjIdentifier()))
    2951           0 :         pRetFrmFmt = InsertOle(*((SdrOle2Obj*)rpObject), rFlySet, aGrSet);
    2952             :     else
    2953             :     {
    2954          26 :         const SdrGrafObj *pGrf= (const SdrGrafObj*)rpObject;
    2955          26 :         bool bDone = false;
    2956          26 :         if (pGrf->IsLinkedGraphic() && !pGrf->GetFileName().isEmpty())
    2957             :         {
    2958           0 :             GraphicType eType = pGrf->GetGraphicType();
    2959             :             String aGrfName(
    2960             :                 URIHelper::SmartRel2Abs(
    2961           0 :                     INetURLObject(sBaseURL), pGrf->GetFileName(),
    2962           0 :                     URIHelper::GetMaybeFileHdl()));
    2963             :             // correction of fix for issue #i10939#:
    2964             :             // One of the two conditions have to be true to insert the graphic
    2965             :             // as a linked graphic -
    2966           0 :             if (GRAPHIC_NONE == eType || CanUseRemoteLink(aGrfName))
    2967             :             {
    2968             :                 pRetFrmFmt = rDoc.Insert(*pPaM, aGrfName, aEmptyStr, 0,
    2969           0 :                     &rFlySet, &aGrSet, NULL);
    2970           0 :                 bDone = true;
    2971           0 :             }
    2972             :         }
    2973          26 :         if (!bDone)
    2974             :         {
    2975          26 :             const Graphic& rGraph = pGrf->GetGraphic();
    2976             :             pRetFrmFmt = rDoc.Insert(*pPaM, aEmptyStr, aEmptyStr, &rGraph,
    2977          26 :                 &rFlySet, &aGrSet, NULL);
    2978             :         }
    2979             :     }
    2980             : 
    2981          26 :     if (pRetFrmFmt)
    2982             :     {
    2983          26 :         if( pRecord )
    2984             :         {
    2985          26 :             if( OBJ_OLE2 != SdrObjKind(rpObject->GetObjIdentifier()) )
    2986          26 :                 SetAttributesAtGrfNode( pRecord, pRetFrmFmt, pF );
    2987             :         }
    2988             :         // mehrfaches Auftreten gleicher Grafik-Namen vermeiden
    2989          26 :         maGrfNameGenerator.SetUniqueGraphName(pRetFrmFmt, aObjectName);
    2990             :     }
    2991             :     //falls alles Ok, Zeiger auf neues Objekt ermitteln und Z-Order-Liste
    2992             :     //entsprechend korrigieren (oder Eintrag loeschen)
    2993          26 :     rpOurNewObject = CreateContactObject(pRetFrmFmt);
    2994             : 
    2995             :     // altes Objekt aus der Z-Order-Liste entfernen
    2996          26 :     pMSDffManager->RemoveFromShapeOrder( rpObject );
    2997             :     // aus der Drawing-Page rausnehmen
    2998          26 :     if( rpObject->GetPage() )
    2999           0 :         pDrawPg->RemoveObject( rpObject->GetOrdNum() );
    3000             : 
    3001             :     // und das Objekt loeschen
    3002          26 :     SdrObject::Free( rpObject );
    3003             :     /*
    3004             :         Achtung: ab jetzt nur noch pOrgShapeObject abfragen!
    3005             :     */
    3006             : 
    3007             :     // Kontakt-Objekt in die Z-Order-Liste und die Page aufnehmen
    3008          26 :     if (rpOurNewObject)
    3009             :     {
    3010          26 :         if (!bHdFtFtnEdn)
    3011          22 :             pMSDffManager->StoreShapeOrder(pF->nSpId, 0, rpOurNewObject, 0 );
    3012             : 
    3013             :         // Das Kontakt-Objekt MUSS in die Draw-Page gesetzt werden, damit in
    3014             :         // SwWW8ImplReader::LoadDoc1() die Z-Order festgelegt werden kann !!!
    3015          26 :         if (!rpOurNewObject->IsInserted())
    3016             :         {
    3017             :             // pass information, if object is in page header|footer to method.
    3018             :             pWWZOrder->InsertEscherObject( rpOurNewObject, pF->nSpId,
    3019          26 :                                            bIsHeader || bIsFooter );
    3020             :         }
    3021             :     }
    3022          26 :     return pRetFrmFmt;
    3023             : }
    3024             : 
    3025         210 : void SwWW8ImplReader::GrafikCtor()  // Fuer SVDraw und VCControls und Escher
    3026             : {
    3027         210 :     if (!pDrawModel)
    3028             :     {
    3029          30 :         rDoc.GetOrCreateDrawModel(); // #i52858# - method name changed
    3030          30 :         pDrawModel  = rDoc.GetDrawModel();
    3031             :         OSL_ENSURE(pDrawModel, "Kann DrawModel nicht anlegen");
    3032          30 :         pDrawPg = pDrawModel->GetPage(0);
    3033             : 
    3034          30 :         pMSDffManager = new SwMSDffManager(*this);
    3035          30 :         pMSDffManager->SetModel(pDrawModel, 1440);
    3036             :         /*
    3037             :          Now the dff manager always needs a controls //converter as well, but a
    3038             :          control converter may still exist //without a dffmanager. cmc
    3039             :         */
    3040          30 :         pFormImpl = new SwMSConvertControls(mpDocShell, pPaM);
    3041             : 
    3042             :         pWWZOrder = new wwZOrderer(sw::util::SetLayer(rDoc), pDrawPg,
    3043          30 :             pMSDffManager ? pMSDffManager->GetShapeOrders() : 0);
    3044             :     }
    3045         210 : }
    3046             : 
    3047          74 : void SwWW8ImplReader::GrafikDtor()
    3048             : {
    3049          74 :     DELETEZ(mpDrawEditEngine); // evtl. von Grafik angelegt
    3050          74 :     DELETEZ(pWWZOrder);       // dito
    3051          74 : }
    3052             : 
    3053         114 : void SwWW8FltAnchorStack::AddAnchor(const SwPosition& rPos, SwFrmFmt *pFmt)
    3054             : {
    3055             :     OSL_ENSURE(pFmt->GetAnchor().GetAnchorId() != FLY_AS_CHAR,
    3056             :         "Don't use fltanchors with inline frames, slap!");
    3057         114 :     NewAttr(rPos, SwFltAnchor(pFmt));
    3058         114 : }
    3059             : 
    3060        3934 : void SwWW8FltAnchorStack::Flush()
    3061             : {
    3062        3934 :     size_t nCnt = size();
    3063        4048 :     for (size_t i=0; i < nCnt; ++i)
    3064             :     {
    3065         114 :         SwFltStackEntry &rEntry = (*this)[i];
    3066         114 :         SwPosition aDummy(rEntry.m_aMkPos.m_nNode);
    3067         114 :         SetAttrInDoc(aDummy, rEntry);
    3068         114 :         DeleteAndDestroy(i--);
    3069         114 :         --nCnt;
    3070         114 :     }
    3071        3970 : }
    3072             : 
    3073             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10