summaryrefslogtreecommitdiff
path: root/sw/source/core/doc/doclay.cxx
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-10-14 14:28:41 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-10-14 15:24:07 +0200
commit8d4f64427528f76afa4bf39a23edaa991850a50a (patch)
tree78e604666184d48e53382e82630c736101b36b6c /sw/source/core/doc/doclay.cxx
parent48c0b19205af6e8d0ddee31afa011890e54b46e5 (diff)
sw: improve duplicated images in copied header/footer text
DOCX import currently maps linked headers to 2 Writer headers, the second header has a copy of the first header's content. The image in the first header is named 'Picture 1', the copied header names the image as 'Image1'. This is similar to what commit 41403fbff8140ad0ca7cf8f81d37cddcfbd19197 (sw: improve duplicated bookmarks in copied header/footer text, 2022-10-13) fixed for bookmarks, what happens is that sw::DocumentLayoutManager::CopyLayoutFormat() clears the name of the image, and then these are filled in at the end of the import in one shot, to improve performance. The downside is that it's not possible for an API user to know which was the original image and which is the copy. Fix the problem by tweaking the in-header-footer && not-in-mail-merge case to generate a name like 'Picture 1 Copy 1': this is meant to preserve the lost connection between the original image and its copy, while maintaining performance for the mail merge and body text cases where we expect lots of images. In the long run it would probably make sense to rather support linked headers/footers in Writer core so we don't have to create such a copy in the first place. Change-Id: I9679c0ce67131ed5c48eaecfcfd38abd1bcd3da4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141360 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/source/core/doc/doclay.cxx')
-rw-r--r--sw/source/core/doc/doclay.cxx26
1 files changed, 23 insertions, 3 deletions
diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx
index e83e6173b4d1..b357bfed522c 100644
--- a/sw/source/core/doc/doclay.cxx
+++ b/sw/source/core/doc/doclay.cxx
@@ -1320,7 +1320,7 @@ namespace
}
}
-static OUString lcl_GetUniqueFlyName(const SwDoc& rDoc, TranslateId pDefStrId, sal_uInt16 eType)
+static OUString lcl_GetUniqueFlyName(const SwDoc& rDoc, TranslateId pDefStrId, sal_uInt16 eType, std::u16string_view rPrefix = std::u16string_view(), SwNodeType nNdTyp = SwNodeType::NONE)
{
assert(eType >= RES_FMT_BEGIN && eType < RES_FMT_END);
if (rDoc.IsInMailMerge())
@@ -1331,6 +1331,26 @@ static OUString lcl_GetUniqueFlyName(const SwDoc& rDoc, TranslateId pDefStrId, s
return newName;
}
+ if (!rPrefix.empty())
+ {
+ // Generate a name that makes it possible to know this is a copy of which original name,
+ // e.g. 'Picture 1 Copy 1'.
+ assert(nNdTyp != SwNodeType::NONE);
+ sal_Int32 nCnt = 1;
+ OUString aPrefix = SwResId(STR_MARK_COPY).replaceFirst("%1", rPrefix);
+ OUString aTmp;
+ while(nCnt < SAL_MAX_INT32)
+ {
+ aTmp = aPrefix + OUString::number(nCnt);
+ ++nCnt;
+ if (!rDoc.FindFlyByName(aTmp, nNdTyp))
+ {
+ break;
+ }
+ }
+ return aTmp;
+ }
+
OUString aName(SwResId(pDefStrId));
sal_Int32 nNmLen = aName.getLength();
@@ -1360,9 +1380,9 @@ static OUString lcl_GetUniqueFlyName(const SwDoc& rDoc, TranslateId pDefStrId, s
return aName + OUString::number(nNum);
}
-OUString SwDoc::GetUniqueGrfName() const
+OUString SwDoc::GetUniqueGrfName(std::u16string_view rPrefix) const
{
- return lcl_GetUniqueFlyName(*this, STR_GRAPHIC_DEFNAME, RES_FLYFRMFMT);
+ return lcl_GetUniqueFlyName(*this, STR_GRAPHIC_DEFNAME, RES_FLYFRMFMT, rPrefix, SwNodeType::Grf);
}
OUString SwDoc::GetUniqueOLEName() const