[Libreoffice-commits] core.git: sw/qa sw/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Aug 7 10:46:12 UTC 2018
sw/qa/extras/unowriter/data/test.jpg |binary
sw/qa/extras/unowriter/unowriter.cxx | 35 +++++++++++++++++++++++++++++++++++
sw/source/core/unocore/unoframe.cxx | 10 ++++++++++
3 files changed, 45 insertions(+)
New commits:
commit bba0ccd743a3d023e4829155571cdf0318fcb81c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Tue Aug 7 11:06:30 2018 +0200
Commit: Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Tue Aug 7 12:45:46 2018 +0200
sw TextGraphicObject: fix GraphicURL handling in the descriptor
Commit dfee7d93b4e863d673c45921f79bb876b5738ea6 (sw: get rid of
FN_UNO_GRAPHIC_U_R_L and "GraphicURL" property, 2018-03-08) removed
support for string-based graphic references, then a later commit
restored the setter. But one scenario (when setting the graphic URL
before inserting the text graphic object) was still unsupported for real
URL setter; restore that as well.
Change-Id: I52a7f96e820f614d9d031df3ba03c794984ad68b
Reviewed-on: https://gerrit.libreoffice.org/58669
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Jenkins
diff --git a/sw/qa/extras/unowriter/data/test.jpg b/sw/qa/extras/unowriter/data/test.jpg
new file mode 100644
index 000000000000..12b393569efb
Binary files /dev/null and b/sw/qa/extras/unowriter/data/test.jpg differ
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
index 59a045586423..cde8b9b9c47d 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -9,15 +9,23 @@
#include <swmodeltestbase.hxx>
#include <com/sun/star/awt/FontSlant.hpp>
+#include <com/sun/star/text/TextContentAnchorType.hpp>
+
+namespace
+{
+char const DATA_DIRECTORY[] = "/sw/qa/extras/unowriter/data/";
+}
/// Test to assert UNO API call results of Writer.
class SwUnoWriter : public SwModelTestBase
{
public:
void testDefaultCharStyle();
+ void testGraphicDesciptorURL();
CPPUNIT_TEST_SUITE(SwUnoWriter);
CPPUNIT_TEST(testDefaultCharStyle);
+ CPPUNIT_TEST(testGraphicDesciptorURL);
CPPUNIT_TEST_SUITE_END();
};
@@ -47,6 +55,33 @@ void SwUnoWriter::testDefaultCharStyle()
getProperty<awt::FontSlant>(xCursorProps, "CharPosture"));
}
+void SwUnoWriter::testGraphicDesciptorURL()
+{
+ loadURL("private:factory/swriter", nullptr);
+
+ // Create a graphic object, but don't insert it yet.
+ uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xTextGraphic(
+ xFactory->createInstance("com.sun.star.text.TextGraphicObject"), uno::UNO_QUERY);
+
+ // Set an URL on it.
+ OUString aGraphicURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "test.jpg";
+ xTextGraphic->setPropertyValue("GraphicURL", uno::makeAny(aGraphicURL));
+ xTextGraphic->setPropertyValue("AnchorType",
+ uno::makeAny(text::TextContentAnchorType_AT_CHARACTER));
+
+ // Insert it.
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XText> xBodyText(xTextDocument->getText(), uno::UNO_QUERY);
+ uno::Reference<text::XTextCursor> xCursor(xBodyText->createTextCursor());
+ uno::Reference<text::XTextContent> xTextContent(xTextGraphic, uno::UNO_QUERY);
+ xBodyText->insertTextContent(xCursor, xTextContent, false);
+
+ // This failed, the graphic object had no graphic.
+ auto xGraphic = getProperty<uno::Reference<graphic::XGraphic>>(getShape(1), "Graphic");
+ CPPUNIT_ASSERT(xGraphic.is());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUnoWriter);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index bf25aeb4d4f7..c16f1b301b20 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -2748,6 +2748,16 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan
{
UnoActionContext aActionContext(pDoc);
Graphic aGraphic;
+
+ // Read graphic URL from the descriptor, if it has any.
+ const ::uno::Any* pGraphicURL;
+ if (m_pProps->GetProperty(FN_UNO_GRAPHIC_URL, 0, pGraphicURL))
+ {
+ OUString sGraphicURL;
+ if (((*pGraphicURL) >>= sGraphicURL) && !sGraphicURL.isEmpty())
+ aGraphic = vcl::graphic::loadFromURL(sGraphicURL);
+ }
+
const ::uno::Any* pGraphicAny;
const bool bHasGraphic = m_pProps->GetProperty(FN_UNO_GRAPHIC, 0, pGraphicAny);
if (bHasGraphic)
More information about the Libreoffice-commits
mailing list