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 { 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 82ddde725dSArmin Le Grand multiImageImportHelper::multiImageImportHelper() 83ddde725dSArmin Le Grand : maImplContextVector(), 84ddde725dSArmin Le Grand mbSupportsMultipleContents(false) 85ddde725dSArmin Le Grand { 86ddde725dSArmin Le Grand } 87ddde725dSArmin Le Grand 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 97*598d8f9fSArmin Le Grand const SvXMLImportContext* multiImageImportHelper::solveMultipleImages() 98ddde725dSArmin Le Grand { 99*598d8f9fSArmin Le Grand const SvXMLImportContext* pRetval = 0; 100ddde725dSArmin Le Grand 101*598d8f9fSArmin Le Grand if(maImplContextVector.size()) 102*598d8f9fSArmin Le Grand { 103*598d8f9fSArmin Le Grand if(maImplContextVector.size() > 1) 104ddde725dSArmin Le Grand { 105*598d8f9fSArmin Le Grand // multiple child contexts were imported, decide which is the most valuable one 106*598d8f9fSArmin Le Grand // and remove the rest 107*598d8f9fSArmin Le Grand sal_uInt32 nIndexOfPreferred(maImplContextVector.size()); 108*598d8f9fSArmin Le Grand sal_uInt32 nBestQuality(0), a(0); 109ddde725dSArmin Le Grand 110*598d8f9fSArmin Le Grand for(a = 0; a < maImplContextVector.size(); a++) 111ddde725dSArmin Le Grand { 112*598d8f9fSArmin Le Grand const rtl::OUString aStreamURL(getGraphicURLFromImportContext(**maImplContextVector[a])); 113*598d8f9fSArmin Le Grand const sal_uInt32 nNewQuality(getQualityIndex(aStreamURL)); 114*598d8f9fSArmin Le Grand 115*598d8f9fSArmin Le Grand if(nNewQuality > nBestQuality) 116*598d8f9fSArmin Le Grand { 117*598d8f9fSArmin Le Grand nBestQuality = nNewQuality; 118*598d8f9fSArmin Le Grand nIndexOfPreferred = a; 119*598d8f9fSArmin Le Grand } 120ddde725dSArmin Le Grand } 121ddde725dSArmin Le Grand 122*598d8f9fSArmin Le Grand // correct if needed, default is to use the last entry 123*598d8f9fSArmin Le Grand if(nIndexOfPreferred >= maImplContextVector.size()) 124*598d8f9fSArmin Le Grand { 125*598d8f9fSArmin Le Grand nIndexOfPreferred = maImplContextVector.size() - 1; 126*598d8f9fSArmin Le Grand } 127ddde725dSArmin Le Grand 128*598d8f9fSArmin Le Grand // get the winner 129*598d8f9fSArmin Le Grand pRetval = *maImplContextVector[nIndexOfPreferred]; 130ddde725dSArmin Le Grand 131*598d8f9fSArmin Le Grand // remove the rest from parent 132*598d8f9fSArmin Le Grand for(a = 0; a < maImplContextVector.size(); a++) 133*598d8f9fSArmin Le Grand { 134*598d8f9fSArmin Le Grand if(a != nIndexOfPreferred) 135*598d8f9fSArmin Le Grand { 136*598d8f9fSArmin Le Grand removeGraphicFromImportContext(**maImplContextVector[a]); 137*598d8f9fSArmin Le Grand } 138*598d8f9fSArmin Le Grand } 139*598d8f9fSArmin Le Grand } 140*598d8f9fSArmin Le Grand else 141ddde725dSArmin Le Grand { 142*598d8f9fSArmin Le Grand // only one, winner is implicit 143*598d8f9fSArmin Le Grand pRetval = *maImplContextVector[0]; 144ddde725dSArmin Le Grand } 145ddde725dSArmin Le Grand } 146*598d8f9fSArmin Le Grand 147*598d8f9fSArmin Le Grand return pRetval; 148ddde725dSArmin Le Grand } 149ddde725dSArmin Le Grand 150ddde725dSArmin Le Grand void multiImageImportHelper::addContent(const SvXMLImportContext& rSvXMLImportContext) 151ddde725dSArmin Le Grand { 152ddde725dSArmin Le Grand if(dynamic_cast< const SvXMLImportContext* >(&rSvXMLImportContext)) 153ddde725dSArmin Le Grand { 154ddde725dSArmin Le Grand maImplContextVector.push_back(new SvXMLImportContextRef(const_cast< SvXMLImportContext* >(&rSvXMLImportContext))); 155ddde725dSArmin Le Grand } 156ddde725dSArmin Le Grand } 157ddde725dSArmin Le Grand 158ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 159ddde725dSArmin Le Grand //eof 160