xref: /aoo41x/main/vcl/unx/generic/gdi/salcvt.hxx (revision ebfcd9af)
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 
23 #ifndef SAL_CONVERTER_CACHE_HXX_
24 #define SAL_CONVERTER_CACHE_HXX_
25 
26 #include <rtl/tencinfo.h>
27 #include <rtl/textcvt.h>
28 
29 #include <unx/salunx.h>
30 
31 #include <map>
32 
33 extern "C" const char*
34 pGetEncodingName( rtl_TextEncoding nEncoding );
35 
36 //
37 // Cache TextToUnicode and UnicodeToText converter and conversion info which is
38 // used in DrawXYZ routines and in the Event loop
39 //
40 
41 class SalConverterCache {
42 
43 	public:
44 						SalConverterCache();
45 						~SalConverterCache();
46 		Bool			EncodingHasChar(
47 								rtl_TextEncoding nEncoding, sal_Unicode nChar );
48 		rtl_UnicodeToTextConverter
49 						GetU2TConverter( rtl_TextEncoding nEncoding );
50 		rtl_TextToUnicodeConverter
51 						GetT2UConverter( rtl_TextEncoding nEncoding );
52 		Bool			IsSingleByteEncoding( rtl_TextEncoding nEncoding );
53 		sal_Size 		ConvertStringUTF16( const sal_Unicode *pText, int nTextLen,
54 								sal_Char *pBuffer, sal_Size nBufferSize,
55 								rtl_TextEncoding nEncoding);
56 
57 		static SalConverterCache*
58 						GetInstance ();
59 
60 	private:
61 
62 		struct ConverterT {
63 			rtl_UnicodeToTextConverter 	mpU2T;
64 			rtl_TextToUnicodeConverter 	mpT2U;
65 			Bool						mbSingleByteEncoding;
66 			Bool						mbValid;
ConverterTSalConverterCache::ConverterT67             ConverterT() :
68                     mpU2T( NULL ),
69                     mpT2U( NULL ),
70                     mbSingleByteEncoding( False ),
71                     mbValid( False )
72             {
73             }
~ConverterTSalConverterCache::ConverterT74             ~ConverterT()
75             {
76                 if( mpU2T )
77                     rtl_destroyUnicodeToTextConverter( mpU2T );
78                 if( mpT2U )
79                     rtl_destroyTextToUnicodeConverter( mpT2U );
80             }
81 		};
82 
83     std::map< rtl_TextEncoding, ConverterT >		m_aConverters;
84 };
85 
86 
87 
88 #endif /* SAL_CONVERTER_CACHE_HXX_ */
89 
90