diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-03-11 13:01:16 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-03-11 16:14:57 +0100 |
commit | 08e783903cf67e9c6673e21f99dfff816f8d5872 (patch) | |
tree | ea359afb12e7b112ce3324dd2fa021c506ffb39f /xmloff/source/style/XMLFontAutoStylePool.cxx | |
parent | f92510321dc860f43e471473db67167c0fefcbea (diff) |
ODF export: sort <style:font-face> elements based on the style:name attribute
m_pFontAutoStylePool is already sorted, but sorting ignores
XMLFontAutoStylePoolEntry_Impl::sName, and changing
XMLFontAutoStylePoolEntryCmp_Impl would affect how find() works in
XMLFontAutoStylePool::Add(), so just extend
XMLFontAutoStylePool::exportXML() instead.
With this, the order of <style:font-face> elements is meant to be stable
in content.xml and styles.xml, helping use-cases where a document is
converted to ODF multiple times and an integration test wants to assert
that the output is the same.
Change-Id: If0dbfa40a1b204aebe5e141fe64f71ac2ca92405
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112339
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'xmloff/source/style/XMLFontAutoStylePool.cxx')
-rw-r--r-- | xmloff/source/style/XMLFontAutoStylePool.cxx | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/xmloff/source/style/XMLFontAutoStylePool.cxx b/xmloff/source/style/XMLFontAutoStylePool.cxx index 248bb2bc8dcf..bffdfad796a5 100644 --- a/xmloff/source/style/XMLFontAutoStylePool.cxx +++ b/xmloff/source/style/XMLFontAutoStylePool.cxx @@ -406,8 +406,20 @@ void XMLFontAutoStylePool::exportXML() if (m_bEmbedUsedOnly) aUsedFontNames = getUsedFontList(); + // Sort <style:font-face> elements based on their style:name attribute. + std::vector<XMLFontAutoStylePoolEntry_Impl*> aFontAutoStyles; for (const auto& pEntry : *m_pFontAutoStylePool) { + aFontAutoStyles.push_back(pEntry.get()); + } + std::sort( + aFontAutoStyles.begin(), aFontAutoStyles.end(), + [](const XMLFontAutoStylePoolEntry_Impl* pA, XMLFontAutoStylePoolEntry_Impl* pB) -> bool { + return pA->GetName() < pB->GetName(); + }); + + for (const auto& pEntry : aFontAutoStyles) + { GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NAME, pEntry->GetName()); aAny <<= pEntry->GetFamilyName(); |