summaryrefslogtreecommitdiff
path: root/sw/source/filter/xml
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-09-09 13:04:01 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-09-09 14:27:52 +0200
commit7a8bb65e1b8dc7fdd7f89c8c546e71e4208da574 (patch)
treea7e3503c90395052a071b543f21be5303ddef947 /sw/source/filter/xml
parenta9cd44f8deeccbb8afc7209fdf86fbc26ea7a464 (diff)
ODT export: order <style:font-face> elements inside <office:font-face-decls>
This builds on top of commit 92471550b8c43d8ff0cef8b414884d697edf9e63 (ODF export: sort <style:font-face> elements based on the style:name attribute, 2021-03-11), the additional problem was that the style:name attribute already has number suffixes to have unique names for fonts where the style name would match. This means that even if we sort the container right before writing the elements, which font gets the number suffix depends on the insert order. Fix this by additionally sorting the font items before insertion, given that a single call-site does all the insertion, at least for Writer documents. This is required as SfxItemPool::GetItemSurrogates() exposes a container which is based on SfxPoolItemArray_Impl, which uses an o3tl::sorted_vector<> of pointers, so effectively unsorted, the order depends on the pointer address of the font items. Change-Id: I46569b40796243f7f95b92870504c2023b2ce943 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121823 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/source/filter/xml')
-rw-r--r--sw/source/filter/xml/xmlfonte.cxx18
1 files changed, 12 insertions, 6 deletions
diff --git a/sw/source/filter/xml/xmlfonte.cxx b/sw/source/filter/xml/xmlfonte.cxx
index ce415aeb41e5..b8c0f7730d57 100644
--- a/sw/source/filter/xml/xmlfonte.cxx
+++ b/sw/source/filter/xml/xmlfonte.cxx
@@ -46,21 +46,27 @@ SwXMLFontAutoStylePool_Impl::SwXMLFontAutoStylePool_Impl(SwXMLExport& _rExport,
RES_CHRATR_CTL_FONT };
const SfxItemPool& rPool = _rExport.getDoc()->GetAttrPool();
+ std::vector<const SvxFontItem *> aFonts;
for(sal_uInt16 nWhichId : aWhichIds)
{
const SvxFontItem& rFont =
static_cast<const SvxFontItem&>(rPool.GetDefaultItem( nWhichId ));
- Add( rFont.GetFamilyName(), rFont.GetStyleName(),
- rFont.GetFamily(), rFont.GetPitch(),
- rFont.GetCharSet() );
+ aFonts.push_back(&rFont);
for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(nWhichId))
{
auto pFont = static_cast<const SvxFontItem *>(pItem);
- Add( pFont->GetFamilyName(), pFont->GetStyleName(),
- pFont->GetFamily(), pFont->GetPitch(),
- pFont->GetCharSet() );
+ aFonts.push_back(pFont);
}
}
+
+ std::sort(aFonts.begin(), aFonts.end(),
+ [](const SvxFontItem* pA, const SvxFontItem* pB) -> bool { return *pA < *pB; });
+ for (const auto& pFont : aFonts)
+ {
+ Add(pFont->GetFamilyName(), pFont->GetStyleName(), pFont->GetFamily(), pFont->GetPitch(),
+ pFont->GetCharSet());
+ }
+
auto const & pDocument = _rExport.getDoc();
m_bEmbedUsedOnly = pDocument->getIDocumentSettingAccess().get(DocumentSettingId::EMBED_USED_FONTS);