LCOV - code coverage report
Current view: top level - sc/source/filter/html - htmlexp2.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 91 114 79.8 %
Date: 2015-06-13 12:38:46 Functions: 6 6 100.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           3 : void ScHTMLExport::PrepareGraphics( ScDrawLayer* pDrawLayer, SCTAB nTab,
      44             :         SCCOL nStartCol, SCROW nStartRow,   SCCOL nEndCol, SCROW nEndRow )
      45             : {
      46           3 :     if ( pDrawLayer->HasObjectsInRows( nTab, nStartRow, nEndRow ) )
      47             :     {
      48           2 :         SdrPage* pDrawPage = pDrawLayer->GetPage( static_cast<sal_uInt16>(nTab) );
      49           2 :         if ( pDrawPage )
      50             :         {
      51           2 :             bTabHasGraphics = true;
      52           2 :             FillGraphList( pDrawPage, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
      53           2 :             size_t ListSize = aGraphList.size();
      54           4 :             for ( size_t i = 0; i < ListSize; ++i )
      55             :             {
      56           2 :                 ScHTMLGraphEntry* pE = &aGraphList[ i ];
      57           2 :                 if ( !pE->bInCell )
      58             :                 {   // not all cells: table next to some
      59           0 :                     bTabAlignedLeft = true;
      60           0 :                     break;
      61             :                 }
      62             :             }
      63             :         }
      64             :     }
      65           3 : }
      66             : 
      67           2 : void ScHTMLExport::FillGraphList( const SdrPage* pPage, SCTAB nTab,
      68             :         SCCOL nStartCol, SCROW nStartRow,   SCCOL nEndCol, SCROW nEndRow )
      69             : {
      70           2 :     if ( pPage->GetObjCount() )
      71             :     {
      72           2 :         Rectangle aRect;
      73           2 :         if ( !bAll )
      74           0 :             aRect = pDoc->GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
      75           2 :         SdrObjListIter aIter( *pPage, IM_FLAT );
      76           2 :         SdrObject* pObject = aIter.Next();
      77           6 :         while ( pObject )
      78             :         {
      79           2 :             Rectangle aObjRect = pObject->GetCurrentBoundRect();
      80           2 :             if ( bAll || aRect.IsInside( aObjRect ) )
      81             :             {
      82           2 :                 Size aSpace;
      83           2 :                 ScRange aR = pDoc->GetRange( nTab, aObjRect );
      84             :                 // Rectangle in mm/100
      85           2 :                 Size aSize( MMToPixel( aObjRect.GetSize() ) );
      86             :                 // If the image is somewhere in a merged range we must
      87             :                 // move the anchor to the upper left (THE span cell).
      88           2 :                 pDoc->ExtendOverlapped( aR );
      89           2 :                 SCCOL nCol1 = aR.aStart.Col();
      90           2 :                 SCROW nRow1 = aR.aStart.Row();
      91           2 :                 SCCOL nCol2 = aR.aEnd.Col();
      92           2 :                 SCROW nRow2 = aR.aEnd.Row();
      93             :                 // All cells empty under object?
      94             :                 bool bInCell = (pDoc->GetEmptyLinesInBlock(
      95           2 :                     nCol1, nRow1, nTab, nCol2, nRow2, nTab, DIR_TOP )
      96           2 :                     == static_cast< SCSIZE >( nRow2 - nRow1 ));    // rows-1 !
      97           2 :                 if ( bInCell )
      98             :                 {   // Spacing in spanning cell
      99             :                     Rectangle aCellRect = pDoc->GetMMRect(
     100           2 :                         nCol1, nRow1, nCol2, nRow2, nTab );
     101             :                     aSpace = MMToPixel( Size(
     102           2 :                         aCellRect.GetWidth() - aObjRect.GetWidth(),
     103           4 :                         aCellRect.GetHeight() - aObjRect.GetHeight() ));
     104           2 :                     aSpace.Width() += (nCol2-nCol1) * (nCellSpacing+1);
     105           2 :                     aSpace.Height() += (nRow2-nRow1) * (nCellSpacing+1);
     106           2 :                     aSpace.Width() /= 2;
     107           2 :                     aSpace.Height() /= 2;
     108             :                 }
     109             :                 ScHTMLGraphEntry* pE = new ScHTMLGraphEntry( pObject,
     110           2 :                     aR, aSize, bInCell, aSpace );
     111           2 :                 aGraphList.push_back( pE );
     112             :             }
     113           2 :             pObject = aIter.Next();
     114           2 :         }
     115             :     }
     116           2 : }
     117             : 
     118           1 : void ScHTMLExport::WriteGraphEntry( ScHTMLGraphEntry* pE )
     119             : {
     120           1 :     SdrObject* pObject = pE->pObject;
     121           1 :     OStringBuffer aBuf;
     122           1 :     aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_width).append('=').
     123           2 :         append(static_cast<sal_Int32>(pE->aSize.Width()));
     124           1 :     aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_height).append('=').
     125           2 :         append(static_cast<sal_Int32>(pE->aSize.Height()));
     126           1 :     if ( pE->bInCell )
     127             :     {
     128           1 :         aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_hspace).append('=').
     129           2 :             append(static_cast<sal_Int32>(pE->aSpace.Width()));
     130           1 :         aBuf.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_vspace).append('=').
     131           2 :             append(static_cast<sal_Int32>(pE->aSpace.Height()));
     132             :     }
     133           2 :     OString aOpt = aBuf.makeStringAndClear();
     134           1 :     switch ( pObject->GetObjIdentifier() )
     135             :     {
     136             :         case OBJ_GRAF:
     137             :         {
     138           1 :             const SdrGrafObj* pSGO = static_cast<SdrGrafObj*>(pObject);
     139           1 :             const SdrGrafObjGeoData* pGeo = static_cast<SdrGrafObjGeoData*>(pSGO->GetGeoData());
     140           1 :             sal_uInt16 nMirrorCase = (pGeo->aGeo.nRotationAngle == 18000 ?
     141           1 :                     ( pGeo->bMirrored ? 3 : 4 ) : ( pGeo->bMirrored ? 2 : 1 ));
     142           1 :             bool bHMirr = ( ( nMirrorCase == 2 ) || ( nMirrorCase == 4 ) );
     143           1 :             bool bVMirr = ( ( nMirrorCase == 3 ) || ( nMirrorCase == 4 ) );
     144           1 :             sal_uLong nXOutFlags = 0;
     145           1 :             if ( bHMirr )
     146           0 :                 nXOutFlags |= XOUTBMP_MIRROR_HORZ;
     147           1 :             if ( bVMirr )
     148           0 :                 nXOutFlags |= XOUTBMP_MIRROR_VERT;
     149           1 :             OUString aLinkName;
     150           1 :             if ( pSGO->IsLinkedGraphic() )
     151           0 :                 aLinkName = pSGO->GetFileName();
     152           1 :             WriteImage( aLinkName, pSGO->GetGraphic(), aOpt, nXOutFlags );
     153           1 :             pE->bWritten = true;
     154             :         }
     155           1 :         break;
     156             :         case OBJ_OLE2:
     157             :         {
     158           0 :             const Graphic* pGraphic = static_cast<SdrOle2Obj*>(pObject)->GetGraphic();
     159           0 :             if ( pGraphic )
     160             :             {
     161           0 :                 OUString aLinkName;
     162           0 :                 WriteImage( aLinkName, *pGraphic, aOpt );
     163           0 :                 pE->bWritten = true;
     164             :             }
     165             :         }
     166           0 :         break;
     167             :         default:
     168             :         {
     169             :             Graphic aGraph( SdrExchangeView::GetObjGraphic(
     170           0 :                 pDoc->GetDrawLayer(), pObject ) );
     171           0 :             OUString aLinkName;
     172           0 :             WriteImage( aLinkName, aGraph, aOpt );
     173           0 :             pE->bWritten = true;
     174             :         }
     175           1 :     }
     176           1 : }
     177             : 
     178           1 : void ScHTMLExport::WriteImage( OUString& rLinkName, const Graphic& rGrf,
     179             :             const OString& rImgOptions, sal_uLong nXOutFlags )
     180             : {
     181             :     // Embedded graphic -> create an image file
     182           1 :     if( rLinkName.isEmpty() )
     183             :     {
     184           1 :         if( !aStreamPath.isEmpty() )
     185             :         {
     186             :             // Save as a PNG
     187           1 :             OUString aGrfNm( aStreamPath );
     188           1 :             nXOutFlags |= XOUTBMP_USE_NATIVE_IF_POSSIBLE;
     189             :             sal_uInt16 nErr = XOutBitmap::WriteGraphic( rGrf, aGrfNm,
     190           1 :                 "PNG", nXOutFlags );
     191             : 
     192             :             // If it worked, create a URL for the IMG tag
     193           1 :             if( !nErr )
     194             :             {
     195           2 :                 rLinkName = URIHelper::SmartRel2Abs(
     196             :                         INetURLObject(aBaseURL),
     197             :                         aGrfNm,
     198           1 :                         URIHelper::GetMaybeFileHdl());
     199           1 :                 if ( HasCId() )
     200           0 :                     MakeCIdURL( rLinkName );
     201           1 :             }
     202             :         }
     203             :     }
     204             :     else
     205             :     {
     206             :         // Linked graphic - figure out the URL for the IMG tag
     207           0 :         if( bCopyLocalFileToINet || HasCId() )
     208             :         {
     209           0 :             CopyLocalFileToINet( rLinkName, aStreamPath );
     210           0 :             if ( HasCId() )
     211           0 :                 MakeCIdURL( rLinkName );
     212             :         }
     213             :         else
     214           0 :             rLinkName = URIHelper::SmartRel2Abs(
     215             :                     INetURLObject(aBaseURL),
     216             :                     rLinkName,
     217           0 :                     URIHelper::GetMaybeFileHdl());
     218             :     }
     219             : 
     220             :     // If a URL was set, output the IMG tag.
     221             :     // <IMG SRC="..."[ rImgOptions]>
     222           1 :     if( !rLinkName.isEmpty() )
     223             :     {
     224           1 :         rStrm.WriteChar( '<' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_image ).WriteChar( ' ' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_O_src ).WriteCharPtr( "=\"" );
     225             :         HTMLOutFuncs::Out_String( rStrm, URIHelper::simpleNormalizedMakeRelative(
     226             :                     aBaseURL,
     227           1 :                     rLinkName ), eDestEnc ).WriteChar( '\"' );
     228           1 :         if ( !rImgOptions.isEmpty() )
     229           1 :             rStrm.WriteCharPtr( rImgOptions.getStr() );
     230           1 :         rStrm.WriteChar( '>' ).WriteCharPtr( SAL_NEWLINE_STRING ).WriteCharPtr( GetIndentStr() );
     231             :     }
     232          31 : }
     233             : 
     234             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11