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 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_linguistic.hxx" 26 27 #include "linguistic/hyphdta.hxx" 28 #include "linguistic/lngprops.hxx" 29 #include "linguistic/misc.hxx" 30 #include <osl/mutex.hxx> 31 32 33 #include <rtl/ustrbuf.hxx> 34 #include <tools/debug.hxx> 35 #include <svl/lngmisc.hxx> 36 #include <unotools/localedatawrapper.hxx> 37 38 //using namespace utl; 39 using namespace osl; 40 using namespace rtl; 41 using namespace com::sun::star; 42 //using namespace com::sun::star::beans; 43 using namespace com::sun::star::lang; 44 using namespace com::sun::star::uno; 45 using namespace com::sun::star::linguistic2; 46 47 namespace linguistic 48 { 49 /////////////////////////////////////////////////////////////////////////// 50 51 52 HyphenatedWord::HyphenatedWord(const OUString &rWord, sal_Int16 nLang, sal_Int16 nHPos, 53 const OUString &rHyphWord, sal_Int16 nPos ) : 54 aWord (rWord), 55 aHyphenatedWord (rHyphWord), 56 nHyphPos (nPos), 57 nHyphenationPos (nHPos), 58 nLanguage (nLang) 59 { 60 String aSingleQuote( GetLocaleDataWrapper( nLanguage ).getQuotationMarkEnd() ); 61 DBG_ASSERT( 1 == aSingleQuote.Len(), "unexpected length of quotation mark" ); 62 if (aSingleQuote.Len()) 63 { 64 // ignore typographical apostrophes (which got replaced in original 65 // word when being checked for hyphenation) in results. 66 OUString aTmpWord( rWord ); 67 OUString aTmpHyphWord( rHyphWord ); 68 aTmpWord = aTmpWord .replace( aSingleQuote.GetChar(0), '\'' ); 69 aTmpHyphWord = aTmpHyphWord.replace( aSingleQuote.GetChar(0), '\'' ); 70 bIsAltSpelling = aTmpWord != aTmpHyphWord; 71 } 72 else 73 bIsAltSpelling = rWord != rHyphWord; 74 } 75 76 77 HyphenatedWord::~HyphenatedWord() 78 { 79 } 80 81 82 OUString SAL_CALL HyphenatedWord::getWord() 83 { 84 MutexGuard aGuard( GetLinguMutex() ); 85 return aWord; 86 } 87 88 89 Locale SAL_CALL HyphenatedWord::getLocale() 90 { 91 MutexGuard aGuard( GetLinguMutex() ); 92 93 Locale aRes; 94 return LanguageToLocale( aRes, nLanguage ); 95 } 96 97 98 sal_Int16 SAL_CALL HyphenatedWord::getHyphenationPos() 99 { 100 MutexGuard aGuard( GetLinguMutex() ); 101 return nHyphenationPos; 102 } 103 104 105 OUString SAL_CALL HyphenatedWord::getHyphenatedWord() 106 { 107 MutexGuard aGuard( GetLinguMutex() ); 108 return aHyphenatedWord; 109 } 110 111 112 sal_Int16 SAL_CALL HyphenatedWord::getHyphenPos() 113 { 114 MutexGuard aGuard( GetLinguMutex() ); 115 return nHyphPos; 116 } 117 118 119 sal_Bool SAL_CALL HyphenatedWord::isAlternativeSpelling() 120 { 121 MutexGuard aGuard( GetLinguMutex() ); 122 return bIsAltSpelling; 123 } 124 125 126 /////////////////////////////////////////////////////////////////////////// 127 128 129 PossibleHyphens::PossibleHyphens(const OUString &rWord, sal_Int16 nLang, 130 const OUString &rHyphWord, 131 const Sequence< sal_Int16 > &rPositions) : 132 aWord (rWord), 133 aWordWithHyphens(rHyphWord), 134 aOrigHyphenPos (rPositions), 135 nLanguage (nLang) 136 { 137 } 138 139 140 PossibleHyphens::~PossibleHyphens() 141 { 142 } 143 144 145 OUString SAL_CALL PossibleHyphens::getWord() 146 { 147 MutexGuard aGuard( GetLinguMutex() ); 148 return aWord; 149 } 150 151 152 Locale SAL_CALL PossibleHyphens::getLocale() 153 { 154 MutexGuard aGuard( GetLinguMutex() ); 155 return CreateLocale( nLanguage ); 156 } 157 158 159 OUString SAL_CALL PossibleHyphens::getPossibleHyphens() 160 { 161 MutexGuard aGuard( GetLinguMutex() ); 162 return aWordWithHyphens; 163 } 164 165 166 Sequence< sal_Int16 > SAL_CALL PossibleHyphens::getHyphenationPositions() 167 { 168 MutexGuard aGuard( GetLinguMutex() ); 169 return aOrigHyphenPos; 170 } 171 172 com::sun::star::uno::Reference <com::sun::star::linguistic2::XHyphenatedWord> HyphenatedWord::CreateHyphenatedWord( 173 const ::rtl::OUString &rWord, sal_Int16 nLang, sal_Int16 nHyphenationPos, 174 const ::rtl::OUString &rHyphenatedWord, sal_Int16 nHyphenPos ) 175 { 176 return new HyphenatedWord( rWord, nLang, nHyphenationPos, rHyphenatedWord, nHyphenPos ); 177 } 178 179 com::sun::star::uno::Reference < com::sun::star::linguistic2::XPossibleHyphens > PossibleHyphens::CreatePossibleHyphens 180 (const ::rtl::OUString &rWord, sal_Int16 nLang, 181 const ::rtl::OUString &rHyphWord, 182 const ::com::sun::star::uno::Sequence< sal_Int16 > &rPositions) 183 { 184 return new PossibleHyphens( rWord, nLang, rHyphWord, rPositions ); 185 } 186 187 188 /////////////////////////////////////////////////////////////////////////// 189 190 } // namespace linguistic 191