LCOV - code coverage report
Current view: top level - xmloff/source/core - xmlmultiimagehelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 49 57 86.0 %
Date: 2014-11-03 Functions: 5 6 83.3 %
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 <xmloff/xmlmultiimagehelper.hxx>
      21             : #include <rtl/ustring.hxx>
      22             : 
      23             : using namespace ::com::sun::star;
      24             : 
      25             : namespace
      26             : {
      27          16 :     sal_uInt32 getQualityIndex(const OUString& rString)
      28             :     {
      29          16 :         sal_uInt32 nRetval(0);
      30             : 
      31             :         // pixel formats first
      32          16 :         if(rString.endsWithAsciiL(".bmp", 4))
      33             :         {
      34           0 :             return 10;
      35             :         }
      36          16 :         if(rString.endsWithAsciiL(".gif", 4))
      37             :         {
      38           0 :             return 20;
      39             :         }
      40          16 :         if(rString.endsWithAsciiL(".jpg", 4))
      41             :         {
      42           0 :             return 30;
      43             :         }
      44          16 :         if(rString.endsWithAsciiL(".png", 4))
      45             :         {
      46           8 :             return 40;
      47             :         }
      48             : 
      49             :         // vector formats, prefer always
      50           8 :         if(rString.endsWithAsciiL(".svm", 4))
      51             :         {
      52           0 :             return 1000;
      53             :         }
      54           8 :         if(rString.endsWithAsciiL(".wmf", 4))
      55             :         {
      56           0 :             return 1010;
      57             :         }
      58           8 :         if(rString.endsWithAsciiL(".emf", 4))
      59             :         {
      60           0 :             return 1020;
      61             :         }
      62           8 :         else if(rString.endsWithAsciiL(".svg", 4))
      63             :         {
      64           8 :             return 1030;
      65             :         }
      66             : 
      67           0 :         return nRetval;
      68             :     }
      69             : }
      70             : 
      71        1970 : MultiImageImportHelper::MultiImageImportHelper()
      72             : :   maImplContextVector(),
      73        1970 :     mbSupportsMultipleContents(false)
      74             : {
      75        1970 : }
      76             : 
      77        3940 : MultiImageImportHelper::~MultiImageImportHelper()
      78             : {
      79        4280 :     while(!maImplContextVector.empty())
      80             :     {
      81         340 :         delete *(maImplContextVector.end() - 1);
      82         340 :         maImplContextVector.pop_back();
      83             :     }
      84        1970 : }
      85             : 
      86        1970 : SvXMLImportContextRef MultiImageImportHelper::solveMultipleImages()
      87             : {
      88        1970 :     SvXMLImportContextRef pContext;
      89        1970 :     if(maImplContextVector.size() > 1)
      90             :     {
      91             :         // multiple child contexts were imported, decide which is the most valuable one
      92             :         // and remove the rest
      93           8 :         sal_uInt32 nIndexOfPreferred(maImplContextVector.size());
      94           8 :         sal_uInt32 nBestQuality(0), a(0);
      95             : 
      96          24 :         for(a = 0; a < maImplContextVector.size(); a++)
      97             :         {
      98          16 :             const OUString aStreamURL(getGraphicURLFromImportContext(**maImplContextVector[a]));
      99          16 :             const sal_uInt32 nNewQuality(getQualityIndex(aStreamURL));
     100             : 
     101          16 :             if(nNewQuality > nBestQuality)
     102             :             {
     103          12 :                 nBestQuality = nNewQuality;
     104          12 :                 nIndexOfPreferred = a;
     105             :             }
     106          16 :         }
     107             : 
     108             :         // correct if needed, default is to use the last entry
     109           8 :         if(nIndexOfPreferred >= maImplContextVector.size())
     110             :         {
     111           0 :             nIndexOfPreferred = maImplContextVector.size() - 1;
     112             :         }
     113             : 
     114             :         // Take out the most valuable one
     115           8 :         const std::vector< SvXMLImportContextRef* >::iterator aRemove(maImplContextVector.begin() + nIndexOfPreferred);
     116           8 :         pContext = **aRemove;
     117           8 :         delete *aRemove;
     118           8 :         maImplContextVector.erase(aRemove);
     119             : 
     120             :         // remove the rest from parent
     121          16 :         for(a = 0; a < maImplContextVector.size(); a++)
     122             :         {
     123           8 :             SvXMLImportContext& rCandidate = **maImplContextVector[a];
     124             : 
     125           8 :             if(pContext)
     126             :             {
     127             :                 // #i124143# evtl. copy imported GluePoints before deprecating
     128             :                 // this graphic and context
     129           8 :                 pContext->onDemandRescueUsefulDataFromTemporary(rCandidate);
     130             :             }
     131             : 
     132           8 :             removeGraphicFromImportContext(rCandidate);
     133             :         }
     134             :     }
     135        1962 :     else if (maImplContextVector.size() == 1)
     136             :     {
     137         332 :         pContext = *maImplContextVector.front();
     138             :     }
     139             : 
     140        1970 :     return pContext;
     141             : }
     142             : 
     143         348 : void MultiImageImportHelper::addContent(const SvXMLImportContext& rSvXMLImportContext)
     144             : {
     145         348 :     if(dynamic_cast< const SvXMLImportContext* >(&rSvXMLImportContext))
     146             :     {
     147         348 :         maImplContextVector.push_back(new SvXMLImportContextRef(const_cast< SvXMLImportContext* >(&rSvXMLImportContext)));
     148             :     }
     149         348 : }
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10