diff options
-rw-r--r-- | include/xmloff/xmlnumfi.hxx | 2 | ||||
-rw-r--r-- | sw/qa/extras/odfimport/data/tdf133459.odt | bin | 0 -> 8061 bytes | |||
-rw-r--r-- | sw/qa/extras/odfimport/odfimport.cxx | 30 | ||||
-rw-r--r-- | xmloff/source/core/xmlimp.cxx | 5 | ||||
-rw-r--r-- | xmloff/source/style/xmlnumfi.cxx | 16 |
5 files changed, 49 insertions, 4 deletions
diff --git a/include/xmloff/xmlnumfi.hxx b/include/xmloff/xmlnumfi.hxx index 21eac93a3cd9..b337fad36832 100644 --- a/include/xmloff/xmlnumfi.hxx +++ b/include/xmloff/xmlnumfi.hxx @@ -91,6 +91,7 @@ public: SvXMLNumImpData* getData() { return pData.get(); } const SvXMLTokenMap& GetStylesElemTokenMap(); + LanguageType GetLanguageForKey(sal_Int32 nKey); // sal_uInt32 GetKeyForName( const OUString& rName ); }; @@ -164,6 +165,7 @@ public: const OUString& rLName, const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList, const sal_Int32 nKey, + LanguageType nLang, SvXMLStylesContext& rStyles ); virtual ~SvXMLNumFormatContext() override; diff --git a/sw/qa/extras/odfimport/data/tdf133459.odt b/sw/qa/extras/odfimport/data/tdf133459.odt Binary files differnew file mode 100644 index 000000000000..9468d7918a6c --- /dev/null +++ b/sw/qa/extras/odfimport/data/tdf133459.odt diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx index 30737c3454dd..70d5a158b22c 100644 --- a/sw/qa/extras/odfimport/odfimport.cxx +++ b/sw/qa/extras/odfimport/odfimport.cxx @@ -30,6 +30,9 @@ #include <com/sun/star/text/PageNumberType.hpp> #include <com/sun/star/text/VertOrientation.hpp> #include <com/sun/star/view/XControlAccess.hpp> +#include <com/sun/star/util/XNumberFormatTypes.hpp> +#include <com/sun/star/util/XNumberFormatsSupplier.hpp> +#include <com/sun/star/lang/Locale.hpp> #include <IDocumentSettingAccess.hxx> #include <wrtsh.hxx> @@ -1048,5 +1051,32 @@ DECLARE_ODFIMPORT_TEST(testTdf123968, "tdf123968.odt") rStart.GetText()); } +DECLARE_ODFIMPORT_TEST(testTdf133459, "tdf133459.odt") +{ + // Test that the number format was correctly imported, and used by both fields. + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xFields(xTextFieldsSupplier->getTextFields()->createEnumeration()); + + // First Field + uno::Reference<text::XTextField> xField(xFields->nextElement(), uno::UNO_QUERY); + const OUString sPresentation(xField->getPresentation(false)); + const sal_Int32 nFormat(getProperty<sal_Int32>(xField, "NumberFormat")); + CPPUNIT_ASSERT_EQUAL(sal_True, getProperty<sal_Bool>(xField, "IsFixedLanguage")); + + // Second field + xField.set(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sPresentation, xField->getPresentation(false)); + CPPUNIT_ASSERT_EQUAL(nFormat, getProperty<sal_Int32>(xField, "NumberFormat")); + CPPUNIT_ASSERT_EQUAL(sal_True, getProperty<sal_Bool>(xField, "IsFixedLanguage")); + + // Test the number format itself + uno::Reference<util::XNumberFormatsSupplier> xNumberFormatsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xFormat(xNumberFormatsSupplier->getNumberFormats()->getByKey(nFormat)); + lang::Locale aLocale(getProperty<lang::Locale>(xFormat, "Locale")); + CPPUNIT_ASSERT_EQUAL(OUString("ru"), aLocale.Language); + CPPUNIT_ASSERT_EQUAL(OUString("RU"), aLocale.Country); + CPPUNIT_ASSERT_EQUAL(OUString("QQ YYYY"), getProperty<OUString>(xFormat, "FormatString")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx index 36550f1f8192..1e77eca85928 100644 --- a/xmloff/source/core/xmlimp.cxx +++ b/xmloff/source/core/xmlimp.cxx @@ -1625,7 +1625,7 @@ void SvXMLImport::SetStyles( SvXMLStylesContext *pStyles ) void SvXMLImport::SetAutoStyles( SvXMLStylesContext *pAutoStyles ) { - if (pAutoStyles && mxNumberStyles.is() && (mnImportFlags & SvXMLImportFlags::CONTENT) ) + if (pAutoStyles && mxNumberStyles.is()) { uno::Reference<xml::sax::XAttributeList> xAttrList; const uno::Sequence<OUString> aStyleNames = mxNumberStyles->getElementNames(); @@ -1636,7 +1636,8 @@ void SvXMLImport::SetAutoStyles( SvXMLStylesContext *pAutoStyles ) if (aAny >>= nKey) { SvXMLStyleContext* pContext = new SvXMLNumFormatContext( - *this, XML_NAMESPACE_NUMBER, name, xAttrList, nKey, *pAutoStyles); + *this, XML_NAMESPACE_NUMBER, name, xAttrList, nKey, + GetDataStylesImport()->GetLanguageForKey(nKey), *pAutoStyles); pAutoStyles->AddStyle(*pContext); } } diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx index 79a68e424be8..61b6bc1cfb08 100644 --- a/xmloff/source/style/xmlnumfi.cxx +++ b/xmloff/source/style/xmlnumfi.cxx @@ -1470,7 +1470,7 @@ SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport, SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const uno::Reference<xml::sax::XAttributeList>& xAttrList, - const sal_Int32 nTempKey, + const sal_Int32 nTempKey, LanguageType nLang, SvXMLStylesContext& rStyles ) : SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XmlStyleFamily::DATA_STYLE ), pData( nullptr ), @@ -1478,7 +1478,7 @@ SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport, aMyConditions(), nType( 0 ), nKey(nTempKey), - nFormatLang( LANGUAGE_SYSTEM ), + nFormatLang( nLang ), bAutoOrder( false ), bFromSystem( false ), bTruncate( true ), @@ -2302,4 +2302,16 @@ const SvXMLTokenMap& SvXMLNumFmtHelper::GetStylesElemTokenMap() return pData->GetStylesElemTokenMap(); } +LanguageType SvXMLNumFmtHelper::GetLanguageForKey(sal_Int32 nKey) +{ + if (pData->GetNumberFormatter()) + { + const SvNumberformat* pEntry = pData->GetNumberFormatter()->GetEntry(nKey); + if (pEntry) + return pEntry->GetLanguage(); + } + + return LANGUAGE_SYSTEM; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |