1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
27 sal_uInt32
getQualityIndex(const OUString
& rString
)
29 sal_uInt32
nRetval(0);
31 // pixel formats first
32 if(rString
.endsWith(".bmp"))
36 if(rString
.endsWith(".gif"))
40 if(rString
.endsWith(".jpg"))
44 if(rString
.endsWith(".png"))
49 // vector formats, prefer always
50 if(rString
.endsWith(".svm"))
54 if(rString
.endsWith(".wmf"))
58 if(rString
.endsWith(".emf"))
62 if(rString
.endsWith(".svg"))
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
;
118 maImplContextVector
.erase(aRemove
);
120 // remove the rest from parent
121 for(a
= 0; a
< maImplContextVector
.size(); a
++)
123 SvXMLImportContext
& rCandidate
= **maImplContextVector
[a
];
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();
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: */