oox/source/ppt/pptshape.cxx | 25 ++++++++++++++++--------- sd/qa/unit/import-tests.cxx | 4 ++-- 2 files changed, 18 insertions(+), 11 deletions(-)
New commits: commit 253bee65bc24d999c3629a4d503d0fa01b355cfc Author: Tibor Nagy <[email protected]> AuthorDate: Wed Jun 16 11:02:48 2021 +0200 Commit: László Németh <[email protected]> CommitDate: Mon Jun 28 09:01:58 2021 +0200 tdf#142646 PPTX import: count repeating slide names instead of using the default slide name "Slide n". PPTX slides are named after their titles. Now repeating titles got a number instead of using the default slide name "Slide n". E.g. "Title", "Title", "Title" will be slide names "Title", "Title (2)", Title (3)", and not "Title", "Slide 2", "Slide 3". Follow-up to commit I98511c3c9a59598ea113e7387db5202d7f8a7cd4 "tdf#103347: PTX import: fix duplicated slide name" Change-Id: I449d6f7d7599291b3dae7df65ad6ff86a4269fb8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117317 Tested-by: László Németh <[email protected]> Reviewed-by: László Németh <[email protected]> diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx index 7f3786c41992..8b25523e5c3d 100644 --- a/oox/source/ppt/pptshape.cxx +++ b/oox/source/ppt/pptshape.cxx @@ -432,6 +432,7 @@ void PPTShape::addShape( { try { + sal_Int32 nCount = 1; OUString aTitleText; Reference<XTextRange> xText(xShape, UNO_QUERY_THROW); aTitleText = xText->getString(); @@ -442,17 +443,23 @@ void PPTShape::addShape( // just a magic value, but we don't want to set slide names which are too long aTitleText.getLength() < 64; // check duplicated title name - for (sal_uInt32 nPage = 0; bUseTitleAsSlideName && nPage < nMaxPages; ++nPage) - { - Reference<XDrawPage> xDrawPage(xDrawPages->getByIndex(nPage), uno::UNO_QUERY); - Reference<container::XNamed> xNamed(xDrawPage, UNO_QUERY_THROW); - if ( xNamed->getName() == aTitleText ) - bUseTitleAsSlideName = false; - } - if ( bUseTitleAsSlideName ) + if (bUseTitleAsSlideName) { + for (sal_uInt32 nPage = 0; nPage < nMaxPages; ++nPage) + { + Reference<XDrawPage> xDrawPage(xDrawPages->getByIndex(nPage), uno::UNO_QUERY); + Reference<container::XNamed> xNamed(xDrawPage, UNO_QUERY_THROW); + OUString sRest; + if (xNamed->getName().startsWith(aTitleText, &sRest) + && (sRest.isEmpty() + || (sRest.startsWith(" (") && sRest.endsWith(")") + && sRest.copy(2, sRest.getLength() - 3).toInt32() > 0))) + nCount++; + } Reference<container::XNamed> xName(rSlidePersist.getPage(), UNO_QUERY_THROW); - xName->setName(aTitleText); + xName->setName( + aTitleText + + (nCount == 1 ? OUString("") : " (" + OUString::number(nCount) + ")")); } } catch (uno::Exception&) diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx index 7637700eac1f..8723c0ee53b8 100644 --- a/sd/qa/unit/import-tests.cxx +++ b/sd/qa/unit/import-tests.cxx @@ -3449,11 +3449,11 @@ void SdImportTest::testTdf103347() uno::Reference<drawing::XDrawPage> xPage2(xDoc->getDrawPages()->getByIndex(1), uno::UNO_QUERY); uno::Reference<container::XNamed> xNamed2(xPage2, uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT_EQUAL(OUString("page2"), xNamed2->getName()); + CPPUNIT_ASSERT_EQUAL(OUString("Hello (2)"), xNamed2->getName()); uno::Reference<drawing::XDrawPage> xPage3(xDoc->getDrawPages()->getByIndex(2), uno::UNO_QUERY); uno::Reference<container::XNamed> xNamed3(xPage3, uno::UNO_QUERY_THROW); - CPPUNIT_ASSERT_EQUAL(OUString("page3"), xNamed3->getName()); + CPPUNIT_ASSERT_EQUAL(OUString("Hello (3)"), xNamed3->getName()); xDocShRef->DoClose(); } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
