1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef SAL_CONVERTER_CACHE_HXX_ 28 #define SAL_CONVERTER_CACHE_HXX_ 29 30 #include <rtl/tencinfo.h> 31 #include <rtl/textcvt.h> 32 33 #include <unx/salunx.h> 34 35 #include <map> 36 37 extern "C" const char* 38 pGetEncodingName( rtl_TextEncoding nEncoding ); 39 40 // 41 // Cache TextToUnicode and UnicodeToText converter and conversion info which is 42 // used in DrawXYZ routines and in the Event loop 43 // 44 45 class SalConverterCache { 46 47 public: 48 SalConverterCache(); 49 ~SalConverterCache(); 50 Bool EncodingHasChar( 51 rtl_TextEncoding nEncoding, sal_Unicode nChar ); 52 rtl_UnicodeToTextConverter 53 GetU2TConverter( rtl_TextEncoding nEncoding ); 54 rtl_TextToUnicodeConverter 55 GetT2UConverter( rtl_TextEncoding nEncoding ); 56 Bool IsSingleByteEncoding( rtl_TextEncoding nEncoding ); 57 sal_Size ConvertStringUTF16( const sal_Unicode *pText, int nTextLen, 58 sal_Char *pBuffer, sal_Size nBufferSize, 59 rtl_TextEncoding nEncoding); 60 61 static SalConverterCache* 62 GetInstance (); 63 64 private: 65 66 struct ConverterT { 67 rtl_UnicodeToTextConverter mpU2T; 68 rtl_TextToUnicodeConverter mpT2U; 69 Bool mbSingleByteEncoding; 70 Bool mbValid; 71 ConverterT() : 72 mpU2T( NULL ), 73 mpT2U( NULL ), 74 mbSingleByteEncoding( False ), 75 mbValid( False ) 76 { 77 } 78 ~ConverterT() 79 { 80 if( mpU2T ) 81 rtl_destroyUnicodeToTextConverter( mpU2T ); 82 if( mpT2U ) 83 rtl_destroyTextToUnicodeConverter( mpT2U ); 84 } 85 }; 86 87 std::map< rtl_TextEncoding, ConverterT > m_aConverters; 88 }; 89 90 91 92 #endif /* SAL_CONVERTER_CACHE_HXX_ */ 93 94