Kaydet (Commit) d4a54ec9 authored tarafından Szymon Kłos's avatar Szymon Kłos

tdf#114338 don't crash on watermark insert w/ existing header

Change-Id: I63abaf48c33d6660f1829b7d503de295e4a57f9c
Reviewed-on: https://gerrit.libreoffice.org/46126Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarSzymon Kłos <szymon.klos@collabora.com>
üst 686e55d9
...@@ -169,8 +169,10 @@ bool lcl_hasField(const uno::Reference<text::XText>& xText, const OUString& rSer ...@@ -169,8 +169,10 @@ bool lcl_hasField(const uno::Reference<text::XText>& xText, const OUString& rSer
} }
/// Search for a frame with WATERMARK_NAME in name of type rServiceName in xText. Returns found name in rShapeName. /// Search for a frame with WATERMARK_NAME in name of type rServiceName in xText. Returns found name in rShapeName.
uno::Reference<drawing::XShape> lcl_getWatermark(const uno::Reference<text::XText>& xText, const OUString& rServiceName, OUString& rShapeName) uno::Reference<drawing::XShape> lcl_getWatermark(const uno::Reference<text::XText>& xText,
const OUString& rServiceName, OUString& rShapeName, bool& bSuccess)
{ {
bSuccess = false;
uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xText, uno::UNO_QUERY); uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xText, uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration(); uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
while (xParagraphs->hasMoreElements()) while (xParagraphs->hasMoreElements())
...@@ -179,6 +181,8 @@ uno::Reference<drawing::XShape> lcl_getWatermark(const uno::Reference<text::XTex ...@@ -179,6 +181,8 @@ uno::Reference<drawing::XShape> lcl_getWatermark(const uno::Reference<text::XTex
if (!xTextPortionEnumerationAccess.is()) if (!xTextPortionEnumerationAccess.is())
continue; continue;
bSuccess = true;
uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration(); uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
while (xTextPortions->hasMoreElements()) while (xTextPortions->hasMoreElements())
{ {
...@@ -1382,7 +1386,8 @@ SfxWatermarkItem SwEditShell::GetWatermark() ...@@ -1382,7 +1386,8 @@ SfxWatermarkItem SwEditShell::GetWatermark()
OUString aShapeServiceName = "com.sun.star.drawing.CustomShape"; OUString aShapeServiceName = "com.sun.star.drawing.CustomShape";
OUString sWatermark = ""; OUString sWatermark = "";
uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark); bool bSuccess = false;
uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark, bSuccess);
if (xWatermark.is()) if (xWatermark.is())
{ {
...@@ -1416,10 +1421,14 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark, ...@@ -1416,10 +1421,14 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark,
const uno::Reference<beans::XPropertySet>& xPageStyle, const uno::Reference<beans::XPropertySet>& xPageStyle,
const uno::Reference<text::XText>& xHeaderText) const uno::Reference<text::XText>& xHeaderText)
{ {
if (!xHeaderText.is())
return;
uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY); uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
OUString aShapeServiceName = "com.sun.star.drawing.CustomShape"; OUString aShapeServiceName = "com.sun.star.drawing.CustomShape";
OUString sWatermark = WATERMARK_NAME; OUString sWatermark = WATERMARK_NAME;
uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark); bool bSuccess = false;
uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark, bSuccess);
bool bDeleteWatermark = rWatermark.GetText().isEmpty(); bool bDeleteWatermark = rWatermark.GetText().isEmpty();
if (xWatermark.is()) if (xWatermark.is())
...@@ -1453,7 +1462,7 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark, ...@@ -1453,7 +1462,7 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark,
} }
} }
if (xWatermark.is() || bDeleteWatermark) if (!bSuccess || xWatermark.is() || bDeleteWatermark)
return; return;
OUString sFont = rWatermark.GetFont(); OUString sFont = rWatermark.GetFont();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment