1ddde725dSArmin Le Grand /**************************************************************
2ddde725dSArmin Le Grand  *
3ddde725dSArmin Le Grand  * Licensed to the Apache Software Foundation (ASF) under one
4ddde725dSArmin Le Grand  * or more contributor license agreements.  See the NOTICE file
5ddde725dSArmin Le Grand  * distributed with this work for additional information
6ddde725dSArmin Le Grand  * regarding copyright ownership.  The ASF licenses this file
7ddde725dSArmin Le Grand  * to you under the Apache License, Version 2.0 (the
8ddde725dSArmin Le Grand  * "License"); you may not use this file except in compliance
9ddde725dSArmin Le Grand  * with the License.  You may obtain a copy of the License at
10ddde725dSArmin Le Grand  *
11ddde725dSArmin Le Grand  *   http://www.apache.org/licenses/LICENSE-2.0
12ddde725dSArmin Le Grand  *
13ddde725dSArmin Le Grand  * Unless required by applicable law or agreed to in writing,
14ddde725dSArmin Le Grand  * software distributed under the License is distributed on an
15ddde725dSArmin Le Grand  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ddde725dSArmin Le Grand  * KIND, either express or implied.  See the License for the
17ddde725dSArmin Le Grand  * specific language governing permissions and limitations
18ddde725dSArmin Le Grand  * under the License.
19ddde725dSArmin Le Grand  *
20ddde725dSArmin Le Grand  *************************************************************/
21ddde725dSArmin Le Grand 
22ddde725dSArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove
23ddde725dSArmin Le Grand #include "precompiled_xmloff.hxx"
24ddde725dSArmin Le Grand 
25ddde725dSArmin Le Grand #include <xmloff/xmlmultiimagehelper.hxx>
26ddde725dSArmin Le Grand #include <rtl/ustring.hxx>
27ddde725dSArmin Le Grand 
28ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
29ddde725dSArmin Le Grand 
30ddde725dSArmin Le Grand using namespace ::com::sun::star;
31ddde725dSArmin Le Grand 
32ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
33ddde725dSArmin Le Grand 
34ddde725dSArmin Le Grand namespace
35ddde725dSArmin Le Grand {
getQualityIndex(const rtl::OUString & rString)36ddde725dSArmin Le Grand     sal_uInt32 getQualityIndex(const rtl::OUString& rString)
37ddde725dSArmin Le Grand     {
38ddde725dSArmin Le Grand         sal_uInt32 nRetval(0);
39ddde725dSArmin Le Grand 
40ddde725dSArmin Le Grand         // pixel formats first
41ddde725dSArmin Le Grand         if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".bmp")))
42ddde725dSArmin Le Grand         {
43ddde725dSArmin Le Grand             return 10;
44ddde725dSArmin Le Grand         }
45ddde725dSArmin Le Grand         if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".gif")))
46ddde725dSArmin Le Grand         {
47ddde725dSArmin Le Grand             return 20;
48ddde725dSArmin Le Grand         }
49ddde725dSArmin Le Grand         if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".jpg")))
50ddde725dSArmin Le Grand         {
51ddde725dSArmin Le Grand             return 30;
52ddde725dSArmin Le Grand         }
53ddde725dSArmin Le Grand         if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".png")))
54ddde725dSArmin Le Grand         {
55ddde725dSArmin Le Grand             return 40;
56ddde725dSArmin Le Grand         }
57ddde725dSArmin Le Grand 
58ddde725dSArmin Le Grand         // vector formats, prefer always
59ddde725dSArmin Le Grand         if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".svm")))
60ddde725dSArmin Le Grand         {
61ddde725dSArmin Le Grand             return 1000;
62ddde725dSArmin Le Grand         }
63ddde725dSArmin Le Grand         if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".wmf")))
64ddde725dSArmin Le Grand         {
65ddde725dSArmin Le Grand             return 1010;
66ddde725dSArmin Le Grand         }
67ddde725dSArmin Le Grand         if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".emf")))
68ddde725dSArmin Le Grand         {
69ddde725dSArmin Le Grand             return 1020;
70ddde725dSArmin Le Grand         }
71ddde725dSArmin Le Grand         else if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".svg")))
72ddde725dSArmin Le Grand         {
73ddde725dSArmin Le Grand             return 1030;
74ddde725dSArmin Le Grand         }
75ddde725dSArmin Le Grand 
76ddde725dSArmin Le Grand         return nRetval;
77ddde725dSArmin Le Grand     }
78ddde725dSArmin Le Grand }
79ddde725dSArmin Le Grand 
80ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
81ddde725dSArmin Le Grand 
multiImageImportHelper()82ddde725dSArmin Le Grand multiImageImportHelper::multiImageImportHelper()
83ddde725dSArmin Le Grand :   maImplContextVector(),
84ddde725dSArmin Le Grand     mbSupportsMultipleContents(false)
85ddde725dSArmin Le Grand {
86ddde725dSArmin Le Grand }
87ddde725dSArmin Le Grand 
~multiImageImportHelper()88ddde725dSArmin Le Grand multiImageImportHelper::~multiImageImportHelper()
89ddde725dSArmin Le Grand {
90ddde725dSArmin Le Grand     while(!maImplContextVector.empty())
91ddde725dSArmin Le Grand     {
92ddde725dSArmin Le Grand         delete *(maImplContextVector.end() - 1);
93ddde725dSArmin Le Grand         maImplContextVector.pop_back();
94ddde725dSArmin Le Grand     }
95ddde725dSArmin Le Grand }
96ddde725dSArmin Le Grand 
solveMultipleImages()97598d8f9fSArmin Le Grand const SvXMLImportContext* multiImageImportHelper::solveMultipleImages()
98ddde725dSArmin Le Grand {
99*f3b8b509SArmin Le Grand     SvXMLImportContext* pRetval = 0;
100ddde725dSArmin Le Grand 
101598d8f9fSArmin Le Grand     if(maImplContextVector.size())
102598d8f9fSArmin Le Grand     {
103598d8f9fSArmin Le Grand         if(maImplContextVector.size() > 1)
104ddde725dSArmin Le Grand         {
105598d8f9fSArmin Le Grand             // multiple child contexts were imported, decide which is the most valuable one
106598d8f9fSArmin Le Grand             // and remove the rest
107598d8f9fSArmin Le Grand             sal_uInt32 nIndexOfPreferred(maImplContextVector.size());
108598d8f9fSArmin Le Grand             sal_uInt32 nBestQuality(0), a(0);
109ddde725dSArmin Le Grand 
110598d8f9fSArmin Le Grand             for(a = 0; a < maImplContextVector.size(); a++)
111ddde725dSArmin Le Grand             {
112598d8f9fSArmin Le Grand                 const rtl::OUString aStreamURL(getGraphicURLFromImportContext(**maImplContextVector[a]));
113598d8f9fSArmin Le Grand                 const sal_uInt32 nNewQuality(getQualityIndex(aStreamURL));
114598d8f9fSArmin Le Grand 
115598d8f9fSArmin Le Grand                 if(nNewQuality > nBestQuality)
116598d8f9fSArmin Le Grand                 {
117598d8f9fSArmin Le Grand                     nBestQuality = nNewQuality;
118598d8f9fSArmin Le Grand                     nIndexOfPreferred = a;
119598d8f9fSArmin Le Grand                 }
120ddde725dSArmin Le Grand             }
121ddde725dSArmin Le Grand 
122598d8f9fSArmin Le Grand             // correct if needed, default is to use the last entry
123598d8f9fSArmin Le Grand             if(nIndexOfPreferred >= maImplContextVector.size())
124598d8f9fSArmin Le Grand             {
125598d8f9fSArmin Le Grand                 nIndexOfPreferred = maImplContextVector.size() - 1;
126598d8f9fSArmin Le Grand             }
127ddde725dSArmin Le Grand 
128598d8f9fSArmin Le Grand             // get the winner
129598d8f9fSArmin Le Grand             pRetval = *maImplContextVector[nIndexOfPreferred];
130ddde725dSArmin Le Grand 
131598d8f9fSArmin Le Grand             // remove the rest from parent
132598d8f9fSArmin Le Grand             for(a = 0; a < maImplContextVector.size(); a++)
133598d8f9fSArmin Le Grand             {
134598d8f9fSArmin Le Grand                 if(a != nIndexOfPreferred)
135598d8f9fSArmin Le Grand                 {
136*f3b8b509SArmin Le Grand                     SvXMLImportContext& rCandidate = **maImplContextVector[a];
137*f3b8b509SArmin Le Grand 
138*f3b8b509SArmin Le Grand                     if(pRetval)
139*f3b8b509SArmin Le Grand                     {
140*f3b8b509SArmin Le Grand                         // #124143# evtl. copy imported GluePoints before deprecating
141*f3b8b509SArmin Le Grand                         // this graphic and context
142*f3b8b509SArmin Le Grand                         pRetval->onDemandRescueUsefulDataFromTemporary(rCandidate);
143*f3b8b509SArmin Le Grand                     }
144*f3b8b509SArmin Le Grand 
145*f3b8b509SArmin Le Grand                     removeGraphicFromImportContext(rCandidate);
146598d8f9fSArmin Le Grand                 }
147598d8f9fSArmin Le Grand             }
148598d8f9fSArmin Le Grand         }
149598d8f9fSArmin Le Grand         else
150ddde725dSArmin Le Grand         {
151598d8f9fSArmin Le Grand             // only one, winner is implicit
152598d8f9fSArmin Le Grand             pRetval = *maImplContextVector[0];
153ddde725dSArmin Le Grand         }
154ddde725dSArmin Le Grand     }
155598d8f9fSArmin Le Grand 
156598d8f9fSArmin Le Grand     return pRetval;
157ddde725dSArmin Le Grand }
158ddde725dSArmin Le Grand 
addContent(const SvXMLImportContext & rSvXMLImportContext)159ddde725dSArmin Le Grand void multiImageImportHelper::addContent(const SvXMLImportContext& rSvXMLImportContext)
160ddde725dSArmin Le Grand {
161ddde725dSArmin Le Grand     if(dynamic_cast< const SvXMLImportContext* >(&rSvXMLImportContext))
162ddde725dSArmin Le Grand     {
163ddde725dSArmin Le Grand         maImplContextVector.push_back(new SvXMLImportContextRef(const_cast< SvXMLImportContext* >(&rSvXMLImportContext)));
164ddde725dSArmin Le Grand     }
165ddde725dSArmin Le Grand }
166ddde725dSArmin Le Grand 
167ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
168ddde725dSArmin Le Grand //eof
169