Kaydet (Commit) bba0ccd7 authored tarafından Miklos Vajna's avatar Miklos Vajna

sw TextGraphicObject: fix GraphicURL handling in the descriptor

Commit dfee7d93 (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/58669Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins
üst c57191e0
......@@ -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();
......
......@@ -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)
......
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