LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpgrfobj.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 185 318 58.2 %
Date: 2014-11-03 Functions: 15 18 83.3 %
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             : * 2005/2  draft code for chart
      59             : ****************************************************************************/
      60             : 
      61             : /**
      62             :  * @file
      63             :  *  For LWP filter architecture prototype
      64             : */
      65             : #include <stdio.h>
      66             : 
      67             : #include <boost/scoped_ptr.hpp>
      68             : 
      69             : #include "lwp9reader.hxx"
      70             : #include "lwpgrfobj.hxx"
      71             : #include "lwpsdwfileloader.hxx"
      72             : #include "bento.hxx"
      73             : 
      74             : #include "lwpglobalmgr.hxx"
      75             : #include "xfilter/xfframe.hxx"
      76             : #include "xfilter/xfimage.hxx"
      77             : #include "xfilter/xfimagestyle.hxx"
      78             : #include "xfilter/xfstylemanager.hxx"
      79             : #include "xfilter/xfparagraph.hxx"
      80             : #include "xfilter/xfannotation.hxx"
      81             : 
      82             : //For chart
      83             : #include "string.h"
      84             : 
      85             : #include <osl/thread.h>
      86             : 
      87             : #define EF_NONE 0x0000
      88             : #define EF_ODMA 0x0002
      89             : 
      90          14 : LwpGraphicObject::LwpGraphicObject(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
      91             :     : LwpGraphicOleObject(objHdr, pStrm)
      92             :     , m_nCachedBaseLine(0)
      93             :     , m_bIsLinked(0)
      94          14 :     , m_bCompressed(0)
      95             : {
      96          14 :     memset(m_sDataFormat, 0, sizeof(m_sDataFormat));
      97          14 :     memset(m_sServerContextFormat, 0, sizeof(m_sServerContextFormat));
      98          14 : }
      99             : 
     100          28 : LwpGraphicObject::~LwpGraphicObject()
     101             : {
     102          28 : }
     103             : 
     104          14 : void LwpGraphicObject::Read()
     105             : {
     106          14 :     LwpGraphicOleObject::Read();
     107          12 :     m_pObjStrm->QuickReaduInt16(); //disksize
     108          12 :     sal_uInt16 strsize = m_pObjStrm->QuickReaduInt16();
     109          12 :     if (strsize<AFID_MAX_FILE_FORMAT_SIZE)
     110             :     {
     111          12 :         m_pObjStrm->QuickRead(m_sDataFormat,strsize);
     112          12 :         m_sDataFormat[strsize] = '\0';
     113             :     }
     114          12 :     sal_uInt32 nServerContextSize = m_pObjStrm->QuickReaduInt32();
     115          12 :     unsigned char *pServerContext = NULL;
     116          12 :     if (nServerContextSize > 0)
     117             :     {
     118           8 :         pServerContext = new unsigned char[nServerContextSize];
     119           8 :         m_pObjStrm->QuickRead(pServerContext, static_cast<sal_uInt16>(nServerContextSize));
     120           8 :         if (nServerContextSize > 44)
     121             :         {
     122           8 :             m_aIPData.nBrightness = pServerContext[14];
     123           8 :             m_aIPData.nContrast = pServerContext[19];
     124           8 :             m_aIPData.nEdgeEnchancement = pServerContext[24];
     125           8 :             m_aIPData.nSmoothing = pServerContext[29];
     126           8 :             m_aIPData.bInvertImage = (pServerContext[34] == 0x01);
     127           8 :             m_aIPData.bAutoContrast = (pServerContext[44] == 0x00);
     128             :         }
     129             :     }
     130          12 :     m_pObjStrm->QuickReaduInt16(); //disksize
     131          12 :     strsize = m_pObjStrm->QuickReaduInt16();
     132          12 :     if (strsize<AFID_MAX_FILE_FORMAT_SIZE)
     133             :     {
     134          12 :         m_pObjStrm->QuickRead(m_sServerContextFormat,strsize);
     135          12 :         m_sServerContextFormat[strsize] = '\0';
     136             :     }
     137          12 :     if (nServerContextSize == 0)
     138             :     {
     139           4 :         if (strcmp((char *)m_sServerContextFormat, ".cht") == 0 &&
     140           0 :             strcmp((char *)m_sDataFormat, ".sdw") == 0)
     141             :         {
     142           0 :             strcpy((char *)m_sServerContextFormat, ".lch");
     143           0 :             strcpy((char *)m_sDataFormat, ".lch");
     144             :         }
     145             :     }
     146          12 :     m_nCachedBaseLine = m_pObjStrm->QuickReadInt32();
     147          12 :     m_bIsLinked = m_pObjStrm->QuickReadInt16();
     148          12 :     unsigned char * pFilterContext = NULL;
     149             : 
     150          12 :     if (m_bIsLinked)
     151             :     {
     152           0 :         m_LinkedFilePath = m_pObjStrm->QuickReadStringPtr();
     153             : 
     154           0 :         sal_uInt32 nFilterContextSize = m_pObjStrm->QuickReaduInt32();
     155           0 :         if (nFilterContextSize > 0)
     156             :         {
     157           0 :             pFilterContext = new unsigned char[nFilterContextSize];
     158           0 :             m_pObjStrm->QuickRead(pFilterContext, static_cast<sal_uInt16>(nFilterContextSize));
     159             :         }
     160           0 :         if (LwpFileHeader::m_nFileRevision >= 0x000b)
     161             :         {
     162             : 
     163             :             // read external file object stuff
     164           0 :             sal_uInt16 type = m_pObjStrm->QuickReaduInt16();
     165           0 :             if ((EF_ODMA != type) && (EF_NONE != type)) // don't know about this
     166             :             {
     167           0 :                 sal_uInt32 size = m_pObjStrm->QuickReaduInt32();
     168           0 :                 m_pObjStrm->SeekRel(static_cast<sal_uInt16>(size));
     169             :             }
     170             :             // else no external file object
     171             :         }
     172             :     }
     173             : 
     174          12 :     if (LwpFileHeader::m_nFileRevision >= 0x000b)
     175             :     {
     176          12 :         m_bCompressed = m_pObjStrm->QuickReadInt16();
     177          12 :         m_Cache.LinkedFileSize = m_pObjStrm->QuickReaduInt32();
     178          12 :         m_Cache.LinkedFileTime = m_pObjStrm->QuickReaduInt32();
     179          12 :         m_Cache.Width = m_pObjStrm->QuickReadInt32();
     180          12 :         m_Cache.Height = m_pObjStrm->QuickReadInt32();
     181             :     }
     182             : 
     183          12 :     if(LwpFileHeader::m_nFileRevision >= 0x000c)
     184             :     {
     185          12 :         m_WatermarkName = m_pObjStrm->QuickReadStringPtr();
     186             :     }
     187             : 
     188          12 :     if (pServerContext != NULL)
     189           8 :         delete[] pServerContext;
     190             : 
     191          12 :     if (pFilterContext != NULL)
     192           0 :         delete[] pFilterContext;
     193             : 
     194          12 : }
     195             : 
     196           8 : void LwpGraphicObject::XFConvert (XFContentContainer* pCont)
     197             : {
     198           8 :     if ((m_sServerContextFormat[1]=='s'&&m_sServerContextFormat[2]=='d'&&m_sServerContextFormat[3]=='w'))
     199             :     {
     200           0 :         std::vector< rtl::Reference<XFFrame> >::iterator iter;
     201           0 :         for (iter = m_vXFDrawObjects.begin(); iter != m_vXFDrawObjects.end(); ++iter)
     202             :         {
     203           0 :             pCont->Add(iter->get());
     204           0 :         }
     205             :     }
     206           8 :     else if (this->IsGrafFormatValid())
     207             :     {
     208           8 :         XFImage* pImage = static_cast<XFImage*>(m_vXFDrawObjects.front().get());
     209             : 
     210           8 :         if (m_bIsLinked)
     211             :         {
     212           0 :             OUString fileURL = LwpTools::convertToFileUrl(OUStringToOString(m_LinkedFilePath, osl_getThreadTextEncoding()));
     213           0 :             pImage->SetFileURL(fileURL);
     214             :         }
     215             :         else
     216             :         {
     217           8 :             sal_uInt8* pGrafData = NULL;
     218           8 :             sal_uInt32 nDataLen = this->GetRawGrafData(pGrafData);
     219             : 
     220           8 :             if (pGrafData)
     221             :             {
     222           0 :                 pImage->SetImageData(pGrafData, nDataLen);
     223             : 
     224             :                 // delete used image data
     225           0 :                 delete [] pGrafData;
     226           0 :                 pGrafData = NULL;
     227             :             }
     228             :         }
     229             : 
     230           8 :         pCont->Add(pImage);
     231             :     }
     232           0 :     else if((m_sServerContextFormat[1]=='t'&&m_sServerContextFormat[2]=='e'&&m_sServerContextFormat[3]=='x'))
     233             :     {
     234           0 :         XFConvertEquation(pCont);
     235             :     }
     236           8 : }
     237             : 
     238             : #include "lwpframelayout.hxx"
     239             : 
     240             : /**
     241             :  * @descr   judge if the graphic format is what we can support: bmp, jpg, wmf, gif, tgf(tif). other format will be filtered to
     242             :  *  these formats by Word Pro.
     243             :  * @return  sal_True if yes sal_False if not.
     244             :  */
     245          20 : bool LwpGraphicObject::IsGrafFormatValid()
     246             : {
     247          20 :     if ((m_sServerContextFormat[1]=='b'&& m_sServerContextFormat[2]=='m' && m_sServerContextFormat[3]=='p')
     248          16 :     || (m_sServerContextFormat[1]=='j' && m_sServerContextFormat[2]=='p' && m_sServerContextFormat[3]=='g')
     249          10 :     || (m_sServerContextFormat[1]=='w' && m_sServerContextFormat[2]=='m' && m_sServerContextFormat[3]=='f')
     250           0 :     || (m_sServerContextFormat[1]=='g' && m_sServerContextFormat[2]=='i' && m_sServerContextFormat[3]=='f')
     251           0 :     || (m_sServerContextFormat[1]=='t' && m_sServerContextFormat[2]=='g' && m_sServerContextFormat[3]=='f')
     252           0 :     || (m_sServerContextFormat[1]=='p' && m_sServerContextFormat[2]=='n' && m_sServerContextFormat[3]=='g')
     253           0 :     || (m_sServerContextFormat[1]=='e' && m_sServerContextFormat[2]=='p' && m_sServerContextFormat[3]=='s'))
     254             :     {
     255          20 :         return true;
     256             :     }
     257             :     else
     258             :     {
     259           0 :         return false;
     260             :     }
     261             : }
     262             : 
     263             : /**
     264             :  * @descr   create drawing object and image object.
     265             :  */
     266          12 : void LwpGraphicObject::RegisterStyle()
     267             : {
     268          12 :     if (m_sServerContextFormat[1]=='s'&&m_sServerContextFormat[2]=='d'&&m_sServerContextFormat[3]=='w')
     269             :     {
     270           0 :         this->CreateDrawObjects();
     271             :     }
     272             :     // test codes for importing pictures
     273          12 :     else if(this->IsGrafFormatValid())
     274             :     {
     275          12 :         this->CreateGrafObject();
     276             :     }
     277             : 
     278          12 :     if (m_sServerContextFormat[1]=='l'&&m_sServerContextFormat[2]=='c'&&m_sServerContextFormat[3]=='h')
     279             :     {
     280           0 :         LwpVirtualLayout* pMyLayout = GetLayout(NULL);
     281           0 :         if (pMyLayout && pMyLayout->IsFrame())
     282             :         {
     283           0 :             XFFrameStyle* pXFFrameStyle = new XFFrameStyle();
     284           0 :             pXFFrameStyle->SetXPosType(enumXFFrameXPosFromLeft, enumXFFrameXRelFrame);
     285           0 :             pXFFrameStyle->SetYPosType(enumXFFrameYPosFromTop, enumXFFrameYRelPara);
     286           0 :             XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     287           0 :             m_strStyleName = pXFStyleManager->AddStyle(pXFFrameStyle)->GetStyleName();
     288             :         }
     289             :     }
     290             : 
     291          12 : }
     292             : 
     293             : /**
     294             :  * @descr   create drawing object.
     295             :  */
     296           0 : void LwpGraphicObject::CreateDrawObjects()
     297             : {
     298             :     // if small file, use the compressed stream for BENTO
     299           0 :     LwpSvStream* pStream = m_pStrm->GetCompressedStream() ?  m_pStrm->GetCompressedStream(): m_pStrm;
     300             : 
     301             :     OpenStormBento::LtcBenContainer* pBentoContainer;
     302           0 :     sal_uLong ulRet = OpenStormBento::BenOpenContainer(pStream, &pBentoContainer);
     303           0 :     if (ulRet != OpenStormBento::BenErr_OK)
     304           0 :         return;
     305             : 
     306           0 :     SvStream* pDrawObjStream = NULL;
     307             : 
     308             :     // get graphic object's bento objet name
     309           0 :     LwpObjectID& rMyID = this->GetObjectID();
     310           0 :     std::string aGrfObjName;
     311           0 :     this->GetBentoNamebyID(rMyID,  aGrfObjName);
     312             : 
     313             :     // get bento stream by the name
     314           0 :     pBentoContainer->CreateGraphicStream(pDrawObjStream, aGrfObjName.c_str());
     315           0 :     if (pDrawObjStream)
     316             :     {
     317           0 :         LwpSdwFileLoader fileLoader(pDrawObjStream, this);
     318           0 :         fileLoader.CreateDrawObjects(&m_vXFDrawObjects);
     319             : 
     320           0 :         delete pDrawObjStream;
     321           0 :         pDrawObjStream = NULL;
     322           0 :     }
     323             : }
     324             : 
     325             : /**
     326             :  * @descr   create drawing object.
     327             :  */
     328           8 : void LwpGraphicObject::GetBentoNamebyID(LwpObjectID& rMyID, std::string& rName)
     329             : {
     330           8 :     sal_uInt16 nHigh = rMyID.GetHigh();
     331           8 :     sal_uInt16 nLow = rMyID.GetLow();
     332             :     char pTempStr[32];
     333           8 :     rName = std::string("Gr");
     334           8 :     sprintf(pTempStr, "%X,%X", nHigh, nLow);
     335           8 :     rName.append(pTempStr);
     336           8 : }
     337             : 
     338             : /**
     339             :  * @descr   get the image data read from bento stream according to the VO_GRAPHIC ID.
     340             :  * @param   pGrafData   the array to store the image data. the pointer need to be deleted outside.
     341             :  * @return  the length of the image data.
     342             :  */
     343           8 : sal_uInt32 LwpGraphicObject::GetRawGrafData(sal_uInt8*& pGrafData)
     344             : {
     345             :     // create graphic object
     346             :     // if small file, use the compressed stream for BENTO
     347           8 :     LwpSvStream* pStream = m_pStrm->GetCompressedStream() ?  m_pStrm->GetCompressedStream(): m_pStrm;
     348             : 
     349           8 :     boost::scoped_ptr<OpenStormBento::LtcBenContainer> pBentoContainer;
     350             :     {
     351           8 :         OpenStormBento::LtcBenContainer* pTmp(0);
     352           8 :         sal_uLong ulRet = OpenStormBento::BenOpenContainer(pStream, &pTmp);
     353           8 :         pBentoContainer.reset(pTmp);
     354           8 :         if (ulRet != OpenStormBento::BenErr_OK)
     355           0 :             return 0;
     356             :     }
     357             : 
     358           8 :     SvStream* pGrafStream = NULL;
     359             : 
     360             :     // get graphic object's bento objet name
     361           8 :     LwpObjectID& rMyID = this->GetObjectID();
     362          16 :     std::string aGrfObjName;
     363           8 :     this->GetBentoNamebyID(rMyID,  aGrfObjName);
     364             : 
     365             :     // get bento stream by the name
     366           8 :     pBentoContainer->CreateGraphicStream(pGrafStream, aGrfObjName.c_str());
     367           8 :     SvMemoryStream* pMemGrafStream = static_cast<SvMemoryStream*>(pGrafStream);
     368             : 
     369           8 :     if (pMemGrafStream)
     370             :     {
     371             :         // read image data
     372           0 :         sal_uInt32 nDataLen = pMemGrafStream->GetEndOfData();
     373           0 :         pGrafData = new sal_uInt8 [nDataLen];
     374           0 :         pMemGrafStream->Read(pGrafData, nDataLen);
     375             : 
     376           0 :         delete pMemGrafStream;
     377           0 :         pMemGrafStream = NULL;
     378             : 
     379           0 :         return nDataLen;
     380             :     }
     381             : 
     382          16 :     return 0;
     383             : }
     384             : 
     385             : /**
     386             :  * @descr   get the image data (only -D dara) read from bento stream according to the VO_GRAPHIC ID.
     387             :  * @param   pGrafData   the array to store the image data. the pointer need to be deleted outside.
     388             :  * @return  the length of the image data.
     389             :  */
     390           0 : sal_uInt32 LwpGraphicObject::GetGrafData(sal_uInt8*& pGrafData)
     391             : {
     392             :     // create graphic object
     393             :     // if small file, use the compressed stream for BENTO
     394           0 :     LwpSvStream* pStream = m_pStrm->GetCompressedStream() ?  m_pStrm->GetCompressedStream(): m_pStrm;
     395             : 
     396             :     OpenStormBento::LtcBenContainer* pBentoContainer;
     397           0 :     sal_uLong ulRet = OpenStormBento::BenOpenContainer(pStream, &pBentoContainer);
     398           0 :     if (ulRet != OpenStormBento::BenErr_OK)
     399           0 :         return 0;
     400             : 
     401           0 :     SvStream* pGrafStream = NULL;
     402             : 
     403             :     // get graphic object's bento objet name
     404           0 :     LwpObjectID& rMyID = this->GetObjectID();
     405           0 :     std::string aGrfObjName;
     406           0 :     this->GetBentoNamebyID(rMyID,  aGrfObjName);
     407             : 
     408           0 :     char sDName[64]="";
     409           0 :     sprintf(sDName, "%s-D", aGrfObjName.c_str());
     410             : 
     411             :     // get bento stream by the name
     412           0 :     pGrafStream = pBentoContainer->FindValueStreamWithPropertyName(sDName);
     413             : 
     414           0 :     SvMemoryStream* pMemGrafStream = static_cast<SvMemoryStream*>(pGrafStream);
     415             : 
     416           0 :     if (pMemGrafStream)
     417             :     {
     418             :         // read image data
     419           0 :         sal_uInt32 nPos = pGrafStream->Tell();
     420           0 :         pGrafStream->Seek(STREAM_SEEK_TO_END);
     421           0 :         sal_uInt32 nDataLen = pGrafStream->Tell();
     422           0 :         pGrafStream->Seek(nPos);
     423             : 
     424           0 :         pGrafData = new sal_uInt8 [nDataLen];
     425           0 :         pMemGrafStream->Read(pGrafData, nDataLen);
     426             : 
     427           0 :         delete pMemGrafStream;
     428           0 :         pMemGrafStream = NULL;
     429             : 
     430           0 :         return nDataLen;
     431             :     }
     432             : 
     433           0 :     return 0;
     434             : }
     435             : 
     436             : /**
     437             :  * @descr   create xf-image object and save it in the container: m_vXFDrawObjects.
     438             :  */
     439          12 : void LwpGraphicObject::CreateGrafObject()
     440             : {
     441          12 :     rtl::Reference<XFImage> pImage = new XFImage();
     442             : 
     443             :     // set image processing styles
     444          12 :     XFImageStyle* pImageStyle = new XFImageStyle();
     445          12 :     if (m_sServerContextFormat[1]!='w' || m_sServerContextFormat[2]!='m' || m_sServerContextFormat[3]!='f')
     446             :     {
     447           6 :         if (m_aIPData.nBrightness != 50)
     448             :         {
     449           0 :             sal_Int32 nSODCBrightness = (sal_Int32)m_aIPData.nBrightness*2 - 100;
     450           0 :             pImageStyle->SetBrightness(nSODCBrightness);
     451             :         }
     452           6 :         if (m_aIPData.nContrast != 50)
     453             :         {
     454           0 :             sal_Int32 nSODCContrast = (sal_Int32)(80 - (double)m_aIPData.nContrast*1.6);
     455           0 :             pImageStyle->SetContrast(nSODCContrast);
     456             :         }
     457             :     }
     458             : 
     459             :     // set scale and crop styles
     460          12 :     LwpAssociatedLayouts& rLayoutWithMe = GetLayoutsWithMe();
     461             :     LwpFrameLayout* pMyFrameLayout =
     462          12 :         static_cast<LwpFrameLayout*>(rLayoutWithMe.GetOnlyLayout().obj(VO_FRAMELAYOUT).get());
     463          12 :     if (pMyFrameLayout)
     464             :     {
     465          12 :         LwpLayoutScale* pMyScale = pMyFrameLayout->GetLayoutScale();
     466          12 :         LwpLayoutGeometry* pFrameGeo = pMyFrameLayout->GetGeometry();
     467             : 
     468             :         // original image size
     469          12 :         double fOrgGrafWidth = (double)m_Cache.Width/TWIPS_PER_CM;
     470          12 :         double fOrgGrafHeight = (double)m_Cache.Height/TWIPS_PER_CM;
     471             : 
     472             :         // get margin values
     473          12 :         double fLeftMargin = pMyFrameLayout->GetMarginsValue(MARGIN_LEFT);
     474          12 :         double fRightMargin = pMyFrameLayout->GetMarginsValue(MARGIN_RIGHT);
     475          12 :         double fTopMargin = pMyFrameLayout->GetMarginsValue(MARGIN_TOP);
     476          12 :         double fBottomMargin = pMyFrameLayout->GetMarginsValue(MARGIN_BOTTOM);
     477             : 
     478          12 :         if (pMyScale && pFrameGeo)
     479             :         {
     480             :             // frame size
     481          12 :             double fFrameWidth = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetWidth());
     482          12 :             double fFrameHeight = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetHeight());
     483             : 
     484             :             // calculate the displayed size of the frame
     485          12 :             double fDisFrameWidth = fFrameWidth - (fLeftMargin+fRightMargin);
     486          12 :             double fDisFrameHeight = fFrameHeight - (fTopMargin+fBottomMargin);
     487             : 
     488             :             // scaled image size
     489          12 :             double fSclGrafWidth = fOrgGrafWidth;
     490          12 :             double fSclGrafHeight = fOrgGrafHeight;
     491             : 
     492             :             // get scale mode
     493          12 :             sal_uInt16 nScalemode = pMyScale->GetScaleMode();
     494          12 :             if (nScalemode & LwpLayoutScale::CUSTOM)
     495             :             {
     496           0 :                 fSclGrafWidth = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
     497           0 :                 fSclGrafHeight = LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
     498             :             }
     499          12 :             else if (nScalemode & LwpLayoutScale::PERCENTAGE)
     500             :             {
     501           0 :                 double fScalePercentage = (double)pMyScale->GetScalePercentage() / 1000;
     502           0 :                 fSclGrafWidth = fScalePercentage * fOrgGrafWidth;
     503           0 :                 fSclGrafHeight = fScalePercentage * fOrgGrafHeight;
     504             :             }
     505          12 :             else if (nScalemode & LwpLayoutScale::FIT_IN_FRAME)
     506             :             {
     507          12 :                 if (pMyFrameLayout->IsFitGraphic())
     508             :                 {
     509           0 :                     fSclGrafWidth = fOrgGrafWidth;
     510           0 :                     fSclGrafHeight = fOrgGrafHeight;
     511             :                 }
     512          12 :                 else if (nScalemode & LwpLayoutScale::MAINTAIN_ASPECT_RATIO)
     513             :                 {
     514           6 :                     if (fOrgGrafWidth/fOrgGrafHeight >= fDisFrameWidth/fDisFrameHeight)
     515             :                     {
     516           4 :                         fSclGrafWidth = fDisFrameWidth;
     517           4 :                         fSclGrafHeight = (fDisFrameWidth/fOrgGrafWidth) * fOrgGrafHeight;
     518             :                     }
     519             :                     else
     520             :                     {
     521           2 :                         fSclGrafHeight = fDisFrameHeight;
     522           2 :                         fSclGrafWidth = (fDisFrameHeight/fOrgGrafHeight) * fOrgGrafWidth;
     523             :                     }
     524             :                 }
     525             :                 else
     526             :                 {
     527           6 :                     fSclGrafWidth = fDisFrameWidth;
     528           6 :                     fSclGrafHeight = fDisFrameHeight;
     529             :                 }
     530             :             }
     531             : 
     532             :             // scaled ratio
     533          12 :             double fXRatio = fSclGrafWidth / fOrgGrafWidth;
     534          12 :             double fYRatio = fSclGrafHeight / fOrgGrafHeight;
     535             : 
     536             :             // set image to scaled size.
     537          12 :             pImage->SetWidth(fSclGrafWidth);
     538          12 :             pImage->SetHeight(fSclGrafHeight);
     539             : 
     540             :             // placement:centered or tiled. tiled style is not supported so it's processed together with centered.
     541          12 :             if (pMyFrameLayout->GetScaleCenter() || pMyFrameLayout->GetScaleTile())
     542             :             {
     543             :                 // set center alignment
     544           6 :                 pImageStyle->SetXPosType(enumXFFrameXPosCenter, enumXFFrameXRelFrame);
     545           6 :                 pImageStyle->SetYPosType(enumXFFrameYPosMiddle, enumXFFrameYRelFrame);
     546             : 
     547             :                 // need horizontal crop?
     548           6 :                 double fClipWidth = 0;
     549           6 :                 double fClipHeight = 0;
     550           6 :                 bool sal_bCropped = false;
     551           6 :                 if (fSclGrafWidth > fDisFrameWidth)
     552             :                 {
     553           0 :                     fClipWidth = (fSclGrafWidth-fDisFrameWidth ) / 2 / fXRatio;
     554           0 :                     sal_bCropped = true;
     555             :                 }
     556             : 
     557             :                 // need vertical crop?
     558           6 :                 if (fSclGrafHeight > fDisFrameHeight)
     559             :                 {
     560           0 :                     fClipHeight = (fSclGrafHeight-fDisFrameHeight ) / 2 / fYRatio;
     561           0 :                     sal_bCropped = true;
     562             :                 }
     563             : 
     564           6 :                 if (sal_bCropped)
     565             :                 {
     566           0 :                     pImageStyle->SetClip(fClipWidth, fClipWidth, fClipHeight, fClipHeight);
     567           0 :                     pImage->SetWidth(fDisFrameWidth);
     568           0 :                     pImage->SetHeight(fDisFrameHeight);
     569             :                 }
     570             :             }
     571             :             // placement:automatic
     572             :             else
     573             :             {
     574             :                 // set left-top alignment
     575           6 :                 pImageStyle->SetYPosType(enumXFFrameYPosFromTop, enumXFFrameYRelFrame);
     576           6 :                 pImageStyle->SetXPosType(enumXFFrameXPosFromLeft, enumXFFrameXRelFrame);
     577             : 
     578             :                 // get image position offset
     579           6 :                 LwpPoint& rOffset = pMyScale->GetOffset();
     580           6 :                 double fOffsetX = LwpTools::ConvertFromUnitsToMetric(rOffset.GetX());
     581           6 :                 double fOffsetY = LwpTools::ConvertFromUnitsToMetric(rOffset.GetY());
     582             : 
     583             :                 struct LwpRect
     584             :                 {
     585             :                     double fLeft;
     586             :                     double fRight;
     587             :                     double fTop;
     588             :                     double fBottom;
     589             : 
     590           6 :                     LwpRect()
     591             :                     {
     592           6 :                         fLeft = 0.00;
     593           6 :                         fRight = 0.00;
     594           6 :                         fTop = 0.00;
     595           6 :                         fBottom = 0.00;
     596           6 :                     }
     597          12 :                     LwpRect(double fL, double fR, double fT, double fB)
     598             :                     {
     599          12 :                         fLeft = fL;
     600          12 :                         fRight = fR;
     601          12 :                         fTop = fT;
     602          12 :                         fBottom = fB;
     603          12 :                     }
     604             :                 };
     605           6 :                 LwpRect aFrameRect(-fOffsetX, (fDisFrameWidth-fOffsetX), (-fOffsetY), ((fDisFrameHeight-fOffsetY)));
     606           6 :                 LwpRect aImageRect(0, fSclGrafWidth, 0, fSclGrafHeight);
     607           6 :                 LwpRect aCropRect;
     608             : 
     609           6 :                 if (aFrameRect.fRight <= aImageRect.fLeft || aFrameRect.fLeft >= aImageRect.fRight
     610           6 :                     ||aFrameRect.fBottom <= aImageRect.fTop|| aFrameRect.fTop >= aImageRect.fBottom)
     611             :                 {
     612             :                     // display blank
     613             :                 }
     614             :                 else// need cropped
     615             :                 {
     616             :                     // horizontal crop
     617           6 :                     if (aFrameRect.fLeft > aImageRect.fLeft)
     618             :                     {
     619           0 :                         aCropRect.fLeft = (aFrameRect.fLeft - aImageRect.fLeft) / fXRatio;
     620             :                     }
     621             : 
     622           6 :                     if (aFrameRect.fRight < aImageRect.fRight)
     623             :                     {
     624           0 :                         aCropRect.fRight = (aImageRect.fRight - aFrameRect.fRight) / fXRatio;
     625             :                     }
     626             : 
     627             :                     // vertical crop
     628           6 :                     if (aFrameRect.fTop > aImageRect.fTop)
     629             :                     {
     630           0 :                         aCropRect.fTop = (aFrameRect.fTop - aImageRect.fTop) / fYRatio;
     631             :                     }
     632           6 :                     if (aFrameRect.fBottom < aImageRect.fBottom)
     633             :                     {
     634           0 :                         aCropRect.fBottom = (aImageRect.fBottom - aFrameRect.fBottom) / fYRatio;
     635             :                     }
     636             : 
     637           6 :                     pImageStyle->SetClip(aCropRect.fLeft, aCropRect.fRight, aCropRect.fTop, aCropRect.fBottom);
     638           6 :                     double fPicWidth = fSclGrafWidth - (aCropRect.fLeft+aCropRect.fRight)*fXRatio;
     639           6 :                     double fPicHeight = fSclGrafHeight- (aCropRect.fTop+aCropRect.fBottom)*fYRatio;
     640           6 :                     double fX = fOffsetX > 0 ? fOffsetX : 0.00;
     641           6 :                     double fY = fOffsetY > 0 ? fOffsetY : 0.00;
     642           6 :                     pImage->SetPosition((fX+fLeftMargin), (fY+fTopMargin), fPicWidth, fPicHeight);
     643             :                 }
     644             :             }
     645             :         }
     646             :     }
     647             : 
     648             :     // set style for the image
     649          12 :     XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
     650          12 :     pImage->SetStyleName(pXFStyleManager->AddStyle(pImageStyle)->GetStyleName());
     651             : 
     652             :     // set archor to frame
     653          12 :     pImage->SetAnchorType(enumXFAnchorFrame);
     654             : 
     655             :     // set object name
     656          12 :     LwpAtomHolder& rHolder = this->GetName();
     657          12 :     if ( !rHolder.str().isEmpty() )
     658             :     {
     659           0 :         pImage->SetName(rHolder.str());
     660             :     }
     661             : 
     662             :     // insert image object into array
     663          12 :     m_vXFDrawObjects.push_back(pImage.get());
     664             : 
     665          12 : }
     666             : 
     667             : /**
     668             :  * @descr   Reserve the equation text in a note in the context.
     669             :  */
     670           0 : void LwpGraphicObject::XFConvertEquation(XFContentContainer * pCont)
     671             : {
     672           0 :     sal_uInt8* pGrafData = NULL;
     673           0 :     sal_uInt32 nDataLen = this->GetGrafData(pGrafData);
     674           0 :     if(pGrafData)
     675             :     {
     676             :         //convert equation
     677           0 :         XFParagraph* pXFPara = new XFParagraph;
     678           0 :         pXFPara->Add("Formula:");
     679             :         //add notes
     680           0 :         XFAnnotation* pXFNote = new XFAnnotation;
     681             :         //add equation to comment notes
     682           0 :         XFParagraph* pXFNotePara = new XFParagraph;
     683             :         //equation header text: Times New Roman,
     684             :         //                                18,12,0,0,0,0,0.
     685             :         //                                 .TCIformat{2}
     686             :         //total head length = 45
     687           0 :         sal_uInt32 nBegin = 45;
     688           0 :         sal_uInt32 nEnd = nDataLen -1;
     689             : 
     690           0 :         if(pGrafData[nEnd] == '$' && pGrafData[nEnd-1]!= '\\')
     691             :         {
     692             :             //equation body is contained by '$';
     693           0 :             nBegin++;
     694           0 :             nEnd--;
     695             :         }
     696             : 
     697           0 :         if(nEnd >= nBegin)
     698             :         {
     699           0 :             sal_uInt8* pEquData = new sal_uInt8[nEnd - nBegin + 1];
     700           0 :             for(sal_uInt32 nIndex = 0; nIndex < nEnd - nBegin +1 ; nIndex++)
     701             :             {
     702           0 :                 pEquData[nIndex] = pGrafData[nBegin + nIndex];
     703             :             }
     704           0 :             pXFNotePara->Add(OUString((sal_Char*)pEquData, (nEnd - nBegin + 1), osl_getThreadTextEncoding()));
     705           0 :             delete [] pEquData;
     706             :         }
     707           0 :         pXFNote->Add(pXFNotePara);
     708             : 
     709           0 :         pXFPara->Add(pXFNote);
     710           0 :         pCont->Add(pXFPara);
     711             : 
     712           0 :         delete [] pGrafData;
     713           0 :         pGrafData = NULL;
     714             :     }
     715             : 
     716           0 : }
     717             : 
     718           8 : void LwpGraphicObject::GetGrafOrgSize(double & rWidth, double & rHeight)
     719             : {
     720             :     // original image size
     721           8 :     rWidth = (double)m_Cache.Width/TWIPS_PER_CM;
     722           8 :     rHeight = (double)m_Cache.Height/TWIPS_PER_CM;
     723          14 : }
     724             : 
     725             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10