diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-08-02 17:53:06 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-08-02 19:10:23 +0200 |
commit | 6ca5d288ca810f128163da121777ee2e11c46edc (patch) | |
tree | 6f421bfc721366f3b51dd55134a5c1c56ca1d842 /sw/source/core/fields/usrfld.cxx | |
parent | 82828c6c4030ccc8b7af8ee4e7eebd9c6d32fdf9 (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.
Change-Id: I26ff18e74f477729a66b066c4baf6d215a7685bc
Reviewed-on: https://gerrit.libreoffice.org/58492
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins
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 d81ba1c84ae8..5537fc36ea92 100644 --- a/sw/source/core/fields/usrfld.cxx +++ b/sw/source/core/fields/usrfld.cxx @@ -41,6 +41,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) @@ -232,7 +244,21 @@ double SwUserFieldType::GetValue( SwCalc& rCalc ) rCalc.SetCalcError( SwCalcError::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() ) @@ -313,10 +339,7 @@ void 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_uInt16>(LANGUAGE_SYSTEM)); + aContent = DoubleToString(nValue, static_cast<sal_uInt16>(GetFieldTypeLanguage())); } break; case FIELD_PROP_PAR2: |