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

Generated by: LCOV version 1.10