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