LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/html - htmlexp2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 112 0.0 %
Date: 2012-12-27 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <svx/svditer.hxx>
      21             : #include <svx/svdograf.hxx>
      22             : #include <svx/svdoole2.hxx>
      23             : #include <svx/svdpage.hxx>
      24             : #include <svx/xoutbmp.hxx>
      25             : #include <svx/svdxcgv.hxx>
      26             : #include <sot/exchange.hxx>
      27             : #include <svtools/htmlkywd.hxx>
      28             : #include <svtools/htmlout.hxx>
      29             : #include <svtools/transfer.hxx>
      30             : #include <svtools/embedtransfer.hxx>
      31             : #include <svl/urihelper.hxx>
      32             : #include <tools/urlobj.hxx>
      33             : 
      34             : #include "htmlexp.hxx"
      35             : #include "global.hxx"
      36             : #include "document.hxx"
      37             : #include "drwlayer.hxx"
      38             : #include "ftools.hxx"
      39             : #include <rtl/strbuf.hxx>
      40             : 
      41             : using namespace com::sun::star;
      42             : 
      43             : //------------------------------------------------------------------------
      44             : 
      45           0 : void ScHTMLExport::PrepareGraphics( ScDrawLayer* pDrawLayer, SCTAB nTab,
      46             :         SCCOL nStartCol, SCROW nStartRow,   SCCOL nEndCol, SCROW nEndRow )
      47             : {
      48           0 :     if ( pDrawLayer->HasObjectsInRows( nTab, nStartRow, nEndRow ) )
      49             :     {
      50           0 :         SdrPage* pDrawPage = pDrawLayer->GetPage( static_cast<sal_uInt16>(nTab) );
      51           0 :         if ( pDrawPage )
      52             :         {
      53           0 :             bTabHasGraphics = true;
      54           0 :             FillGraphList( pDrawPage, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
      55           0 :             size_t ListSize = aGraphList.size();
      56           0 :             for ( size_t i = 0; i < ListSize; ++i )
      57             :             {
      58           0 :                 ScHTMLGraphEntry* pE = &aGraphList[ i ];
      59           0 :                 if ( !pE->bInCell )
      60             :                 {   // not all cells: table next to some
      61           0 :                     bTabAlignedLeft = sal_True;
      62           0 :                     break;
      63             :                 }
      64             :             }
      65             :         }
      66             :     }
      67           0 : }
      68             : 
      69             : 
      70           0 : void ScHTMLExport::FillGraphList( const SdrPage* pPage, SCTAB nTab,
      71             :         SCCOL nStartCol, SCROW nStartRow,   SCCOL nEndCol, SCROW nEndRow )
      72             : {
      73           0 :     sal_uLong   nObjCount = pPage->GetObjCount();
      74           0 :     if ( nObjCount )
      75             :     {
      76           0 :         Rectangle aRect;
      77           0 :         if ( !bAll )
      78           0 :             aRect = pDoc->GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
      79           0 :         SdrObjListIter aIter( *pPage, IM_FLAT );
      80           0 :         SdrObject* pObject = aIter.Next();
      81           0 :         while ( pObject )
      82             :         {
      83           0 :             Rectangle aObjRect = pObject->GetCurrentBoundRect();
      84           0 :             if ( bAll || aRect.IsInside( aObjRect ) )
      85             :             {
      86           0 :                 Size aSpace;
      87           0 :                 ScRange aR = pDoc->GetRange( nTab, aObjRect );
      88             :                 // Rectangle in mm/100
      89           0 :                 Size aSize( MMToPixel( aObjRect.GetSize() ) );
      90             :                 // If the image is somewhere in a merged range we must
      91             :                 // move the anchor to the upper left (THE span cell).
      92           0 :                 pDoc->ExtendOverlapped( aR );
      93           0 :                 SCCOL nCol1 = aR.aStart.Col();
      94           0 :                 SCROW nRow1 = aR.aStart.Row();
      95           0 :                 SCCOL nCol2 = aR.aEnd.Col();
      96           0 :                 SCROW nRow2 = aR.aEnd.Row();
      97             :                 // All cells empty under object?
      98             :                 sal_Bool bInCell = (pDoc->GetEmptyLinesInBlock(
      99           0 :                     nCol1, nRow1, nTab, nCol2, nRow2, nTab, DIR_TOP )
     100           0 :                     == static_cast< SCSIZE >( nRow2 - nRow1 ));    // rows-1 !
     101           0 :                 if ( bInCell )
     102             :                 {   // Spacing in spanning cell
     103             :                     Rectangle aCellRect = pDoc->GetMMRect(
     104           0 :                         nCol1, nRow1, nCol2, nRow2, nTab );
     105             :                     aSpace = MMToPixel( Size(
     106           0 :                         aCellRect.GetWidth() - aObjRect.GetWidth(),
     107           0 :                         aCellRect.GetHeight() - aObjRect.GetHeight() ));
     108           0 :                     aSpace.Width() += (nCol2-nCol1) * (nCellSpacing+1);
     109           0 :                     aSpace.Height() += (nRow2-nRow1) * (nCellSpacing+1);
     110           0 :                     aSpace.Width() /= 2;
     111           0 :                     aSpace.Height() /= 2;
     112             :                 }
     113             :                 ScHTMLGraphEntry* pE = new ScHTMLGraphEntry( pObject,
     114           0 :                     aR, aSize, bInCell, aSpace );
     115           0 :                 aGraphList.push_back( pE );
     116             :             }
     117           0 :             pObject = aIter.Next();
     118           0 :         }
     119             :     }
     120           0 : }
     121             : 
     122             : 
     123           0 : void ScHTMLExport::WriteGraphEntry( ScHTMLGraphEntry* pE )
     124             : {
     125           0 :     SdrObject* pObject = pE->pObject;
     126           0 :     rtl::OStringBuffer aBuf;
     127           0 :     aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_width).append('=').
     128           0 :         append(static_cast<sal_Int32>(pE->aSize.Width()));
     129           0 :     aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_height).append('=').
     130           0 :         append(static_cast<sal_Int32>(pE->aSize.Height()));
     131           0 :     if ( pE->bInCell )
     132             :     {
     133           0 :         aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_hspace).append('=').
     134           0 :             append(static_cast<sal_Int32>(pE->aSpace.Width()));
     135           0 :         aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_vspace).append('=').
     136           0 :             append(static_cast<sal_Int32>(pE->aSpace.Height()));
     137             :     }
     138           0 :     rtl::OString aOpt = aBuf.makeStringAndClear();
     139           0 :     switch ( pObject->GetObjIdentifier() )
     140             :     {
     141             :         case OBJ_GRAF:
     142             :         {
     143           0 :             const SdrGrafObj* pSGO = (SdrGrafObj*)pObject;
     144           0 :             const SdrGrafObjGeoData* pGeo = (SdrGrafObjGeoData*)pSGO->GetGeoData();
     145             :             sal_uInt16 nMirrorCase = (pGeo->aGeo.nDrehWink == 18000 ?
     146           0 :                     ( pGeo->bMirrored ? 3 : 4 ) : ( pGeo->bMirrored ? 2 : 1 ));
     147           0 :             sal_Bool bHMirr = ( ( nMirrorCase == 2 ) || ( nMirrorCase == 4 ) );
     148           0 :             sal_Bool bVMirr = ( ( nMirrorCase == 3 ) || ( nMirrorCase == 4 ) );
     149           0 :             sal_uLong nXOutFlags = 0;
     150           0 :             if ( bHMirr )
     151           0 :                 nXOutFlags |= XOUTBMP_MIRROR_HORZ;
     152           0 :             if ( bVMirr )
     153           0 :                 nXOutFlags |= XOUTBMP_MIRROR_VERT;
     154           0 :             String aLinkName;
     155           0 :             if ( pSGO->IsLinkedGraphic() )
     156           0 :                 aLinkName = pSGO->GetFileName();
     157           0 :             WriteImage( aLinkName, pSGO->GetGraphic(), aOpt, nXOutFlags );
     158           0 :             pE->bWritten = sal_True;
     159             :         }
     160           0 :         break;
     161             :         case OBJ_OLE2:
     162             :         {
     163           0 :             Graphic* pGraphic = ((SdrOle2Obj*)pObject)->GetGraphic();
     164           0 :             if ( pGraphic )
     165             :             {
     166           0 :                 String aLinkName;
     167           0 :                 WriteImage( aLinkName, *pGraphic, aOpt );
     168           0 :                 pE->bWritten = sal_True;
     169             :             }
     170             :         }
     171           0 :         break;
     172             :         default:
     173             :         {
     174             :             Graphic aGraph( SdrExchangeView::GetObjGraphic(
     175           0 :                 pDoc->GetDrawLayer(), pObject ) );
     176           0 :             String aLinkName;
     177           0 :             WriteImage( aLinkName, aGraph, aOpt );
     178           0 :             pE->bWritten = sal_True;
     179             :         }
     180           0 :     }
     181           0 : }
     182             : 
     183             : 
     184           0 : void ScHTMLExport::WriteImage( String& rLinkName, const Graphic& rGrf,
     185             :             const rtl::OString& rImgOptions, sal_uLong nXOutFlags )
     186             : {
     187             :     // Embedded graphic -> create an image file
     188           0 :     if( !rLinkName.Len() )
     189             :     {
     190           0 :         if( aStreamPath.Len() > 0 )
     191             :         {
     192             :             // Save as a PNG
     193           0 :             String aGrfNm( aStreamPath );
     194           0 :             nXOutFlags |= XOUTBMP_USE_NATIVE_IF_POSSIBLE;
     195             :             sal_uInt16 nErr = XOutBitmap::WriteGraphic( rGrf, aGrfNm,
     196           0 :                 CREATE_STRING( "PNG" ), nXOutFlags );
     197             : 
     198             :             // If it worked, create a URL for the IMG tag
     199           0 :             if( !nErr )
     200             :             {
     201             :                 rLinkName = URIHelper::SmartRel2Abs(
     202             :                         INetURLObject(aBaseURL),
     203             :                         aGrfNm,
     204           0 :                         URIHelper::GetMaybeFileHdl());
     205           0 :                 if ( HasCId() )
     206           0 :                     MakeCIdURL( rLinkName );
     207           0 :             }
     208             :         }
     209             :     }
     210             :     else
     211             :     {
     212             :         // Linked graphic - figure out the URL for the IMG tag
     213           0 :         if( bCopyLocalFileToINet || HasCId() )
     214             :         {
     215           0 :             CopyLocalFileToINet( rLinkName, aStreamPath );
     216           0 :             if ( HasCId() )
     217           0 :                 MakeCIdURL( rLinkName );
     218             :         }
     219             :         else
     220             :             rLinkName = URIHelper::SmartRel2Abs(
     221             :                     INetURLObject(aBaseURL),
     222             :                     rLinkName,
     223           0 :                     URIHelper::GetMaybeFileHdl());
     224             :     }
     225             : 
     226             :     // If a URL was set, output the IMG tag.
     227             :     // <IMG SRC="..."[ rImgOptions]>
     228           0 :     if( rLinkName.Len() )
     229             :     {
     230           0 :         rStrm << '<' << OOO_STRING_SVTOOLS_HTML_image << ' ' << OOO_STRING_SVTOOLS_HTML_O_src << "=\"";
     231             :         HTMLOutFuncs::Out_String( rStrm, URIHelper::simpleNormalizedMakeRelative(
     232             :                     aBaseURL,
     233           0 :                     rLinkName ), eDestEnc ) << '\"';
     234           0 :         if ( !rImgOptions.isEmpty() )
     235           0 :             rStrm << rImgOptions.getStr();
     236           0 :         rStrm << '>' << sNewLine << GetIndentStr();
     237             :     }
     238           0 : }
     239             : 
     240             : 
     241             : 
     242             : 
     243             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10