From 9b72524722efbc60532a04bb55660a3c35696adf Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Mon, 1 Jul 2024 23:43:01 +0200 Subject: [PATCH] pptx export: Respect user defined initials instead of generating new ones. Change-Id: I8979eaa694642cebd552534eeddcff5483831e6e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169846 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt --- sd/source/filter/eppt/epptbase.hxx | 1 - sd/source/filter/eppt/epptooxml.hxx | 3 ++- sd/source/filter/eppt/pptx-epptbase.cxx | 20 -------------------- sd/source/filter/eppt/pptx-epptooxml.cxx | 12 +++++++++--- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/sd/source/filter/eppt/epptbase.hxx b/sd/source/filter/eppt/epptbase.hxx index 18199210cc6b..70bcd3a4b6ce 100644 --- a/sd/source/filter/eppt/epptbase.hxx +++ b/sd/source/filter/eppt/epptbase.hxx @@ -379,7 +379,6 @@ protected: ::tools::Rectangle MapRectangle( const css::awt::Rectangle& ); bool ContainsOtherShapeThanPlaceholders(); - static OUString GetInitials(std::u16string_view sName); public: PPTWriterBase(); diff --git a/sd/source/filter/eppt/epptooxml.hxx b/sd/source/filter/eppt/epptooxml.hxx index 9646afb865d8..7d1fa57f11d3 100644 --- a/sd/source/filter/eppt/epptooxml.hxx +++ b/sd/source/filter/eppt/epptooxml.hxx @@ -109,7 +109,7 @@ private: sal_uInt32 GetNewSlideId() { return mnSlideIdMax ++; } sal_uInt32 GetNewSlideMasterId() { return mnSlideMasterIdMax ++; } - sal_Int32 GetAuthorIdAndLastIndex( const OUString& sAuthor, sal_Int32& nLastIndex ); + sal_Int32 GetAuthorIdAndLastIndex( const OUString& sAuthor, const OUString& sInitials, sal_Int32& nLastIndex ); // Write docProps/core.xml and docprops/custom.xml and docprops/app.xml void writeDocumentProperties(); @@ -165,6 +165,7 @@ private: struct AuthorComments { sal_Int32 nId; sal_Int32 nLastIndex; + OUString sInitials; }; typedef std::unordered_map< OUString, struct AuthorComments > AuthorsMap; AuthorsMap maAuthors; diff --git a/sd/source/filter/eppt/pptx-epptbase.cxx b/sd/source/filter/eppt/pptx-epptbase.cxx index fe9444865797..eebf01410c15 100644 --- a/sd/source/filter/eppt/pptx-epptbase.cxx +++ b/sd/source/filter/eppt/pptx-epptbase.cxx @@ -998,24 +998,4 @@ bool PPTWriterBase::ContainsOtherShapeThanPlaceholders() return bOtherThanPlaceHolders; } -OUString PPTWriterBase::GetInitials(std::u16string_view sName) -{ - OUStringBuffer sRet; - - if (!sName.empty()) - { - sRet.append(sName[0]); - size_t nStart = 0, nOffset; - - while ((nOffset = sName.find(' ', nStart)) != std::u16string_view::npos) - { - if (nOffset + 1 < sName.size()) - sRet.append(sName[ nOffset + 1 ]); - nStart = nOffset + 1; - } - } - - return sRet.makeStringAndClear(); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx index f7379a3cd68e..6c1b8c466e01 100644 --- a/sd/source/filter/eppt/pptx-epptooxml.cxx +++ b/sd/source/filter/eppt/pptx-epptooxml.cxx @@ -1036,7 +1036,7 @@ void PowerPointExport::WriteAuthors() pFS->singleElementNS(XML_p, XML_cmAuthor, XML_id, OString::number(i.second.nId), XML_name, i.first, - XML_initials, GetInitials(i.first), + XML_initials, i.second.sInitials, XML_lastIdx, OString::number(i.second.nLastIndex), XML_clrIdx, OString::number(i.second.nId)); } @@ -1046,7 +1046,9 @@ void PowerPointExport::WriteAuthors() pFS->endDocument(); } -sal_Int32 PowerPointExport::GetAuthorIdAndLastIndex(const OUString& sAuthor, sal_Int32& nLastIndex) +sal_Int32 PowerPointExport::GetAuthorIdAndLastIndex(const OUString& sAuthor, + const OUString& sInitials, + sal_Int32& nLastIndex) { if (maAuthors.count(sAuthor) <= 0) { @@ -1054,6 +1056,7 @@ sal_Int32 PowerPointExport::GetAuthorIdAndLastIndex(const OUString& sAuthor, sal aAuthorComments.nId = maAuthors.size(); aAuthorComments.nLastIndex = 0; + aAuthorComments.sInitials = sInitials; maAuthors[ sAuthor ] = aAuthorComments; } @@ -1172,7 +1175,10 @@ bool PowerPointExport::WriteComments(sal_uInt32 nPageNum) ? "Author" + OUString::number(GetInfoID(xAnnotation->getAuthor())) : xAnnotation->getAuthor()); - sal_Int32 nId = GetAuthorIdAndLastIndex(sAuthor, nLastIndex); + OUString sInitials(bRemoveCommentAuthorDates + ? "A" + OUString::number(GetInfoID(xAnnotation->getAuthor())) + : xAnnotation->getInitials()); + sal_Int32 nId = GetAuthorIdAndLastIndex(sAuthor, sInitials, nLastIndex); char cDateTime[sizeof("-32768-65535-65535T65535:65535:65535.4294967295")]; // reserve enough space for hypothetical max length