LCOV - code coverage report
Current view: top level - filter/source/graphicfilter/epict - epict.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 1148 0.0 %
Date: 2014-04-11 Functions: 0 53 0.0 %
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 <vcl/metaact.hxx>
      21             : #include <vcl/graphicfilter.hxx>
      22             : #include <svl/solar.hrc>
      23             : #include <vcl/fltcall.hxx>
      24             : 
      25             : #include <math.h>
      26             : #include <vcl/bmpacc.hxx>
      27             : #include <vcl/graph.hxx>
      28             : #include <vcl/gradient.hxx>
      29             : #include <vcl/hatch.hxx>
      30             : #include <vcl/metric.hxx>
      31             : #include <vcl/font.hxx>
      32             : #include <vcl/virdev.hxx>
      33             : #include <vcl/svapp.hxx>
      34             : #include <vcl/msgbox.hxx>
      35             : #include <vcl/gdimtf.hxx>
      36             : #include <tools/bigint.hxx>
      37             : 
      38             : #include <basegfx/polygon/b2dpolygon.hxx>
      39             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      40             : #include <boost/scoped_array.hpp>
      41             : 
      42             : // PictWriter
      43           0 : struct PictWriterAttrStackMember {
      44             :     struct PictWriterAttrStackMember *  pSucc;
      45             :     Color                               aLineColor;
      46             :     Color                               aFillColor;
      47             :     RasterOp                            eRasterOp;
      48             :     Font                                aFont;
      49             :     MapMode                             aMapMode;
      50             :     Rectangle                           aClipRect;
      51             : };
      52             : 
      53             : 
      54             : enum PictDrawingMethod {
      55             :     PDM_FRAME, PDM_PAINT, PDM_ERASE, PDM_INVERT, PDM_FILL
      56             : };
      57             : 
      58             : 
      59             : struct PictPattern {
      60             :     sal_uInt32 nLo, nHi;
      61             : };
      62             : 
      63           0 : class PictWriter {
      64             : 
      65             : private:
      66             : 
      67             :     sal_Bool bStatus;
      68             :     sal_uLong nLastPercent; // with which number pCallback has been called the last time
      69             :     com::sun::star::uno::Reference< com::sun::star::task::XStatusIndicator > xStatusIndicator;
      70             : 
      71             :     SvStream * pPict;
      72             : 
      73             :     // current attributes in the source-metafile:
      74             :     Color       aLineColor;
      75             :     Color       aFillColor;
      76             :     RasterOp    eSrcRasterOp;
      77             :     Font        aSrcFont;
      78             :     MapMode     aSrcMapMode;
      79             :     MapMode     aTargetMapMode;
      80             :     Rectangle   aClipRect;
      81             :     PictWriterAttrStackMember * pAttrStack;
      82             : 
      83             :     // current attributes in the target-metafile and whether they are valid
      84             :     sal_Bool bDstBkPatValid;
      85             :     sal_uInt8        nDstTxFace;            sal_Bool bDstTxFaceValid;
      86             :     RasterOp    eDstTxMode;         sal_Bool bDstTxModeValid;
      87             :     sal_uInt16      nDstPnSize;         sal_Bool bDstPnSizeValid;
      88             :     RasterOp    eDstPnMode;         sal_Bool bDstPnModeValid;
      89             :     PictPattern aDstPnPat;          sal_Bool bDstPnPatValid;
      90             :     sal_Bool bDstFillPatValid;
      91             :     sal_uInt16      nDstTxSize;         sal_Bool bDstTxSizeValid;
      92             :     Color       aDstFgCol;          sal_Bool bDstFgColValid;
      93             :     Color       aDstBkCol;          sal_Bool bDstBkColValid;
      94             :     Point       aDstPenPosition;    sal_Bool bDstPenPositionValid;
      95             :     Point       aDstTextPosition;   sal_Bool bDstTextPositionValid;
      96             :     OUString    aDstFontName; sal_uInt16 nDstFontNameId; sal_Bool bDstFontNameValid;
      97             : 
      98             :     sal_uLong nNumberOfActions;  // number of actions in the GDIMetafile
      99             :     sal_uLong nNumberOfBitmaps;  // number of bitmaps
     100             :     sal_uLong nWrittenActions;   // number of already processed actions during writing the Opcodes
     101             :     sal_uLong nWrittenBitmaps;   // number of already written Bitmaps
     102             :     sal_uLong nActBitmapPercent; // what percentage of the next bitmap is already written
     103             : 
     104             :     void MayCallback();
     105             :         // calculates a percentage on the basis of the 5 parameters above
     106             :         // and then does a Callback should the situation arise. Sets bStatus to sal_False
     107             :         // if the user wants to cancel
     108             : 
     109             :     void CountActionsAndBitmaps(const GDIMetaFile & rMTF);
     110             :         // counts the bitmaps and actions (nNumberOfActions and nNumberOfBitmaps
     111             :         // have to be set to 0 at the beginning, since this method is recursive)
     112             : 
     113             :     Polygon PolyPolygonToPolygon(const PolyPolygon & rPoly);
     114             :         // generates a relatively sane polygon on the basis of a PolyPolygon
     115             : 
     116             :     Rectangle MapRectangle( const Rectangle& rRect );
     117             :     void WritePoint(const Point & rPoint);
     118             :     void WriteSize(const Size & rSize);
     119             :     void WriteRGBColor(const Color & rColor);
     120             :     void WriteString( const OUString & rString );
     121             :     void WriteRectangle(const Rectangle & rRect);
     122             :     void WritePolygon(const Polygon & rPoly);
     123             :     void WriteArcAngles(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt);
     124             : 
     125             :     void ConvertLinePattern(PictPattern & rPat, sal_Bool bVisible) const;
     126             :     void ConvertFillPattern(PictPattern & rPat, sal_Bool bVisible) const;
     127             : 
     128             :     void WriteOpcode_TxFace(const Font & rFont);
     129             :     void WriteOpcode_TxMode(RasterOp eMode);
     130             :     void WriteOpcode_PnSize(sal_uInt16 nSize);
     131             :     void WriteOpcode_PnMode(RasterOp eMode);
     132             :     void WriteOpcode_PnLinePat(sal_Bool bVisible);
     133             :     void WriteOpcode_PnFillPat(sal_Bool bVisible);
     134             :     void WriteOpcode_OvSize(const Size & rSize);
     135             :     void WriteOpcode_TxSize(sal_uInt16 nSize);
     136             :     void WriteOpcode_RGBFgCol(const Color & rColor);
     137             :     void WriteOpcode_RGBBkCol(const Color & rColor);
     138             :     void WriteOpcode_Line(const Point & rLocPt, const Point & rNewPt);
     139             :     void WriteOpcode_LineFrom(const Point & rNewPt);
     140             :     void WriteOpcode_Text(const Point & rPoint, const OUString& rString, sal_Bool bDelta);
     141             :     void WriteOpcode_FontName(const Font & rFont);
     142             :     void WriteOpcode_ClipRect( const Rectangle& rRect );
     143             :     void WriteOpcode_Rect(PictDrawingMethod eMethod, const Rectangle & rRect);
     144             :     void WriteOpcode_SameRect(PictDrawingMethod eMethod);
     145             :     void WriteOpcode_RRect(PictDrawingMethod eMethod, const Rectangle & rRect);
     146             :     void WriteOpcode_SameRRect(PictDrawingMethod eMethod);
     147             :     void WriteOpcode_Oval(PictDrawingMethod eMethod, const Rectangle & rRect);
     148             :     void WriteOpcode_SameOval(PictDrawingMethod eMethod);
     149             :     void WriteOpcode_Arc(PictDrawingMethod eMethod, const Rectangle & rRect,
     150             :                          const Point & rStartPt, const Point & rEndPt);
     151             :     void WriteOpcode_SameArc(PictDrawingMethod eMethod, const Rectangle & rRect,
     152             :                              const Point & rStartPt, const Point & rEndPt);
     153             :     void WriteOpcode_Poly(PictDrawingMethod eMethod, const Polygon & rPoly);
     154             :     void WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize, const Bitmap & rBitmap);
     155             :     void WriteOpcode_EndOfFile();
     156             : 
     157             :     void SetAttrForPaint();
     158             :     void SetAttrForFrame();
     159             :     void SetAttrForText();
     160             : 
     161             :     void WriteTextArray(Point & rPoint, const OUString& rString, const sal_Int32 * pDXAry);
     162             : 
     163             :     void HandleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon);
     164             :     void WriteOpcodes(const GDIMetaFile & rMTF);
     165             : 
     166             :     void WriteHeader(const GDIMetaFile & rMTF);
     167             :     void UpdateHeader();
     168             : 
     169             : public:
     170             : 
     171             :     sal_Bool WritePict( const GDIMetaFile & rMTF, SvStream & rTargetStream, FilterConfigItem* pFilterConfigItem );
     172             : };
     173             : 
     174             : 
     175             : // Methods of PictWriter
     176           0 : void PictWriter::MayCallback()
     177             : {
     178           0 :     if ( xStatusIndicator.is() )
     179             :     {
     180             :         sal_uLong nPercent;
     181           0 :         nPercent=((nWrittenBitmaps<<14)+(nActBitmapPercent<<14)/100+nWrittenActions)
     182           0 :                 *100
     183           0 :                 /((nNumberOfBitmaps<<14)+nNumberOfActions);
     184             : 
     185           0 :         if (nPercent>=nLastPercent+3)
     186             :         {
     187           0 :             nLastPercent=nPercent;
     188           0 :             if( nPercent<=100 )
     189           0 :                 xStatusIndicator->setValue( nPercent );
     190             :         }
     191             :     }
     192           0 : }
     193             : 
     194           0 : void PictWriter::CountActionsAndBitmaps(const GDIMetaFile & rMTF)
     195             : {
     196             :     size_t              nAction, nActionCount;
     197             :     const MetaAction*   pMA;
     198             : 
     199           0 :     nActionCount = rMTF.GetActionSize();
     200             : 
     201           0 :     for (nAction=0; nAction < nActionCount; nAction++)
     202             :     {
     203           0 :         pMA = rMTF.GetAction( nAction );
     204             : 
     205           0 :         switch( pMA->GetType() )
     206             :         {
     207             :             case META_BMP_ACTION:
     208             :             case META_BMPSCALE_ACTION:
     209             :             case META_BMPSCALEPART_ACTION:
     210             :             case META_BMPEX_ACTION:
     211             :             case META_BMPEXSCALE_ACTION:
     212             :             case META_BMPEXSCALEPART_ACTION:
     213           0 :                 nNumberOfBitmaps++;
     214           0 :             break;
     215             :         }
     216             : 
     217           0 :         nNumberOfActions++;
     218             :     }
     219           0 : }
     220             : 
     221             : 
     222           0 : Polygon PictWriter::PolyPolygonToPolygon(const PolyPolygon & rPolyPoly)
     223             : {
     224             :     sal_uInt16 nCount,nSize1,nSize2,np,i1,i2,i3,nBestIdx1,nBestIdx2;
     225             :     long nDistSqr,nBestDistSqr, nCountdownTests;
     226           0 :     Point aP1,aPRel;
     227           0 :     Polygon aPoly1, aPoly2, aPoly3;
     228             : 
     229           0 :     nCount=rPolyPoly.Count();
     230           0 :     if (nCount==0) return Polygon(0);
     231             : 
     232           0 :     aPoly1=rPolyPoly.GetObject(0);
     233           0 :     for (np=1; np<nCount; np++) {
     234           0 :         aPoly2=rPolyPoly.GetObject(np);
     235             : 
     236             :         // The following code merges aPoly1 and aPoly2 to aPoly1
     237           0 :         nSize1=aPoly1.GetSize();
     238           0 :         nSize2=aPoly2.GetSize();
     239             : 
     240             :         // At first we look for a point in aPoly1 (referenced by nBestIdx1) and a
     241             :         // point in aPoly2 (referenced by nBestid2), which are as close together as
     242             :         // possible. Because this is following square complexity and therefore some
     243             :         // pictures would need infinite time to export, we limit the the number of test
     244             :         // by the number of 1000 and cancel the search if necessary preliminarily.
     245             :         // The result of this will not be wrong but rather not so beautiful.
     246           0 :         nCountdownTests=1000;
     247           0 :         nBestDistSqr=0x7fffffff;
     248           0 :         nBestIdx1=0;
     249           0 :         nBestIdx2=0;
     250           0 :         for (i1=0; i1<nSize1; i1++) {
     251           0 :             aP1=aPoly1.GetPoint(i1);
     252           0 :             for (i2=0; i2<nSize2; i2++) {
     253           0 :                 aPRel=aPoly2.GetPoint(i2); aPRel-=aP1;
     254           0 :                 nDistSqr=aPRel.X()*aPRel.X()+aPRel.Y()*aPRel.Y();
     255           0 :                 if (nDistSqr<nBestDistSqr) {
     256           0 :                     nBestIdx1=i1;
     257           0 :                     nBestIdx2=i2;
     258           0 :                     nBestDistSqr=nDistSqr;
     259             :                 }
     260           0 :                 if (nCountdownTests<=0) break;
     261           0 :                 nCountdownTests--;
     262             :             }
     263           0 :             if (nCountdownTests<=0) break;
     264             :         }
     265             : 
     266             :         // Now aPoly1 and aPoly2 are being merged to a polygon aPoly3 (later aPoly1)
     267             :         // Both polygons are being connected by two additional edges between the points found above
     268           0 :         aPoly3.Clear();
     269           0 :         aPoly3.SetSize(nSize1+nSize2+2);
     270           0 :         i3=0;
     271           0 :         for (i1=nBestIdx1; i1<nSize1;     i1++) aPoly3.SetPoint(aPoly1.GetPoint(i1),i3++);
     272           0 :         for (i1=0;         i1<=nBestIdx1; i1++) aPoly3.SetPoint(aPoly1.GetPoint(i1),i3++);
     273           0 :         for (i2=nBestIdx2; i2<nSize2;     i2++) aPoly3.SetPoint(aPoly2.GetPoint(i2),i3++);
     274           0 :         for (i2=0;         i2<=nBestIdx2; i2++) aPoly3.SetPoint(aPoly2.GetPoint(i2),i3++);
     275             : 
     276           0 :         aPoly1=aPoly3;
     277             :     }
     278           0 :     return aPoly1;
     279             : }
     280             : 
     281             : 
     282           0 : void PictWriter::WritePoint(const Point & rPoint)
     283             : {
     284           0 :     Point aPoint = OutputDevice::LogicToLogic( rPoint, aSrcMapMode, aTargetMapMode );
     285           0 :     pPict->WriteInt16( (short)aPoint.Y() ).WriteInt16( (short)aPoint.X() );
     286           0 : }
     287             : 
     288             : 
     289           0 : void PictWriter::WriteSize(const Size & rSize)
     290             : {
     291           0 :     OutputDevice::LogicToLogic( rSize, aSrcMapMode, aTargetMapMode ); // -Wall is this needed.
     292           0 :     pPict->WriteInt16( (short)rSize.Height() ).WriteInt16( (short)rSize.Width() );
     293           0 : }
     294             : 
     295             : 
     296           0 : void PictWriter::WriteRGBColor(const Color & rColor)
     297             : {
     298           0 :     const sal_uInt16 nR = ( (sal_uInt16) rColor.GetRed() << 8 ) | (sal_uInt16) rColor.GetRed();
     299           0 :     const sal_uInt16 nG = ( (sal_uInt16) rColor.GetGreen() << 8 ) | (sal_uInt16) rColor.GetGreen();
     300           0 :     const sal_uInt16 nB = ( (sal_uInt16) rColor.GetBlue() << 8 ) | (sal_uInt16) rColor.GetBlue();
     301             : 
     302           0 :     pPict->WriteUInt16( nR ).WriteUInt16( nG ).WriteUInt16( nB );
     303           0 : }
     304             : 
     305           0 : void PictWriter::WriteString( const OUString & rString )
     306             : {
     307           0 :     OString aString(OUStringToOString(rString, osl_getThreadTextEncoding()));
     308           0 :     sal_Int32 nLen = aString.getLength();
     309           0 :     if ( nLen > 255 )
     310           0 :         nLen = 255;
     311           0 :     pPict->WriteUChar(  (sal_uInt8)nLen  );
     312           0 :     for (sal_Int32 i = 0; i < nLen; ++i)
     313           0 :         pPict->WriteChar( aString[i] );
     314           0 : }
     315             : 
     316           0 : Rectangle PictWriter::MapRectangle( const Rectangle& rRect )
     317             : {
     318           0 :     Point   aPoint = OutputDevice::LogicToLogic( rRect.TopLeft(), aSrcMapMode, aTargetMapMode );
     319           0 :     Size    aSize = OutputDevice::LogicToLogic( rRect.GetSize(), aSrcMapMode, aTargetMapMode );
     320           0 :     Rectangle aRect( aPoint, aSize );
     321           0 :     aRect.Justify();
     322           0 :     ++aRect.Bottom();
     323           0 :     ++aRect.Right();
     324           0 :     return aRect;
     325             : }
     326             : 
     327           0 : void PictWriter::WriteRectangle(const Rectangle & rRect)
     328             : {
     329           0 :     Rectangle aRect( MapRectangle( rRect ) );
     330           0 :     pPict ->WriteInt16( (sal_Int16)aRect.Top() ).WriteInt16( (sal_Int16)aRect.Left() )
     331           0 :            .WriteInt16( (sal_Int16)aRect.Bottom() ).WriteInt16( (sal_Int16)aRect.Right() );
     332           0 : }
     333             : 
     334           0 : void PictWriter::WritePolygon(const Polygon & rPoly)
     335             : {
     336             :     sal_uInt16 nDataSize,i,nSize;
     337           0 :     short nMinX = 0, nMinY = 0, nMaxX = 0, nMaxY = 0;
     338             :     short nx,ny;
     339           0 :     Polygon aPoly(rPoly);
     340             : 
     341           0 :     nSize=aPoly.GetSize();
     342             : 
     343           0 :     if (aPoly.GetPoint(0) != aPoly.GetPoint(nSize-1))
     344             :     {
     345           0 :         nSize++;
     346           0 :         aPoly.SetSize(nSize);
     347           0 :         aPoly.SetPoint(aPoly.GetPoint(0),nSize-1);
     348             :     }
     349             : 
     350           0 :     nDataSize=nSize*4+10;
     351           0 :     for (i=0; i<nSize; i++)
     352             :     {
     353           0 :         Point aPoint = OutputDevice::LogicToLogic( aPoly.GetPoint( i ),
     354             :                                                    aSrcMapMode,
     355           0 :                                                    aTargetMapMode );
     356             : 
     357           0 :         nx = (short) aPoint.X();
     358           0 :         ny = (short) aPoint.Y();
     359             : 
     360           0 :         if ( i==0 || nMinX>nx )
     361           0 :             nMinX=nx;
     362           0 :         if ( i==0 || nMinY>ny )
     363           0 :             nMinY=ny;
     364           0 :         if ( i==0 || nMaxX<nx )
     365           0 :             nMaxX=nx;
     366           0 :         if ( i==0 || nMaxY<ny )
     367           0 :             nMaxY=ny;
     368             :     }
     369             : 
     370           0 :     pPict->WriteUInt16( nDataSize ).WriteInt16( nMinY ).WriteInt16( nMinX ).WriteInt16( nMaxY ).WriteInt16( nMaxX );
     371             : 
     372           0 :     for (i=0; i<nSize; i++)
     373           0 :         WritePoint( aPoly.GetPoint(i) );
     374           0 : }
     375             : 
     376             : 
     377           0 : void PictWriter::WriteArcAngles(const Rectangle & rRect, const Point & rStartPt, const Point & rEndPt)
     378             : {
     379             :     Point       aStartPt = OutputDevice::LogicToLogic( rStartPt,
     380             :                                                        aSrcMapMode,
     381           0 :                                                        aTargetMapMode );
     382             :     Point       aEndPt = OutputDevice::LogicToLogic( rEndPt,
     383             :                                                      aSrcMapMode,
     384           0 :                                                      aTargetMapMode );
     385             :     Rectangle   aRect( OutputDevice::LogicToLogic( rRect.TopLeft(),
     386             :                                                    aSrcMapMode,
     387           0 :                                                    aTargetMapMode ),
     388             :                        OutputDevice::LogicToLogic( rRect.GetSize(),
     389             :                                                    aSrcMapMode,
     390           0 :                                                    aTargetMapMode ) );
     391           0 :     Point aCenter;
     392             :     double fAngS, fAngE, fdx, fdy;
     393             :     short nStartAngle, nArcAngle;
     394             : 
     395             : 
     396           0 :     aCenter=Point( ( aRect.Left() + aRect.Right() ) >> 1,
     397           0 :                    ( aRect.Top() + aRect.Bottom() ) >> 1 );
     398             : 
     399           0 :     fdx=(double)(aStartPt.X()-aCenter.X());
     400           0 :     fdy=(double)(aStartPt.Y()-aCenter.Y());
     401           0 :     if ( fdx==0.0 && fdy==0.0 )
     402           0 :         fdx=1.0;
     403           0 :     fAngE=atan2(fdx,-fdy);
     404             : 
     405           0 :     fdx=(double)(aEndPt.X()-aCenter.X());
     406           0 :     fdy=(double)(aEndPt.Y()-aCenter.Y());
     407           0 :     if ( fdx==0.0 && fdy==0.0 )
     408           0 :         fdx=1.0;
     409           0 :     fAngS=atan2(fdx,-fdy);
     410             : 
     411           0 :     nStartAngle=(short)(fAngS*180.0/3.14159265359);
     412           0 :     nArcAngle=((short)(fAngE*180.0/3.14159265359))-nStartAngle;
     413           0 :     if (nArcAngle<0)
     414           0 :         nArcAngle += 360;
     415           0 :     pPict->WriteInt16( nStartAngle ).WriteInt16( nArcAngle );
     416           0 : }
     417             : 
     418             : 
     419           0 : void PictWriter::ConvertLinePattern(PictPattern & rPat, sal_Bool bVisible) const
     420             : {
     421           0 :     if( bVisible )
     422             :     {
     423           0 :         rPat.nHi=0xffffffff;
     424           0 :         rPat.nLo=0xffffffff;
     425             :     }
     426             :     else
     427             :     {
     428           0 :         rPat.nHi=0x00000000;
     429           0 :         rPat.nLo=0x00000000;
     430             :     }
     431           0 : }
     432             : 
     433           0 : void PictWriter::ConvertFillPattern(PictPattern & rPat, sal_Bool bVisible) const
     434             : {
     435           0 :     if( bVisible )
     436             :     {
     437           0 :         rPat.nHi=0xffffffff;
     438           0 :         rPat.nLo=0xffffffff;
     439             :     }
     440             :     else
     441             :     {
     442           0 :         rPat.nHi=0x00000000;
     443           0 :         rPat.nLo=0x00000000;
     444             :     }
     445           0 : }
     446             : 
     447             : 
     448           0 : void PictWriter::WriteOpcode_TxFace(const Font & rFont)
     449             : {
     450             :     sal_uInt8 nFace;
     451             :     FontWeight eWeight;
     452             : 
     453           0 :     nFace=0;
     454           0 :     eWeight=rFont.GetWeight();
     455           0 :     if (eWeight==WEIGHT_BOLD ||
     456           0 :         eWeight==WEIGHT_SEMIBOLD ||
     457           0 :         eWeight==WEIGHT_ULTRABOLD ||
     458           0 :         eWeight==WEIGHT_BLACK)                nFace|=0x01;
     459           0 :     if (rFont.GetItalic()!=ITALIC_NONE)       nFace|=0x02;
     460           0 :     if (rFont.GetUnderline()!=UNDERLINE_NONE) nFace|=0x04;
     461           0 :     if (rFont.IsOutline())              nFace|=0x08;
     462           0 :     if (rFont.IsShadow())               nFace|=0x10;
     463             : 
     464           0 :     if (bDstTxFaceValid==sal_False || nDstTxFace!=nFace) {
     465           0 :         pPict->WriteUInt16( (sal_uInt16)0x0004 ).WriteUChar( nFace ).WriteUChar( (sal_uInt8)0 );
     466           0 :         nDstTxFace=nFace;
     467           0 :         bDstTxFaceValid=sal_True;
     468             :     }
     469           0 : }
     470             : 
     471             : 
     472           0 : void PictWriter::WriteOpcode_TxMode(RasterOp eMode)
     473             : {
     474             :     sal_uInt16 nVal;
     475             : 
     476           0 :     if (bDstTxModeValid==sal_False || eDstTxMode!=eMode) {
     477           0 :         switch (eMode) {
     478           0 :             case ROP_INVERT: nVal=0x000c; break;
     479           0 :             case ROP_XOR:    nVal=0x000a; break;
     480           0 :             default:         nVal=0x0008;
     481             :         }
     482           0 :         pPict->WriteUInt16( (sal_uInt16)0x0005 ).WriteUInt16( nVal );
     483           0 :         eDstTxMode=eMode;
     484           0 :         bDstTxModeValid=sal_True;
     485             :     }
     486           0 : }
     487             : 
     488             : 
     489           0 : void PictWriter::WriteOpcode_PnSize(sal_uInt16 nSize)
     490             : {
     491           0 :     if (nSize==0) nSize=1;
     492           0 :     if (bDstPnSizeValid==sal_False || nDstPnSize!=nSize) {
     493           0 :         pPict->WriteUInt16( (sal_uInt16)0x0007 ).WriteUInt16( nSize ).WriteUInt16( nSize );
     494           0 :         nDstPnSize=nSize;
     495           0 :         bDstPnSizeValid=sal_True;
     496             :     }
     497           0 : }
     498             : 
     499             : 
     500           0 : void PictWriter::WriteOpcode_PnMode(RasterOp eMode)
     501             : {
     502             :     sal_uInt16 nVal;
     503             : 
     504           0 :     if (bDstPnModeValid==sal_False || eDstPnMode!=eMode) {
     505           0 :         switch (eMode)
     506             :         {
     507           0 :             case ROP_INVERT: nVal=0x000c; break;
     508           0 :             case ROP_XOR:    nVal=0x000a; break;
     509           0 :             default:         nVal=0x0008;
     510             :         }
     511           0 :         pPict->WriteUInt16( (sal_uInt16)0x0008 ).WriteUInt16( nVal );
     512           0 :         eDstPnMode=eMode;
     513           0 :         bDstPnModeValid=sal_True;
     514             :     }
     515           0 : }
     516             : 
     517             : 
     518           0 : void PictWriter::WriteOpcode_PnLinePat(sal_Bool bVisible)
     519             : {
     520             :     PictPattern aPat;
     521             : 
     522           0 :     ConvertLinePattern(aPat,bVisible);
     523           0 :     if (bDstPnPatValid==sal_False || aDstPnPat.nHi!=aPat.nHi || aDstPnPat.nLo!=aPat.nLo) {
     524           0 :         pPict->WriteUInt16( (sal_uInt16)0x0009 ).WriteUInt32( aPat.nHi ).WriteUInt32( aPat.nLo );
     525           0 :         aDstPnPat=aPat;
     526           0 :         bDstPnPatValid=sal_True;
     527             :     }
     528           0 : }
     529             : 
     530             : 
     531           0 : void PictWriter::WriteOpcode_PnFillPat(sal_Bool bVisible)
     532             : {
     533             :     PictPattern aPat;
     534             : 
     535           0 :     ConvertFillPattern(aPat,bVisible);
     536           0 :     if (bDstPnPatValid==sal_False || aDstPnPat.nHi!=aPat.nHi || aDstPnPat.nLo!=aPat.nLo) {
     537           0 :         pPict->WriteUInt16( (sal_uInt16)0x0009 ).WriteUInt32( aPat.nHi ).WriteUInt32( aPat.nLo );
     538           0 :         aDstPnPat=aPat;
     539           0 :         bDstPnPatValid=sal_True;
     540             :     }
     541           0 : }
     542             : 
     543             : 
     544           0 : void PictWriter::WriteOpcode_OvSize(const Size & rSize)
     545             : {
     546           0 :     pPict->WriteUInt16( (sal_uInt16)0x000b );
     547           0 :     WriteSize(rSize);
     548           0 : }
     549             : 
     550             : 
     551           0 : void PictWriter::WriteOpcode_TxSize(sal_uInt16 nSize)
     552             : {
     553           0 :     if (bDstTxSizeValid==sal_False || nDstTxSize!=nSize) {
     554             : 
     555             :         nDstTxSize = (sal_uInt16) OutputDevice::LogicToLogic( Size( 0, nSize ),
     556           0 :                                                           aSrcMapMode, aTargetMapMode ).Height();
     557             : 
     558           0 :         pPict->WriteUInt16( (sal_uInt16)0x000d ).WriteUInt16( nDstTxSize );
     559           0 :         bDstTxSizeValid=sal_True;
     560             :     }
     561           0 : }
     562             : 
     563             : 
     564           0 : void PictWriter::WriteOpcode_RGBFgCol(const Color & rColor)
     565             : {
     566           0 :     if (bDstFgColValid==sal_False || aDstFgCol!=rColor) {
     567           0 :         pPict->WriteUInt16( (sal_uInt16)0x001a );
     568           0 :         WriteRGBColor(rColor);
     569           0 :         aDstFgCol=rColor;
     570           0 :         bDstFgColValid=sal_True;
     571             :     }
     572           0 : }
     573             : 
     574             : 
     575           0 : void PictWriter::WriteOpcode_RGBBkCol(const Color & rColor)
     576             : {
     577           0 :     if (bDstBkColValid==sal_False || aDstBkCol!=rColor) {
     578           0 :         pPict->WriteUInt16( (sal_uInt16)0x001b );
     579           0 :         WriteRGBColor(rColor);
     580           0 :         aDstBkCol=rColor;
     581           0 :         bDstBkColValid=sal_True;
     582             :     }
     583           0 : }
     584             : 
     585             : 
     586           0 : void PictWriter::WriteOpcode_Line(const Point & rLocPt, const Point & rNewPt)
     587             : {
     588             :     Point aLocPt = OutputDevice::LogicToLogic( rLocPt,
     589             :                                                aSrcMapMode,
     590           0 :                                                aTargetMapMode );
     591             :     Point aNewPt = OutputDevice::LogicToLogic( rNewPt,
     592             :                                                aSrcMapMode,
     593           0 :                                                aTargetMapMode );
     594             :     long  dh,dv;
     595             : 
     596           0 :     dh=aNewPt.X()-aLocPt.X();
     597           0 :     dv=aNewPt.Y()-aLocPt.Y();
     598           0 :     if (dh<=127 && dh>=-128 && dv<=127 && dv>=-128)
     599             :     { // ShortLine
     600           0 :         pPict->WriteUInt16( (sal_uInt16)0x0022 );
     601           0 :         WritePoint(rLocPt);
     602           0 :         pPict->WriteChar( (char)dh ).WriteChar( (char)dv );
     603             :     }
     604             :     else
     605             :     {
     606           0 :         pPict->WriteUInt16( (sal_uInt16)0x0020 );
     607           0 :         WritePoint(rLocPt);
     608           0 :         WritePoint(rNewPt);
     609             :     }
     610           0 :     aDstPenPosition=rNewPt;
     611           0 :     bDstPenPositionValid=sal_True;
     612           0 : }
     613             : 
     614             : 
     615           0 : void PictWriter::WriteOpcode_LineFrom(const Point & rNewPt)
     616             : {
     617             :     Point aNewPt = OutputDevice::LogicToLogic( rNewPt,
     618             :                                                aSrcMapMode,
     619           0 :                                                aTargetMapMode );
     620             :     long  dh,dv;
     621             : 
     622           0 :     dh = aNewPt.X()-aDstPenPosition.X();
     623           0 :     dv = aNewPt.Y()-aDstPenPosition.Y();
     624             : 
     625           0 :     if (dh<=127 && dh>=-128 && dv<=127 && dv>=-128)
     626             :     { // ShortLine
     627           0 :         pPict->WriteUInt16( (sal_uInt16)0x0023 );
     628           0 :         pPict->WriteChar( (char)dh ).WriteChar( (char)dv );
     629             :     }
     630             :     else
     631             :     {
     632           0 :         pPict->WriteUInt16( (sal_uInt16)0x0021 );
     633           0 :         WritePoint(rNewPt);
     634             :     }
     635           0 :     aDstPenPosition=rNewPt;
     636           0 :     bDstPenPositionValid=sal_True;
     637           0 : }
     638             : 
     639             : 
     640           0 : void PictWriter::WriteOpcode_Text(const Point & rPoint, const OUString& rString, sal_Bool bDelta)
     641             : {
     642             :     Point aPoint = OutputDevice::LogicToLogic( rPoint,
     643             :                                                aSrcMapMode,
     644           0 :                                                aTargetMapMode );
     645             :     long  dh,dv;
     646             :     sal_uLong nPos;
     647             : 
     648           0 :     nPos = pPict->Tell();
     649           0 :     dh = aPoint.X()-aDstTextPosition.X();
     650           0 :     dv = aPoint.Y()-aDstTextPosition.Y();
     651             : 
     652           0 :     if (bDstTextPositionValid==sal_False || dh<0 || dh>255 || dv<0 || dv>255 || bDelta==sal_False)
     653             :     {
     654           0 :         pPict->WriteUInt16( (sal_uInt16)0x0028 );
     655           0 :         WritePoint(rPoint);
     656             :     }
     657           0 :     else if (dv==0)
     658             :     {
     659           0 :         pPict->WriteUInt16( (sal_uInt16)0x0029 ).WriteUChar( (sal_uInt8)dh );
     660             :     }
     661           0 :     else if (dh==0)
     662             :     {
     663           0 :         pPict->WriteUInt16( (sal_uInt16)0x002a ).WriteUChar( (sal_uInt8)dv );
     664             :     }
     665             :     else
     666             :     {
     667           0 :         pPict->WriteUInt16( (sal_uInt16)0x002b ).WriteUChar( (sal_uInt8)dh ).WriteUChar( (sal_uInt8)dv );
     668             :     }
     669             : 
     670           0 :     WriteString( rString );
     671           0 :     if (((pPict->Tell()-nPos)&1)!=0)
     672           0 :         pPict->WriteUChar( (sal_uInt8)0 );
     673             : 
     674           0 :     aDstTextPosition = aPoint;
     675           0 :     bDstTextPositionValid=sal_True;
     676           0 : }
     677             : 
     678             : 
     679           0 : void PictWriter::WriteOpcode_FontName(const Font & rFont)
     680             : {
     681             :     sal_uInt16 nDataLen,nFontId;
     682             : 
     683           0 :     switch (rFont.GetFamily()) {
     684           0 :         case FAMILY_MODERN:     nFontId=22; break;
     685           0 :         case FAMILY_ROMAN:      nFontId=20; break;
     686           0 :         case FAMILY_SWISS:      nFontId=21; break;
     687           0 :         default:                nFontId=1;
     688             :     }
     689             : 
     690           0 :     if (bDstFontNameValid==sal_False || nDstFontNameId!=nFontId || aDstFontName!=rFont.GetName())
     691             :     {
     692           0 :         OString aString(OUStringToOString(rFont.GetName(), osl_getThreadTextEncoding()));
     693           0 :         sal_uInt16 nFontNameLen = aString.getLength();
     694           0 :         if ( nFontNameLen )
     695             :         {
     696           0 :             nDataLen = 3 + nFontNameLen;
     697           0 :             pPict->WriteUInt16( (sal_uInt16)0x002c ).WriteUInt16( nDataLen ).WriteUInt16( nFontId );
     698           0 :             WriteString( rFont.GetName() );
     699           0 :             if ( ( nFontNameLen & 1 ) == 0 )
     700           0 :                 pPict->WriteUChar( (sal_uInt8)0 );
     701             :         }
     702           0 :         pPict->WriteUInt16( (sal_uInt16)0x0003 ).WriteUInt16( nFontId );
     703           0 :         aDstFontName=rFont.GetName();
     704           0 :         nDstFontNameId=nFontId;
     705           0 :         bDstFontNameValid=sal_True;
     706             :     }
     707           0 : }
     708             : 
     709           0 : void PictWriter::WriteOpcode_ClipRect( const Rectangle& rRect )
     710             : {
     711           0 :     Rectangle aRect( MapRectangle( rRect ) );
     712           0 :     ++aRect.Bottom();
     713           0 :     ++aRect.Right();
     714           0 :     pPict ->WriteUInt16( (sal_uInt16)1 )    // opcode 1
     715           0 :            .WriteUInt16( (sal_uInt16)10 )   // data size
     716           0 :            .WriteInt16( (sal_Int16)aRect.Top() ).WriteInt16( (sal_Int16)aRect.Left() )
     717           0 :            .WriteInt16( (sal_Int16)aRect.Bottom() ).WriteInt16( (sal_Int16)aRect.Right() );
     718           0 :     aClipRect = aRect;
     719           0 : }
     720             : 
     721           0 : void PictWriter::WriteOpcode_Rect(PictDrawingMethod eMethod, const Rectangle & rRect)
     722             : {
     723             :     sal_uInt16 oc;
     724           0 :     switch (eMethod) {
     725           0 :         case PDM_FRAME:  oc=0x0030; break;
     726           0 :         case PDM_PAINT:  oc=0x0031; break;
     727           0 :         case PDM_ERASE:  oc=0x0032; break;
     728           0 :         case PDM_INVERT: oc=0x0033; break;
     729           0 :         case PDM_FILL:   oc=0x0034; break;
     730           0 :         default:         oc=0;      break;   // -Wall a default for oc...
     731             :     }
     732           0 :     pPict->WriteUInt16( oc );
     733           0 :     WriteRectangle(rRect);
     734           0 : }
     735             : 
     736             : 
     737           0 : void PictWriter::WriteOpcode_SameRect(PictDrawingMethod eMethod)
     738             : {
     739             :     sal_uInt16 oc;
     740           0 :     switch (eMethod) {
     741           0 :         case PDM_FRAME:  oc=0x0038; break;
     742           0 :         case PDM_PAINT:  oc=0x0039; break;
     743           0 :         case PDM_ERASE:  oc=0x003a; break;
     744           0 :         case PDM_INVERT: oc=0x003b; break;
     745           0 :         case PDM_FILL:   oc=0x003c; break;
     746           0 :         default:         oc=0;      break;   // -Wall a default for oc...
     747             :     }
     748           0 :     pPict->WriteUInt16( oc );
     749           0 : }
     750             : 
     751             : 
     752           0 : void PictWriter::WriteOpcode_RRect(PictDrawingMethod eMethod, const Rectangle & rRect)
     753             : {
     754             :     sal_uInt16 oc;
     755           0 :     switch (eMethod) {
     756           0 :         case PDM_FRAME:  oc=0x0040; break;
     757           0 :         case PDM_PAINT:  oc=0x0041; break;
     758           0 :         case PDM_ERASE:  oc=0x0042; break;
     759           0 :         case PDM_INVERT: oc=0x0043; break;
     760           0 :         case PDM_FILL:   oc=0x0044; break;
     761           0 :         default:         oc=0;      break;   // -Wall a default for oc...
     762             :     }
     763           0 :     pPict->WriteUInt16( oc );
     764           0 :     WriteRectangle(rRect);
     765           0 : }
     766             : 
     767             : 
     768           0 : void PictWriter::WriteOpcode_SameRRect(PictDrawingMethod eMethod)
     769             : {
     770             :     sal_uInt16 oc;
     771           0 :     switch (eMethod) {
     772           0 :         case PDM_FRAME:  oc=0x0048; break;
     773           0 :         case PDM_PAINT:  oc=0x0049; break;
     774           0 :         case PDM_ERASE:  oc=0x004a; break;
     775           0 :         case PDM_INVERT: oc=0x004b; break;
     776           0 :         case PDM_FILL:   oc=0x004c; break;
     777           0 :         default:         oc=0;      break;   // -Wall a default for oc...
     778             :     }
     779           0 :     pPict->WriteUInt16( oc );
     780           0 : }
     781             : 
     782             : 
     783           0 : void PictWriter::WriteOpcode_Oval(PictDrawingMethod eMethod, const Rectangle & rRect)
     784             : {
     785             :     sal_uInt16 oc;
     786           0 :     switch (eMethod) {
     787           0 :         case PDM_FRAME:  oc=0x0050; break;
     788           0 :         case PDM_PAINT:  oc=0x0051; break;
     789           0 :         case PDM_ERASE:  oc=0x0052; break;
     790           0 :         case PDM_INVERT: oc=0x0053; break;
     791           0 :         case PDM_FILL:   oc=0x0054; break;
     792           0 :         default:         oc=0;      break;   // -Wall a default for oc...
     793             :     }
     794           0 :     pPict->WriteUInt16( oc );
     795           0 :     WriteRectangle(rRect);
     796           0 : }
     797             : 
     798             : 
     799           0 : void PictWriter::WriteOpcode_SameOval(PictDrawingMethod eMethod)
     800             : {
     801             :     sal_uInt16 oc;
     802           0 :     switch (eMethod) {
     803           0 :         case PDM_FRAME:  oc=0x0058; break;
     804           0 :         case PDM_PAINT:  oc=0x0059; break;
     805           0 :         case PDM_ERASE:  oc=0x005a; break;
     806           0 :         case PDM_INVERT: oc=0x005b; break;
     807           0 :         case PDM_FILL:   oc=0x005c; break;
     808           0 :         default:         oc=0;      break;   // -Wall a default for oc...
     809             :     }
     810           0 :     pPict->WriteUInt16( oc );
     811           0 : }
     812             : 
     813             : 
     814           0 : void PictWriter::WriteOpcode_Arc(PictDrawingMethod eMethod, const Rectangle & rRect,
     815             :                                  const Point & rStartPt, const Point & rEndPt)
     816             : {
     817             :     sal_uInt16 oc;
     818           0 :     switch (eMethod) {
     819           0 :         case PDM_FRAME:  oc=0x0060; break;
     820           0 :         case PDM_PAINT:  oc=0x0061; break;
     821           0 :         case PDM_ERASE:  oc=0x0062; break;
     822           0 :         case PDM_INVERT: oc=0x0063; break;
     823           0 :         case PDM_FILL:   oc=0x0064; break;
     824           0 :         default:         oc=0;      break;   // -Wall a default for oc...
     825             :     }
     826           0 :     pPict->WriteUInt16( oc );
     827           0 :     WriteRectangle(rRect);
     828           0 :     WriteArcAngles(rRect,rStartPt,rEndPt);
     829           0 : }
     830             : 
     831             : 
     832           0 : void PictWriter::WriteOpcode_SameArc(PictDrawingMethod eMethod, const Rectangle & rRect,
     833             :                                      const Point & rStartPt, const Point & rEndPt)
     834             : {
     835             :     sal_uInt16 oc;
     836           0 :     switch (eMethod) {
     837           0 :         case PDM_FRAME:  oc=0x0068; break;
     838           0 :         case PDM_PAINT:  oc=0x0069; break;
     839           0 :         case PDM_ERASE:  oc=0x006a; break;
     840           0 :         case PDM_INVERT: oc=0x006b; break;
     841           0 :         case PDM_FILL:   oc=0x006c; break;
     842           0 :         default:         oc=0;      break;   // -Wall a default for oc...
     843             :     }
     844           0 :     pPict->WriteUInt16( oc );
     845           0 :     WriteArcAngles(rRect,rStartPt,rEndPt);
     846           0 : }
     847             : 
     848             : 
     849           0 : void PictWriter::WriteOpcode_Poly(PictDrawingMethod eMethod, const Polygon & rPoly)
     850             : {
     851             :     sal_uInt16 oc;
     852             : 
     853           0 :     if (rPoly.GetSize()<3) return;
     854           0 :     switch (eMethod) {
     855           0 :         case PDM_FRAME:  oc=0x0070; break;
     856           0 :         case PDM_PAINT:  oc=0x0071; break;
     857           0 :         case PDM_ERASE:  oc=0x0072; break;
     858           0 :         case PDM_INVERT: oc=0x0073; break;
     859           0 :         case PDM_FILL:   oc=0x0074; break;
     860           0 :         default:         oc=0;      break;   // -Wall a default for oc...
     861             :     }
     862           0 :     pPict->WriteUInt16( oc );
     863           0 :     WritePolygon(rPoly);
     864             : }
     865             : 
     866             : 
     867           0 : void PictWriter::WriteOpcode_BitsRect(const Point & rPoint, const Size & rSize, const Bitmap & rBitmap)
     868             : {
     869           0 :     BitmapReadAccess*   pAcc = NULL;
     870           0 :     Bitmap              aBitmap( rBitmap );
     871             : 
     872             :     sal_uLong   nWidth, nHeight, nDstRowBytes, nx, nc, ny, nCount, nColTabSize, i;
     873             :     sal_uLong   nDstRowPos, nSrcRowBytes, nEqu3, nPos, nDstMapPos;
     874             :     sal_uInt16  nBitsPerPixel, nPackType;
     875             :     sal_uInt8   *pComp[4], *pTemp;
     876           0 :     sal_uInt8    nEquData = 0;
     877             :     sal_uInt8    nFlagCounterByte, nRed, nGreen, nBlue;
     878             : 
     879           0 :     SetAttrForPaint();
     880             : 
     881             :     // generating a temporary Windows-BMP-File:
     882           0 :     nActBitmapPercent=30;
     883           0 :     MayCallback();
     884             : 
     885           0 :     if ( bStatus == sal_False )
     886           0 :         return;
     887           0 :     if ( ( pAcc = aBitmap.AcquireReadAccess() ) == NULL )
     888           0 :         return;
     889             : 
     890           0 :     nBitsPerPixel = aBitmap.GetBitCount();
     891             : 
     892             :     // export code below only handles four discrete cases
     893             :     nBitsPerPixel =
     894           0 :         nBitsPerPixel <= 1 ? 1 : nBitsPerPixel <= 4 ? 4 : nBitsPerPixel <= 8 ? 8 : 24;
     895             : 
     896           0 :     nWidth = pAcc->Width();
     897           0 :     nHeight = pAcc->Height();
     898             : 
     899             :     // If 24-Bit, then create the Opcode 'DirectBitsRect':
     900           0 :     if ( nBitsPerPixel == 24 )
     901             :     {
     902             :         // Calculate the number of bytes of an (uncompressed) line of source and destination.
     903           0 :         nSrcRowBytes =( ( 3 * nWidth ) + 0x0003 ) & 0xfffc;
     904           0 :         nDstRowBytes = nWidth * 4;
     905             : 
     906             :         // writing Opcode and BaseAddr (?):
     907           0 :         pPict->WriteUInt16( (sal_uInt16)0x009a ).WriteUInt32( (sal_uInt32)0x000000ff );
     908             : 
     909             :         // Normally we want to produce packing type 4 (run length encoding
     910             :         // for 32-bit pixels). But if RowBytes<8 is true, generally all data is
     911             :         // unpacked even if packing type 4 is specified, which seems a little bit
     912             :         // strange. Hence we want to specify packing type 1 (no packing) in these cases:
     913             : 
     914           0 :         if ( nDstRowBytes < 8 )
     915           0 :             nPackType = 1;
     916             :         else
     917           0 :             nPackType = 4;
     918             : 
     919             :         // writing PixMap-Structure:
     920           0 :         pPict->WriteUInt16( (sal_uInt16)(nDstRowBytes|0x8000) ) // Bytes per row and the fact that it's a 'PixMap'
     921           0 :               .WriteUInt16( (sal_uInt16)0x0000 )                // Y1-position of the bitmap in the source
     922           0 :               .WriteUInt16( (sal_uInt16)0x0000 )                // X1-position of the bitmap in the source
     923           0 :               .WriteUInt16( (sal_uInt16)nHeight )               // Y2-position of the bitmap in the source
     924           0 :               .WriteUInt16( (sal_uInt16)nWidth )                // X2-position of the bitmap in the source
     925           0 :               .WriteUInt16( (sal_uInt16)0x0000 )                // Version
     926           0 :               .WriteUInt16( (sal_uInt16)nPackType )             // Packing type
     927           0 :               .WriteUInt32( (sal_uInt32) 0x00000000 )            // Packing size (?)
     928           0 :               .WriteUInt32( (sal_uInt32) 0x00480000 )            // H-Res
     929           0 :               .WriteUInt32( (sal_uInt32) 0x00480000 )            // V-Res
     930           0 :               .WriteUInt16( (sal_uInt16)0x0010 )                // Pixel type (?)
     931           0 :               .WriteUInt16( (sal_uInt16)0x0020 )                // Pixel size: 32 bit
     932           0 :               .WriteUInt16( (sal_uInt16)0x0004 )                // CmpCount: 4 components
     933           0 :               .WriteUInt16( (sal_uInt16)0x0008 )                // CmpSize: 8 bits
     934           0 :               .WriteUInt32( (sal_uInt32) 0x00000000 )            // PlaneBytes (?)
     935           0 :               .WriteUInt32( (sal_uInt32) 0x00000000 )            // (?)
     936           0 :               .WriteUInt32( (sal_uInt32) 0x00000000 );           // (?)
     937             : 
     938             :         // Source-Rectangle schreiben:
     939           0 :         pPict->WriteUInt16( (sal_uInt16)0x0000 )                // Y1-position on the bitmap
     940           0 :               .WriteUInt16( (sal_uInt16)0x0000 )                // X1-position on the bitmap
     941           0 :               .WriteUInt16( (sal_uInt16)nHeight )               // Y2-position on the bitmap
     942           0 :               .WriteUInt16( (sal_uInt16)nWidth );               // X2-position on the bitmap
     943             : 
     944             :         // writing the Destination-Rectangle:
     945           0 :         WritePoint( rPoint );
     946           0 :         WritePoint( Point( rPoint.X() + rSize.Width(), rPoint.Y() + rSize.Height() ) );
     947             : 
     948             :         // writing the Transfer mode:
     949           0 :         pPict->WriteUInt16( (sal_uInt16)0x0000 ); // (?)
     950             : 
     951             :         // remember position of the Map-data in the target:
     952           0 :         nDstMapPos=pPict->Tell();
     953             : 
     954           0 :         if ( nPackType == 1 )               //  when 24 bits nWidth == 1 !!
     955             :         {                                   // don't pack
     956           0 :             for ( ny = 0; ny < nHeight; ny++ )
     957             :             {
     958           0 :                 pPict->WriteUChar( (sal_uInt8)0 );
     959           0 :                 pPict->WriteUChar( (sal_uInt8)pAcc->GetPixel( ny, 0 ).GetRed() );
     960           0 :                 pPict->WriteUChar( (sal_uInt8)pAcc->GetPixel( ny, 0 ).GetGreen() );
     961           0 :                 pPict->WriteUChar( (sal_uInt8)pAcc->GetPixel( ny, 0 ).GetBlue() );
     962             :                 // count percentages, Callback, check errors:
     963           0 :                 nActBitmapPercent = ( ny * 70 / nHeight ) + 30; // (30% already added up to the writing of the Win-BMP file)
     964           0 :                 MayCallback();
     965             :             }
     966             :         }
     967             :         else    // packing ( PackType == 4 )
     968             :         {
     969             :             // allocate memory for lines-intermediate-data-structure
     970           0 :             for ( nc = 0; nc < 4; nc++ )
     971           0 :                 pComp[ nc ] = new sal_uInt8[ nWidth ];
     972             : 
     973             :             // loop trough rows:
     974           0 :             for ( ny = 0; ny < nHeight; ny++ )
     975             :             {
     976             :                 // read line ny of source into the intermediate data structure
     977             : 
     978           0 :                 for ( nx = 0; nx < nWidth; nx++ )
     979             :                 {
     980           0 :                     pComp[ 1 ][ nx ] = (sal_uInt8)pAcc->GetPixel( ny, nx ) .GetRed();
     981           0 :                     pComp[ 2 ][ nx ] = (sal_uInt8)pAcc->GetPixel( ny, nx ) .GetGreen();
     982           0 :                     pComp[ 3 ][ nx ] = (sal_uInt8)pAcc->GetPixel( ny, nx ) .GetBlue();
     983           0 :                     pComp[ 0 ][ nx ] = 0;
     984             :                 }
     985             : 
     986             :                 // remember start of the row in the target:
     987           0 :                 nDstRowPos = pPict->Tell();
     988             : 
     989             :                 // ByteCount (that's the size of the packed row) is at first 0 (will be corrected later):
     990           0 :                 if ( nDstRowBytes > 250 )
     991           0 :                     pPict->WriteUInt16( (sal_uInt16)0 );
     992             :                 else
     993           0 :                     pPict->WriteUChar( (sal_uInt8)0 );
     994             : 
     995             :                 // loop trough components:
     996           0 :                 for ( nc = 0; nc < 4; nc++ )
     997             :                 {
     998             :                     // loop through x:
     999           0 :                     nx = 0;
    1000           0 :                     while ( nx < nWidth )
    1001             :                     {
    1002             :                         // look up the position of 3 equal bytes and seve it in nEqu3
    1003             :                         // if it's not found, set nEqu3=nWidth
    1004             :                         // if it's found save the value of the bytes in nEquData
    1005           0 :                         nEqu3 = nx;
    1006             :                         for (;;)
    1007             :                         {
    1008           0 :                             if ( nEqu3 + 2 >= nWidth )
    1009             :                             {
    1010           0 :                                 nEqu3 = nWidth;
    1011           0 :                                 break;
    1012             :                             }
    1013           0 :                             nEquData = pComp[nc][nEqu3];
    1014           0 :                             if ( nEquData == pComp[nc][nEqu3+1] && nEquData==pComp[nc][nEqu3+2] )
    1015           0 :                                 break;
    1016           0 :                             nEqu3++;
    1017             :                         }
    1018             : 
    1019             :                         // write the data from nx to nEqu3 uncompressed (into multiple records if necessarcy);
    1020           0 :                         while ( nEqu3 > nx )
    1021             :                         {
    1022           0 :                             nCount = nEqu3 - nx;
    1023           0 :                             if ( nCount > 128 )
    1024           0 :                                 nCount=128;
    1025           0 :                             nFlagCounterByte = (sal_uInt8)(nCount-1);
    1026           0 :                             pPict->WriteUChar( nFlagCounterByte );
    1027           0 :                             do
    1028             :                             {
    1029           0 :                                 pPict->WriteUChar( pComp[nc][nx++] );
    1030           0 :                                 nCount--;
    1031             :                             }
    1032             :                             while ( nCount > 0 );
    1033             :                         }
    1034             : 
    1035             :                         // now create a compression record (if at least 3 identical bytes were found above)
    1036           0 :                         if ( nx < nWidth )
    1037             :                         {               // Hint: Then one has nx==nEqu3 (hopefully)
    1038           0 :                             nCount=3;   // Three bytes are equal, as we found out above
    1039             :                                         // Check, whether there are further equal bytes (and pay attention to Max.-Record-Size):
    1040           0 :                             while ( nx + nCount < nWidth && nCount < 128 )
    1041             :                             {
    1042           0 :                                 if ( nEquData != pComp[ nc ][ nx + nCount ] )
    1043           0 :                                     break;
    1044           0 :                                 nCount++;
    1045             :                             }
    1046             :                             // nCount write equal Bytes compressed:
    1047           0 :                             nFlagCounterByte = (sal_uInt8)( 1 - (long)nCount );
    1048           0 :                             pPict->WriteUChar( nFlagCounterByte ).WriteUChar( nEquData );
    1049           0 :                             nx += nCount;
    1050             :                         }
    1051             :                     }
    1052             :                 }
    1053             :                 // correct ByteCount:
    1054           0 :                 nPos = pPict->Tell();
    1055           0 :                 pPict->Seek( nDstRowPos );
    1056           0 :                 if ( nDstRowBytes > 250 )
    1057           0 :                     pPict->WriteUInt16(  (sal_uInt16)( nPos - nDstRowPos - 2 )  );
    1058             :                 else
    1059           0 :                     pPict->WriteUChar(  (sal_uInt8)( nPos - nDstRowPos - 1 )  );
    1060           0 :                 pPict->Seek( nPos );
    1061             : 
    1062             :                 // count percentages, Callback, check errors:
    1063           0 :                 nActBitmapPercent = ( ny * 70 / nHeight ) + 30; // (30% already added up to the writing of the Win-BMP file)
    1064           0 :                 MayCallback();
    1065             :             }
    1066             :             // clean up:
    1067           0 :             for ( nc = 0; nc < 4; nc++ )
    1068           0 :                 delete pComp[ nc ];
    1069             :         }
    1070             :     }
    1071             :     else
    1072             :     {   // don't generate 24-bit i.e. Opcode 'PackBitsRect':
    1073             : 
    1074             :         // Some input filters are ignoring the palette of 1-bit images and are using
    1075             :         // the foreground and the background color instead.
    1076           0 :         if ( nBitsPerPixel == 1 )
    1077             :         {
    1078           0 :             WriteOpcode_RGBBkCol( pAcc->GetPaletteColor( 0 ) );
    1079           0 :             WriteOpcode_RGBFgCol( pAcc->GetPaletteColor( 1 ) );
    1080             :         }
    1081             :         else
    1082             :         {
    1083           0 :             WriteOpcode_RGBBkCol( Color( COL_BLACK ) );
    1084           0 :             WriteOpcode_RGBFgCol( Color( COL_WHITE ) );
    1085             :         }
    1086             : 
    1087             :         // Calculate the number of bytes of an (unpacked) line of source an destination.
    1088           0 :         nDstRowBytes = ( nWidth * nBitsPerPixel + 7 ) >> 3;
    1089           0 :         nSrcRowBytes = ( nDstRowBytes + 3 ) & 0xfffffffc;
    1090             : 
    1091             :         // writing Opcode:
    1092           0 :         pPict->WriteUInt16( (sal_uInt16)0x0098 );
    1093             : 
    1094             :         // Normally we want to produce packing type 0 (default packing).
    1095             :         // But if RowBytes<8 is true, generally all data is unpacked even if packing
    1096             :         // type 0 is specified, which seems a little bit strange. Hence we want to
    1097             :         // specify packing type 1 (no packing) in these cases.
    1098           0 :         if ( nDstRowBytes < 8 )
    1099           0 :             nPackType = 1;
    1100             :         else
    1101           0 :             nPackType = 0;
    1102             : 
    1103             :         // write PixMap-Structure:
    1104           0 :         pPict->WriteUInt16( (sal_uInt16)(nDstRowBytes|0x8000) ) // Bytes per row and the fact that it's a 'PixMap'
    1105           0 :               .WriteUInt16( (sal_uInt16)0x0000 )                // Y1-position of the bitmap in the source
    1106           0 :               .WriteUInt16( (sal_uInt16)0x0000 )                // X1-position of the bitmap in the source
    1107           0 :               .WriteUInt16( (sal_uInt16)nHeight )               // Y2-position of the bitmap in the source
    1108           0 :               .WriteUInt16( (sal_uInt16)nWidth )                // X2-position of the bitmap in the source
    1109           0 :               .WriteUInt16( (sal_uInt16)0x0000 )                // Version
    1110           0 :               .WriteUInt16( (sal_uInt16)nPackType )             // Packing type
    1111           0 :               .WriteUInt32( (sal_uInt32) 0x00000000 )            // Packing size (?)
    1112           0 :               .WriteUInt32( (sal_uInt32) 0x00480000 )            // H-Res
    1113           0 :               .WriteUInt32( (sal_uInt32) 0x00480000 )            // V-Res
    1114           0 :               .WriteUInt16( (sal_uInt16)0x0000 )                // Pixel type (?)
    1115           0 :               .WriteUInt16( (sal_uInt16)nBitsPerPixel )         // Pixel size
    1116           0 :               .WriteUInt16( (sal_uInt16)0x0001 )                // CmpCount: 1 component
    1117           0 :               .WriteUInt16( (sal_uInt16)nBitsPerPixel )         // CmpSize
    1118           0 :               .WriteUInt32( (sal_uInt32) 0x00000000 )            // PlaneBytes (?)
    1119           0 :               .WriteUInt32( (sal_uInt32) 0x00000000 )            // (?)
    1120           0 :               .WriteUInt32( (sal_uInt32) 0x00000000 );           // (?)
    1121             : 
    1122             :         // writing and reading the palette:
    1123           0 :         nColTabSize = pAcc->GetPaletteEntryCount();
    1124           0 :         pPict->WriteUInt32( (sal_uInt32)0 ).WriteUInt16( (sal_uInt16)0x8000 ).WriteUInt16( (sal_uInt16)( nColTabSize - 1 ) );
    1125             : 
    1126           0 :         for ( i = 0; i < nColTabSize; i++ )
    1127             :         {
    1128           0 :             nRed = (sal_uInt8)pAcc->GetPaletteColor( (sal_uInt16)i ).GetRed();
    1129           0 :             nGreen = (sal_uInt8)pAcc->GetPaletteColor( (sal_uInt16)i ).GetGreen();
    1130           0 :             nBlue = (sal_uInt8)pAcc->GetPaletteColor( (sal_uInt16)i ).GetBlue();
    1131           0 :             pPict->WriteUInt16( (sal_uInt16)0 ).WriteUChar( nRed ).WriteUChar( nRed ).WriteUChar( nGreen ).WriteUChar( nGreen ).WriteUChar( nBlue ).WriteUChar( nBlue );
    1132             :         }
    1133             : 
    1134             :         // writing Source-Rectangle:
    1135           0 :         pPict->WriteUInt16( (sal_uInt16)0 ).WriteUInt16( (sal_uInt16)0 ).WriteUInt16( (sal_uInt16)nHeight ).WriteUInt16( (sal_uInt16)nWidth );
    1136             : 
    1137             :         // writing Destination-Rectangle:
    1138           0 :         WritePoint( rPoint );
    1139           0 :         WritePoint( Point( rPoint.X() + rSize.Width(), rPoint.Y() + rSize.Height() ) );
    1140             : 
    1141             :         // writing Transfer mode:
    1142           0 :         pPict->WriteUInt16( (sal_uInt16)0 );            // (?)
    1143             : 
    1144             :         // allocate memory for a row:
    1145           0 :         boost::scoped_array<sal_uInt8> pPix(new sal_uInt8[ nSrcRowBytes ]);
    1146             : 
    1147             :         // remember position of the map-data in the target:
    1148           0 :         nDstMapPos=pPict->Tell();
    1149             : 
    1150             :         // loop trough rows:
    1151           0 :         for ( ny = 0; ny < nHeight; ny++ )
    1152             :         {
    1153             :             // read line ny of source into the buffer:
    1154           0 :             switch ( nBitsPerPixel )
    1155             :             {
    1156             :                 case 1 :
    1157           0 :                     for ( pTemp = pPix.get(), i = 0; i < nSrcRowBytes; i++ )
    1158           0 :                         *pTemp++ = (sal_uInt8)0;
    1159           0 :                     for ( i = 0; i < nWidth; i++ )
    1160           0 :                         pPix[ ( i >> 3 ) ] |= (pAcc->GetPixelIndex( ny, i ) & 1) << ((i & 7) ^ 7);
    1161           0 :                     break;
    1162             :                 case 4 :
    1163           0 :                     for ( pTemp = pPix.get(), i = 0; i < nSrcRowBytes; i++ )
    1164           0 :                         *pTemp++ = (sal_uInt8)0;
    1165           0 :                     for ( i = 0; i < nWidth; i++ )
    1166           0 :                         pPix[ ( i >> 1 ) ] |= (pAcc->GetPixelIndex( ny, i ) & 15) << ((i & 1) << 2);
    1167           0 :                     break;
    1168             :                 case 8 :
    1169           0 :                     for ( i = 0; i < nWidth; i++ )
    1170           0 :                         pPix[ i ] = pAcc->GetPixelIndex( ny, i );
    1171           0 :                     break;
    1172             :             }
    1173             : 
    1174           0 :             if ( nPackType == 1 )
    1175             :             {   // don't pack
    1176           0 :                 pPict->Write( pPix.get(), nDstRowBytes );
    1177             :             }
    1178             :             else
    1179             :             {   // Ppacking (nPackType==0)
    1180             : 
    1181             :                 // remember start of the row in the target:
    1182           0 :                 nDstRowPos = pPict->Tell();
    1183             : 
    1184             :                 // ByteCount (this is the size of the packed line) initialized with 0 (will be corrected later):
    1185           0 :                 if ( nDstRowBytes > 250 )
    1186           0 :                     pPict->WriteUInt16( (sal_uInt16)0 );
    1187             :                 else
    1188           0 :                     pPict->WriteUChar( (sal_uInt8)0 );
    1189             : 
    1190             :                 // loop trough bytes of the row:
    1191           0 :                 nx=0;
    1192           0 :                 while ( nx < nDstRowBytes && bStatus )
    1193             :                 {
    1194             :                     // Look for the position of three identical bytes and remember it in nEqu3.
    1195             :                     // Set nEqu3=nDstRowBytes if not found.
    1196             :                     // Else remember the value of these bytes in nEquData.
    1197           0 :                     nEqu3 = nx;
    1198             :                     for (;;)
    1199             :                     {
    1200           0 :                         if ( nEqu3 + 2 >= nDstRowBytes )
    1201             :                         {
    1202           0 :                             nEqu3 = nDstRowBytes;
    1203           0 :                             break;
    1204             :                         }
    1205           0 :                         nEquData = pPix[ nEqu3 ];
    1206           0 :                         if ( nEquData == pPix[ nEqu3 + 1 ] && nEquData == pPix[ nEqu3 + 2 ] )
    1207           0 :                             break;
    1208           0 :                         nEqu3++;
    1209             :                     }
    1210             : 
    1211             :                     // Write the data unpacked from nx to nEqu3 (in multiple records if necessary):
    1212           0 :                     while ( nEqu3 > nx )
    1213             :                     {
    1214           0 :                         nCount = nEqu3 - nx;
    1215           0 :                         if ( nCount > 128 )
    1216           0 :                             nCount = 128;
    1217           0 :                         nFlagCounterByte = (sal_uInt8)( nCount - 1 );
    1218           0 :                         pPict->WriteUChar( nFlagCounterByte );
    1219           0 :                         do
    1220             :                         {
    1221           0 :                             pPict->WriteUChar( pPix[ nx++ ] );
    1222           0 :                             nCount--;
    1223             :                         } while ( nCount > 0 );
    1224             :                     }
    1225             : 
    1226             :                     // Now create a compression record (if at least 3 identical bytes were found above):
    1227           0 :                     if ( nx < nDstRowBytes )
    1228             :                     {   // Note: it is imperative nx==nEqu3 (hopefully)
    1229           0 :                         nCount = 3; // three bytes are identically, as identified above
    1230             :                         // Check if more identical bytes exist. (in doing so, consider max record size):
    1231           0 :                         while ( nx + nCount < nDstRowBytes && nCount < 128 )
    1232             :                         {
    1233           0 :                             if ( nEquData != pPix[ nx + nCount ] )
    1234           0 :                                 break;
    1235           0 :                             nCount++;
    1236             :                         }
    1237             :                         // write nCount identical bytes unpacked:
    1238           0 :                         nFlagCounterByte = (sal_uInt8)( 1 - (long)nCount );
    1239           0 :                         pPict->WriteUChar( nFlagCounterByte ).WriteUChar( nEquData );
    1240           0 :                         nx += nCount;
    1241             :                     }
    1242             :                 }
    1243             : 
    1244             :                 // correct ByteCount:
    1245           0 :                 nPos = pPict->Tell();
    1246           0 :                 pPict->Seek( nDstRowPos );
    1247           0 :                 if ( nDstRowBytes > 250 )
    1248           0 :                     pPict->WriteUInt16(  (sal_uInt16)( nPos - nDstRowPos - 2 )  );
    1249             :                 else
    1250           0 :                     pPict->WriteUChar(  (sal_uInt8)( nPos - nDstRowPos - 1 )  );
    1251           0 :                 pPict->Seek( nPos );
    1252             :             }
    1253             : 
    1254             :             // count percentages, Callback, check errors:
    1255           0 :             nActBitmapPercent =( ny * 70 / nHeight ) + 30; // (30% already added up to the writing of the Win-BMP file)
    1256           0 :             MayCallback();
    1257           0 :             if ( pPict->GetError() )
    1258           0 :                 bStatus = sal_False;
    1259           0 :         }
    1260             :     }
    1261             : 
    1262             :     // Map-Data has to be an even number of bytes:
    1263           0 :     if ( ( ( pPict->Tell() - nDstMapPos ) & 1 ) != 0 )
    1264           0 :         pPict->WriteUChar( (sal_uInt8)0 );
    1265             : 
    1266             :     // counting Bitmaps:
    1267           0 :     nWrittenBitmaps++;
    1268           0 :     nActBitmapPercent = 0;
    1269           0 :     if ( pAcc )
    1270           0 :         aBitmap.ReleaseAccess( pAcc );
    1271             : }
    1272             : 
    1273           0 : void PictWriter::WriteOpcode_EndOfFile()
    1274             : {
    1275           0 :     pPict->WriteUInt16( (sal_uInt16)0x00ff );
    1276           0 : }
    1277             : 
    1278             : 
    1279           0 : void PictWriter::SetAttrForPaint()
    1280             : {
    1281           0 :     WriteOpcode_PnMode(eSrcRasterOp);
    1282           0 :     WriteOpcode_RGBFgCol(aFillColor);
    1283           0 :     WriteOpcode_RGBBkCol(aFillColor);
    1284           0 :     WriteOpcode_PnFillPat(aFillColor!=Color( COL_TRANSPARENT ));
    1285           0 : }
    1286             : 
    1287             : 
    1288           0 : void PictWriter::SetAttrForFrame()
    1289             : {
    1290           0 :     WriteOpcode_PnMode(eSrcRasterOp);
    1291           0 :     WriteOpcode_PnSize(0);
    1292           0 :     WriteOpcode_RGBFgCol(aLineColor);
    1293           0 :     WriteOpcode_PnLinePat(aLineColor!=Color( COL_TRANSPARENT ));
    1294           0 : }
    1295             : 
    1296             : 
    1297           0 : void PictWriter::SetAttrForText()
    1298             : {
    1299           0 :     WriteOpcode_RGBFgCol(aSrcFont.GetColor());
    1300           0 :     WriteOpcode_RGBBkCol(aSrcFont.GetFillColor());
    1301           0 :     WriteOpcode_PnLinePat(sal_True);
    1302           0 :     WriteOpcode_FontName(aSrcFont);
    1303           0 :     WriteOpcode_TxSize((sal_uInt16)(aSrcFont.GetSize().Height()));
    1304           0 :     WriteOpcode_TxMode(eSrcRasterOp);
    1305           0 :     WriteOpcode_TxFace(aSrcFont);
    1306           0 : }
    1307             : 
    1308             : 
    1309           0 : void PictWriter::WriteTextArray(Point & rPoint, const OUString& rString, const sal_Int32 * pDXAry)
    1310             : {
    1311             :     sal_Bool bDelta;
    1312           0 :     Point aPt;
    1313             : 
    1314           0 :     if ( pDXAry == NULL )
    1315           0 :         WriteOpcode_Text( rPoint, rString, sal_False );
    1316             :     else
    1317             :     {
    1318           0 :         bDelta = sal_False;
    1319           0 :         sal_Int32 nLen = rString.getLength();
    1320           0 :         for ( sal_Int32 i = 0; i < nLen; i++ )
    1321             :         {
    1322           0 :             sal_Unicode c = rString[ i ];
    1323           0 :             if ( c && ( c != 0x20 ) )
    1324             :             {
    1325           0 :                 aPt = rPoint;
    1326           0 :                 if ( i > 0 )
    1327           0 :                     aPt.X() += pDXAry[ i - 1 ];
    1328             : 
    1329           0 :                 WriteOpcode_Text( aPt, OUString( c ), bDelta );
    1330           0 :                 bDelta = sal_True;
    1331             :             }
    1332             :         }
    1333             :     }
    1334           0 : }
    1335             : 
    1336           0 : void PictWriter::HandleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon)
    1337             : {
    1338           0 :     if(rLinePolygon.count())
    1339             :     {
    1340           0 :         basegfx::B2DPolyPolygon aLinePolyPolygon(rLinePolygon);
    1341           0 :         basegfx::B2DPolyPolygon aFillPolyPolygon;
    1342             : 
    1343           0 :         rInfo.applyToB2DPolyPolygon(aLinePolyPolygon, aFillPolyPolygon);
    1344             : 
    1345           0 :         if(aLinePolyPolygon.count())
    1346             :         {
    1347           0 :             aLinePolyPolygon = aLinePolyPolygon.getDefaultAdaptiveSubdivision();
    1348           0 :             const sal_uInt32 nPolyCount(aLinePolyPolygon.count());
    1349           0 :             SetAttrForFrame();
    1350             : 
    1351           0 :             for(sal_uInt32 a(0); a < nPolyCount; a++)
    1352             :             {
    1353           0 :                 const basegfx::B2DPolygon aCandidate(aLinePolyPolygon.getB2DPolygon(a));
    1354           0 :                 const sal_uInt32 nPointCount(aCandidate.count());
    1355             : 
    1356           0 :                 if(nPointCount)
    1357             :                 {
    1358           0 :                     const sal_uInt32 nEdgeCount(aCandidate.isClosed() ? nPointCount + 1 : nPointCount);
    1359           0 :                     const basegfx::B2DPoint aCurr(aCandidate.getB2DPoint(0));
    1360           0 :                     Point nCurr(basegfx::fround(aCurr.getX()), basegfx::fround(aCurr.getY()));
    1361             : 
    1362           0 :                     for(sal_uInt32 b(0); b < nEdgeCount; b++)
    1363             :                     {
    1364           0 :                         const sal_uInt32 nNextIndex((b + 1) % nPointCount);
    1365           0 :                         const basegfx::B2DPoint aNext(aCandidate.getB2DPoint(nNextIndex));
    1366           0 :                         const Point nNext(basegfx::fround(aNext.getX()), basegfx::fround(aNext.getY()));
    1367             : 
    1368           0 :                         WriteOpcode_Line(nCurr, nNext);
    1369           0 :                         nCurr = nNext;
    1370           0 :                     }
    1371             :                 }
    1372           0 :             }
    1373             :         }
    1374             : 
    1375           0 :         if(aFillPolyPolygon.count())
    1376             :         {
    1377           0 :             const Color aOldLineColor(aLineColor);
    1378           0 :             const Color aOldFillColor(aFillColor);
    1379             : 
    1380           0 :             aLineColor = Color( COL_TRANSPARENT );
    1381           0 :             aFillColor = aOldLineColor;
    1382           0 :             SetAttrForPaint();
    1383             : 
    1384           0 :             for(sal_uInt32 a(0); a < aFillPolyPolygon.count(); a++)
    1385             :             {
    1386           0 :                 const Polygon aPolygon(aFillPolyPolygon.getB2DPolygon(a).getDefaultAdaptiveSubdivision());
    1387           0 :                 WriteOpcode_Poly(PDM_PAINT, aPolygon);
    1388           0 :             }
    1389             : 
    1390           0 :             aLineColor = aOldLineColor;
    1391           0 :             aFillColor = aOldFillColor;
    1392           0 :         }
    1393             :     }
    1394           0 : }
    1395             : 
    1396           0 : void PictWriter::WriteOpcodes( const GDIMetaFile & rMTF )
    1397             : {
    1398             :     size_t nA, nACount;
    1399             :     const MetaAction* pMA;
    1400             : 
    1401           0 :     if( !bStatus)
    1402           0 :         return;
    1403             : 
    1404           0 :     nACount = rMTF.GetActionSize();
    1405             : 
    1406           0 :     for (nA=0; nA < nACount; nA++)
    1407             :     {
    1408           0 :         pMA = rMTF.GetAction(nA);
    1409             : 
    1410           0 :         switch (pMA->GetType())
    1411             :         {
    1412             :             case META_PIXEL_ACTION:
    1413             :             {
    1414           0 :                 const MetaPixelAction* pA = (const MetaPixelAction*) pMA;
    1415           0 :                 WriteOpcode_PnMode(eSrcRasterOp);
    1416           0 :                 WriteOpcode_PnSize(1);
    1417           0 :                 WriteOpcode_RGBFgCol(pA->GetColor());
    1418           0 :                 WriteOpcode_PnLinePat(sal_True);
    1419           0 :                 WriteOpcode_Line(pA->GetPoint(),pA->GetPoint());
    1420             :             }
    1421           0 :             break;
    1422             : 
    1423             :             case META_POINT_ACTION:
    1424             :             {
    1425           0 :                 const MetaPointAction* pA = (const MetaPointAction*) pMA;
    1426             : 
    1427           0 :                 if( aLineColor != Color( COL_TRANSPARENT ) )
    1428             :                 {
    1429           0 :                     SetAttrForFrame();
    1430           0 :                     WriteOpcode_Line( pA->GetPoint(),pA->GetPoint() );
    1431             :                 }
    1432             :             }
    1433           0 :             break;
    1434             : 
    1435             :             case META_LINE_ACTION:
    1436             :             {
    1437           0 :                 const MetaLineAction* pA = (const MetaLineAction*) pMA;
    1438             : 
    1439           0 :                 if( aLineColor != Color( COL_TRANSPARENT ) )
    1440             :                 {
    1441           0 :                     if(pA->GetLineInfo().IsDefault())
    1442             :                     {
    1443           0 :                         SetAttrForFrame();
    1444           0 :                         WriteOpcode_Line( pA->GetStartPoint(),pA->GetEndPoint() );
    1445             :                     }
    1446             :                     else
    1447             :                     {
    1448             :                         // LineInfo used; handle Dash/Dot and fat lines
    1449           0 :                         basegfx::B2DPolygon aPolygon;
    1450           0 :                         aPolygon.append(basegfx::B2DPoint(pA->GetStartPoint().X(), pA->GetStartPoint().Y()));
    1451           0 :                         aPolygon.append(basegfx::B2DPoint(pA->GetEndPoint().X(), pA->GetEndPoint().Y()));
    1452           0 :                         HandleLineInfoPolyPolygons(pA->GetLineInfo(), aPolygon);
    1453             :                     }
    1454             :                 }
    1455           0 :                 break;
    1456             :             }
    1457             : 
    1458             :             case META_RECT_ACTION:
    1459             :             {
    1460           0 :                 const MetaRectAction* pA = (const MetaRectAction*) pMA;
    1461             : 
    1462           0 :                 if (aFillColor!=Color( COL_TRANSPARENT ))
    1463             :                 {
    1464           0 :                     SetAttrForPaint();
    1465           0 :                     WriteOpcode_Rect(PDM_PAINT,pA->GetRect());
    1466           0 :                     if (aLineColor!=Color( COL_TRANSPARENT ))
    1467             :                     {
    1468           0 :                         SetAttrForFrame();
    1469           0 :                         WriteOpcode_SameRect(PDM_FRAME);
    1470             :                     }
    1471             :                 }
    1472           0 :                 else if (aLineColor!=Color( COL_TRANSPARENT ))
    1473             :                 {
    1474           0 :                     SetAttrForFrame();
    1475           0 :                     WriteOpcode_Rect(PDM_FRAME,pA->GetRect());
    1476             :                 }
    1477             :             }
    1478           0 :             break;
    1479             : 
    1480             :             case META_ROUNDRECT_ACTION:
    1481             :             {
    1482           0 :                 const MetaRoundRectAction* pA = (const MetaRoundRectAction*) pMA;
    1483             : 
    1484           0 :                 WriteOpcode_OvSize( Size( pA->GetHorzRound(), pA->GetVertRound() ) );
    1485             : 
    1486           0 :                 if (aFillColor!=Color( COL_TRANSPARENT ))
    1487             :                 {
    1488           0 :                     SetAttrForPaint();
    1489           0 :                     WriteOpcode_RRect(PDM_PAINT,pA->GetRect());
    1490           0 :                     if (aLineColor!=Color( COL_TRANSPARENT ))
    1491             :                     {
    1492           0 :                         SetAttrForFrame();
    1493           0 :                         WriteOpcode_SameRRect(PDM_FRAME);
    1494             :                     }
    1495             :                 }
    1496           0 :                 else if (aLineColor!=Color( COL_TRANSPARENT ))
    1497             :                 {
    1498           0 :                     SetAttrForFrame();
    1499           0 :                     WriteOpcode_RRect(PDM_FRAME,pA->GetRect());
    1500             :                 }
    1501             :             }
    1502           0 :             break;
    1503             : 
    1504             :             case META_ELLIPSE_ACTION:
    1505             :             {
    1506           0 :                 const MetaEllipseAction* pA = (const MetaEllipseAction*) pMA;
    1507             : 
    1508           0 :                 if (aFillColor!=Color( COL_TRANSPARENT ))
    1509             :                 {
    1510           0 :                     SetAttrForPaint();
    1511           0 :                     WriteOpcode_Oval(PDM_PAINT,pA->GetRect());
    1512           0 :                     if (aLineColor!=Color( COL_TRANSPARENT ))
    1513             :                     {
    1514           0 :                         SetAttrForFrame();
    1515           0 :                         WriteOpcode_SameOval(PDM_FRAME);
    1516             :                     }
    1517             :                 }
    1518           0 :                 else if (aLineColor!=Color( COL_TRANSPARENT ))
    1519             :                 {
    1520           0 :                     SetAttrForFrame();
    1521           0 :                     WriteOpcode_Oval(PDM_FRAME,pA->GetRect());
    1522             :                 }
    1523             :             }
    1524           0 :             break;
    1525             : 
    1526             :             case META_ARC_ACTION:
    1527             :             {
    1528           0 :                 const MetaArcAction* pA = (const MetaArcAction*) pMA;
    1529             : 
    1530           0 :                 if (aLineColor!=Color( COL_TRANSPARENT ))
    1531             :                 {
    1532           0 :                     SetAttrForFrame();
    1533           0 :                     WriteOpcode_Arc(PDM_FRAME,pA->GetRect(),pA->GetStartPoint(),pA->GetEndPoint());
    1534             :                 }
    1535             :             }
    1536           0 :             break;
    1537             : 
    1538             :             case META_PIE_ACTION:
    1539             :             {
    1540           0 :                 const MetaPieAction* pA = (const MetaPieAction *) pMA;
    1541             : 
    1542           0 :                 if (aFillColor!=Color( COL_TRANSPARENT ))
    1543             :                 {
    1544           0 :                     SetAttrForPaint();
    1545           0 :                     WriteOpcode_Arc(PDM_PAINT,pA->GetRect(),pA->GetStartPoint(),pA->GetEndPoint());
    1546             : 
    1547           0 :                     if (aLineColor!=Color( COL_TRANSPARENT ))
    1548             :                     {
    1549           0 :                         SetAttrForFrame();
    1550           0 :                         WriteOpcode_SameArc(PDM_FRAME,pA->GetRect(),pA->GetStartPoint(),pA->GetEndPoint());
    1551             :                     }
    1552             :                 }
    1553           0 :                 else if (aLineColor!=Color( COL_TRANSPARENT ))
    1554             :                 {
    1555           0 :                     SetAttrForFrame();
    1556           0 :                     WriteOpcode_Arc(PDM_FRAME,pA->GetRect(),pA->GetStartPoint(),pA->GetEndPoint());
    1557             :                 }
    1558             : 
    1559           0 :                 if (aLineColor!=Color( COL_TRANSPARENT ))
    1560             :                 {
    1561             :                     double fxc,fyc,fxr,fyr,fx1,fy1,fx2,fy2,l1,l2;
    1562             : 
    1563           0 :                     fxc=((double)(pA->GetRect().Left()+pA->GetRect().Right()))/2.0;
    1564           0 :                     fyc=((double)(pA->GetRect().Top()+pA->GetRect().Bottom()))/2.0;
    1565           0 :                     fxr=((double)pA->GetRect().GetWidth())/2.0;
    1566           0 :                     fyr=((double)pA->GetRect().GetHeight())/2.0;
    1567           0 :                     fx1=((double)pA->GetStartPoint().X())-fxc;
    1568           0 :                     fy1=((double)pA->GetStartPoint().Y())-fyc;
    1569           0 :                     fx2=((double)pA->GetEndPoint().X())-fxc;
    1570           0 :                     fy2=((double)pA->GetEndPoint().Y())-fyc;
    1571           0 :                     l1=sqrt(fx1*fx1+fy1*fy1);
    1572           0 :                     l2=sqrt(fx2*fx2+fy2*fy2);
    1573             : 
    1574           0 :                     if (l1>0)
    1575             :                     {
    1576           0 :                         fx1=fx1/l1*fxr;
    1577           0 :                         fy1=fy1/l1*fyr;
    1578             :                     }
    1579             : 
    1580           0 :                     if (l2>0)
    1581             :                     {
    1582           0 :                         fx2=fx2/l2*fxr;
    1583           0 :                         fy2=fy2/l2*fyr;
    1584             :                     }
    1585           0 :                     fx1+=fxc; fy1+=fyc; fx2+=fxc; fy2+=fyc;
    1586           0 :                     WriteOpcode_Line(Point((long)(fx1+0.5),(long)(fy1+0.5)), Point((long)(fxc+0.5),(long)(fyc+0.5)));
    1587           0 :                     WriteOpcode_LineFrom(Point((long)(fx2+0.5),(long)(fy2+0.5)));
    1588             :                 }
    1589             :             }
    1590           0 :             break;
    1591             : 
    1592             :             case META_CHORD_ACTION:
    1593             :             {
    1594             :                 // OSL_FAIL( "Unsupported PICT-Action: META_CHORD_ACTION!" );
    1595             :             }
    1596           0 :             break;
    1597             : 
    1598             :             case META_POLYLINE_ACTION:
    1599             :             {
    1600           0 :                 const MetaPolyLineAction* pA = (const MetaPolyLineAction*) pMA;
    1601             : 
    1602           0 :                 if( aLineColor!=Color( COL_TRANSPARENT ) )
    1603             :                 {
    1604           0 :                     const Polygon&  rPoly = pA->GetPolygon();
    1605             : 
    1606           0 :                     if( rPoly.GetSize() )
    1607             :                     {
    1608           0 :                         if(pA->GetLineInfo().IsDefault())
    1609             :                         {
    1610           0 :                             Polygon aSimplePoly;
    1611           0 :                             if ( rPoly.HasFlags() )
    1612           0 :                                 rPoly.AdaptiveSubdivide( aSimplePoly );
    1613             :                             else
    1614           0 :                                 aSimplePoly = rPoly;
    1615             : 
    1616           0 :                             const sal_uInt16    nSize = aSimplePoly.GetSize();
    1617           0 :                             Point           aLast;
    1618             : 
    1619           0 :                             if ( nSize )
    1620             :                             {
    1621           0 :                                 SetAttrForFrame();
    1622           0 :                                 aLast = aSimplePoly[0];
    1623             : 
    1624           0 :                                 for ( sal_uInt16 i = 1; i < nSize; i++ )
    1625             :                                 {
    1626           0 :                                     WriteOpcode_Line( aLast, aSimplePoly[i] );
    1627           0 :                                     aLast = aSimplePoly[i];
    1628             :                                 }
    1629           0 :                             }
    1630             :                         }
    1631             :                         else
    1632             :                         {
    1633             :                             // LineInfo used; handle Dash/Dot and fat lines
    1634           0 :                             HandleLineInfoPolyPolygons(pA->GetLineInfo(), rPoly.getB2DPolygon());
    1635             :                         }
    1636             :                     }
    1637             :                 }
    1638             :             }
    1639           0 :             break;
    1640             : 
    1641             :             case META_POLYGON_ACTION:
    1642             :             {
    1643           0 :                 const MetaPolygonAction* pA = (const MetaPolygonAction*) pMA;
    1644             : 
    1645           0 :                 const Polygon& rPoly = pA->GetPolygon();
    1646             : 
    1647           0 :                 Polygon aSimplePoly;
    1648           0 :                 if ( rPoly.HasFlags() )
    1649           0 :                     rPoly.AdaptiveSubdivide( aSimplePoly );
    1650             :                 else
    1651           0 :                     aSimplePoly = rPoly;
    1652             : 
    1653           0 :                 if (aFillColor!=Color( COL_TRANSPARENT ))
    1654             :                 {
    1655           0 :                     SetAttrForPaint();
    1656           0 :                     WriteOpcode_Poly( PDM_PAINT, aSimplePoly );
    1657             :                 }
    1658           0 :                 if (aLineColor!=Color( COL_TRANSPARENT ))
    1659             :                 {
    1660           0 :                     SetAttrForFrame();
    1661           0 :                     WriteOpcode_Poly( PDM_FRAME, aSimplePoly );
    1662           0 :                 }
    1663             :             }
    1664           0 :             break;
    1665             : 
    1666             :             case META_POLYPOLYGON_ACTION:
    1667             :             {
    1668           0 :                 const MetaPolyPolygonAction* pA = (const MetaPolyPolygonAction*) pMA;
    1669             : 
    1670           0 :                 const PolyPolygon& rPolyPoly = pA->GetPolyPolygon();
    1671           0 :                 sal_uInt16 nPolyCount = rPolyPoly.Count();
    1672           0 :                 PolyPolygon aSimplePolyPoly( rPolyPoly );
    1673           0 :                 for ( sal_uInt16 i = 0; i < nPolyCount; i++ )
    1674             :                 {
    1675           0 :                     if ( aSimplePolyPoly[ i ].HasFlags() )
    1676             :                     {
    1677           0 :                         Polygon aSimplePoly;
    1678           0 :                         aSimplePolyPoly[ i ].AdaptiveSubdivide( aSimplePoly );
    1679           0 :                         aSimplePolyPoly[ i ] = aSimplePoly;
    1680             :                     }
    1681             :                 }
    1682           0 :                 if (aFillColor!=Color( COL_TRANSPARENT ))
    1683             :                 {
    1684           0 :                     SetAttrForPaint();
    1685           0 :                     WriteOpcode_Poly( PDM_PAINT, PolyPolygonToPolygon( aSimplePolyPoly ));
    1686             :                 }
    1687             : 
    1688           0 :                 if (aLineColor!=Color( COL_TRANSPARENT ))
    1689             :                 {
    1690             :                     sal_uInt16 nCount,i;
    1691           0 :                     SetAttrForFrame();
    1692           0 :                     nCount = aSimplePolyPoly.Count();
    1693           0 :                     for ( i = 0; i < nCount; i++ )
    1694           0 :                         WriteOpcode_Poly( PDM_FRAME, aSimplePolyPoly.GetObject( i ) );
    1695           0 :                 }
    1696             :             }
    1697           0 :             break;
    1698             : 
    1699             :             case META_TEXT_ACTION:
    1700             :             {
    1701           0 :                 const MetaTextAction*   pA = (const MetaTextAction*) pMA;
    1702           0 :                 Point                   aPt( pA->GetPoint() );
    1703             : 
    1704           0 :                 if ( aSrcFont.GetAlign() != ALIGN_BASELINE )
    1705             :                 {
    1706           0 :                     VirtualDevice aVirDev;
    1707             : 
    1708           0 :                     if (aSrcFont.GetAlign()==ALIGN_TOP)
    1709           0 :                         aPt.Y()+=(long)aVirDev.GetFontMetric(aSrcFont).GetAscent();
    1710             :                     else
    1711           0 :                         aPt.Y()-=(long)aVirDev.GetFontMetric(aSrcFont).GetDescent();
    1712             :                 }
    1713             : 
    1714           0 :                 SetAttrForText();
    1715           0 :                 OUString aStr = pA->GetText().copy( pA->GetIndex(),pA->GetLen() );
    1716           0 :                 WriteOpcode_Text( aPt, aStr, sal_False );
    1717             :             }
    1718           0 :             break;
    1719             : 
    1720             :             case META_TEXTARRAY_ACTION:
    1721             :             {
    1722           0 :                 const MetaTextArrayAction*  pA = (const MetaTextArrayAction*) pMA;
    1723           0 :                 Point                       aPt( pA->GetPoint() );
    1724             : 
    1725           0 :                 if (aSrcFont.GetAlign()!=ALIGN_BASELINE)
    1726             :                 {
    1727           0 :                     VirtualDevice aVirDev;
    1728             : 
    1729           0 :                     if (aSrcFont.GetAlign()==ALIGN_TOP)
    1730           0 :                         aPt.Y()+=(long)aVirDev.GetFontMetric(aSrcFont).GetAscent();
    1731             :                     else
    1732           0 :                         aPt.Y()-=(long)aVirDev.GetFontMetric(aSrcFont).GetDescent();
    1733             :                 }
    1734           0 :                 SetAttrForText();
    1735           0 :                 OUString aStr = pA->GetText().copy( pA->GetIndex(),pA->GetLen() );
    1736           0 :                 WriteTextArray( aPt, aStr, pA->GetDXArray() );
    1737           0 :                 break;
    1738             :             }
    1739             : 
    1740             :             case META_STRETCHTEXT_ACTION:
    1741             :             {
    1742           0 :                 const MetaStretchTextAction*    pA = (const MetaStretchTextAction*) pMA;
    1743           0 :                 Point                           aPt( pA->GetPoint() );
    1744           0 :                 OUString                        aStr = pA->GetText().copy( pA->GetIndex(),pA->GetLen() );
    1745           0 :                 VirtualDevice                   aVirDev;
    1746           0 :                 boost::scoped_array<sal_Int32>  pDXAry(new sal_Int32[ aStr.getLength() ]);
    1747           0 :                 sal_Int32                       nNormSize( aVirDev.GetTextArray( aStr,pDXAry.get() ) );
    1748             :                 sal_uInt16                          i;
    1749             : 
    1750           0 :                 if (aSrcFont.GetAlign()!=ALIGN_BASELINE)
    1751             :                 {
    1752           0 :                     if (aSrcFont.GetAlign()==ALIGN_TOP)
    1753           0 :                         aPt.Y()+=(long)aVirDev.GetFontMetric(aSrcFont).GetAscent();
    1754             :                     else
    1755           0 :                         aPt.Y()-=(long)aVirDev.GetFontMetric(aSrcFont).GetDescent();
    1756             :                 }
    1757             : 
    1758           0 :                 for ( i = 0; i < aStr.getLength() - 1; i++ )
    1759           0 :                     pDXAry[ i ] = pDXAry[ i ] * ( (long)pA->GetWidth() ) / nNormSize;
    1760             : 
    1761           0 :                 SetAttrForText();
    1762           0 :                 WriteTextArray( aPt, aStr, pDXAry.get() );
    1763             :             }
    1764           0 :             break;
    1765             : 
    1766             :             case META_TEXTRECT_ACTION:
    1767             :             {
    1768             :                 // OSL_FAIL( "Unsupported PICT-Action: META_TEXTRECT_ACTION!" );
    1769             :             }
    1770           0 :             break;
    1771             : 
    1772             :             case META_BMP_ACTION:
    1773             :             {
    1774           0 :                 const MetaBmpAction*    pA = (const MetaBmpAction*) pMA;
    1775           0 :                 const Bitmap            aBmp( pA->GetBitmap() );
    1776           0 :                 VirtualDevice           aVirDev;
    1777             : 
    1778           0 :                 WriteOpcode_BitsRect( pA->GetPoint(), aVirDev.PixelToLogic( aBmp.GetSizePixel(), aSrcMapMode ), aBmp );
    1779             :             }
    1780           0 :             break;
    1781             : 
    1782             :             case META_BMPSCALE_ACTION:
    1783             :             {
    1784           0 :                 const MetaBmpScaleAction* pA = (const MetaBmpScaleAction*) pMA;
    1785           0 :                 WriteOpcode_BitsRect( pA->GetPoint(), pA->GetSize(), pA->GetBitmap() );
    1786             :             }
    1787           0 :             break;
    1788             : 
    1789             :             case META_BMPSCALEPART_ACTION:
    1790             :             {
    1791           0 :                 const MetaBmpScalePartAction*   pA = (const MetaBmpScalePartAction*) pMA;
    1792           0 :                 Bitmap                          aBmp( pA->GetBitmap() );
    1793             : 
    1794           0 :                 aBmp.Crop( Rectangle( pA->GetSrcPoint(), pA->GetSrcSize() ) );
    1795           0 :                 WriteOpcode_BitsRect( pA->GetDestPoint(), pA->GetDestSize(), aBmp );
    1796             :             }
    1797           0 :             break;
    1798             : 
    1799             :             case META_BMPEX_ACTION:
    1800             :             {
    1801           0 :                 const MetaBmpExAction*  pA = (const MetaBmpExAction*) pMA;
    1802           0 :                 const Bitmap            aBmp( Graphic( pA->GetBitmapEx() ).GetBitmap() );
    1803           0 :                 VirtualDevice           aVirDev;
    1804             : 
    1805           0 :                 WriteOpcode_BitsRect( pA->GetPoint(), aVirDev.PixelToLogic( aBmp.GetSizePixel(), aSrcMapMode ), aBmp );
    1806             :             }
    1807           0 :             break;
    1808             : 
    1809             :             case META_BMPEXSCALE_ACTION:
    1810             :             {
    1811           0 :                 const MetaBmpExScaleAction* pA = (const MetaBmpExScaleAction*) pMA;
    1812           0 :                 const Bitmap                aBmp( Graphic( pA->GetBitmapEx() ).GetBitmap() );
    1813             : 
    1814           0 :                 WriteOpcode_BitsRect( pA->GetPoint(), pA->GetSize(), aBmp );
    1815             :             }
    1816           0 :             break;
    1817             : 
    1818             :             case META_BMPEXSCALEPART_ACTION:
    1819             :             {
    1820           0 :                 const MetaBmpExScalePartAction* pA = (const MetaBmpExScalePartAction*) pMA;
    1821           0 :                 Bitmap                          aBmp( Graphic( pA->GetBitmapEx() ).GetBitmap() );
    1822             : 
    1823           0 :                 aBmp.Crop( Rectangle( pA->GetSrcPoint(), pA->GetSrcSize() ) );
    1824           0 :                 WriteOpcode_BitsRect( pA->GetDestPoint(), pA->GetDestSize(), aBmp );
    1825             :             }
    1826           0 :             break;
    1827             : 
    1828             :             case META_EPS_ACTION :
    1829             :             {
    1830           0 :                 const MetaEPSAction* pA = (const MetaEPSAction*)pMA;
    1831           0 :                 const GDIMetaFile aGDIMetaFile( pA->GetSubstitute() );
    1832             : 
    1833           0 :                 size_t nCount = aGDIMetaFile.GetActionSize();
    1834           0 :                 for ( size_t i = 0; i < nCount; i++ )
    1835             :                 {
    1836           0 :                     const MetaAction* pMetaAct = aGDIMetaFile.GetAction( i );
    1837           0 :                     if ( pMetaAct->GetType() == META_BMPSCALE_ACTION )
    1838             :                     {
    1839           0 :                         const MetaBmpScaleAction* pBmpScaleAction = (const MetaBmpScaleAction*)pMetaAct;
    1840           0 :                         WriteOpcode_BitsRect( pA->GetPoint(), pA->GetSize(), pBmpScaleAction->GetBitmap() );
    1841           0 :                         break;
    1842             :                     }
    1843           0 :                 }
    1844             :             }
    1845           0 :             break;
    1846             : 
    1847             :             case META_MASK_ACTION:
    1848             :             case META_MASKSCALE_ACTION:
    1849             :             case META_MASKSCALEPART_ACTION:
    1850             :             {
    1851             :                 // OSL_FAIL( "Unsupported PICT-Action: META_MASK..._ACTION!" );
    1852             :             }
    1853           0 :             break;
    1854             : 
    1855             :             case META_GRADIENT_ACTION:
    1856             :             {
    1857           0 :                 VirtualDevice               aVDev;
    1858           0 :                 GDIMetaFile                 aTmpMtf;
    1859           0 :                 const MetaGradientAction*   pA = (const MetaGradientAction*) pMA;
    1860             : 
    1861           0 :                 aVDev.SetMapMode( aTargetMapMode );
    1862           0 :                 aVDev.AddGradientActions( pA->GetRect(), pA->GetGradient(), aTmpMtf );
    1863           0 :                 WriteOpcodes( aTmpMtf );
    1864             :             }
    1865           0 :             break;
    1866             : 
    1867             :             case META_HATCH_ACTION:
    1868             :             {
    1869           0 :                 VirtualDevice           aVDev;
    1870           0 :                 GDIMetaFile             aTmpMtf;
    1871           0 :                 const MetaHatchAction*  pA = (const MetaHatchAction*) pMA;
    1872             : 
    1873           0 :                 aVDev.SetMapMode( aTargetMapMode );
    1874           0 :                 aVDev.AddHatchActions( pA->GetPolyPolygon(), pA->GetHatch(), aTmpMtf );
    1875           0 :                 WriteOpcodes( aTmpMtf );
    1876             :             }
    1877           0 :             break;
    1878             : 
    1879             :             case META_WALLPAPER_ACTION:
    1880             :             {
    1881             :                 // OSL_FAIL( "Unsupported PICT-Action: META_WALLPAPER_ACTION!" );
    1882             :             }
    1883           0 :             break;
    1884             : 
    1885             :             case META_CLIPREGION_ACTION:
    1886             :             {
    1887             :                 // OSL_FAIL( "Unsupported PICT-Action: META_CLIPREGION_ACTION!" );
    1888             :             }
    1889           0 :             break;
    1890             : 
    1891             :             case META_ISECTRECTCLIPREGION_ACTION:
    1892             :             {
    1893           0 :                 const MetaISectRectClipRegionAction* pA = (const MetaISectRectClipRegionAction*) pMA;
    1894           0 :                 WriteOpcode_ClipRect( pA->GetRect() );
    1895             :             }
    1896           0 :             break;
    1897             : 
    1898             :             case META_ISECTREGIONCLIPREGION_ACTION:
    1899             :             {
    1900             :                 // OSL_FAIL( "Unsupported PICT-Action: META_ISECTREGIONCLIPREGION_ACTION!" );
    1901             :             }
    1902           0 :             break;
    1903             : 
    1904             :             case META_MOVECLIPREGION_ACTION:
    1905             :             {
    1906             :                 // OSL_FAIL( "Unsupported PICT-Action: META_MOVECLIPREGION_ACTION!" );
    1907             :             }
    1908           0 :             break;
    1909             : 
    1910             :             case META_LINECOLOR_ACTION:
    1911             :             {
    1912           0 :                 const MetaLineColorAction* pA = (const MetaLineColorAction*) pMA;
    1913             : 
    1914           0 :                 if( pA->IsSetting() )
    1915           0 :                     aLineColor = pA->GetColor();
    1916             :                 else
    1917           0 :                     aLineColor = Color( COL_TRANSPARENT );
    1918             :             }
    1919           0 :             break;
    1920             : 
    1921             :             case META_FILLCOLOR_ACTION:
    1922             :             {
    1923           0 :                 const MetaFillColorAction* pA = (const MetaFillColorAction*) pMA;
    1924             : 
    1925           0 :                 if( pA->IsSetting() )
    1926           0 :                     aFillColor = pA->GetColor();
    1927             :                 else
    1928           0 :                     aFillColor = Color( COL_TRANSPARENT );
    1929             :             }
    1930           0 :             break;
    1931             : 
    1932             :             case META_TEXTCOLOR_ACTION:
    1933             :             {
    1934           0 :                 const MetaTextColorAction* pA = (const MetaTextColorAction*) pMA;
    1935           0 :                 aSrcFont.SetColor( pA->GetColor() );
    1936             :             }
    1937           0 :             break;
    1938             : 
    1939             :             case META_TEXTFILLCOLOR_ACTION:
    1940             :             {
    1941           0 :                 const MetaTextFillColorAction* pA = (const MetaTextFillColorAction*) pMA;
    1942             : 
    1943           0 :                 if( pA->IsSetting() )
    1944           0 :                     aSrcFont.SetFillColor( pA->GetColor() );
    1945             :                 else
    1946           0 :                     aSrcFont.SetFillColor( Color( COL_TRANSPARENT ) );
    1947             :             }
    1948           0 :             break;
    1949             : 
    1950             :             case META_TEXTALIGN_ACTION:
    1951             :             {
    1952             :                 // OSL_FAIL( "Unsupported PICT-Action: META_TEXTALIGN_ACTION!" );
    1953             :             }
    1954           0 :             break;
    1955             : 
    1956             :             case META_MAPMODE_ACTION:
    1957             :             {
    1958           0 :                 const MetaMapModeAction* pA = (const MetaMapModeAction*) pMA;
    1959             : 
    1960           0 :                 if (aSrcMapMode!=pA->GetMapMode())
    1961             :                 {
    1962           0 :                     if( pA->GetMapMode().GetMapUnit() == MAP_RELATIVE )
    1963             :                     {
    1964           0 :                         MapMode aMM = pA->GetMapMode();
    1965           0 :                         Fraction aScaleX = aMM.GetScaleX();
    1966           0 :                         Fraction aScaleY = aMM.GetScaleY();
    1967             : 
    1968           0 :                         Point aOrigin = aSrcMapMode.GetOrigin();
    1969           0 :                         BigInt aX( aOrigin.X() );
    1970           0 :                         aX *= BigInt( aScaleX.GetDenominator() );
    1971           0 :                         if( aOrigin.X() >= 0 )
    1972             :                         {
    1973           0 :                             if( aScaleX.GetNumerator() >= 0 )
    1974           0 :                                 aX += BigInt( aScaleX.GetNumerator()/2 );
    1975             :                             else
    1976           0 :                                 aX -= BigInt( (aScaleX.GetNumerator()+1)/2 );
    1977             :                         }
    1978             :                         else
    1979             :                         {
    1980           0 :                             if( aScaleX.GetNumerator() >= 0 )
    1981           0 :                                 aX -= BigInt( (aScaleX.GetNumerator()-1)/2 );
    1982             :                             else
    1983           0 :                                 aX += BigInt( aScaleX.GetNumerator()/2 );
    1984             :                         }
    1985             : 
    1986           0 :                         aX /= BigInt( aScaleX.GetNumerator() );
    1987           0 :                         aOrigin.X() = (long)aX + aMM.GetOrigin().X();
    1988           0 :                         BigInt aY( aOrigin.Y() );
    1989           0 :                         aY *= BigInt( aScaleY.GetDenominator() );
    1990             : 
    1991           0 :                         if( aOrigin.Y() >= 0 )
    1992             :                         {
    1993           0 :                             if( aScaleY.GetNumerator() >= 0 )
    1994           0 :                                 aY += BigInt( aScaleY.GetNumerator()/2 );
    1995             :                             else
    1996           0 :                                 aY -= BigInt( (aScaleY.GetNumerator()+1)/2 );
    1997             :                         }
    1998             :                         else
    1999             :                         {
    2000           0 :                             if( aScaleY.GetNumerator() >= 0 )
    2001           0 :                                 aY -= BigInt( (aScaleY.GetNumerator()-1)/2 );
    2002             :                             else
    2003           0 :                                 aY += BigInt( aScaleY.GetNumerator()/2 );
    2004             :                         }
    2005             : 
    2006           0 :                         aY /= BigInt( aScaleY.GetNumerator() );
    2007           0 :                         aOrigin.Y() = (long)aY + aMM.GetOrigin().Y();
    2008           0 :                         aSrcMapMode.SetOrigin( aOrigin );
    2009             : 
    2010           0 :                         aScaleX *= aSrcMapMode.GetScaleX();
    2011           0 :                         aScaleY *= aSrcMapMode.GetScaleY();
    2012           0 :                         aSrcMapMode.SetScaleX( aScaleX );
    2013           0 :                         aSrcMapMode.SetScaleY( aScaleY );
    2014             :                     }
    2015             :                     else
    2016           0 :                         aSrcMapMode = pA->GetMapMode();
    2017             :                 }
    2018             :             }
    2019           0 :             break;
    2020             : 
    2021             :             case META_FONT_ACTION:
    2022             :             {
    2023           0 :                 const MetaFontAction* pA = (const MetaFontAction*) pMA;
    2024           0 :                 aSrcFont=pA->GetFont();
    2025             :             }
    2026           0 :             break;
    2027             : 
    2028             :             case META_PUSH_ACTION:
    2029             :             {
    2030           0 :                 PictWriterAttrStackMember * pAt = new PictWriterAttrStackMember;
    2031           0 :                 pAt->aLineColor=aLineColor;
    2032           0 :                 pAt->aFillColor=aFillColor;
    2033           0 :                 pAt->eRasterOp=eSrcRasterOp;
    2034           0 :                 pAt->aFont=aSrcFont;
    2035           0 :                 pAt->aMapMode=aSrcMapMode;
    2036           0 :                 pAt->aClipRect=aClipRect;
    2037           0 :                 pAt->pSucc=pAttrStack;
    2038           0 :                 pAttrStack=pAt;
    2039             :             }
    2040           0 :             break;
    2041             : 
    2042             :             case META_POP_ACTION:
    2043             :             {
    2044           0 :                 PictWriterAttrStackMember* pAt=pAttrStack;
    2045             : 
    2046           0 :                 if( pAt )
    2047             :                 {
    2048           0 :                     aLineColor=pAt->aLineColor;
    2049           0 :                     aFillColor=pAt->aFillColor;
    2050           0 :                     eSrcRasterOp=pAt->eRasterOp;
    2051           0 :                     aSrcFont=pAt->aFont;
    2052           0 :                     aSrcMapMode=pAt->aMapMode;
    2053           0 :                     if ( pAt->aClipRect != aClipRect )
    2054             :                     {
    2055           0 :                         Rectangle aRect( pAt->aClipRect );
    2056           0 :                         pPict ->WriteUInt16( (sal_uInt16)1 )    // opcode 1
    2057           0 :                                .WriteUInt16( (sal_uInt16)10 )   // data size
    2058           0 :                                .WriteInt16( (sal_Int16)aRect.Top() ).WriteInt16( (sal_Int16)aRect.Left() )
    2059           0 :                                .WriteInt16( (sal_Int16)aRect.Bottom() ).WriteInt16( (sal_Int16)aRect.Right() );
    2060             :                     }
    2061           0 :                     aClipRect=pAt->aClipRect;
    2062           0 :                     pAttrStack=pAt->pSucc;
    2063           0 :                     delete pAt;
    2064             :                 }
    2065             :             }
    2066           0 :             break;
    2067             : 
    2068             :             case META_RASTEROP_ACTION:
    2069             :             {
    2070           0 :                 const MetaRasterOpAction* pA = (const MetaRasterOpAction*) pMA;
    2071           0 :                 eSrcRasterOp=pA->GetRasterOp();
    2072             :             }
    2073           0 :             break;
    2074             : 
    2075             :             case META_TRANSPARENT_ACTION:
    2076             :             {
    2077           0 :                 const PolyPolygon& rPolyPoly = ( (const MetaTransparentAction*) pMA )->GetPolyPolygon();
    2078             : 
    2079           0 :                 if (aFillColor!=Color( COL_TRANSPARENT ))
    2080             :                 {
    2081           0 :                     SetAttrForPaint();
    2082           0 :                     WriteOpcode_Poly( PDM_PAINT, PolyPolygonToPolygon( rPolyPoly ) );
    2083             :                 }
    2084             : 
    2085           0 :                 if (aLineColor!=Color( COL_TRANSPARENT ))
    2086             :                 {
    2087           0 :                     SetAttrForFrame();
    2088           0 :                     for( sal_uInt16 i = 0, nCount = rPolyPoly.Count(); i < nCount; i++ )
    2089           0 :                         WriteOpcode_Poly( PDM_FRAME, rPolyPoly.GetObject( i ) );
    2090             :                 }
    2091             :             }
    2092           0 :             break;
    2093             : 
    2094             :             case META_FLOATTRANSPARENT_ACTION:
    2095             :             {
    2096           0 :                 const MetaFloatTransparentAction* pA = (const MetaFloatTransparentAction*) pMA;
    2097             : 
    2098           0 :                 GDIMetaFile     aTmpMtf( pA->GetGDIMetaFile() );
    2099           0 :                 Point           aSrcPt( aTmpMtf.GetPrefMapMode().GetOrigin() );
    2100           0 :                 const Size      aSrcSize( aTmpMtf.GetPrefSize() );
    2101           0 :                 const Point     aDestPt( pA->GetPoint() );
    2102           0 :                 const Size      aDestSize( pA->GetSize() );
    2103           0 :                 const double    fScaleX = aSrcSize.Width() ? (double) aDestSize.Width() / aSrcSize.Width() : 1.0;
    2104           0 :                 const double    fScaleY = aSrcSize.Height() ? (double) aDestSize.Height() / aSrcSize.Height() : 1.0;
    2105             :                 long            nMoveX, nMoveY;
    2106             : 
    2107           0 :                 if( fScaleX != 1.0 || fScaleY != 1.0 )
    2108             :                 {
    2109           0 :                     aTmpMtf.Scale( fScaleX, fScaleY );
    2110           0 :                     aSrcPt.X() = FRound( aSrcPt.X() * fScaleX ), aSrcPt.Y() = FRound( aSrcPt.Y() * fScaleY );
    2111             :                 }
    2112             : 
    2113           0 :                 nMoveX = aDestPt.X() - aSrcPt.X(), nMoveY = aDestPt.Y() - aSrcPt.Y();
    2114             : 
    2115           0 :                 if( nMoveX || nMoveY )
    2116           0 :                     aTmpMtf.Move( nMoveX, nMoveY );
    2117             : 
    2118           0 :                 WriteOpcodes( aTmpMtf );
    2119             :             }
    2120           0 :             break;
    2121             :         }
    2122             : 
    2123           0 :         nWrittenActions++;
    2124           0 :         MayCallback();
    2125             : 
    2126           0 :         if (pPict->GetError())
    2127           0 :             bStatus=sal_False;
    2128             : 
    2129           0 :         if (bStatus==sal_False)
    2130           0 :             break;
    2131             :     }
    2132             : }
    2133             : 
    2134             : 
    2135           0 : void PictWriter::WriteHeader(const GDIMetaFile & rMTF)
    2136             : {
    2137             :     sal_uInt16  i;
    2138           0 :     Size aSize( rMTF.GetPrefSize() );
    2139           0 :     Point aPoint;
    2140           0 :     Rectangle   aRect( aPoint, aSize );
    2141             : 
    2142             :     // 512 Bytes "trash" at the beginning:
    2143           0 :     for (i=0;i<128;i++) pPict->WriteUInt32( (sal_uInt32)0 );
    2144             : 
    2145             :     // Lo-16-Bits of the file size without the 512 bytes trash:
    2146           0 :     pPict->WriteUInt16( (sal_uInt16)0 ); // gets corrected later on by UpdateHeader()
    2147             : 
    2148             :     // The Bounding-Rectangle (y1,x1,y2,x2 !):
    2149           0 :     WriteRectangle( aRect );
    2150             : 
    2151             :     // Version 2:
    2152           0 :     pPict->WriteUInt32( (sal_uInt32)0x001102ff );
    2153             : 
    2154             :     // Extended-Version-2-Header:
    2155           0 :     pPict->WriteUInt16( (sal_uInt16)0x0c00 )                            // Opcode
    2156           0 :           .WriteUInt16( (sal_uInt16)0xfffe )                            // Version (?)
    2157           0 :           .WriteUInt16( (sal_uInt16)0x0000 )                            // Reserved
    2158           0 :           .WriteUInt32( (sal_uInt32) 0x00480000 )                        // hRes
    2159           0 :           .WriteUInt32( (sal_uInt32) 0x00480000 );
    2160           0 :     WriteRectangle( aRect );
    2161           0 :     pPict->WriteUInt32( (sal_uInt32)0x00000000 );                        // Reserved
    2162             : 
    2163             :     // many import filters demand the declaration
    2164             :     // of a clipping area at the beginning
    2165             : 
    2166           0 :     WriteOpcode_ClipRect( aRect );
    2167           0 : }
    2168             : 
    2169             : 
    2170           0 : void PictWriter::UpdateHeader()
    2171             : {
    2172             :     sal_uLong nPos;
    2173             : 
    2174             :     // correct the Lo-16-Bits of the file size without the 512 bytes trash:
    2175           0 :     nPos=pPict->Tell();
    2176           0 :     pPict->Seek(512);
    2177           0 :     pPict->WriteUInt16( (sal_uInt16)((nPos-512)&0x0000ffff) );
    2178           0 :     pPict->Seek(nPos);
    2179           0 : }
    2180             : 
    2181             : 
    2182           0 : sal_Bool PictWriter::WritePict(const GDIMetaFile & rMTF, SvStream & rTargetStream, FilterConfigItem* pFilterConfigItem )
    2183             : {
    2184             :     PictWriterAttrStackMember*  pAt;
    2185           0 :     MapMode                     aMap72( MAP_INCH );
    2186           0 :     Fraction                    aDPIFrac( 1, 72 );
    2187             : 
    2188           0 :     bStatus=sal_True;
    2189           0 :     nLastPercent=0;
    2190             : 
    2191           0 :     if ( pFilterConfigItem )
    2192             :     {
    2193           0 :         xStatusIndicator = pFilterConfigItem->GetStatusIndicator();
    2194           0 :         if ( xStatusIndicator.is() )
    2195             :         {
    2196           0 :             OUString aMsg;
    2197           0 :             xStatusIndicator->start( aMsg, 100 );
    2198             :         }
    2199             :     }
    2200             : 
    2201           0 :     pPict=&rTargetStream;
    2202           0 :     pPict->SetNumberFormatInt(NUMBERFORMAT_INT_BIGENDIAN);
    2203             : 
    2204           0 :     aLineColor=Color( COL_BLACK );
    2205           0 :     aFillColor=Color( COL_WHITE );
    2206           0 :     eSrcRasterOp=ROP_OVERPAINT;
    2207           0 :     aSrcFont=Font();
    2208           0 :     aSrcMapMode = rMTF.GetPrefMapMode();
    2209             : 
    2210           0 :     aMap72.SetScaleX( aDPIFrac );
    2211           0 :     aMap72.SetScaleY( aDPIFrac );
    2212           0 :     aTargetMapMode = aMap72;
    2213             : 
    2214           0 :     pAttrStack=NULL;
    2215             : 
    2216           0 :     bDstBkPatValid=sal_False;
    2217           0 :     bDstTxFaceValid=sal_False;
    2218           0 :     bDstTxModeValid=sal_False;
    2219           0 :     bDstPnSizeValid=sal_False;
    2220           0 :     bDstPnModeValid=sal_False;
    2221           0 :     bDstPnPatValid=sal_False;
    2222           0 :     bDstFillPatValid=sal_False;
    2223           0 :     bDstTxSizeValid=sal_False;
    2224           0 :     bDstFgColValid=sal_False;
    2225           0 :     bDstBkColValid=sal_False;
    2226           0 :     bDstPenPositionValid=sal_False;
    2227           0 :     bDstTextPositionValid=sal_False;
    2228           0 :     bDstFontNameValid=sal_False;
    2229             : 
    2230           0 :     nNumberOfActions=0;
    2231           0 :     nNumberOfBitmaps=0;
    2232           0 :     nWrittenActions=0;
    2233           0 :     nWrittenBitmaps=0;
    2234           0 :     nActBitmapPercent=0;
    2235             : 
    2236           0 :     CountActionsAndBitmaps(rMTF);
    2237             : 
    2238           0 :     WriteHeader(rMTF);
    2239           0 :     WriteOpcodes(rMTF);
    2240           0 :     WriteOpcode_EndOfFile();
    2241           0 :     UpdateHeader();
    2242             : 
    2243           0 :     while (pAttrStack!=NULL) {
    2244           0 :         pAt=pAttrStack;
    2245           0 :         pAttrStack=pAt->pSucc;
    2246           0 :         delete pAt;
    2247             :     }
    2248             : 
    2249           0 :     if ( xStatusIndicator.is() )
    2250           0 :         xStatusIndicator->end();
    2251             : 
    2252           0 :     return bStatus;
    2253             : }
    2254             : 
    2255             : // GraphicExport - the exported Function
    2256             : 
    2257             : // this needs to be kept in sync with
    2258             : // ImpFilterLibCacheEntry::GetImportFunction() from
    2259             : // vcl/source/filter/graphicfilter.cxx
    2260             : #if defined(DISABLE_DYNLOADING)
    2261             : #define GraphicExport eptGraphicExport
    2262             : #endif
    2263             : 
    2264             : extern "C" SAL_DLLPUBLIC_EXPORT bool SAL_CALL
    2265           0 : GraphicExport( SvStream & rStream, Graphic & rGraphic, FilterConfigItem* pFilterConfigItem )
    2266             : {
    2267           0 :     PictWriter      aPictWriter;
    2268             : 
    2269             :     // #i119735# just use GetGDIMetaFile, it will create a bufferd version of contained bitmap now automatically
    2270           0 :     GDIMetaFile aScaledMtf( rGraphic.GetGDIMetaFile() );
    2271             : 
    2272           0 :     return aPictWriter.WritePict( aScaledMtf, rStream, pFilterConfigItem );
    2273             : }
    2274             : 
    2275             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10