summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMaxim Monastirsky <momonasmon@gmail.com>2020-06-12 16:38:13 +0300
committerAdolfo Jayme Barrientos <fitojb@ubuntu.com>2020-06-14 11:37:05 +0200
commit2c2820b98c62e8de0806fd79c34b5fcf37f00c7e (patch)
tree0253823475e7d94bfef1654adcd435e1e2c79bc7 /xmloff
parent2a88edb1e102373620f5ca06900f1104f253a6f9 (diff)
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@gmail.com> (cherry picked from commit cd0dc1bc592d7952c36659da33d99ab964fe2e93) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96267 Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/core/xmlimp.cxx5
-rw-r--r--xmloff/source/style/xmlnumfi.cxx16
2 files changed, 17 insertions, 4 deletions
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: */