bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / core / xmlmultiimagehelper.cxx
blobb0607a2fddd143605e07da0b266df12ad3d77283
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 using namespace ::com::sun::star;
25 namespace
27 sal_uInt32 getQualityIndex(const OUString& rString)
29 sal_uInt32 nRetval(0);
31 // pixel formats first
32 if(rString.endsWith(".bmp"))
34 return 10;
36 if(rString.endsWith(".gif"))
38 return 20;
40 if(rString.endsWith(".jpg"))
42 return 30;
44 if(rString.endsWith(".png"))
46 return 40;
49 // vector formats, prefer always
50 if(rString.endsWith(".svm"))
52 return 1000;
54 if(rString.endsWith(".wmf"))
56 return 1010;
58 if(rString.endsWith(".emf"))
60 return 1020;
62 if(rString.endsWith(".svg"))
64 return 1030;
67 return nRetval;
71 MultiImageImportHelper::MultiImageImportHelper()
72 : maImplContextVector(),
73 mbSupportsMultipleContents(false)
77 MultiImageImportHelper::~MultiImageImportHelper()
79 while(!maImplContextVector.empty())
81 delete *(maImplContextVector.end() - 1);
82 maImplContextVector.pop_back();
86 SvXMLImportContextRef MultiImageImportHelper::solveMultipleImages()
88 SvXMLImportContextRef pContext;
89 if(maImplContextVector.size() > 1)
91 // multiple child contexts were imported, decide which is the most valuable one
92 // and remove the rest
93 sal_uInt32 nIndexOfPreferred(maImplContextVector.size());
94 sal_uInt32 nBestQuality(0), a(0);
96 for(a = 0; a < maImplContextVector.size(); a++)
98 const OUString aStreamURL(getGraphicURLFromImportContext(**maImplContextVector[a]));
99 const sal_uInt32 nNewQuality(getQualityIndex(aStreamURL));
101 if(nNewQuality > nBestQuality)
103 nBestQuality = nNewQuality;
104 nIndexOfPreferred = a;
108 // correct if needed, default is to use the last entry
109 if(nIndexOfPreferred >= maImplContextVector.size())
111 nIndexOfPreferred = maImplContextVector.size() - 1;
114 // Take out the most valuable one
115 const std::vector< SvXMLImportContextRef* >::iterator aRemove(maImplContextVector.begin() + nIndexOfPreferred);
116 pContext = **aRemove;
117 delete *aRemove;
118 maImplContextVector.erase(aRemove);
120 // remove the rest from parent
121 for(a = 0; a < maImplContextVector.size(); a++)
123 SvXMLImportContext& rCandidate = **maImplContextVector[a];
125 if(pContext)
127 // #i124143# evtl. copy imported GluePoints before deprecating
128 // this graphic and context
129 pContext->onDemandRescueUsefulDataFromTemporary(rCandidate);
132 removeGraphicFromImportContext(rCandidate);
135 else if (maImplContextVector.size() == 1)
137 pContext = *maImplContextVector.front();
140 return pContext;
143 void MultiImageImportHelper::addContent(const SvXMLImportContext& rSvXMLImportContext)
145 if(dynamic_cast< const SvXMLImportContext* >(&rSvXMLImportContext))
147 maImplContextVector.push_back(new SvXMLImportContextRef(const_cast< SvXMLImportContext* >(&rSvXMLImportContext)));
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */