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 _I18N_TEXTCONVERSION_KO_HXX_
24 #define _I18N_TEXTCONVERSION_KO_HXX_
25 
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/i18n/XExtendedTextConversion.hpp>
29 #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
30 #include <com/sun/star/linguistic2/XConversionDictionaryList.hpp>
31 #include <cppuhelper/implbase2.hxx> // helper for implementations
32 #include <osl/module.h>
33 
34 namespace com { namespace sun { namespace star { namespace i18n {
35 
36 //  ----------------------------------------------------
37 //  class TextConversion
38 //  ----------------------------------------------------
39 class TextConversion: public cppu::WeakImplHelper2
40 <
41     com::sun::star::i18n::XExtendedTextConversion,
42     com::sun::star::lang::XServiceInfo
43 >
44 {
45 public:
46         TextConversion();
47         ~TextConversion();
48         // Methods
49         virtual com::sun::star::i18n::TextConversionResult SAL_CALL
50         getConversions( const ::rtl::OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
51             const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nTextConversionType,
52             sal_Int32 nTextConversionOptions )
53             throw(  com::sun::star::uno::RuntimeException,
54                     com::sun::star::lang::IllegalArgumentException,
55                     com::sun::star::lang::NoSupportException ) = 0;
56         virtual rtl::OUString SAL_CALL
57         getConversion( const ::rtl::OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
58             const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nTextConversionType,
59             sal_Int32 nTextConversionOptions )
60             throw(  com::sun::star::uno::RuntimeException,
61                     com::sun::star::lang::IllegalArgumentException,
62                     com::sun::star::lang::NoSupportException ) = 0;
63         virtual rtl::OUString SAL_CALL
64         getConversionWithOffset( const ::rtl::OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
65             const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nTextConversionType,
66             sal_Int32 nTextConversionOptions, com::sun::star::uno::Sequence< sal_Int32 >& offset )
67             throw(  com::sun::star::uno::RuntimeException,
68                     com::sun::star::lang::IllegalArgumentException,
69                     com::sun::star::lang::NoSupportException ) = 0;
70         virtual sal_Bool SAL_CALL
71         interactiveConversion(const ::com::sun::star::lang::Locale& aLocale,
72             sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions )
73             throw(  com::sun::star::uno::RuntimeException,
74                     com::sun::star::lang::IllegalArgumentException,
75                     com::sun::star::lang::NoSupportException ) = 0;
76 
77     //XServiceInfo
78     rtl::OUString SAL_CALL
79         getImplementationName()
80             throw( com::sun::star::uno::RuntimeException );
81     sal_Bool SAL_CALL
82         supportsService(const rtl::OUString& ServiceName)
83             throw( com::sun::star::uno::RuntimeException );
84     com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
85         getSupportedServiceNames()
86             throw( com::sun::star::uno::RuntimeException );
87 protected :
88     const sal_Char* implementationName;
89     oslModule hModule;
90     oslGenericFunction SAL_CALL getFunctionBySymbol(const sal_Char* func);
91 };
92 
93 // for Hangul2Hanja conversion
94 typedef struct {
95     sal_Unicode code;
96     sal_Int16 address;
97     sal_Int16 count;
98 } Hangul_Index;
99 
100 //  ----------------------------------------------------
101 //  class TextConversion_ko
102 //  ----------------------------------------------------
103 class TextConversion_ko : public TextConversion
104 {
105 public:
106     TextConversion_ko( const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rxMSF );
107 
108         // Methods
109         com::sun::star::i18n::TextConversionResult SAL_CALL
110         getConversions( const ::rtl::OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
111             const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nTextConversionType,
112             sal_Int32 nTextConversionOptions )
113             throw(  com::sun::star::uno::RuntimeException,
114                     com::sun::star::lang::IllegalArgumentException,
115                     com::sun::star::lang::NoSupportException );
116         rtl::OUString SAL_CALL
117         getConversion( const ::rtl::OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
118             const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nTextConversionType,
119             sal_Int32 nTextConversionOptions )
120             throw(  com::sun::star::uno::RuntimeException,
121                     com::sun::star::lang::IllegalArgumentException,
122                     com::sun::star::lang::NoSupportException );
123         rtl::OUString SAL_CALL
124         getConversionWithOffset( const ::rtl::OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
125             const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nTextConversionType,
126             sal_Int32 nTextConversionOptions, com::sun::star::uno::Sequence< sal_Int32 >& offset )
127             throw(  com::sun::star::uno::RuntimeException,
128                     com::sun::star::lang::IllegalArgumentException,
129                     com::sun::star::lang::NoSupportException );
130         sal_Bool SAL_CALL
131         interactiveConversion(const ::com::sun::star::lang::Locale& aLocale,
132             sal_Int16 nTextConversionType,
133             sal_Int32 nTextConversionOptions )
134             throw(  com::sun::star::uno::RuntimeException,
135                     com::sun::star::lang::IllegalArgumentException,
136                     com::sun::star::lang::NoSupportException );
137 
138 private :
139         // Hangul/Hanja system dictionary
140         com::sun::star::uno::Reference < com::sun::star::linguistic2::XConversionDictionary > xCD;
141         // Hangul/Hanja user defined dictionary list
142         com::sun::star::uno::Reference < com::sun::star::linguistic2::XConversionDictionaryList > xCDL;
143         sal_Int32 maxLeftLength;
144         sal_Int32 maxRightLength;
145         com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
146             getCharConversions(const rtl::OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, sal_Bool toHanja);
147 };
148 
149 //  ----------------------------------------------------
150 //  class TextConversion_zh
151 //  ----------------------------------------------------
152 
153 // for SChines/TChinese word conversion
154 typedef struct {
155     sal_uInt16 start;
156     sal_Int16 count;
157 } STC_WordIndex;
158 
159 class TextConversion_zh : public TextConversion
160 {
161 public:
162     TextConversion_zh( const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rxMSF );
163 
164         // Methods
165         com::sun::star::i18n::TextConversionResult SAL_CALL
166         getConversions( const ::rtl::OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
167             const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nTextConversionType,
168             sal_Int32 nTextConversionOptions )
169             throw(  com::sun::star::uno::RuntimeException,
170                     com::sun::star::lang::IllegalArgumentException,
171                     com::sun::star::lang::NoSupportException );
172         rtl::OUString SAL_CALL
173         getConversion( const ::rtl::OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
174             const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nTextConversionType,
175             sal_Int32 nTextConversionOptions )
176             throw(  com::sun::star::uno::RuntimeException,
177                     com::sun::star::lang::IllegalArgumentException,
178                     com::sun::star::lang::NoSupportException );
179         rtl::OUString SAL_CALL
180         getConversionWithOffset( const ::rtl::OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
181             const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nTextConversionType,
182             sal_Int32 nTextConversionOptions, com::sun::star::uno::Sequence< sal_Int32 >& offset )
183             throw(  com::sun::star::uno::RuntimeException,
184                     com::sun::star::lang::IllegalArgumentException,
185                     com::sun::star::lang::NoSupportException );
186         sal_Bool SAL_CALL
187         interactiveConversion(const ::com::sun::star::lang::Locale& aLocale,
188             sal_Int16 nTextConversionType,
189             sal_Int32 nTextConversionOptions )
190             throw(  com::sun::star::uno::RuntimeException,
191                     com::sun::star::lang::IllegalArgumentException,
192                     com::sun::star::lang::NoSupportException );
193 private :
194         // user defined dictionary list
195         com::sun::star::uno::Reference < com::sun::star::linguistic2::XConversionDictionaryList > xCDL;
196         rtl::OUString SAL_CALL getWordConversion(const ::rtl::OUString& aText,
197             sal_Int32 nStartPos, sal_Int32 nLength, sal_Bool toSChinese, sal_Int32 nConversionOptions, com::sun::star::uno::Sequence <sal_Int32>& offset);
198         rtl:: OUString SAL_CALL getCharConversion(const rtl:: OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, sal_Bool toSChinese, sal_Int32 nConversionOptions);
199         com::sun::star::lang::Locale aLocale;
200 };
201 
202 } // i18n
203 } // star
204 } // sun
205 } // com
206 
207 #endif
208