bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / core / xmlmultiimagehelper.cxx
blob98aaef7f3d371ed53d8cbb01c8315ad6908d1967
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <xmloff/xmlmultiimagehelper.hxx>
21 #include <rtl/ustring.hxx>
23 //////////////////////////////////////////////////////////////////////////////
25 using namespace ::com::sun::star;
27 //////////////////////////////////////////////////////////////////////////////
29 namespace
31 sal_uInt32 getQualityIndex(const OUString& rString)
33 sal_uInt32 nRetval(0);
35 // pixel formats first
36 if(rString.endsWithAsciiL(".bmp", 4))
38 return 10;
40 if(rString.endsWithAsciiL(".gif", 4))
42 return 20;
44 if(rString.endsWithAsciiL(".jpg", 4))
46 return 30;
48 if(rString.endsWithAsciiL(".png", 4))
50 return 40;
53 // vector formats, prefer always
54 if(rString.endsWithAsciiL(".svm", 4))
56 return 1000;
58 if(rString.endsWithAsciiL(".wmf", 4))
60 return 1010;
62 if(rString.endsWithAsciiL(".emf", 4))
64 return 1020;
66 else if(rString.endsWithAsciiL(".svg", 4))
68 return 1030;
71 return nRetval;
75 //////////////////////////////////////////////////////////////////////////////
77 MultiImageImportHelper::MultiImageImportHelper()
78 : maImplContextVector(),
79 mbSupportsMultipleContents(false)
83 MultiImageImportHelper::~MultiImageImportHelper()
85 while(!maImplContextVector.empty())
87 delete *(maImplContextVector.end() - 1);
88 maImplContextVector.pop_back();
92 SvXMLImportContextRef MultiImageImportHelper::solveMultipleImages()
94 SvXMLImportContextRef pContext;
95 if(maImplContextVector.size() > 1)
97 // multiple child contexts were imported, decide which is the most valuable one
98 // and remove the rest
99 sal_uInt32 nIndexOfPreferred(maImplContextVector.size());
100 sal_uInt32 nBestQuality(0), a(0);
102 for(a = 0; a < maImplContextVector.size(); a++)
104 const OUString aStreamURL(getGraphicURLFromImportContext(**maImplContextVector[a]));
105 const sal_uInt32 nNewQuality(getQualityIndex(aStreamURL));
107 if(nNewQuality > nBestQuality)
109 nBestQuality = nNewQuality;
110 nIndexOfPreferred = a;
114 // correct if needed, default is to use the last entry
115 if(nIndexOfPreferred >= maImplContextVector.size())
117 nIndexOfPreferred = maImplContextVector.size() - 1;
120 // Take out the most valuable one
121 const std::vector< SvXMLImportContextRef* >::iterator aRemove(maImplContextVector.begin() + nIndexOfPreferred);
122 pContext = **aRemove;
123 delete *aRemove;
124 maImplContextVector.erase(aRemove);
126 // remove the rest from parent
127 for(a = 0; a < maImplContextVector.size(); a++)
129 removeGraphicFromImportContext(**maImplContextVector[a]);
132 else if (maImplContextVector.size() == 1)
134 pContext = *maImplContextVector.front();
137 return pContext;
140 void MultiImageImportHelper::addContent(const SvXMLImportContext& rSvXMLImportContext)
142 if(dynamic_cast< const SvXMLImportContext* >(&rSvXMLImportContext))
144 maImplContextVector.push_back(new SvXMLImportContextRef(const_cast< SvXMLImportContext* >(&rSvXMLImportContext)));
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */