LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/editeng - hangulhanja.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 6 0.0 %
Date: 2012-08-25 Functions: 0 3 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10