LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpsdwgrouploaderv0102.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 143 0.7 %
Date: 2014-11-03 Functions: 2 7 28.6 %
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             :  *
       4             :  *  The Contents of this file are made available subject to the terms of
       5             :  *  either of the following licenses
       6             :  *
       7             :  *         - GNU Lesser General Public License Version 2.1
       8             :  *         - Sun Industry Standards Source License Version 1.1
       9             :  *
      10             :  *  Sun Microsystems Inc., October, 2000
      11             :  *
      12             :  *  GNU Lesser General Public License Version 2.1
      13             :  *  =============================================
      14             :  *  Copyright 2000 by Sun Microsystems, Inc.
      15             :  *  901 San Antonio Road, Palo Alto, CA 94303, USA
      16             :  *
      17             :  *  This library is free software; you can redistribute it and/or
      18             :  *  modify it under the terms of the GNU Lesser General Public
      19             :  *  License version 2.1, as published by the Free Software Foundation.
      20             :  *
      21             :  *  This library is distributed in the hope that it will be useful,
      22             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      23             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24             :  *  Lesser General Public License for more details.
      25             :  *
      26             :  *  You should have received a copy of the GNU Lesser General Public
      27             :  *  License along with this library; if not, write to the Free Software
      28             :  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      29             :  *  MA  02111-1307  USA
      30             :  *
      31             :  *
      32             :  *  Sun Industry Standards Source License Version 1.1
      33             :  *  =================================================
      34             :  *  The contents of this file are subject to the Sun Industry Standards
      35             :  *  Source License Version 1.1 (the "License"); You may not use this file
      36             :  *  except in compliance with the License. You may obtain a copy of the
      37             :  *  License at http://www.openoffice.org/license.html.
      38             :  *
      39             :  *  Software provided under this License is provided on an "AS IS" basis,
      40             :  *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
      41             :  *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
      42             :  *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
      43             :  *  See the License for the specific provisions governing your rights and
      44             :  *  obligations concerning the Software.
      45             :  *
      46             :  *  The Initial Developer of the Original Code is: IBM Corporation
      47             :  *
      48             :  *  Copyright: 2008 by IBM Corporation
      49             :  *
      50             :  *  All Rights Reserved.
      51             :  *
      52             :  *  Contributor(s): _______________________________________
      53             :  *
      54             :  *
      55             :  ************************************************************************/
      56             : /*****************************************************************************
      57             :  * Change History
      58             :  * Mar 2005         revised for new processing procedure.
      59             :  * Jan 2005         created
      60             :  ****************************************************************************/
      61             : #include "lwpsdwgrouploaderv0102.hxx"
      62             : #include "lwpdrawobj.hxx"
      63             : #include "lwptools.hxx"
      64             : #include "lwpcharsetmgr.hxx"
      65             : #include "lwpgrfobj.hxx"
      66             : #include "lwpframelayout.hxx"
      67             : 
      68             : #include "xfilter/xfcolor.hxx"
      69             : #include "xfilter/xfdrawline.hxx"
      70             : #include "xfilter/xfdrawpath.hxx"
      71             : #include "xfilter/xfdrawpolyline.hxx"
      72             : #include "xfilter/xfdrawrect.hxx"
      73             : #include "xfilter/xfdrawpolygon.hxx"
      74             : #include "xfilter/xfdrawgroup.hxx"
      75             : #include "xfilter/xfdrawstyle.hxx"
      76             : #include "xfilter/xfdrawlinestyle.hxx"
      77             : #include "xfilter/xfparagraph.hxx"
      78             : #include "xfilter/xfstylemanager.hxx"
      79             : 
      80           0 : LwpSdwGroupLoaderV0102::LwpSdwGroupLoaderV0102(SvStream* pStream, LwpGraphicObject* pGraphicObj)
      81             :     : m_pStream(pStream)
      82             :     , m_pGraphicObj(pGraphicObj)
      83           0 :     , m_pDrawObjVector(NULL)
      84             : {
      85           0 : }
      86             : 
      87           0 : LwpSdwGroupLoaderV0102::~LwpSdwGroupLoaderV0102()
      88             : {
      89           0 : }
      90             : 
      91             : /**
      92             :  * @descr   entry of lwp-drawing objects. the functin begins to parse the sdw-drawing bento stream and create
      93             :  *      the corresponding drawing objects.
      94             :  * @param   pDrawObjVector   a container which will contains the created drawing object of XF-Model.
      95             :  */
      96           0 : void LwpSdwGroupLoaderV0102::BeginDrawObjects(std::vector< rtl::Reference<XFFrame> >* pDrawObjVector)
      97             : {
      98             :     // save the container
      99           0 :     m_pDrawObjVector = pDrawObjVector;
     100             : 
     101             :     //flag
     102             :     unsigned char BinSignature[2];
     103           0 :     m_pStream->Read(BinSignature,2);
     104           0 :     if (BinSignature[0] != 'S' || BinSignature[1] != 'M')
     105             :     {
     106             :         assert(false);
     107           0 :         return;
     108             :     }
     109             :     //version
     110             :     unsigned short nVersion;
     111           0 :     m_pStream->Read(&nVersion,2);
     112           0 :     if (nVersion<0x0102)
     113             :     {
     114             :         assert(false);
     115           0 :         return;
     116             :     }
     117             :     // topObj, botObj
     118           0 :     m_pStream->SeekRel(4);
     119             :     //record count
     120             :     unsigned short nRecCount;
     121           0 :     m_pStream->Read(&nRecCount,2);
     122             :     // selCount
     123           0 :     m_pStream->SeekRel(2);
     124             :     //boundrect
     125             :     unsigned short left,top,right,bottom;
     126           0 :     m_pStream->Read(&left,2);
     127           0 :     m_pStream->Read(&top,2);
     128           0 :     m_pStream->Read(&right,2);
     129           0 :     m_pStream->Read(&bottom,2);
     130             :     // fileSize
     131           0 :     m_pStream->SeekRel(2);
     132             : 
     133             :     //for calculating transformation params.
     134           0 :     LwpFrameLayout* pMyFrameLayout = static_cast<LwpFrameLayout*>(m_pGraphicObj->GetLayout(NULL));
     135           0 :     if (pMyFrameLayout)
     136             :     {
     137           0 :         LwpLayoutScale* pMyScale = pMyFrameLayout->GetLayoutScale();
     138           0 :         LwpLayoutGeometry* pFrameGeo = pMyFrameLayout->GetGeometry();
     139           0 :         if (pMyScale && pFrameGeo)
     140             :         {
     141             :             // original drawing size
     142           0 :             long nWidth = 0, nHeight = 0;
     143           0 :             m_pGraphicObj->GetGrafOrgSize(nWidth, nHeight);
     144           0 :             double fGrafOrgWidth = (double)nWidth/TWIPS_PER_CM;
     145           0 :             double fGrafOrgHeight = (double)nHeight/TWIPS_PER_CM;
     146             : 
     147             :             // get margin values
     148           0 :             double fLeftMargin = pMyFrameLayout->GetMarginsValue(MARGIN_LEFT);
     149             : //          double fRightMargin = pMyFrameLayout->GetMarginsValue(MARGIN_RIGHT);
     150           0 :             double fTopMargin = pMyFrameLayout->GetMarginsValue(MARGIN_TOP);
     151             : //          double fBottomMargin = pMyFrameLayout->GetMarginsValue(MARGIN_BOTTOM);
     152             : 
     153             :             // frame size
     154           0 :             double fFrameWidth = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetWidth());
     155           0 :             double fFrameHeight = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetHeight());
     156             : 
     157             :             // get frame offset
     158           0 :             LwpPoint& rOffset = pMyScale->GetOffset();
     159           0 :             double fOffsetX = LwpTools::ConvertFromUnitsToMetric(rOffset.GetX());
     160           0 :             double fOffsetY = LwpTools::ConvertFromUnitsToMetric(rOffset.GetY());
     161             : 
     162             :             // get scale mode
     163           0 :             sal_uInt16 nScalemode = pMyScale->GetScaleMode();
     164             : 
     165           0 :             if (nScalemode & LwpLayoutScale::CUSTOM)
     166             :             {
     167             :                 m_aTransformData.fScaleX =
     168           0 :                     LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth()) / fGrafOrgWidth;
     169             :                 m_aTransformData.fScaleY =
     170           0 :                     LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight()) / fGrafOrgHeight;
     171             :             }
     172           0 :             else if (nScalemode & LwpLayoutScale::PERCENTAGE)
     173             :             {
     174           0 :                 double fScalePercentage = (double)pMyScale->GetScalePercentage() / 1000;
     175           0 :                 m_aTransformData.fScaleX = fScalePercentage;
     176           0 :                 m_aTransformData.fScaleY = fScalePercentage;
     177             :             }
     178           0 :             else if (nScalemode & LwpLayoutScale::FIT_IN_FRAME)
     179             :             {
     180           0 :                 double fWidth0 = (double)right / TWIPS_PER_CM;
     181           0 :                 double fHeight0 = (double)bottom / TWIPS_PER_CM;
     182             : 
     183           0 :                 double fWidth1 = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
     184           0 :                 double fHeight1 = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
     185             : 
     186           0 :                 double fScaleX = fWidth1 / fWidth0;
     187           0 :                 double fScaleY = fHeight1 / fHeight0;
     188             : 
     189           0 :                 if (nScalemode & LwpLayoutScale::MAINTAIN_ASPECT_RATIO)
     190             :                 {
     191           0 :                     m_aTransformData.fScaleX = std::min(fScaleX, fScaleY);
     192           0 :                     m_aTransformData.fScaleY = m_aTransformData.fScaleX;
     193             :                 }
     194             :                 else
     195             :                 {
     196           0 :                     m_aTransformData.fScaleX = fWidth1 / fWidth0;
     197           0 :                     m_aTransformData.fScaleY = fHeight1 / fHeight0;
     198             :                 }
     199             :             }
     200             : 
     201             :             // placement: centered
     202           0 :             if (pMyFrameLayout->GetScaleCenter())
     203             :             {
     204           0 :                 Rectangle aBoundRect(static_cast<long>(left*m_aTransformData.fScaleX + fLeftMargin),
     205           0 :                     static_cast<long>(top    * m_aTransformData.fScaleY + fTopMargin),
     206           0 :                     static_cast<long>(right  * m_aTransformData.fScaleX),
     207           0 :                     static_cast<long>(bottom * m_aTransformData.fScaleY));
     208           0 :                 Point aCenter = aBoundRect.Center();
     209             : 
     210           0 :                 double fNewCenterX = (double(left)/TWIPS_PER_CM + fFrameWidth/*-fOffsetX*/) / 2;
     211           0 :                 double fNewCenterY = (double(top)/TWIPS_PER_CM + fFrameHeight/*-fOffsetY*/) / 2;
     212             : 
     213           0 :                 m_aTransformData.fOffsetX = fNewCenterX - (double)aCenter.X()/TWIPS_PER_CM;
     214           0 :                 m_aTransformData.fOffsetY = fNewCenterY -(double)aCenter.Y()/TWIPS_PER_CM;
     215             :             }
     216             :             else
     217             :             {
     218           0 :                 m_aTransformData.fOffsetX = fOffsetX;
     219           0 :                 m_aTransformData.fOffsetY = fOffsetY;
     220             :             }
     221             : 
     222           0 :             m_aTransformData.fOffsetX += fLeftMargin;
     223           0 :             m_aTransformData.fOffsetY += fTopMargin;
     224           0 :             m_aTransformData.fLeftMargin = fLeftMargin;
     225           0 :             m_aTransformData.fTopMargin = fTopMargin;
     226             :         }
     227             :     }
     228             : 
     229             :     //load draw object
     230           0 :     for (unsigned short i = 0; i < nRecCount; i++)
     231             :     {
     232           0 :         XFFrame* pXFDrawObj = this->CreateDrawObject();
     233             : 
     234           0 :         if (pXFDrawObj)
     235             :         {
     236           0 :             pDrawObjVector->push_back(pXFDrawObj);
     237             :         }
     238             :     }
     239             : }
     240             : 
     241             : /**
     242             :  * @descr   when we encounter a group object the function will be called to create a XF-drawgroup object
     243             :  *      the corresponding drawing objects.
     244             :  * @param   pDrawObjVector   a container which will contains the created drawing object of XF-Model.
     245             :  */
     246           0 : XFDrawGroup* LwpSdwGroupLoaderV0102::CreateDrawGroupObject(void)
     247             : {
     248             :     //flag
     249             :     unsigned char BinSignature[2];
     250           0 :     m_pStream->Read(BinSignature,2);
     251           0 :     if (BinSignature[0] != 'S' || BinSignature[1] != 'M')
     252             :     {
     253             :         assert(false);
     254           0 :         return NULL;
     255             :     }
     256             :     //version
     257             :     unsigned short nVersion;
     258           0 :     m_pStream->Read(&nVersion,2);
     259           0 :     if (nVersion<0x0102)
     260             :     {
     261             :         assert(false);
     262           0 :         return NULL;
     263             :     }
     264             :     // topObj, botObj
     265           0 :     m_pStream->SeekRel(4);
     266             :     //record count
     267             :     unsigned short nRecCount;
     268           0 :     m_pStream->Read(&nRecCount,2);
     269             :     // selCount
     270           0 :     m_pStream->SeekRel(2);
     271             :     //boundrect
     272             :     unsigned short left,top,right,bottom;
     273           0 :     m_pStream->Read(&left,2);
     274           0 :     m_pStream->Read(&top,2);
     275           0 :     m_pStream->Read(&right,2);
     276           0 :     m_pStream->Read(&bottom,2);
     277             :     // fileSize
     278           0 :     m_pStream->SeekRel(2);
     279             : 
     280           0 :     XFDrawGroup* pXFDrawGroup = new XFDrawGroup();
     281             : 
     282             :     //load draw object
     283           0 :     for (unsigned short i = 0; i < nRecCount; i++)
     284             :     {
     285           0 :         XFFrame* pXFDrawObj = this->CreateDrawObject();
     286             : 
     287           0 :         if (pXFDrawObj)
     288             :         {
     289           0 :             if (pXFDrawObj->GetFrameType() == enumXFFrameImage)
     290             :             {
     291           0 :                 m_pDrawObjVector->push_back(pXFDrawObj);
     292             :             }
     293             :             else
     294             :             {
     295           0 :                 pXFDrawGroup->Add(pXFDrawObj);
     296             :             }
     297             :         }
     298             :     }
     299             : 
     300           0 :     return pXFDrawGroup;
     301             : }
     302             : 
     303             : /**
     304             :  * @descr   Create the XF-drawing objects according to the object type read from bento stream.
     305             :  * @return   the created XF-drawing objects.
     306             :  */
     307           0 : XFFrame* LwpSdwGroupLoaderV0102::CreateDrawObject(void)
     308             : {
     309             :     //record type
     310             :     unsigned char recType;
     311           0 :     m_pStream->Read(&recType,1);
     312             : 
     313           0 :     LwpDrawObj* pDrawObj = NULL;
     314           0 :     XFFrame* pRetObjct = NULL;
     315             : 
     316           0 :     switch(recType)
     317             :     {
     318             :     case OT_PERPLINE://fall-through
     319             :     case OT_LINE:
     320             :     {
     321           0 :         pDrawObj = new LwpDrawLine(m_pStream, &m_aTransformData);
     322           0 :         break;
     323             :     }
     324             :     case OT_POLYLINE:
     325             :     {
     326           0 :         pDrawObj = new LwpDrawPolyLine(m_pStream, &m_aTransformData);
     327           0 :         break;
     328             :     }
     329             :     case OT_POLYGON:
     330             :     {
     331           0 :         pDrawObj = new LwpDrawPolygon(m_pStream, &m_aTransformData);
     332           0 :         pDrawObj->SetObjectType(OT_POLYGON);
     333           0 :         break;
     334             :     }
     335             :     case OT_SQUARE://fall-through
     336             :     case OT_RECT:
     337             :     {
     338           0 :         pDrawObj = new LwpDrawRectangle(m_pStream, &m_aTransformData);
     339           0 :         break;
     340             :     }
     341             :     case OT_RNDSQUARE://fall-through
     342             :     case OT_RNDRECT:
     343             :     {
     344           0 :         pDrawObj = new LwpDrawRectangle(m_pStream, &m_aTransformData);
     345           0 :         pDrawObj->SetObjectType(OT_RNDRECT);
     346           0 :         break;
     347             :     }
     348             :     case OT_CIRCLE://fall-through
     349             :     case OT_OVAL:
     350             :     {
     351           0 :         pDrawObj = new LwpDrawEllipse(m_pStream, &m_aTransformData);
     352           0 :         break;
     353             :     }
     354             :     case OT_ARC:
     355             :     {
     356           0 :         pDrawObj = new LwpDrawArc(m_pStream, &m_aTransformData);
     357           0 :         break;
     358             :     }
     359             :     case OT_TEXT:
     360             :     {
     361           0 :         pDrawObj = new LwpDrawTextBox(m_pStream);
     362           0 :         break;
     363             :     }
     364             :     case OT_TEXTART:
     365             :     {
     366           0 :         pDrawObj = new LwpDrawTextArt(m_pStream, &m_aTransformData);
     367           0 :         pDrawObj->SetObjectType(OT_TEXTART);
     368           0 :         break;
     369             :     }
     370             :     case OT_GROUP:
     371             :     {
     372           0 :         m_pStream->SeekRel(2);
     373             :         // read out the object header
     374           0 :         pDrawObj = new LwpDrawGroup(m_pStream);
     375             : 
     376           0 :         pRetObjct = this->CreateDrawGroupObject();
     377             : 
     378             :         // set anchor type
     379           0 :         pRetObjct->SetAnchorType(enumXFAnchorFrame);
     380           0 :         break;
     381             :     }
     382             :     case OT_CHART://fall-through
     383             :     case OT_METAFILE://fall-through
     384             :     case OT_METAFILEIMG:
     385             :     {
     386           0 :         LwpDrawMetafile aMeta(m_pStream);
     387           0 :         break;
     388             :     }
     389             :     case OT_BITMAP:
     390           0 :         pDrawObj = new LwpDrawBitmap(m_pStream);
     391           0 :         pDrawObj->SetObjectType(OT_BITMAP);
     392           0 :         break;
     393             :     }
     394             : 
     395             :     // we don't need create the corresponding XF-object of a group object.
     396           0 :     if (pDrawObj && recType != OT_GROUP)
     397             :     {
     398           0 :         pRetObjct = pDrawObj->CreateXFDrawObject();
     399             :     }
     400             : 
     401           0 :     if (pDrawObj)
     402             :     {
     403           0 :         delete pDrawObj;
     404           0 :         pDrawObj = NULL;
     405             :     }
     406             : 
     407           0 :     return pRetObjct;
     408           6 : }
     409             : // end add
     410             : 
     411             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10