LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlfonte.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 64 64 100.0 %
Date: 2015-06-13 12:38:46 Functions: 7 7 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 "scitems.hxx"
      21             : 
      22             : #include <editeng/eeitem.hxx>
      23             : 
      24             : #include <xmloff/XMLFontAutoStylePool.hxx>
      25             : #include <editeng/fontitem.hxx>
      26             : #include <editeng/editeng.hxx>
      27             : #include "document.hxx"
      28             : #include "docpool.hxx"
      29             : #include "xmlexprt.hxx"
      30             : #include "stlpool.hxx"
      31             : #include "attrib.hxx"
      32             : 
      33             : class ScXMLFontAutoStylePool_Impl: public XMLFontAutoStylePool
      34             : {
      35             : private:
      36             :     // #i120077# remember owned pool
      37             :     SfxItemPool*    mpEditEnginePool;
      38             : 
      39             :     void AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const bool bExportDefaults);
      40             : 
      41             : public:
      42             :     ScXMLFontAutoStylePool_Impl( ScXMLExport& rExport, bool bBlockFontEmbedding );
      43             :     virtual ~ScXMLFontAutoStylePool_Impl();
      44             : };
      45             : 
      46        2204 : void ScXMLFontAutoStylePool_Impl::AddFontItems(sal_uInt16* pWhichIds, sal_uInt8 nIdCount, const SfxItemPool* pItemPool, const bool bExportDefaults)
      47             : {
      48        8816 :     for( sal_uInt16 i=0; i < nIdCount; ++i )
      49             :     {
      50             :         const SfxPoolItem* pItem;
      51        6612 :         sal_uInt16 nWhichId(pWhichIds[i]);
      52        6612 :         if (bExportDefaults && (0 != (pItem = &pItemPool->GetDefaultItem(nWhichId))))
      53             :         {
      54         174 :             const SvxFontItem *pFont(static_cast<const SvxFontItem *>(pItem));
      55         174 :             Add( pFont->GetFamilyName(), pFont->GetStyleName(),
      56             :                     pFont->GetFamily(), pFont->GetPitch(),
      57         348 :                     pFont->GetCharSet() );
      58             :         }
      59        6612 :         sal_uInt32 nItems(pItemPool->GetItemCount2( nWhichId ));
      60       11334 :         for( sal_uInt32 j = 0; j < nItems; ++j )
      61             :         {
      62        4722 :             if( 0 != (pItem = pItemPool->GetItem2( nWhichId, j ) ) )
      63             :             {
      64        4638 :                 const SvxFontItem *pFont(static_cast<const SvxFontItem *>(pItem));
      65        4638 :                 Add( pFont->GetFamilyName(), pFont->GetStyleName(),
      66             :                      pFont->GetFamily(), pFont->GetPitch(),
      67        9276 :                      pFont->GetCharSet() );
      68             :             }
      69             :         }
      70             :     }
      71        2204 : }
      72             : 
      73          58 : ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScXMLExport& rExportP, bool bBlockFontEmbedding)
      74             :     : XMLFontAutoStylePool(rExportP, bBlockFontEmbedding)
      75          58 :     , mpEditEnginePool(NULL)
      76             : {
      77             :     sal_uInt16 aWhichIds[3] = { ATTR_FONT, ATTR_CJK_FONT,
      78          58 :                                 ATTR_CTL_FONT };
      79             :     sal_uInt16 aEditWhichIds[3] = { EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK,
      80          58 :                                     EE_CHAR_FONTINFO_CTL };
      81             :     sal_uInt16 aPageWhichIds[4] = { ATTR_PAGE_HEADERLEFT, ATTR_PAGE_FOOTERLEFT,
      82          58 :                                     ATTR_PAGE_HEADERRIGHT, ATTR_PAGE_FOOTERRIGHT };
      83             : 
      84          58 :     const SfxItemPool* pItemPool(rExportP.GetDocument()->GetPool());
      85          58 :     AddFontItems(aWhichIds, 3, pItemPool, true);
      86          58 :     const SfxItemPool* pEditPool(rExportP.GetDocument()->GetEditPool());
      87          58 :     AddFontItems(aEditWhichIds, 3, pEditPool, false);
      88             : 
      89          58 :     SfxStyleSheetIteratorPtr pItr = rExportP.GetDocument()->GetStyleSheetPool()->CreateIterator(SFX_STYLE_FAMILY_PAGE, 0xFFFF);
      90             : 
      91          58 :     if(pItr)
      92             :     {
      93          58 :         SfxStyleSheetBase* pStyle(pItr->First());
      94             : 
      95          58 :         if(pStyle)
      96             :         {
      97             :             // #i120077# remember the SfxItemPool in member variable before usage. The
      98             :             // local EditEngine will not take over ownership of the pool.
      99          58 :             mpEditEnginePool = EditEngine::CreatePool();
     100          58 :             EditEngine aEditEngine(mpEditEnginePool);
     101             : 
     102         238 :             while (pStyle)
     103             :             {
     104         122 :                 const SfxItemPool& rPagePool(pStyle->GetPool().GetPool());
     105             : 
     106         610 :                 for (sal_uInt8 j = 0; j < 4; ++j)
     107             :                 {
     108         488 :                     sal_uInt16 nPageWhichId(aPageWhichIds[j]);
     109         488 :                     sal_uInt32 nPageHFItems(rPagePool.GetItemCount2(nPageWhichId));
     110        1624 :                     for (sal_uInt32 k = 0; k < nPageHFItems; ++k)
     111             :                     {
     112             :                         const ScPageHFItem* pPageItem;
     113        1136 :                         if (0 != (pPageItem = static_cast<const ScPageHFItem*>(rPagePool.GetItem2(nPageWhichId, k))))
     114             :                         {
     115         696 :                             const EditTextObject* pLeftArea(pPageItem->GetLeftArea());
     116         696 :                             if (pLeftArea)
     117             :                             {
     118         696 :                                 aEditEngine.SetText(*pLeftArea);
     119         696 :                                 AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false);
     120             :                             }
     121         696 :                             const EditTextObject* pCenterArea(pPageItem->GetCenterArea());
     122         696 :                             if (pCenterArea)
     123             :                             {
     124         696 :                                 aEditEngine.SetText(*pCenterArea);
     125         696 :                                 AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false);
     126             :                             }
     127         696 :                             const EditTextObject* pRightArea(pPageItem->GetRightArea());
     128         696 :                             if (pRightArea)
     129             :                             {
     130         696 :                                 aEditEngine.SetText(*pRightArea);
     131         696 :                                 AddFontItems(aEditWhichIds, 3, mpEditEnginePool, false);
     132             :                             }
     133             :                         }
     134             :                     }
     135             :                 }
     136             : 
     137         122 :                 pStyle = pItr->Next();
     138          58 :             }
     139             :         }
     140          58 :     }
     141          58 : }
     142             : 
     143         174 : ScXMLFontAutoStylePool_Impl::~ScXMLFontAutoStylePool_Impl()
     144             : {
     145          58 :     if(mpEditEnginePool)
     146             :     {
     147             :         // memory leak #i120077#
     148          58 :         SfxItemPool::Free(mpEditEnginePool);
     149             :     }
     150         116 : }
     151             : 
     152          58 : XMLFontAutoStylePool* ScXMLExport::CreateFontAutoStylePool()
     153             : {
     154          58 :     bool blockFontEmbedding = false;
     155             :     // We write font info to both content.xml and styles.xml, but they are both
     156             :     // written by different ScXMLExport instance, and would therefore write each
     157             :     // font file twice without complicated checking for duplicates, so handle
     158             :     // the embedding only in one of them.
     159          58 :     if(!( getExportFlags() & SvXMLExportFlags::CONTENT ))
     160          29 :         blockFontEmbedding = true;
     161          58 :     if( !GetDocument()->IsUsingEmbededFonts())
     162          58 :         blockFontEmbedding = true;
     163          58 :     return new ScXMLFontAutoStylePool_Impl( *this, !blockFontEmbedding );
     164         156 : }
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11