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

Generated by: LCOV version 1.11