1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_EDITENG_HANGULHANJA_HXX
#define INCLUDED_EDITENG_HANGULHANJA_HXX
#include <vcl/window.hxx>
#include <memory>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <editeng/editengdllapi.h>
#include <i18nlangtag/mslangid.hxx>
namespace editeng
{
class HangulHanjaConversion_Impl;
//= HangulHanjaConversion
/** encapsulates Hangul-Hanja conversion functionality
<p>terminology:
<ul><li>A <b>text <em>portion</em></b> is some (potentially large) piece of text
which is to be analyzed for convertible sub-strings.</li>
<li>A <b>text <em>unit</em></b> is a sub string in a text portion, which is
to be converted as a whole.</li>
</ul>
For instance, you could have two independent selections within your document, which are then
two text portions. A text unit would be single Hangul/Hanja words within a portion, or even
single Hangul syllabills when "replace by character" is enabled.
</p>
*/
class EDITENG_DLLPUBLIC HangulHanjaConversion
{
friend class HangulHanjaConversion_Impl;
public:
enum ReplacementAction
{
eExchange, // simply exchange one text with another
eReplacementBracketed, // keep the original, and put the replacement in brackets after it
eOriginalBracketed, // replace the original text, but put it in brackeds after the replacement
eReplacementAbove, // keep the original, and put the replacement text as ruby text above it
eOriginalAbove, // replace the original text, but put it as ruby text above it
eReplacementBelow, // keep the original, and put the replacement text as ruby text below it
eOriginalBelow // replace the original text, but put it as ruby text below it
};
enum ConversionType // does not specify direction...
{
eConvHangulHanja, // Korean Hangul/Hanja conversion
eConvSimplifiedTraditional // Chinese simplified / Chinese traditional conversion
};
// Note: conversion direction for eConvSimplifiedTraditional is
// specified by source language.
// This one is for Hangul/Hanja where source and target language
// are the same.
enum ConversionDirection
{
eHangulToHanja,
eHanjaToHangul
};
enum ConversionFormat
{
eSimpleConversion, // used for simplified / traditional Chinese as well
eHangulBracketed,
eHanjaBracketed,
eRubyHanjaAbove,
eRubyHanjaBelow,
eRubyHangulAbove,
eRubyHangulBelow
};
private:
SAL_WNODEPRECATED_DECLARATIONS_PUSH
::std::auto_ptr< HangulHanjaConversion_Impl > m_pImpl;
SAL_WNODEPRECATED_DECLARATIONS_POP
// used to set initial values of m_pImpl object from saved ones
static bool m_bUseSavedValues; // defines if the followng two values should be used for initialization
static bool m_bTryBothDirectionsSave;
static ConversionDirection m_ePrimaryConversionDirectionSave;
// Forbidden and not implemented.
HangulHanjaConversion (const HangulHanjaConversion &);
HangulHanjaConversion & operator= (const HangulHanjaConversion &);
public:
HangulHanjaConversion(
Window* _pUIParent,
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
const ::com::sun::star::lang::Locale& _rSourceLocale,
const ::com::sun::star::lang::Locale& _rTargetLocale,
const Font* _pTargetFont,
sal_Int32 nOptions,
bool _bIsInteractive
);
virtual ~HangulHanjaConversion( );
// converts the whole document
void ConvertDocument();
LanguageType GetSourceLanguage() const;
LanguageType GetTargetLanguage() const;
const Font * GetTargetFont() const;
sal_Int32 GetConversionOptions() const;
bool IsInteractive() const;
// chinese text conversion
static inline bool IsSimplified( LanguageType nLang );
static inline bool IsTraditional( LanguageType nLang );
static inline bool IsChinese( LanguageType nLang );
// used to specify that the conversion direction states from the
// last incarnation should be used as
// initial conversion direction for the next incarnation.
// (A hack used to transport a state information from
// one incarnation to the next. Used in Writers text conversion...)
static void SetUseSavedConversionDirectionState( bool bVal );
static bool IsUseSavedConversionDirectionState();
protected:
/** retrieves the next text portion which is to be analyzed
<p>pseudo-abstract, needs to be overridden</p>
@param _rNextPortion
upon return, this must contain the next text portion
@param _rLangOfPortion
upon return, this must contain the language for the found text portion.
(necessary for Chinese translation since there are 5 language variants
too look for even if the 'source' language usually is only 'simplified'
or 'traditional'.)
*/
virtual void GetNextPortion(
OUString& /* [out] */ _rNextPortion,
LanguageType& /* [out] */ _rLangOfPortion,
bool /* [in] */ _bAllowImplicitChangesForNotConvertibleText ) = 0;
/** announces a new "current unit"
<p>This will be called whenever it is necessary to interactively ask the user for
a conversion. In such a case, a range within the current portion (see <member>GetNextPortion</member>)
is presented to the user for chosing a substitution. Additionally, this method is called,
so that derived classes can e.g. highlight this text range in a document view.</p>
<p>Note that the indexes are relative to the most recent replace action. See
<member>ReplaceUnit</member> for details.</p>
@param _nUnitStart
the start index of the unit
@param _nUnitEnd
the start index (exclusively!) of the unit.
@param _bAllowImplicitChangesForNotConvertibleText
allows implicit changes other than the text itself for the
text parts not being convertible.
Used for chinese translation to attribute all not convertible
text (e.g. western text, empty paragraphs, spaces, ...) to
the target language and target font of the conversion.
This is to ensure that after the conversion any new text entered
anywhere in the document will have the target language (of course
CJK Language only) and target font (CJK font only) set.
@see GetNextPortion
*/
virtual void HandleNewUnit( const sal_Int32 _nUnitStart, const sal_Int32 _nUnitEnd ) = 0;
/** replaces a text unit within a text portion with a new text
<p>pseudo-abstract, needs to be overridden</p>
<p>Note an important thing about the indices: They are always relative to the <em>previous
call</em> of ReplaceUnit. This means whe you get a call to ReplaceUnit, and replace some text
in your document, than you have to remember the document position immediately <em>behind</em>
the changed text. In a next call to ReplaceUnit, an index of <em>0</em> will denote exactly
this position behind the previous replacement<br/>
The reaons for this is that this class here does not know anything about your document structure,
so after a replacement took place, it's impossible to address anything in the range from the
beginning of the portion up to the replaced text.<br/>
In the very first call to ReplaceUnit, an index of <em>0</em> denotes the very first position of
the current portion.</p>
<p>If the language of the text to be replaced is different from
the target language (as given by 'GetTargetLanguage') for example
when converting simplified Chinese from/to traditional Chinese
the language attribute of the new text has to be changed as well,
**and** the font is to be set to the default (document) font for
that language.</p>
@param _nUnitStart
the start index of the range to replace
@param _nUnitEnd
the end index (exclusively!) of the range to replace. E.g., an index
pair (4,5) indicates a range of length 1.
@param _rOrigText
the original text to be replaced (as returned by GetNextPortion).
Since in Chinese conversion the original text is needed as well
in order to only do the minimal necassry text changes and to keep
as much attributes as possible this is supplied here as well.
@param _rReplaceWith
The replacement text
@param _rOffsets
An sequence matching the indices (characters) of _rReplaceWith
to the indices of the characters in the original text they are
replacing.
This is necessary since some portions of the text may get
converted in portions of different length than the original.
The sequence will be empty if all conversions in the text are
of equal length. That is if always the character at index i in
_rOffsets is replacing the character at index i in the original
text for all valid index values of i.
@param _eAction
replacement action to take
@param pNewUnitLanguage
if the replacement unit is required to have a new language that
is specified here. If the language is to be left unchanged this
is the 0 pointer.
*/
virtual void ReplaceUnit(
const sal_Int32 _nUnitStart, const sal_Int32 _nUnitEnd,
const OUString& _rOrigText,
const OUString& _rReplaceWith,
const ::com::sun::star::uno::Sequence< sal_Int32 > &_rOffsets,
ReplacementAction _eAction,
LanguageType *pNewUnitLanguage
) = 0;
/** specifies if rubies are supported by the document implementing
this class.
@return
<TRUE/> if rubies are supported.
*/
virtual bool HasRubySupport() const = 0;
};
bool HangulHanjaConversion::IsSimplified( LanguageType nLang )
{
return MsLangId::isSimplifiedChinese(nLang);
}
bool HangulHanjaConversion::IsTraditional( LanguageType nLang )
{
return MsLangId::isTraditionalChinese(nLang);
}
bool HangulHanjaConversion::IsChinese( LanguageType nLang )
{
return MsLangId::isChinese(nLang);
}
} // namespace svx
#endif // INCLUDED_EDITENG_HANGULHANJA_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|