summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/qa/uibase/frmdlg/data/image.pngbin0 -> 766 bytes
-rw-r--r--sw/qa/uibase/frmdlg/frmdlg.cxx27
-rw-r--r--sw/source/uibase/frmdlg/frmmgr.cxx14
3 files changed, 40 insertions, 1 deletions
diff --git a/sw/qa/uibase/frmdlg/data/image.png b/sw/qa/uibase/frmdlg/data/image.png
new file mode 100644
index 000000000000..fdad35484e7c
--- /dev/null
+++ b/sw/qa/uibase/frmdlg/data/image.png
Binary files differ
diff --git a/sw/qa/uibase/frmdlg/frmdlg.cxx b/sw/qa/uibase/frmdlg/frmdlg.cxx
index 56b96803686e..ce9367ea815b 100644
--- a/sw/qa/uibase/frmdlg/frmdlg.cxx
+++ b/sw/qa/uibase/frmdlg/frmdlg.cxx
@@ -9,6 +9,8 @@
#include <swmodeltestbase.hxx>
+#include <comphelper/propertyvalue.hxx>
+
#include <com/sun/star/text/TextContentAnchorType.hpp>
constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/uibase/frmdlg/data/";
@@ -32,6 +34,31 @@ CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testWrappedMathObject)
getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType"));
}
+CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testAnchorTypeFromStyle)
+{
+ // Given a document with aGraphics style with anchor type set to as-character:
+ createSwDoc();
+ uno::Reference<beans::XPropertySet> xGraphics(getStyles("FrameStyles")->getByName("Graphics"),
+ uno::UNO_QUERY);
+ xGraphics->setPropertyValue("AnchorType",
+ uno::makeAny(text::TextContentAnchorType_AS_CHARACTER));
+
+ // When inserting an image:
+ OUString aImageURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "image.png";
+ uno::Sequence<beans::PropertyValue> aArgs = {
+ comphelper::makePropertyValue("FileName", aImageURL),
+ };
+ dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs);
+
+ // Then make sure the image's anchor type is as-char:
+ auto eActual = getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType");
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 1 (AS_CHARACTER)
+ // - Actual : 4 (AT_CHARACTER)
+ // i.e. the anchor type from the style was ignored.
+ CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER, eActual);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/frmdlg/frmmgr.cxx b/sw/source/uibase/frmdlg/frmmgr.cxx
index fa5991baac56..2146b05d44e9 100644
--- a/sw/source/uibase/frmdlg/frmmgr.cxx
+++ b/sw/source/uibase/frmdlg/frmmgr.cxx
@@ -92,7 +92,19 @@ SwFlyFrameAttrMgr::SwFlyFrameAttrMgr( bool bNew, SwWrtShell* pSh, Frmmgr_Type nT
{
// Default anchor for new graphics and objects is at-char, except for Math objects.
SwViewOption aViewOpt(*pSh->GetViewOptions());
- m_aSet.Put(SwFormatAnchor(aViewOpt.GetDefaultAnchorType()));//RndStdIds::FLY_AT_CHAR
+
+ RndStdIds eAnchorType = aViewOpt.GetDefaultAnchorType();
+
+ const SwFormatAnchor rStyleAnchor
+ = m_pOwnSh->GetFormatFromPool(nId)->GetAttrSet().GetAnchor();
+ if (rStyleAnchor.GetAnchorId() != RndStdIds::FLY_AT_PARA)
+ {
+ // The style has a custom anchor type, prefer that over the user profile
+ // default.
+ eAnchorType = rStyleAnchor.GetAnchorId();
+ }
+
+ m_aSet.Put(SwFormatAnchor(eAnchorType));
}
}
}