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()
81 SvXMLImportContextRef
MultiImageImportHelper::solveMultipleImages()
83 SvXMLImportContextRef pContext
;
84 if(maImplContextVector
.size() > 1)
86 // multiple child contexts were imported, decide which is the most valuable one
87 // and remove the rest
88 sal_uInt32
nIndexOfPreferred(maImplContextVector
.size());
89 sal_uInt32
nBestQuality(0), a(0);
91 for(a
= 0; a
< maImplContextVector
.size(); a
++)
93 const OUString
aStreamURL(getGraphicURLFromImportContext(*maImplContextVector
[a
]));
94 const sal_uInt32
nNewQuality(getQualityIndex(aStreamURL
));
96 if(nNewQuality
> nBestQuality
)
98 nBestQuality
= nNewQuality
;
99 nIndexOfPreferred
= a
;
103 // correct if needed, default is to use the last entry
104 if(nIndexOfPreferred
>= maImplContextVector
.size())
106 nIndexOfPreferred
= maImplContextVector
.size() - 1;
109 // Take out the most valuable one
110 const std::vector
< SvXMLImportContextRef
>::iterator
aRemove(maImplContextVector
.begin() + nIndexOfPreferred
);
112 maImplContextVector
.erase(aRemove
);
114 // remove the rest from parent
115 for(a
= 0; a
< maImplContextVector
.size(); a
++)
117 SvXMLImportContext
& rCandidate
= *maImplContextVector
[a
];
121 // #i124143# evtl. copy imported GluePoints before deprecating
122 // this graphic and context
123 pContext
->onDemandRescueUsefulDataFromTemporary(rCandidate
);
126 removeGraphicFromImportContext(rCandidate
);
128 // re-insert it so that solveMultipleImages is idempotent
129 maImplContextVector
.clear();
130 maImplContextVector
.push_back(pContext
);
132 else if (maImplContextVector
.size() == 1)
134 pContext
= maImplContextVector
.front();
140 void MultiImageImportHelper::addContent(const SvXMLImportContext
& rSvXMLImportContext
)
142 maImplContextVector
.push_back(SvXMLImportContextRef(const_cast< SvXMLImportContext
* >(&rSvXMLImportContext
)));
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */