LCOV - code coverage report
Current view: top level - sc/source/filter/rtf - eeimpars.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 342 0.0 %
Date: 2014-04-14 Functions: 0 11 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 "scitems.hxx"
      21             : #include <editeng/eeitem.hxx>
      22             : 
      23             : 
      24             : #include <editeng/adjustitem.hxx>
      25             : #include <editeng/editobj.hxx>
      26             : #include <editeng/editview.hxx>
      27             : #include <editeng/escapementitem.hxx>
      28             : #include <editeng/langitem.hxx>
      29             : #include <svx/svdograf.hxx>
      30             : #include <svx/svdpage.hxx>
      31             : #include <editeng/scripttypeitem.hxx>
      32             : #include <svtools/htmlcfg.hxx>
      33             : #include <sfx2/sfxhtml.hxx>
      34             : #include <svtools/parhtml.hxx>
      35             : #include <svl/zforlist.hxx>
      36             : #include <vcl/virdev.hxx>
      37             : #include <vcl/svapp.hxx>
      38             : #include <unotools/syslocale.hxx>
      39             : #include <unotools/charclass.hxx>
      40             : #include <comphelper/string.hxx>
      41             : 
      42             : #include "eeimport.hxx"
      43             : #include "global.hxx"
      44             : #include "document.hxx"
      45             : #include "editutil.hxx"
      46             : #include "stlsheet.hxx"
      47             : #include "docpool.hxx"
      48             : #include "attrib.hxx"
      49             : #include "patattr.hxx"
      50             : #include "eeparser.hxx"
      51             : #include "drwlayer.hxx"
      52             : #include "rangenam.hxx"
      53             : #include "progress.hxx"
      54             : #include "stringutil.hxx"
      55             : #include <rowheightcontext.hxx>
      56             : 
      57             : #include "globstr.hrc"
      58             : 
      59             : #include <boost/scoped_ptr.hpp>
      60             : 
      61             : // in fuins1.cxx
      62             : extern void ScLimitSizeOnDrawPage( Size& rSize, Point& rPos, const Size& rPage );
      63             : 
      64           0 : ScEEImport::ScEEImport( ScDocument* pDocP, const ScRange& rRange ) :
      65             :     maRange( rRange ),
      66             :     mpDoc( pDocP ),
      67           0 :     mpParser( NULL )
      68             : {
      69             :     const ScPatternAttr* pPattern = mpDoc->GetPattern(
      70           0 :         maRange.aStart.Col(), maRange.aStart.Row(), maRange.aStart.Tab() );
      71           0 :     mpEngine = new ScTabEditEngine(*pPattern, mpDoc->GetEditPool(), mpDoc->GetEditPool());
      72           0 :     mpEngine->SetUpdateMode( false );
      73           0 :     mpEngine->EnableUndo( false );
      74           0 : }
      75             : 
      76             : 
      77           0 : ScEEImport::~ScEEImport()
      78             : {
      79             :     // Sequence important, or else we crash in some dtor!
      80             :     // Is guaranteed as ScEEImport is base class
      81           0 :     delete mpEngine; // After Parser!
      82           0 : }
      83             : 
      84             : 
      85           0 : sal_uLong ScEEImport::Read( SvStream& rStream, const OUString& rBaseURL )
      86             : {
      87           0 :     sal_uLong nErr = mpParser->Read( rStream, rBaseURL );
      88             : 
      89             :     SCCOL nEndCol;
      90             :     SCROW nEndRow;
      91           0 :     mpParser->GetDimensions( nEndCol, nEndRow );
      92           0 :     if ( nEndCol != 0 )
      93             :     {
      94           0 :         nEndCol += maRange.aStart.Col() - 1;
      95           0 :         if ( nEndCol > MAXCOL )
      96           0 :             nEndCol = MAXCOL;
      97             :     }
      98             :     else
      99           0 :         nEndCol = maRange.aStart.Col();
     100           0 :     if ( nEndRow != 0 )
     101             :     {
     102           0 :         nEndRow += maRange.aStart.Row() - 1;
     103           0 :         if ( nEndRow > MAXROW )
     104           0 :             nEndRow = MAXROW;
     105             :     }
     106             :     else
     107           0 :         nEndRow = maRange.aStart.Row();
     108           0 :     maRange.aEnd.Set( nEndCol, nEndRow, maRange.aStart.Tab() );
     109             : 
     110           0 :     return nErr;
     111             : }
     112             : 
     113             : 
     114           0 : void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNumberFormatter* pFormatter, bool bConvertDate )
     115             : {
     116           0 :     ScProgress* pProgress = new ScProgress( mpDoc->GetDocumentShell(),
     117           0 :         ScGlobal::GetRscString( STR_LOAD_DOC ), mpParser->ListSize() );
     118           0 :     sal_uLong nProgress = 0;
     119             : 
     120             :     SCCOL nStartCol, nEndCol;
     121             :         SCROW nStartRow, nEndRow;
     122             :         SCTAB nTab;
     123             :         SCROW nOverlapRowMax, nLastMergedRow;
     124             :         SCCOL nMergeColAdd;
     125           0 :     nStartCol = maRange.aStart.Col();
     126           0 :     nStartRow = maRange.aStart.Row();
     127           0 :     nTab = maRange.aStart.Tab();
     128           0 :     nEndCol = maRange.aEnd.Col();
     129           0 :     nEndRow = maRange.aEnd.Row();
     130           0 :     nOverlapRowMax = 0;
     131           0 :     nMergeColAdd = 0;
     132           0 :     nLastMergedRow = SCROW_MAX;
     133           0 :     bool bHasGraphics = false;
     134             :     ScEEParseEntry* pE;
     135           0 :     if (!pFormatter)
     136           0 :         pFormatter = mpDoc->GetFormatTable();
     137           0 :     bool bNumbersEnglishUS = false;
     138           0 :     if (pFormatter->GetLanguage() == LANGUAGE_SYSTEM)
     139             :     {
     140             :         // Automatic language option selected.  Check for the global 'use US English' option.
     141           0 :         SvxHtmlOptions aOpt;
     142           0 :         bNumbersEnglishUS = aOpt.IsNumbersEnglishUS();
     143             :     }
     144           0 :     ScDocumentPool* pDocPool = mpDoc->GetPool();
     145           0 :     ScRangeName* pRangeNames = mpDoc->GetRangeName();
     146           0 :     for ( size_t i = 0, n = mpParser->ListSize(); i < n; ++i )
     147             :     {
     148           0 :         pE = mpParser->ListEntry( i );
     149           0 :         SCROW nRow = nStartRow + pE->nRow;
     150           0 :         if ( nRow != nLastMergedRow )
     151           0 :             nMergeColAdd = 0;
     152           0 :         SCCOL nCol = nStartCol + pE->nCol + nMergeColAdd;
     153             :         // Determine RowMerge
     154             :         // Pure ColMerge and ColMerge of the first MergeRow already done during parsing
     155           0 :         if ( nRow <= nOverlapRowMax )
     156             :         {
     157           0 :             while ( nCol <= MAXCOL && mpDoc->HasAttrib( nCol, nRow, nTab,
     158           0 :                 nCol, nRow, nTab, HASATTR_OVERLAPPED ) )
     159             :             {
     160           0 :                 nCol++;
     161           0 :                 nMergeColAdd++;
     162             :             }
     163           0 :             nLastMergedRow = nRow;
     164             :         }
     165             :         // Add for second run
     166           0 :         pE->nCol = nCol;
     167           0 :         pE->nRow = nRow;
     168           0 :         if ( ValidCol(nCol) && ValidRow(nRow) )
     169             :         {
     170           0 :             SfxItemSet aSet = mpEngine->GetAttribs( pE->aSel );
     171             :             // Remove default: we set left/right ourselves depending on Text or
     172             :             // Number
     173             :             // EditView.GetAttribs always returns complete Set filled with
     174             :             // defaults
     175           0 :             const SfxPoolItem& rItem = aSet.Get( EE_PARA_JUST );
     176           0 :             if ( ((const SvxAdjustItem&)rItem).GetAdjust() == SVX_ADJUST_LEFT )
     177           0 :                 aSet.ClearItem( EE_PARA_JUST );
     178             : 
     179             :             // Test whether simple String without mixed attributes
     180           0 :             sal_Bool bSimple = ( pE->aSel.nStartPara == pE->aSel.nEndPara );
     181           0 :             for (sal_uInt16 nId = EE_CHAR_START; nId <= EE_CHAR_END && bSimple; nId++)
     182             :             {
     183           0 :                 const SfxPoolItem* pItem = 0;
     184           0 :                 SfxItemState eState = aSet.GetItemState( nId, true, &pItem );
     185           0 :                 if (eState == SFX_ITEM_DONTCARE)
     186           0 :                     bSimple = false;
     187           0 :                 else if (eState == SFX_ITEM_SET)
     188             :                 {
     189           0 :                     if ( nId == EE_CHAR_ESCAPEMENT ) // Super-/Subscript always via EE
     190             :                     {
     191           0 :                         if ( (SvxEscapement)((const SvxEscapementItem*)pItem)->GetEnumValue()
     192             :                                 != SVX_ESCAPEMENT_OFF )
     193           0 :                             bSimple = false;
     194             :                     }
     195             :                 }
     196             :             }
     197           0 :             if ( bSimple )
     198             :             {   //  Contains field commands?
     199           0 :                 SfxItemState eFieldState = aSet.GetItemState( EE_FEATURE_FIELD, false );
     200           0 :                 if ( eFieldState == SFX_ITEM_DONTCARE || eFieldState == SFX_ITEM_SET )
     201           0 :                     bSimple = false;
     202             :             }
     203             : 
     204             :             // HTML
     205           0 :             OUString aValStr, aNumStr;
     206             :             double fVal;
     207           0 :             sal_uInt32 nNumForm = 0;
     208           0 :             LanguageType eNumLang = LANGUAGE_NONE;
     209           0 :             if ( pE->pNumStr )
     210             :             {   // SDNUM needs to be if SDVAL
     211           0 :                 aNumStr = *pE->pNumStr;
     212           0 :                 if ( pE->pValStr )
     213           0 :                     aValStr = *pE->pValStr;
     214             :                 fVal = SfxHTMLParser::GetTableDataOptionsValNum(
     215           0 :                     nNumForm, eNumLang, aValStr, aNumStr, *pFormatter );
     216             :             }
     217             : 
     218             :             // Set attributes
     219           0 :             ScPatternAttr aAttr( pDocPool );
     220           0 :             aAttr.GetFromEditItemSet( &aSet );
     221           0 :             SfxItemSet& rSet = aAttr.GetItemSet();
     222           0 :             if (!aNumStr.isEmpty())
     223             :             {
     224           0 :                 rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumForm ) );
     225           0 :                 rSet.Put( SvxLanguageItem( eNumLang, ATTR_LANGUAGE_FORMAT ) );
     226             :             }
     227           0 :             const SfxItemSet& rESet = pE->aItemSet;
     228           0 :             if ( rESet.Count() )
     229             :             {
     230             :                 const SfxPoolItem* pItem;
     231           0 :                 if ( rESet.GetItemState( ATTR_BACKGROUND, false, &pItem) == SFX_ITEM_SET )
     232           0 :                     rSet.Put( *pItem );
     233           0 :                 if ( rESet.GetItemState( ATTR_BORDER, false, &pItem) == SFX_ITEM_SET )
     234           0 :                     rSet.Put( *pItem );
     235           0 :                 if ( rESet.GetItemState( ATTR_SHADOW, false, &pItem) == SFX_ITEM_SET )
     236           0 :                     rSet.Put( *pItem );
     237             :                 // HTML
     238           0 :                 if ( rESet.GetItemState( ATTR_HOR_JUSTIFY, false, &pItem) == SFX_ITEM_SET )
     239           0 :                     rSet.Put( *pItem );
     240           0 :                 if ( rESet.GetItemState( ATTR_VER_JUSTIFY, false, &pItem) == SFX_ITEM_SET )
     241           0 :                     rSet.Put( *pItem );
     242           0 :                 if ( rESet.GetItemState( ATTR_LINEBREAK, false, &pItem) == SFX_ITEM_SET )
     243           0 :                     rSet.Put( *pItem );
     244           0 :                 if ( rESet.GetItemState( ATTR_FONT_COLOR, false, &pItem) == SFX_ITEM_SET )
     245           0 :                     rSet.Put( *pItem );
     246           0 :                 if ( rESet.GetItemState( ATTR_FONT_UNDERLINE, false, &pItem) == SFX_ITEM_SET )
     247           0 :                     rSet.Put( *pItem );
     248             :                 // HTML LATIN/CJK/CTL script type dependent
     249             :                 const SfxPoolItem* pFont;
     250           0 :                 if ( rESet.GetItemState( ATTR_FONT, false, &pFont) != SFX_ITEM_SET )
     251           0 :                     pFont = 0;
     252             :                 const SfxPoolItem* pHeight;
     253           0 :                 if ( rESet.GetItemState( ATTR_FONT_HEIGHT, false, &pHeight) != SFX_ITEM_SET )
     254           0 :                     pHeight = 0;
     255             :                 const SfxPoolItem* pWeight;
     256           0 :                 if ( rESet.GetItemState( ATTR_FONT_WEIGHT, false, &pWeight) != SFX_ITEM_SET )
     257           0 :                     pWeight = 0;
     258             :                 const SfxPoolItem* pPosture;
     259           0 :                 if ( rESet.GetItemState( ATTR_FONT_POSTURE, false, &pPosture) != SFX_ITEM_SET )
     260           0 :                     pPosture = 0;
     261             :                 // Number format
     262           0 :                 const SfxPoolItem* pNumFmt = NULL;
     263           0 :                 if ( rESet.GetItemState(ATTR_VALUE_FORMAT, false, &pNumFmt) == SFX_ITEM_SET )
     264           0 :                     rSet.Put(*pNumFmt);
     265           0 :                 if ( pFont || pHeight || pWeight || pPosture )
     266             :                 {
     267           0 :                     OUString aStr( mpEngine->GetText( pE->aSel ) );
     268           0 :                     sal_uInt8 nScriptType = mpDoc->GetStringScriptType( aStr );
     269             :                     const sal_uInt8 nScripts[3] = { SCRIPTTYPE_LATIN,
     270           0 :                         SCRIPTTYPE_ASIAN, SCRIPTTYPE_COMPLEX };
     271           0 :                     for ( sal_uInt8 j=0; j<3; ++j )
     272             :                     {
     273           0 :                         if ( nScriptType & nScripts[j] )
     274             :                         {
     275           0 :                             if ( pFont )
     276             :                                 rSet.Put( *pFont, ScGlobal::GetScriptedWhichID(
     277           0 :                                             nScripts[j], ATTR_FONT ));
     278           0 :                             if ( pHeight )
     279             :                                 rSet.Put( *pHeight, ScGlobal::GetScriptedWhichID(
     280           0 :                                             nScripts[j], ATTR_FONT_HEIGHT ));
     281           0 :                             if ( pWeight )
     282             :                                 rSet.Put( *pWeight, ScGlobal::GetScriptedWhichID(
     283           0 :                                             nScripts[j], ATTR_FONT_WEIGHT ));
     284           0 :                             if ( pPosture )
     285             :                                 rSet.Put( *pPosture, ScGlobal::GetScriptedWhichID(
     286           0 :                                             nScripts[j], ATTR_FONT_POSTURE ));
     287             :                         }
     288           0 :                     }
     289             :                 }
     290             :             }
     291           0 :             if ( pE->nColOverlap > 1 || pE->nRowOverlap > 1 )
     292             :             {   // Merged cells, with SfxItemSet.Put() is faster than
     293             :                 // with ScDocument.DoMerge() afterwards
     294           0 :                 ScMergeAttr aMerge( pE->nColOverlap, pE->nRowOverlap );
     295           0 :                 rSet.Put( aMerge );
     296           0 :                 SCROW nRO = 0;
     297           0 :                 if ( pE->nColOverlap > 1 )
     298             :                     mpDoc->ApplyFlagsTab( nCol+1, nRow,
     299             :                         nCol + pE->nColOverlap - 1, nRow, nTab,
     300           0 :                         SC_MF_HOR );
     301           0 :                 if ( pE->nRowOverlap > 1 )
     302             :                 {
     303           0 :                     nRO = nRow + pE->nRowOverlap - 1;
     304             :                     mpDoc->ApplyFlagsTab( nCol, nRow+1,
     305             :                         nCol, nRO , nTab,
     306           0 :                         SC_MF_VER );
     307           0 :                     if ( nRO > nOverlapRowMax )
     308           0 :                         nOverlapRowMax = nRO;
     309             :                 }
     310           0 :                 if ( pE->nColOverlap > 1 && pE->nRowOverlap > 1 )
     311             :                     mpDoc->ApplyFlagsTab( nCol+1, nRow+1,
     312             :                         nCol + pE->nColOverlap - 1, nRO, nTab,
     313           0 :                         SC_MF_HOR | SC_MF_VER );
     314             :             }
     315             :             const ScStyleSheet* pStyleSheet =
     316           0 :                 mpDoc->GetPattern( nCol, nRow, nTab )->GetStyleSheet();
     317           0 :             aAttr.SetStyleSheet( (ScStyleSheet*)pStyleSheet );
     318           0 :             mpDoc->SetPattern( nCol, nRow, nTab, aAttr, true );
     319             : 
     320             :             // Add data
     321           0 :             if (bSimple)
     322             :             {
     323           0 :                 ScSetStringParam aParam;
     324           0 :                 aParam.mpNumFormatter = pFormatter;
     325           0 :                 aParam.mbDetectNumberFormat = true;
     326           0 :                 aParam.meSetTextNumFormat = ScSetStringParam::SpecialNumberOnly;
     327           0 :                 aParam.mbHandleApostrophe = false;
     328             : 
     329           0 :                 if (!aValStr.isEmpty())
     330           0 :                     mpDoc->SetValue( nCol, nRow, nTab, fVal );
     331           0 :                 else if ( !pE->aSel.HasRange() )
     332             :                 {
     333             :                     // maybe ALT text of IMG or similar
     334           0 :                     mpDoc->SetString( nCol, nRow, nTab, pE->aAltText, &aParam );
     335             :                     // If SelRange is completely empty, the succeeding text can be in the same paragraph!
     336             :                 }
     337             :                 else
     338             :                 {
     339           0 :                     OUString aStr;
     340           0 :                     if( pE->bEntirePara )
     341             :                     {
     342           0 :                         aStr = mpEngine->GetText( pE->aSel.nStartPara );
     343             :                     }
     344             :                     else
     345             :                     {
     346           0 :                         aStr = comphelper::string::strip(mpEngine->GetText(pE->aSel), ' ');
     347             :                     }
     348             : 
     349           0 :                     bool bTextFormat = false;
     350             : 
     351           0 :                     const SfxPoolItem* pNumFmt = NULL;
     352           0 :                     if (rSet.GetItemState(ATTR_VALUE_FORMAT, false, &pNumFmt) == SFX_ITEM_SET)
     353             :                     {
     354           0 :                         sal_uInt32 nNumFmt = static_cast<const SfxUInt32Item*>(pNumFmt)->GetValue();
     355           0 :                         sal_uInt16 nType = pFormatter->GetType(nNumFmt);
     356           0 :                         if (nType == NUMBERFORMAT_TEXT)
     357             :                             // Format is set to Text.
     358           0 :                             bTextFormat = true;
     359             :                     }
     360             : 
     361             :                     // TODO: RTF import should follow the language tag,
     362             :                     // currently this follows the HTML options for both, HTML
     363             :                     // and RTF.
     364           0 :                     if (bNumbersEnglishUS)
     365             :                     {
     366           0 :                         pFormatter->ChangeIntl( LANGUAGE_ENGLISH_US);
     367           0 :                         sal_uInt32 nIndex = pFormatter->GetStandardIndex( LANGUAGE_ENGLISH_US);
     368           0 :                         double fEnVal = 0.0;
     369           0 :                         if (pFormatter->IsNumberFormat( aStr, nIndex, fEnVal))
     370             :                         {
     371             :                             sal_uInt32 nNewIndex =
     372             :                                 pFormatter->GetFormatForLanguageIfBuiltIn(
     373           0 :                                         nIndex, LANGUAGE_SYSTEM);
     374             :                             OSL_ENSURE( nNewIndex != nIndex, "ScEEImport::WriteToDocument: NumbersEnglishUS not a built-in format?");
     375           0 :                             pFormatter->GetInputLineString( fEnVal, nNewIndex, aStr);
     376             :                         }
     377             :                         else
     378           0 :                             bTextFormat = true;
     379           0 :                         pFormatter->ChangeIntl( LANGUAGE_SYSTEM);
     380             :                     }
     381             : 
     382             :                     //  #105460#, #i4180# String cells can't contain tabs or linebreaks
     383             :                     //  -> replace with spaces
     384           0 :                     aStr = aStr.replaceAll( "\t", " " );
     385           0 :                     aStr = aStr.replaceAll( "\n", " " );
     386             : 
     387           0 :                     if (bTextFormat)
     388             :                     {
     389           0 :                         aParam.mbDetectNumberFormat = false;
     390           0 :                         aParam.meSetTextNumFormat = ScSetStringParam::Always;
     391             :                     }
     392             :                     else
     393           0 :                         aParam.mbDetectNumberFormat = bConvertDate;
     394             : 
     395           0 :                     mpDoc->SetString(nCol, nRow, nTab, aStr, &aParam);
     396             :                 }
     397             :             }
     398             :             else
     399             :             {
     400             :                 // The cell will own the text object instance.
     401           0 :                 mpDoc->SetEditText(ScAddress(nCol,nRow,nTab), mpEngine->CreateTextObject(pE->aSel));
     402             :             }
     403           0 :             if ( pE->maImageList.size() )
     404           0 :                 bHasGraphics |= GraphicSize( nCol, nRow, nTab, pE );
     405           0 :             if ( pE->pName )
     406             :             {   // Anchor Name => RangeName
     407           0 :                 if (!pRangeNames->findByUpperName(ScGlobal::pCharClass->uppercase(*pE->pName)))
     408             :                 {
     409             :                     ScRangeData* pData = new ScRangeData( mpDoc, *pE->pName,
     410           0 :                         ScAddress( nCol, nRow, nTab ) );
     411           0 :                     pRangeNames->insert( pData );
     412             :                 }
     413           0 :             }
     414             :         }
     415           0 :         pProgress->SetStateOnPercent( ++nProgress );
     416             :     }
     417           0 :     if ( bSizeColsRows )
     418             :     {
     419             :         // Column widths
     420           0 :         ColWidthsMap& rColWidths = mpParser->GetColWidths();
     421           0 :         if ( !rColWidths.empty() )
     422             :         {
     423           0 :             nProgress = 0;
     424           0 :             pProgress->SetState( nProgress, nEndCol - nStartCol + 1 );
     425           0 :             for ( SCCOL nCol = nStartCol; nCol <= nEndCol; nCol++ )
     426             :             {
     427           0 :                 sal_uInt16 nWidth = 0;
     428           0 :                 ColWidthsMap::const_iterator it = rColWidths.find( nCol );
     429           0 :                 if ( it != rColWidths.end() )
     430           0 :                     nWidth = it->second;
     431           0 :                 if ( nWidth )
     432           0 :                     mpDoc->SetColWidth( nCol, nTab, nWidth );
     433           0 :                 pProgress->SetState( ++nProgress );
     434             :             }
     435             :         }
     436           0 :         DELETEZ( pProgress ); // SetOptimalHeight has its own ProgressBar
     437             :         // Adjust line height, base is 100% zoom
     438           0 :         Fraction aZoom( 1, 1 );
     439             :         // Factor is printer to display ratio
     440           0 :         double nPPTX = ScGlobal::nScreenPPTX * (double) aZoom / nOutputFactor;
     441           0 :         double nPPTY = ScGlobal::nScreenPPTY * (double) aZoom;
     442           0 :         VirtualDevice aVirtDev;
     443           0 :         sc::RowHeightContext aCxt(nPPTX, nPPTY, aZoom, aZoom, &aVirtDev);
     444           0 :         aCxt.setExtraHeight(ScGlobal::nLastRowHeightExtra);
     445           0 :         mpDoc->SetOptimalHeight(aCxt, 0, nEndRow, 0);
     446             : 
     447           0 :         if ( !maRowHeights.empty() )
     448             :         {
     449           0 :             for ( SCROW nRow = nStartRow; nRow <= nEndRow; nRow++ )
     450             :             {
     451           0 :                 RowHeightMap::const_iterator it = maRowHeights.find( nRow );
     452           0 :                 sal_uInt16 nHeight = it == maRowHeights.end() ? 0 : it->second;
     453           0 :                 if ( nHeight > mpDoc->GetRowHeight( nRow, nTab ) )
     454           0 :                     mpDoc->SetRowHeight( nRow, nTab, nHeight );
     455             :             }
     456           0 :         }
     457             :     }
     458           0 :     if ( bHasGraphics )
     459             :     {
     460             :         // Insert graphics
     461           0 :         for ( size_t i = 0, nListSize = mpParser->ListSize(); i < nListSize; ++i )
     462             :         {
     463           0 :             pE = mpParser->ListEntry( i );
     464           0 :             if ( !pE->maImageList.empty() )
     465             :             {
     466           0 :                 SCCOL nCol = pE->nCol;
     467           0 :                 SCROW nRow = pE->nRow;
     468           0 :                 if ( ValidCol(nCol) && ValidRow(nRow) )
     469           0 :                     InsertGraphic( nCol, nRow, nTab, pE );
     470             :             }
     471             :         }
     472             :     }
     473           0 :     if ( pProgress )
     474           0 :         delete pProgress;
     475           0 : }
     476             : 
     477             : 
     478           0 : bool ScEEImport::GraphicSize( SCCOL nCol, SCROW nRow, SCTAB /*nTab*/, ScEEParseEntry* pE )
     479             : {
     480           0 :     if ( !pE->maImageList.size() )
     481           0 :         return false;
     482           0 :     bool bHasGraphics = false;
     483           0 :     OutputDevice* pDefaultDev = Application::GetDefaultDevice();
     484             :     long nWidth, nHeight;
     485           0 :     nWidth = nHeight = 0;
     486           0 :     sal_Char nDir = nHorizontal;
     487           0 :     for ( sal_uInt32 i = 0; i < pE->maImageList.size() ; ++i )
     488             :     {
     489           0 :         ScHTMLImage* pI = &pE->maImageList[ i ];
     490           0 :         if ( pI->pGraphic )
     491           0 :             bHasGraphics = true;
     492           0 :         Size aSizePix = pI->aSize;
     493           0 :         aSizePix.Width() += 2 * pI->aSpace.X();
     494           0 :         aSizePix.Height() += 2 * pI->aSpace.Y();
     495           0 :         Size aLogicSize = pDefaultDev->PixelToLogic( aSizePix, MapMode( MAP_TWIP ) );
     496           0 :         if ( nDir & nHorizontal )
     497           0 :             nWidth += aLogicSize.Width();
     498           0 :         else if ( nWidth < aLogicSize.Width() )
     499           0 :             nWidth = aLogicSize.Width();
     500           0 :         if ( nDir & nVertical )
     501           0 :             nHeight += aLogicSize.Height();
     502           0 :         else if ( nHeight < aLogicSize.Height() )
     503           0 :             nHeight = aLogicSize.Height();
     504           0 :         nDir = pI->nDir;
     505             :     }
     506             :     // Column widths
     507           0 :     ColWidthsMap& rColWidths = mpParser->GetColWidths();
     508           0 :     long nThisWidth = 0;
     509           0 :     ColWidthsMap::const_iterator it = rColWidths.find( nCol );
     510           0 :     if ( it != rColWidths.end() )
     511           0 :         nThisWidth = it->second;
     512           0 :     long nColWidths = nThisWidth;
     513           0 :     SCCOL nColSpanCol = nCol + pE->nColOverlap;
     514           0 :     for ( SCCOL nC = nCol + 1; nC < nColSpanCol; nC++ )
     515             :     {
     516           0 :         ColWidthsMap::const_iterator it2 = rColWidths.find( nC   );
     517           0 :         if ( it2 != rColWidths.end() )
     518           0 :             nColWidths += it2->second;
     519             :     }
     520           0 :     if ( nWidth > nColWidths )
     521             :     {   // Only insert difference in first column
     522           0 :         rColWidths[ nCol ] = nWidth - nColWidths + nThisWidth;
     523             :     }
     524             :     // Distribute line height difference between all affected lines
     525           0 :     SCROW nRowSpan = pE->nRowOverlap;
     526           0 :     nHeight /= nRowSpan;
     527           0 :     if ( nHeight == 0 )
     528           0 :         nHeight = 1; // For definite comparison
     529           0 :     for ( SCROW nR = nRow; nR < nRow + nRowSpan; nR++ )
     530             :     {
     531           0 :         RowHeightMap::const_iterator it2 = maRowHeights.find( nR );
     532           0 :         long nRowHeight = it2 == maRowHeights.end() ? 0 : it2->second;
     533           0 :         if ( nHeight > nRowHeight )
     534             :         {
     535           0 :             maRowHeights[ nR ] = nHeight;
     536             :         }
     537             :     }
     538           0 :     return bHasGraphics;
     539             : }
     540             : 
     541             : 
     542           0 : void ScEEImport::InsertGraphic( SCCOL nCol, SCROW nRow, SCTAB nTab,
     543             :         ScEEParseEntry* pE )
     544             : {
     545           0 :     if ( !pE->maImageList.size() )
     546           0 :         return ;
     547           0 :     ScDrawLayer* pModel = mpDoc->GetDrawLayer();
     548           0 :     if (!pModel)
     549             :     {
     550           0 :         mpDoc->InitDrawLayer();
     551           0 :         pModel = mpDoc->GetDrawLayer();
     552             :     }
     553           0 :     SdrPage* pPage = pModel->GetPage( static_cast<sal_uInt16>(nTab) );
     554           0 :     OutputDevice* pDefaultDev = Application::GetDefaultDevice();
     555             : 
     556             :     Point aCellInsertPos(
     557           0 :         (long)((double) mpDoc->GetColOffset( nCol, nTab ) * HMM_PER_TWIPS),
     558           0 :         (long)((double) mpDoc->GetRowOffset( nRow, nTab ) * HMM_PER_TWIPS) );
     559             : 
     560           0 :     Point aInsertPos( aCellInsertPos );
     561           0 :     Point aSpace;
     562           0 :     Size aLogicSize;
     563           0 :     sal_Char nDir = nHorizontal;
     564           0 :     for ( sal_uInt32 i = 0; i < pE->maImageList.size(); ++i )
     565             :     {
     566           0 :         ScHTMLImage* pI = &pE->maImageList[ i ];
     567           0 :         if ( nDir & nHorizontal )
     568             :         {   // Horizontal
     569           0 :             aInsertPos.X() += aLogicSize.Width();
     570           0 :             aInsertPos.X() += aSpace.X();
     571           0 :             aInsertPos.Y() = aCellInsertPos.Y();
     572             :         }
     573             :         else
     574             :         {   // Vertical
     575           0 :             aInsertPos.X() = aCellInsertPos.X();
     576           0 :             aInsertPos.Y() += aLogicSize.Height();
     577           0 :             aInsertPos.Y() += aSpace.Y();
     578             :         }
     579             :         // Add offset of Spacing
     580           0 :         aSpace = pDefaultDev->PixelToLogic( pI->aSpace, MapMode( MAP_100TH_MM ) );
     581           0 :         aInsertPos += aSpace;
     582             : 
     583           0 :         Size aSizePix = pI->aSize;
     584           0 :         aLogicSize = pDefaultDev->PixelToLogic( aSizePix, MapMode( MAP_100TH_MM ) );
     585             : 
     586             :         // Limit size
     587           0 :         ::ScLimitSizeOnDrawPage( aLogicSize, aInsertPos, pPage->GetSize() );
     588             : 
     589           0 :         if ( pI->pGraphic )
     590             :         {
     591           0 :             Rectangle aRect ( aInsertPos, aLogicSize );
     592           0 :             SdrGrafObj* pObj = new SdrGrafObj( *pI->pGraphic, aRect );
     593             :             // calling SetGraphicLink here doesn't work
     594           0 :             pObj->SetName( pI->aURL );
     595             : 
     596           0 :             pPage->InsertObject( pObj );
     597             : 
     598             :             // SetGraphicLink has to be used after inserting the object,
     599             :             // otherwise an empty graphic is swapped in and the contact stuff crashes.
     600             :             // See #i37444#.
     601           0 :             pObj->SetGraphicLink( pI->aURL, ""/*TODO?*/, pI->aFilterName );
     602             : 
     603           0 :             pObj->SetLogicRect( aRect ); // Only after InsertObject!
     604             :         }
     605           0 :         nDir = pI->nDir;
     606             :     }
     607             : }
     608             : 
     609             : 
     610           0 : ScEEParser::ScEEParser( EditEngine* pEditP ) :
     611             :         pEdit( pEditP ),
     612           0 :         pPool( EditEngine::CreatePool() ),
     613           0 :         pDocPool( new ScDocumentPool ),
     614             :         nLastToken(0),
     615             :         nColCnt(0),
     616             :         nRowCnt(0),
     617             :         nColMax(0),
     618           0 :         nRowMax(0)
     619             : {
     620             :     // pPool is foisted on SvxRTFParser at RTFIMP_START later on
     621           0 :     pPool->SetSecondaryPool( pDocPool );
     622           0 :     pPool->FreezeIdRanges();
     623           0 :     NewActEntry( NULL );
     624           0 : }
     625             : 
     626             : 
     627           0 : ScEEParser::~ScEEParser()
     628             : {
     629           0 :     delete pActEntry;
     630           0 :     if ( !maList.empty() ) maList.clear();
     631             : 
     632             :     // Don't delete Pool until the lists have been deleted
     633           0 :     pPool->SetSecondaryPool( NULL );
     634           0 :     SfxItemPool::Free(pDocPool);
     635           0 :     SfxItemPool::Free(pPool);
     636           0 : }
     637             : 
     638             : 
     639           0 : void ScEEParser::NewActEntry( ScEEParseEntry* pE )
     640             : {   // New free-flying pActEntry
     641           0 :     pActEntry = new ScEEParseEntry( pPool );
     642           0 :     pActEntry->aSel.nStartPara = (pE ? pE->aSel.nEndPara + 1 : 0);
     643           0 :     pActEntry->aSel.nStartPos = 0;
     644           0 : }
     645             : 
     646             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10