LCOV - code coverage report
Current view: top level - sc/source/filter/html - htmlimp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 64 111 57.7 %
Date: 2012-08-25 Functions: 5 9 55.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 62 244 25.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "scitems.hxx"
      30                 :            : #include <comphelper/string.hxx>
      31                 :            : #include <editeng/eeitem.hxx>
      32                 :            : 
      33                 :            : #include <editeng/lrspitem.hxx>
      34                 :            : #include <editeng/paperinf.hxx>
      35                 :            : #include <editeng/sizeitem.hxx>
      36                 :            : #include <editeng/ulspitem.hxx>
      37                 :            : #include <editeng/boxitem.hxx>
      38                 :            : #include <vcl/svapp.hxx>
      39                 :            : 
      40                 :            : #include "htmlimp.hxx"
      41                 :            : #include "htmlpars.hxx"
      42                 :            : #include "filter.hxx"
      43                 :            : #include "global.hxx"
      44                 :            : #include "document.hxx"
      45                 :            : #include "editutil.hxx"
      46                 :            : #include "stlpool.hxx"
      47                 :            : #include "stlsheet.hxx"
      48                 :            : #include "compiler.hxx"
      49                 :            : #include "rangenam.hxx"
      50                 :            : #include "attrib.hxx"
      51                 :            : #include "ftools.hxx"
      52                 :            : #include "tokenarray.hxx"
      53                 :            : 
      54                 :            : 
      55                 :            : //------------------------------------------------------------------------
      56                 :            : 
      57                 :          3 : FltError ScFormatFilterPluginImpl::ScImportHTML( SvStream &rStream, const String& rBaseURL, ScDocument *pDoc,
      58                 :            :         ScRange& rRange, double nOutputFactor, bool bCalcWidthHeight, SvNumberFormatter* pFormatter,
      59                 :            :         bool bConvertDate )
      60                 :            : {
      61         [ +  - ]:          3 :     ScHTMLImport aImp( pDoc, rBaseURL, rRange, bCalcWidthHeight );
      62         [ +  - ]:          3 :     FltError nErr = (FltError) aImp.Read( rStream, rBaseURL );
      63                 :          3 :     ScRange aR = aImp.GetRange();
      64                 :          3 :     rRange.aEnd = aR.aEnd;
      65         [ +  - ]:          3 :     aImp.WriteToDocument( true, nOutputFactor, pFormatter, bConvertDate );
      66         [ +  - ]:          3 :     return nErr;
      67                 :            : }
      68                 :            : 
      69                 :          0 : ScEEAbsImport *ScFormatFilterPluginImpl::CreateHTMLImport( ScDocument* pDocP, const String& rBaseURL, const ScRange& rRange, bool bCalcWidthHeight )
      70                 :            : {
      71         [ #  # ]:          0 :     return new ScHTMLImport( pDocP, rBaseURL, rRange, bCalcWidthHeight );
      72                 :            : }
      73                 :            : 
      74                 :          3 : ScHTMLImport::ScHTMLImport( ScDocument* pDocP, const String& rBaseURL, const ScRange& rRange, bool bCalcWidthHeight ) :
      75                 :          3 :     ScEEImport( pDocP, rRange )
      76                 :            : {
      77                 :          3 :     Size aPageSize;
      78         [ +  - ]:          3 :     OutputDevice* pDefaultDev = Application::GetDefaultDevice();
      79 [ +  - ][ +  - ]:          3 :     const String& aPageStyle = mpDoc->GetPageStyle( rRange.aStart.Tab() );
      80                 :            :     ScStyleSheet* pStyleSheet = (ScStyleSheet*)mpDoc->
      81 [ +  - ][ +  - ]:          3 :         GetStyleSheetPool()->Find( aPageStyle, SFX_STYLE_FAMILY_PAGE );
      82         [ +  - ]:          3 :     if ( pStyleSheet )
      83                 :            :     {
      84         [ +  - ]:          3 :         const SfxItemSet& rSet = pStyleSheet->GetItemSet();
      85         [ +  - ]:          3 :         const SvxLRSpaceItem* pLRItem = (const SvxLRSpaceItem*) &rSet.Get( ATTR_LRSPACE );
      86                 :          3 :         long nLeftMargin   = pLRItem->GetLeft();
      87                 :          3 :         long nRightMargin  = pLRItem->GetRight();
      88         [ +  - ]:          3 :         const SvxULSpaceItem* pULItem = (const SvxULSpaceItem*) &rSet.Get( ATTR_ULSPACE );
      89                 :          3 :         long nTopMargin    = pULItem->GetUpper();
      90                 :          3 :         long nBottomMargin = pULItem->GetLower();
      91         [ +  - ]:          3 :         aPageSize = ((const SvxSizeItem&) rSet.Get(ATTR_PAGE_SIZE)).GetSize();
      92 [ -  + ][ -  + ]:          3 :         if ( !aPageSize.Width() || !aPageSize.Height() )
                 [ +  - ]
      93                 :            :         {
      94                 :            :             OSL_FAIL("PageSize Null ?!?!?");
      95         [ #  # ]:          0 :             aPageSize = SvxPaperInfo::GetPaperSize( PAPER_A4 );
      96                 :            :         }
      97                 :          3 :         aPageSize.Width() -= nLeftMargin + nRightMargin;
      98                 :          3 :         aPageSize.Height() -= nTopMargin + nBottomMargin;
      99 [ +  - ][ +  - ]:          3 :         aPageSize = pDefaultDev->LogicToPixel( aPageSize, MapMode( MAP_TWIP ) );
                 [ +  - ]
     100                 :            :     }
     101                 :            :     else
     102                 :            :     {
     103                 :            :         OSL_FAIL("kein StyleSheet?!?");
     104                 :            :         aPageSize = pDefaultDev->LogicToPixel(
     105 [ #  # ][ #  # ]:          0 :             SvxPaperInfo::GetPaperSize( PAPER_A4 ), MapMode( MAP_TWIP ) );
         [ #  # ][ #  # ]
     106                 :            :     }
     107         [ -  + ]:          3 :     if( bCalcWidthHeight )
     108 [ #  # ][ #  # ]:          0 :         mpParser = new ScHTMLLayoutParser( mpEngine, rBaseURL, aPageSize, pDocP );
                 [ #  # ]
     109                 :            :     else
     110 [ +  - ][ +  - ]:          3 :         mpParser = new ScHTMLQueryParser( mpEngine, pDocP );
         [ +  - ][ +  - ]
     111                 :          3 : }
     112                 :            : 
     113                 :            : 
     114                 :          3 : ScHTMLImport::~ScHTMLImport()
     115                 :            : {
     116                 :            :     // Reihenfolge wichtig, sonst knallt's irgendwann irgendwo in irgendeinem Dtor!
     117                 :            :     // Ist gewaehrleistet, da ScEEImport Basisklasse ist
     118 [ +  - ][ +  - ]:          3 :     delete (ScHTMLParser*) mpParser;        // vor EditEngine!
     119         [ -  + ]:          3 : }
     120                 :            : 
     121                 :            : 
     122                 :          9 : void ScHTMLImport::InsertRangeName( ScDocument* pDoc, const String& rName, const ScRange& rRange )
     123                 :            : {
     124                 :            :     ScComplexRefData aRefData;
     125                 :          9 :     aRefData.InitRange( rRange );
     126         [ +  - ]:          9 :     ScTokenArray aTokArray;
     127         [ +  - ]:          9 :     aTokArray.AddDoubleReference( aRefData );
     128 [ +  - ][ +  - ]:          9 :     ScRangeData* pRangeData = new ScRangeData( pDoc, rName, aTokArray );
                 [ +  - ]
     129 [ +  - ][ +  - ]:          9 :     pDoc->GetRangeName()->insert( pRangeData );
                 [ +  - ]
     130                 :          9 : }
     131                 :            : 
     132                 :          3 : void ScHTMLImport::WriteToDocument(
     133                 :            :     bool bSizeColsRows, double nOutputFactor, SvNumberFormatter* pFormatter, bool bConvertDate )
     134                 :            : {
     135         [ +  - ]:          3 :     ScEEImport::WriteToDocument( bSizeColsRows, nOutputFactor, pFormatter, bConvertDate );
     136                 :            : 
     137                 :          3 :     const ScHTMLParser* pParser = GetParser();
     138         [ +  - ]:          3 :     const ScHTMLTable* pGlobTable = pParser->GetGlobalTable();
     139         [ +  - ]:          3 :     if( !pGlobTable )
     140                 :          3 :         return;
     141                 :            : 
     142                 :            :     // set cell borders for HTML table cells
     143         [ +  - ]:          3 :     pGlobTable->ApplyCellBorders( mpDoc, maRange.aStart );
     144                 :            : 
     145                 :            :     // correct cell borders for merged cells
     146         [ +  + ]:         24 :     for ( size_t i = 0, n = pParser->ListSize(); i < n; ++i )
     147                 :            :     {
     148         [ +  - ]:         21 :         const ScEEParseEntry* pEntry = pParser->ListEntry( i );
     149 [ +  - ][ -  + ]:         21 :         if( (pEntry->nColOverlap > 1) || (pEntry->nRowOverlap > 1) )
     150                 :            :         {
     151                 :          0 :             SCTAB nTab = maRange.aStart.Tab();
     152         [ #  # ]:          0 :             const ScMergeAttr* pItem = (ScMergeAttr*) mpDoc->GetAttr( pEntry->nCol, pEntry->nRow, nTab, ATTR_MERGE );
     153         [ #  # ]:          0 :             if( pItem->IsMerged() )
     154                 :            :             {
     155                 :          0 :                 SCCOL nColMerge = pItem->GetColMerge();
     156                 :          0 :                 SCROW nRowMerge = pItem->GetRowMerge();
     157                 :            : 
     158                 :            :                 const SvxBoxItem* pToItem = (const SvxBoxItem*)
     159         [ #  # ]:          0 :                     mpDoc->GetAttr( pEntry->nCol, pEntry->nRow, nTab, ATTR_BORDER );
     160         [ #  # ]:          0 :                 SvxBoxItem aNewItem( *pToItem );
     161         [ #  # ]:          0 :                 if( nColMerge > 1 )
     162                 :            :                 {
     163                 :            :                     const SvxBoxItem* pFromItem = (const SvxBoxItem*)
     164         [ #  # ]:          0 :                         mpDoc->GetAttr( pEntry->nCol + nColMerge - 1, pEntry->nRow, nTab, ATTR_BORDER );
     165 [ #  # ][ #  # ]:          0 :                     aNewItem.SetLine( pFromItem->GetLine( BOX_LINE_RIGHT ), BOX_LINE_RIGHT );
     166                 :            :                 }
     167         [ #  # ]:          0 :                 if( nRowMerge > 1 )
     168                 :            :                 {
     169                 :            :                     const SvxBoxItem* pFromItem = (const SvxBoxItem*)
     170         [ #  # ]:          0 :                         mpDoc->GetAttr( pEntry->nCol, pEntry->nRow + nRowMerge - 1, nTab, ATTR_BORDER );
     171 [ #  # ][ #  # ]:          0 :                     aNewItem.SetLine( pFromItem->GetLine( BOX_LINE_BOTTOM ), BOX_LINE_BOTTOM );
     172                 :            :                 }
     173 [ #  # ][ #  # ]:          0 :                 mpDoc->ApplyAttr( pEntry->nCol, pEntry->nRow, nTab, aNewItem );
     174                 :            :             }
     175                 :            :         }
     176                 :            :     }
     177                 :            : 
     178                 :            :     // create ranges for HTML tables
     179                 :            :      // 1 - entire document
     180                 :          3 :     ScRange aNewRange( maRange.aStart );
     181 [ +  - ][ +  - ]:          3 :     aNewRange.aEnd.IncCol( static_cast<SCsCOL>(pGlobTable->GetDocSize( tdCol )) - 1 );
     182 [ +  - ][ +  - ]:          3 :     aNewRange.aEnd.IncRow( pGlobTable->GetDocSize( tdRow ) - 1 );
     183 [ +  - ][ +  - ]:          3 :     InsertRangeName( mpDoc, ScfTools::GetHTMLDocName(), aNewRange );
     184                 :            : 
     185                 :            :     // 2 - all tables
     186 [ +  - ][ +  - ]:          3 :     InsertRangeName( mpDoc, ScfTools::GetHTMLTablesName(), ScRange( maRange.aStart ) );
     187                 :            : 
     188                 :            :     // 3 - single tables
     189                 :          3 :     SCsCOL nColDiff = (SCsCOL)maRange.aStart.Col();
     190                 :          3 :     SCsROW nRowDiff = (SCsROW)maRange.aStart.Row();
     191                 :          3 :     SCsTAB nTabDiff = (SCsTAB)maRange.aStart.Tab();
     192                 :            : 
     193                 :          3 :     ScHTMLTable* pTable = NULL;
     194                 :          3 :     ScHTMLTableId nTableId = SC_HTML_GLOBAL_TABLE;
     195 [ +  - ][ +  + ]:          6 :     while( (pTable = pGlobTable->FindNestedTable( ++nTableId )) != 0 )
     196                 :            :     {
     197         [ +  - ]:          3 :         pTable->GetDocRange( aNewRange );
     198         [ +  - ]:          3 :         aNewRange.Move( nColDiff, nRowDiff, nTabDiff );
     199                 :            :         // insert table number as name
     200 [ +  - ][ +  - ]:          3 :         InsertRangeName( mpDoc, ScfTools::GetNameFromHTMLIndex( nTableId ), aNewRange );
                 [ +  - ]
     201                 :            :         // insert table id as name
     202         [ -  + ]:          3 :         if (!pTable->GetTableName().isEmpty())
     203                 :            :         {
     204 [ #  # ][ #  # ]:          0 :             String aName( ScfTools::GetNameFromHTMLName( pTable->GetTableName() ) );
                 [ #  # ]
     205 [ #  # ][ #  # ]:          0 :             if (!mpDoc->GetRangeName()->findByUpperName(ScGlobal::pCharClass->uppercase(aName)))
         [ #  # ][ #  # ]
                 [ #  # ]
     206 [ #  # ][ #  # ]:          0 :                 InsertRangeName( mpDoc, aName, aNewRange );
     207                 :            :         }
     208                 :            :     }
     209                 :            : }
     210                 :            : 
     211                 :          0 : String ScFormatFilterPluginImpl::GetHTMLRangeNameList( ScDocument* pDoc, const String& rOrigName )
     212                 :            : {
     213                 :          0 :     return ScHTMLImport::GetHTMLRangeNameList( pDoc, rOrigName );
     214                 :            : }
     215                 :            : 
     216                 :          0 : String ScHTMLImport::GetHTMLRangeNameList( ScDocument* pDoc, const String& rOrigName )
     217                 :            : {
     218                 :            :     OSL_ENSURE( pDoc, "ScHTMLImport::GetHTMLRangeNameList - missing document" );
     219                 :            : 
     220         [ #  # ]:          0 :     String aNewName;
     221         [ #  # ]:          0 :     ScRangeName* pRangeNames = pDoc->GetRangeName();
     222         [ #  # ]:          0 :     ScRangeList aRangeList;
     223 [ #  # ][ #  # ]:          0 :     xub_StrLen nTokenCnt = comphelper::string::getTokenCount(rOrigName, ';');
     224                 :          0 :     xub_StrLen nStringIx = 0;
     225         [ #  # ]:          0 :     for( xub_StrLen nToken = 0; nToken < nTokenCnt; nToken++ )
     226                 :            :     {
     227         [ #  # ]:          0 :         String aToken( rOrigName.GetToken( 0, ';', nStringIx ) );
     228 [ #  # ][ #  # ]:          0 :         if( pRangeNames && ScfTools::IsHTMLTablesName( aToken ) )
         [ #  # ][ #  # ]
     229                 :            :         {   // build list with all HTML tables
     230                 :          0 :             sal_uLong nIndex = 1;
     231                 :          0 :             bool bLoop = true;
     232         [ #  # ]:          0 :             while( bLoop )
     233                 :            :             {
     234 [ #  # ][ #  # ]:          0 :                 aToken = ScfTools::GetNameFromHTMLIndex( nIndex++ );
                 [ #  # ]
     235 [ #  # ][ #  # ]:          0 :                 const ScRangeData* pRangeData = pRangeNames->findByUpperName(ScGlobal::pCharClass->uppercase(aToken));
                 [ #  # ]
     236         [ #  # ]:          0 :                 if (pRangeData)
     237                 :            :                 {
     238                 :          0 :                     ScRange aRange;
     239 [ #  # ][ #  # ]:          0 :                     if( pRangeData->IsReference( aRange ) && !aRangeList.In( aRange ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     240                 :            :                     {
     241         [ #  # ]:          0 :                         ScGlobal::AddToken( aNewName, aToken, ';' );
     242         [ #  # ]:          0 :                         aRangeList.Append( aRange );
     243                 :            :                     }
     244                 :            :                 }
     245                 :            :                 else
     246                 :          0 :                     bLoop = false;
     247                 :            :             }
     248                 :            :         }
     249                 :            :         else
     250         [ #  # ]:          0 :             ScGlobal::AddToken( aNewName, aToken, ';' );
     251         [ #  # ]:          0 :     }
     252         [ #  # ]:          0 :     return aNewName;
     253                 :            : }
     254                 :            : 
     255                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10