LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwpgrfobj.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 186 317 58.7 %
Date: 2012-08-25 Functions: 13 16 81.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 91 340 26.8 %

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

Generated by: LCOV version 1.10