diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2009-12-16 14:13:32 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2009-12-16 14:13:32 +0000 |
commit | 8ad186f00e3852bfd39ad9fb97df2e30563a57d5 (patch) | |
tree | fa03ead0aaddba044aa09c9eda9846c755bdd683 /linguistic | |
parent | 7ba4f341b076e877e1ff23a403fe41b113cf2fb6 (diff) | |
parent | 5228b9163b7c889a62b553e543fea51800099f7a (diff) |
tl74: merge with DEV300 m60
Diffstat (limited to 'linguistic')
-rw-r--r-- | linguistic/source/gciterator.cxx | 38 | ||||
-rw-r--r-- | linguistic/source/lngopt.cxx | 18 | ||||
-rw-r--r-- | linguistic/source/lngopt.hxx | 2 |
3 files changed, 41 insertions, 17 deletions
diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx index 4f555aeef8..94caf22eec 100644 --- a/linguistic/source/gciterator.cxx +++ b/linguistic/source/gciterator.cxx @@ -191,7 +191,7 @@ static sal_Int32 lcl_SkipWhiteSpaces( const OUString &rText, sal_Int32 nStartPos static sal_Int32 lcl_BacktraceWhiteSpaces( const OUString &rText, sal_Int32 nStartPos ) { - // note having nStartPos point right behind the string is OK since that one + // note: having nStartPos point right behind the string is OK since that one // is a correct end-of-sentence position to be returned from a grammar checker... const sal_Int32 nLen = rText.getLength(); @@ -215,14 +215,16 @@ static sal_Int32 lcl_BacktraceWhiteSpaces( const OUString &rText, sal_Int32 nSta sal_Int32 nPosBefore = nStartPos - 1; const sal_Unicode *pStart = rText.getStr(); if (0 <= nPosBefore && nPosBefore < nLen && lcl_IsWhiteSpace( pStart[ nPosBefore ] )) - nStartPos = nPosBefore; - if (0 <= nStartPos && nStartPos < nLen) { - const sal_Unicode *pText = rText.getStr() + nStartPos; - while (pText > pStart && lcl_IsWhiteSpace( *pText )) - --pText; - // now add 1 since we wnat to point to the first char after the last char in the sentence... - nRes = pText - pStart + 1; + nStartPos = nPosBefore; + if (0 <= nStartPos && nStartPos < nLen) + { + const sal_Unicode *pText = rText.getStr() + nStartPos; + while (pText > pStart && lcl_IsWhiteSpace( *pText )) + --pText; + // now add 1 since we want to point to the first char after the last char in the sentence... + nRes = pText - pStart + 1; + } } DBG_ASSERT( 0 <= nRes && nRes <= nLen, "lcl_BacktraceWhiteSpaces return value out of range" ); @@ -577,6 +579,7 @@ void GrammarCheckingIterator::DequeueAndCheck() sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex; sal_Int32 nSuggestedEnd = GetSuggestedEndOfSentence( aCurTxt, nStartPos, aCurLocale ); + DBG_ASSERT( nSuggestedEnd > nStartPos, "nSuggestedEndOfSentencePos calculation failed?" ); linguistic2::ProofreadingResult aRes; @@ -586,6 +589,15 @@ void GrammarCheckingIterator::DequeueAndCheck() aGuard.clear(); uno::Sequence< beans::PropertyValue > aEmptyProps; aRes = xGC->doProofreading( aCurDocId, aCurTxt, aCurLocale, nStartPos, nSuggestedEnd, aEmptyProps ); + + //!! work-around to prevent looping if the grammar checker + //!! failed to properly identify the sentence end + if (aRes.nBehindEndOfSentencePosition <= nStartPos) + { + DBG_ASSERT( 0, "!! Grammarchecker failed to provide end of sentence !!" ); + aRes.nBehindEndOfSentencePosition = nSuggestedEnd; + } + aRes.xFlatParagraph = xFlatPara; aRes.nStartOfSentencePosition = nStartPos; } @@ -718,6 +730,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException) ::osl::ClearableGuard< ::osl::Mutex > aGuard( MyMutex::get() ); aDocId = GetOrCreateDocId( xComponent ); nSuggestedEndOfSentencePos = GetSuggestedEndOfSentence( rText, nStartPos, aCurLocale ); + DBG_ASSERT( nSuggestedEndOfSentencePos > nStartPos, "nSuggestedEndOfSentencePos calculation failed?" ); xGC = GetGrammarChecker( aCurLocale ); } @@ -727,6 +740,15 @@ throw (lang::IllegalArgumentException, uno::RuntimeException) { uno::Sequence< beans::PropertyValue > aEmptyProps; aTmpRes = xGC->doProofreading( aDocId, rText, aCurLocale, nStartPos, nSuggestedEndOfSentencePos, aEmptyProps ); + + //!! work-around to prevent looping if the grammar checker + //!! failed to properly identify the sentence end + if (aTmpRes.nBehindEndOfSentencePosition <= nStartPos) + { + DBG_ASSERT( 0, "!! Grammarchecker failed to provide end of sentence !!" ); + aTmpRes.nBehindEndOfSentencePosition = nSuggestedEndOfSentencePos; + } + aTmpRes.xFlatParagraph = xFlatPara; aTmpRes.nStartOfSentencePosition = nStartPos; nEndPos = aTmpRes.nBehindEndOfSentencePosition; diff --git a/linguistic/source/lngopt.cxx b/linguistic/source/lngopt.cxx index bb750b2eb7..fc6f4c7cc3 100644 --- a/linguistic/source/lngopt.cxx +++ b/linguistic/source/lngopt.cxx @@ -46,7 +46,9 @@ #include <com/sun/star/registry/XSimpleRegistry.hpp> #include <com/sun/star/registry/XRegistryKey.hpp> #include <com/sun/star/lang/Locale.hpp> +#include <com/sun/star/i18n/ScriptType.hpp> #include <unotools/processfactory.hxx> +#include <i18npool/mslangid.hxx> using namespace utl; using namespace osl; @@ -100,13 +102,13 @@ LinguOptions::~LinguOptions() } -BOOL LinguOptions::SetLocale_Impl( INT16 &rLanguage, Any &rOld, const Any &rVal) +BOOL LinguOptions::SetLocale_Impl( INT16 &rLanguage, Any &rOld, const Any &rVal, sal_Int16 nType) { BOOL bRes = FALSE; Locale aNew; rVal >>= aNew; - INT16 nNew = LocaleToLanguage( aNew ); + INT16 nNew = MsLangId::resolveSystemLanguageByScriptType(MsLangId::convertLocaleToLanguage(aNew), nType); if (nNew != rLanguage) { Locale aLocale( CreateLocale( rLanguage ) ); @@ -149,17 +151,17 @@ BOOL LinguOptions::SetValue( Any &rOld, const Any &rVal, INT32 nWID ) case WID_HYPH_MIN_WORD_LENGTH : pnVal = &pData->nHyphMinWordLength; break; case WID_DEFAULT_LOCALE : { - bRes = SetLocale_Impl( pData->nDefaultLanguage, rOld, rVal ); + bRes = SetLocale_Impl( pData->nDefaultLanguage, rOld, rVal, ::com::sun::star::i18n::ScriptType::LATIN ); break; } case WID_DEFAULT_LOCALE_CJK : { - bRes = SetLocale_Impl( pData->nDefaultLanguage_CJK, rOld, rVal ); + bRes = SetLocale_Impl( pData->nDefaultLanguage_CJK, rOld, rVal, ::com::sun::star::i18n::ScriptType::ASIAN ); break; } case WID_DEFAULT_LOCALE_CTL : { - bRes = SetLocale_Impl( pData->nDefaultLanguage_CTL, rOld, rVal ); + bRes = SetLocale_Impl( pData->nDefaultLanguage_CTL, rOld, rVal, ::com::sun::star::i18n::ScriptType::COMPLEX ); break; } default : @@ -227,19 +229,19 @@ void LinguOptions::GetValue( Any &rVal, INT32 nWID ) const case WID_HYPH_MIN_WORD_LENGTH : pnVal = &pData->nHyphMinWordLength; break; case WID_DEFAULT_LOCALE : { - Locale aLocale( CreateLocale( pData->nDefaultLanguage ) ); + Locale aLocale( MsLangId::convertLanguageToLocale( pData->nDefaultLanguage ) ); rVal.setValue( &aLocale, ::getCppuType((Locale*)0 )); break; } case WID_DEFAULT_LOCALE_CJK : { - Locale aLocale( CreateLocale( pData->nDefaultLanguage_CJK ) ); + Locale aLocale( MsLangId::convertLanguageToLocale( pData->nDefaultLanguage_CJK ) ); rVal.setValue( &aLocale, ::getCppuType((Locale*)0 )); break; } case WID_DEFAULT_LOCALE_CTL : { - Locale aLocale( CreateLocale( pData->nDefaultLanguage_CTL ) ); + Locale aLocale( MsLangId::convertLanguageToLocale( pData->nDefaultLanguage_CTL ) ); rVal.setValue( &aLocale, ::getCppuType((Locale*)0 )); break; } diff --git a/linguistic/source/lngopt.hxx b/linguistic/source/lngopt.hxx index d983088265..2188ef4d88 100644 --- a/linguistic/source/lngopt.hxx +++ b/linguistic/source/lngopt.hxx @@ -77,7 +77,7 @@ class LinguOptions BOOL SetLocale_Impl( INT16 &rLanguage, ::com::sun::star::uno::Any &rOld, - const ::com::sun::star::uno::Any &rVal); + const ::com::sun::star::uno::Any &rVal, sal_Int16 nType ); public: LinguOptions(); |