1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_xmloff.hxx" 24 25 #include <xmloff/xmlmultiimagehelper.hxx> 26 #include <rtl/ustring.hxx> 27 28 ////////////////////////////////////////////////////////////////////////////// 29 30 using namespace ::com::sun::star; 31 32 ////////////////////////////////////////////////////////////////////////////// 33 34 namespace 35 { 36 sal_uInt32 getQualityIndex(const rtl::OUString& rString) 37 { 38 sal_uInt32 nRetval(0); 39 40 // pixel formats first 41 if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".bmp"))) 42 { 43 return 10; 44 } 45 if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".gif"))) 46 { 47 return 20; 48 } 49 if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".jpg"))) 50 { 51 return 30; 52 } 53 if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".png"))) 54 { 55 return 40; 56 } 57 58 // vector formats, prefer always 59 if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".svm"))) 60 { 61 return 1000; 62 } 63 if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".wmf"))) 64 { 65 return 1010; 66 } 67 if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".emf"))) 68 { 69 return 1020; 70 } 71 else if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".svg"))) 72 { 73 return 1030; 74 } 75 76 return nRetval; 77 } 78 } 79 80 ////////////////////////////////////////////////////////////////////////////// 81 82 multiImageImportHelper::multiImageImportHelper() 83 : maImplContextVector(), 84 mbSupportsMultipleContents(false) 85 { 86 } 87 88 multiImageImportHelper::~multiImageImportHelper() 89 { 90 while(!maImplContextVector.empty()) 91 { 92 delete *(maImplContextVector.end() - 1); 93 maImplContextVector.pop_back(); 94 } 95 } 96 97 void multiImageImportHelper::solveMultipleImages() 98 { 99 if(maImplContextVector.size() > 1) 100 { 101 // multiple child contexts were imported, decide which is the most valuable one 102 // and remove the rest 103 sal_uInt32 nIndexOfPreferred(maImplContextVector.size()); 104 sal_uInt32 nBestQuality(0), a(0); 105 106 for(a = 0; a < maImplContextVector.size(); a++) 107 { 108 const rtl::OUString aStreamURL(getGraphicURLFromImportContext(**maImplContextVector[a])); 109 const sal_uInt32 nNewQuality(getQualityIndex(aStreamURL)); 110 111 if(nNewQuality > nBestQuality) 112 { 113 nBestQuality = nNewQuality; 114 nIndexOfPreferred = a; 115 } 116 } 117 118 // correct if needed, default is to use the last entry 119 if(nIndexOfPreferred >= maImplContextVector.size()) 120 { 121 nIndexOfPreferred = maImplContextVector.size() - 1; 122 } 123 124 // Take out the most valuable one 125 const std::vector< SvXMLImportContextRef* >::iterator aRemove(maImplContextVector.begin() + nIndexOfPreferred); 126 delete *aRemove; 127 maImplContextVector.erase(aRemove); 128 129 // remove the rest from parent 130 for(a = 0; a < maImplContextVector.size(); a++) 131 { 132 removeGraphicFromImportContext(**maImplContextVector[a]); 133 } 134 } 135 } 136 137 void multiImageImportHelper::addContent(const SvXMLImportContext& rSvXMLImportContext) 138 { 139 if(dynamic_cast< const SvXMLImportContext* >(&rSvXMLImportContext)) 140 { 141 maImplContextVector.push_back(new SvXMLImportContextRef(const_cast< SvXMLImportContext* >(&rSvXMLImportContext))); 142 } 143 } 144 145 ////////////////////////////////////////////////////////////////////////////// 146 //eof 147