1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_linguistic.hxx" 30 31 #include "linguistic/hyphdta.hxx" 32 #include "linguistic/lngprops.hxx" 33 #include "linguistic/misc.hxx" 34 #include <osl/mutex.hxx> 35 36 37 #include <rtl/ustrbuf.hxx> 38 #include <tools/debug.hxx> 39 #include <svl/lngmisc.hxx> 40 #include <unotools/localedatawrapper.hxx> 41 42 //using namespace utl; 43 using namespace osl; 44 using namespace rtl; 45 using namespace com::sun::star; 46 //using namespace com::sun::star::beans; 47 using namespace com::sun::star::lang; 48 using namespace com::sun::star::uno; 49 using namespace com::sun::star::linguistic2; 50 51 namespace linguistic 52 { 53 /////////////////////////////////////////////////////////////////////////// 54 55 56 HyphenatedWord::HyphenatedWord(const OUString &rWord, sal_Int16 nLang, sal_Int16 nHPos, 57 const OUString &rHyphWord, sal_Int16 nPos ) : 58 aWord (rWord), 59 aHyphenatedWord (rHyphWord), 60 nHyphPos (nPos), 61 nHyphenationPos (nHPos), 62 nLanguage (nLang) 63 { 64 String aSingleQuote( GetLocaleDataWrapper( nLanguage ).getQuotationMarkEnd() ); 65 DBG_ASSERT( 1 == aSingleQuote.Len(), "unexpectend length of quotation mark" ); 66 if (aSingleQuote.Len()) 67 { 68 // ignore typographical apostrophes (which got replaced in original 69 // word when being checked for hyphenation) in results. 70 OUString aTmpWord( rWord ); 71 OUString aTmpHyphWord( rHyphWord ); 72 aTmpWord = aTmpWord .replace( aSingleQuote.GetChar(0), '\'' ); 73 aTmpHyphWord = aTmpHyphWord.replace( aSingleQuote.GetChar(0), '\'' ); 74 bIsAltSpelling = aTmpWord != aTmpHyphWord; 75 } 76 else 77 bIsAltSpelling = rWord != rHyphWord; 78 } 79 80 81 HyphenatedWord::~HyphenatedWord() 82 { 83 } 84 85 86 OUString SAL_CALL HyphenatedWord::getWord() 87 throw(RuntimeException) 88 { 89 MutexGuard aGuard( GetLinguMutex() ); 90 return aWord; 91 } 92 93 94 Locale SAL_CALL HyphenatedWord::getLocale() 95 throw(RuntimeException) 96 { 97 MutexGuard aGuard( GetLinguMutex() ); 98 99 Locale aRes; 100 return LanguageToLocale( aRes, nLanguage ); 101 } 102 103 104 sal_Int16 SAL_CALL HyphenatedWord::getHyphenationPos() 105 throw(RuntimeException) 106 { 107 MutexGuard aGuard( GetLinguMutex() ); 108 return nHyphenationPos; 109 } 110 111 112 OUString SAL_CALL HyphenatedWord::getHyphenatedWord() 113 throw(RuntimeException) 114 { 115 MutexGuard aGuard( GetLinguMutex() ); 116 return aHyphenatedWord; 117 } 118 119 120 sal_Int16 SAL_CALL HyphenatedWord::getHyphenPos() 121 throw(RuntimeException) 122 { 123 MutexGuard aGuard( GetLinguMutex() ); 124 return nHyphPos; 125 } 126 127 128 sal_Bool SAL_CALL HyphenatedWord::isAlternativeSpelling() 129 throw(RuntimeException) 130 { 131 MutexGuard aGuard( GetLinguMutex() ); 132 return bIsAltSpelling; 133 } 134 135 136 /////////////////////////////////////////////////////////////////////////// 137 138 139 PossibleHyphens::PossibleHyphens(const OUString &rWord, sal_Int16 nLang, 140 const OUString &rHyphWord, 141 const Sequence< sal_Int16 > &rPositions) : 142 aWord (rWord), 143 aWordWithHyphens(rHyphWord), 144 aOrigHyphenPos (rPositions), 145 nLanguage (nLang) 146 { 147 } 148 149 150 PossibleHyphens::~PossibleHyphens() 151 { 152 } 153 154 155 OUString SAL_CALL PossibleHyphens::getWord() 156 throw(RuntimeException) 157 { 158 MutexGuard aGuard( GetLinguMutex() ); 159 return aWord; 160 } 161 162 163 Locale SAL_CALL PossibleHyphens::getLocale() 164 throw(RuntimeException) 165 { 166 MutexGuard aGuard( GetLinguMutex() ); 167 return CreateLocale( nLanguage ); 168 } 169 170 171 OUString SAL_CALL PossibleHyphens::getPossibleHyphens() 172 throw(RuntimeException) 173 { 174 MutexGuard aGuard( GetLinguMutex() ); 175 return aWordWithHyphens; 176 } 177 178 179 Sequence< sal_Int16 > SAL_CALL PossibleHyphens::getHyphenationPositions() 180 throw(RuntimeException) 181 { 182 MutexGuard aGuard( GetLinguMutex() ); 183 return aOrigHyphenPos; 184 } 185 186 /////////////////////////////////////////////////////////////////////////// 187 188 } // namespace linguistic 189 190