sw/source/core/doc/textboxhelper.cxx | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
New commits: commit 0b5801fc2c768d1774957c2c122c9061d3a74756 Author: Attila Bakos (NISZ) <bakos.attilakar...@nisz.hu> AuthorDate: Wed Oct 21 15:50:25 2020 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Wed Oct 28 19:41:13 2020 +0100 tdf#137798 sw: apply textbox Text alignment set in "Text" dialog window using "Text Anchor" in Format -> Text Box and Shape -> Text attributes... on the selected text box. Follow up of commit 726c911b90b9a3170fa6b3a34bb952a8d2dbe148 (tdf#137025 sw: apply textbox padding set in Text). Change-Id: I8c575ceb1d0b0772c1f7d99dc746531b0cd7ceb4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104632 Tested-by: Jenkins Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index e5b7f82dc94b..e982174e51ac 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -46,6 +46,8 @@ #include <com/sun/star/table/BorderLine2.hpp> #include <com/sun/star/text/WritingMode.hpp> #include <com/sun/star/text/WritingMode2.hpp> +#include <com/sun/star/drawing/TextHorizontalAdjust.hpp> +#include <com/sun/star/style/ParagraphAdjust.hpp> using namespace com::sun::star; @@ -148,6 +150,8 @@ void SwTextBoxHelper::create(SwFrameFormat* pShape) if (xShapePropertySet->getPropertyValue(UNO_NAME_TEXT_WRITINGMODE) >>= eMode) syncProperty(pShape, RES_FRAMEDIR, 0, uno::makeAny(sal_Int16(eMode))); + // TODO: Text dialog attr setting to frame + const SwFormatAnchor& rAnch = pShape->GetAnchor(); if (!((rAnch.GetAnchorId() == RndStdIds::FLY_AT_PAGE && rAnch.GetPageNum() != 0) || ((rAnch.GetAnchorId() == RndStdIds::FLY_AT_PARA @@ -395,6 +399,45 @@ tools::Rectangle SwTextBoxHelper::getTextRectangle(SwFrameFormat* pShape, bool b void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, const OUString& rPropertyName, const css::uno::Any& rValue) { + // Textframes does not have valid horizontal adjust property, so map it to paragraph adjust property + if (rPropertyName == UNO_NAME_TEXT_HORZADJUST) + { + SwFrameFormat* pFormat = getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT); + if (!pFormat) + return; + + auto xTextFrame = SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), pFormat); + uno::Reference<text::XTextCursor> xCursor = xTextFrame->getText()->createTextCursor(); + + // Select all paragraps in the textframe + xCursor->gotoStart(false); + xCursor->gotoEnd(true); + uno::Reference<beans::XPropertySet> xFrameParaProps(xCursor, uno::UNO_QUERY); + + // And simply map the property + switch (rValue.get<drawing::TextHorizontalAdjust>()) + { + case drawing::TextHorizontalAdjust::TextHorizontalAdjust_CENTER: + xFrameParaProps->setPropertyValue( + UNO_NAME_PARA_ADJUST, + uno::makeAny(style::ParagraphAdjust::ParagraphAdjust_CENTER)); //3 + break; + case drawing::TextHorizontalAdjust::TextHorizontalAdjust_LEFT: + xFrameParaProps->setPropertyValue( + UNO_NAME_PARA_ADJUST, + uno::makeAny(style::ParagraphAdjust::ParagraphAdjust_LEFT)); //0 + break; + case drawing::TextHorizontalAdjust::TextHorizontalAdjust_RIGHT: + xFrameParaProps->setPropertyValue( + UNO_NAME_PARA_ADJUST, + uno::makeAny(style::ParagraphAdjust::ParagraphAdjust_RIGHT)); //1 + break; + default: + break; + } + return; + } + if (rPropertyName == "CustomShapeGeometry") { // CustomShapeGeometry changes the textbox position offset and size, so adjust both. @@ -838,6 +881,7 @@ void SwTextBoxHelper::updateTextBoxMargin(SdrObject* pObj) if (!pParentFormat) return; + // Sync the padding syncProperty(pParentFormat, UNO_NAME_TEXT_LEFTDIST, xPropertySet->getPropertyValue(UNO_NAME_TEXT_LEFTDIST)); syncProperty(pParentFormat, UNO_NAME_TEXT_RIGHTDIST, @@ -846,6 +890,16 @@ void SwTextBoxHelper::updateTextBoxMargin(SdrObject* pObj) xPropertySet->getPropertyValue(UNO_NAME_TEXT_UPPERDIST)); syncProperty(pParentFormat, UNO_NAME_TEXT_LOWERDIST, xPropertySet->getPropertyValue(UNO_NAME_TEXT_LOWERDIST)); + + // Sync the text aligning + syncProperty(pParentFormat, UNO_NAME_TEXT_VERTADJUST, + xPropertySet->getPropertyValue(UNO_NAME_TEXT_VERTADJUST)); + syncProperty(pParentFormat, UNO_NAME_TEXT_HORZADJUST, + xPropertySet->getPropertyValue(UNO_NAME_TEXT_HORZADJUST)); + + //FIXME: Sync autogrow: needs repositioning after sync + //syncProperty(pParentFormat, RES_FRM_SIZE, MID_FRMSIZE_IS_AUTO_HEIGHT, + // xPropertySet->getPropertyValue(UNO_NAME_TEXT_AUTOGROWHEIGHT)); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits