[Libreoffice-commits] core.git: Branch 'libreoffice-6-4' - include/xmloff sw/qa xmloff/source
Maxim Monastirsky (via logerrit)
logerrit at kemper.freedesktop.org
Sun Jun 14 09:37:35 UTC 2020
include/xmloff/xmlnumfi.hxx | 2 ++
sw/qa/extras/odfimport/data/tdf133459.odt |binary
sw/qa/extras/odfimport/odfimport.cxx | 30 ++++++++++++++++++++++++++++++
xmloff/source/core/xmlimp.cxx | 5 +++--
xmloff/source/style/xmlnumfi.cxx | 16 ++++++++++++++--
5 files changed, 49 insertions(+), 4 deletions(-)
New commits:
commit 2c2820b98c62e8de0806fd79c34b5fcf37f00c7e
Author: Maxim Monastirsky <momonasmon at gmail.com>
AuthorDate: Fri Jun 12 16:38:13 2020 +0300
Commit: Adolfo Jayme Barrientos <fitojb at ubuntu.com>
CommitDate: Sun Jun 14 11:37:05 2020 +0200
tdf#133459 Fix import of fields with user defined number formats
commit 59ace23c367f83491a37e844d16f7d716eff6346 ("tdf#101710 Fix
invalid style:data-style-name attribute") had a side effect of
exporting user defined number formats under <office:styles> instead
of under <office:automatic-styles> (which is valid, and what Calc
does since forever). As it turned out, this didn't work well for
fields:
- For fields inside headers or footers, their number format wasn't
imported at all. The reason here is that fields use the
XMLTextImportHelper::GetDataStyleKey method to resolve data styles,
and that method checks only automatic styles. Actually it resolves
also styles from <office:styles>, because SvXMLImport::SetAutoStyles
has a special code that merges styles from <office:styles> into
automatic styles during content.xml reading. The problem is that
headers and footers have their contents stored inside styles.xml,
and no merging happens at this stage (unless it's a flat odf file).
One way to solve this could be to explicitly check for styles from
<office:styles> in XMLTextImportHelper::GetDataStyleKey (e.g. see
previous gerrit patchsets, or XMLTableStyleContext::GetNumberFormat)
I chose to simply modify the condition in SvXMLImport::SetAutoStyles,
so that merging happens anyway.
- Fields whose format resolution depends on the merging of
SvXMLImport::SetAutoStyles, did import the number format itself,
but not its language setting. This can be in one of three ways:
(a) Fields in the document and the header, when both use the same
format. In this case the format is stored once in styles.xml, so
at least the consumer from content.xml depends on merging.
(b) Field in the document with a user defined format - a regression
of the above commit. Now stored in styles.xml under <office:styles>
instead of in content.xml under <office:automatic-styles>.
(c) Field in a header with a user defined format - depends
on merging as a result of the above fix.
The reason here is that the merging isn't done with the original
SvXMLNumFormatContext objects, but with a newly created fake ones,
which only have the format id correct (with the assumption that
those formats already imported, and calling code could just find
them by the id). The problem is that the fields code uses
XMLTextImportHelper::GetDataStyleKey to get the language setting
from style objects, and set the IsFixedLanguage property according
to it, while we know that those fake objects don't have the
language correctly set. Try to fix that problem by setting the
correct language on those fake objects.
Conflicts:
sw/qa/extras/odfimport/odfimport.cxx
Change-Id: Ibb362df019921e040708d3bda83bf155535ec7af
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95612
Tested-by: Jenkins
Reviewed-by: Maxim Monastirsky <momonasmon at gmail.com>
(cherry picked from commit cd0dc1bc592d7952c36659da33d99ab964fe2e93)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96267
Reviewed-by: Adolfo Jayme Barrientos <fitojb at ubuntu.com>
diff --git a/include/xmloff/xmlnumfi.hxx b/include/xmloff/xmlnumfi.hxx
index 4a1eaca5b256..f772a54b4d28 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
new file mode 100644
index 000000000000..9468d7918a6c
Binary files /dev/null and b/sw/qa/extras/odfimport/data/tdf133459.odt differ
diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx
index eb65f0d63540..27e1809eaeff 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -23,6 +23,9 @@
#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/text/PageNumberType.hpp>
#include <com/sun/star/text/VertOrientation.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>
@@ -970,5 +973,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 e3c15d63fa82..ef63550ff2be 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -1621,7 +1621,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();
@@ -1632,7 +1632,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 c01992740f5e..6711d4471606 100644
--- a/xmloff/source/style/xmlnumfi.cxx
+++ b/xmloff/source/style/xmlnumfi.cxx
@@ -1480,7 +1480,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, XML_STYLE_FAMILY_DATA_STYLE ),
pData( nullptr ),
@@ -1488,7 +1488,7 @@ SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport,
aMyConditions(),
nType( 0 ),
nKey(nTempKey),
- nFormatLang( LANGUAGE_SYSTEM ),
+ nFormatLang( nLang ),
bAutoOrder( false ),
bFromSystem( false ),
bTruncate( true ),
@@ -2308,4 +2308,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: */
More information about the Libreoffice-commits
mailing list