diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-08-02 17:53:06 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-06-07 15:40:27 +0200 |
commit | e87f6c248a939c27d7023e752a16c3c278aa922b (patch) | |
tree | ca6654e867e0e1ef5d39a5663446d255fe8b899d /sw/source/core/fields/usrfld.cxx | |
parent | db51bd203ff2796f268b0c89fd1c13f6b81f95d7 (diff) |
sw user field type: fix locale of string -> float conversion
The key part is the SwUserFieldType::GetValue() hunk, the field type has
to always use the same locale, which means if we get an SwCalc reference
that works with the document or field locale that has to be switched
temporarily.
Reviewed-on: https://gerrit.libreoffice.org/58492
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins
(cherry picked from commit 6ca5d288ca810f128163da121777ee2e11c46edc)
Conflicts:
sw/qa/extras/layout/layout.cxx
sw/source/core/fields/usrfld.cxx
Change-Id: I26ff18e74f477729a66b066c4baf6d215a7685bc
(cherry picked from commit 5109f63c66dc8b91e7ff4ac62ebec59ece5eb3a9)
Diffstat (limited to 'sw/source/core/fields/usrfld.cxx')
-rw-r--r-- | sw/source/core/fields/usrfld.cxx | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/sw/source/core/fields/usrfld.cxx b/sw/source/core/fields/usrfld.cxx index e14ffa13e037..f67f74a81113 100644 --- a/sw/source/core/fields/usrfld.cxx +++ b/sw/source/core/fields/usrfld.cxx @@ -35,6 +35,18 @@ using namespace ::com::sun::star; +namespace +{ +/** + * Returns the language used for float <-> string conversions in + * SwUserFieldType. + */ +LanguageType GetFieldTypeLanguage() +{ + return LANGUAGE_SYSTEM; +} +} + // Userfields SwUserField::SwUserField(SwUserFieldType* pTyp, sal_uInt16 nSub, sal_uInt32 nFormat) @@ -218,7 +230,21 @@ double SwUserFieldType::GetValue( SwCalc& rCalc ) rCalc.SetCalcError( CALC_SYNTAX ); return 0; } + + // See if we need to temporarily switch rCalc's language: in case it + // differs from the field type locale. + CharClass* pCharClass = rCalc.GetCharClass(); + LanguageTag aCalcLanguage = pCharClass->getLanguageTag(); + LanguageTag aFieldTypeLanguage(GetFieldTypeLanguage()); + bool bSwitchLanguage = aCalcLanguage != aFieldTypeLanguage; + if (bSwitchLanguage) + pCharClass->setLanguageTag(aFieldTypeLanguage); + nValue = rCalc.Calculate( aContent ).GetDouble(); + + if (bSwitchLanguage) + pCharClass->setLanguageTag(aCalcLanguage); + rCalc.Pop(); if( !rCalc.IsCalcError() ) @@ -302,10 +328,7 @@ bool SwUserFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) rAny >>= fVal; nValue = fVal; - // The following line is in fact wrong, since the language is unknown (is part of the - // field) and, thus, aContent should also belong to the field. Each field can have a - // different language, but the same content with just different formatting. - aContent = DoubleToString(nValue, static_cast<sal_uInt32>(LANGUAGE_SYSTEM)); + aContent = DoubleToString(nValue, static_cast<sal_uInt16>(GetFieldTypeLanguage())); } break; case FIELD_PROP_PAR2: |