diff options
Diffstat (limited to 'sw/source/core/text/porfly.cxx')
-rw-r--r-- | sw/source/core/text/porfly.cxx | 92 |
1 files changed, 37 insertions, 55 deletions
diff --git a/sw/source/core/text/porfly.cxx b/sw/source/core/text/porfly.cxx index 34edc3082b71..19ac692cf42f 100644 --- a/sw/source/core/text/porfly.cxx +++ b/sw/source/core/text/porfly.cxx @@ -26,11 +26,11 @@ #include <frmfmt.hxx> #include <viewsh.hxx> #include <textboxhelper.hxx> +#include <IDocumentState.hxx> #include <sal/log.hxx> #include <fmtanchr.hxx> #include <fmtflcnt.hxx> -#include <fmtornt.hxx> #include <flyfrms.hxx> #include <txatbase.hxx> #include "porfly.hxx" @@ -39,6 +39,7 @@ #include <sortedobjs.hxx> #include <officecfg/Office/Common.hxx> +#include <PostItMgr.hxx> /** * class SwFlyPortion => we expect a frame-locale SwRect! @@ -57,7 +58,17 @@ bool SwFlyPortion::Format( SwTextFormatInfo &rInf ) rInf.GetLastTab()->FormatEOL( rInf ); rInf.GetLast()->FormatEOL( rInf ); - PrtWidth( static_cast<sal_uInt16>(GetFix() - rInf.X() + PrtWidth()) ); + + SetBlankWidth(0); + if (auto blankWidth = rInf.GetLast()->ExtraBlankWidth()) + { + // Swallow previous blank width + SetBlankWidth(blankWidth); + rInf.GetLast()->ExtraBlankWidth(0); + rInf.X(rInf.X() - blankWidth); // Step back + } + + PrtWidth( o3tl::narrowing<sal_uInt16>(GetFix() - rInf.X() + PrtWidth()) ); if( !Width() ) { OSL_ENSURE( Width(), "+SwFlyPortion::Format: a fly is a fly is a fly" ); @@ -77,11 +88,11 @@ bool SwFlyPortion::Format( SwTextFormatInfo &rInf ) && ' ' != rInf.GetChar(rInf.GetIdx() - TextFrameIndex(1)) && ( !rInf.GetLast() || !rInf.GetLast()->IsBreakPortion() ) ) { - SetBlankWidth( rInf.GetTextSize(OUString(' ')).Width() ); + SetBlankWidth(GetBlankWidth() + rInf.GetTextSize(OUString(' ')).Width()); SetLen(TextFrameIndex(1)); } - const sal_uInt16 nNewWidth = static_cast<sal_uInt16>(rInf.X() + PrtWidth()); + const sal_uInt16 nNewWidth = o3tl::narrowing<sal_uInt16>(rInf.X() + PrtWidth()); if( rInf.Width() <= nNewWidth ) { Truncate(); @@ -108,7 +119,7 @@ bool SwFlyCntPortion::Format( SwTextFormatInfo &rInf ) // KerningPortions at beginning of line, e.g., for grid layout // must be considered. const SwLinePortion* pLastPor = rInf.GetLast(); - const sal_uInt16 nLeft = ( pLastPor && + const auto nLeft = ( pLastPor && ( pLastPor->IsKernPortion() || pLastPor->IsErgoSumPortion() ) ) ? pLastPor->Width() : @@ -157,14 +168,14 @@ void SwTextFrame::MoveFlyInCnt(SwTextFrame *pNew, { // Consider changed type of <SwSortedList> entries SwAnchoredObject* pAnchoredObj = (*pObjs)[i]; - const SwFormatAnchor& rAnch = pAnchoredObj->GetFrameFormat().GetAnchor(); + const SwFormatAnchor& rAnch = pAnchoredObj->GetFrameFormat()->GetAnchor(); if (rAnch.GetAnchorId() == RndStdIds::FLY_AS_CHAR) { const SwPosition* pPos = rAnch.GetContentAnchor(); TextFrameIndex const nIndex(MapModelToViewPos(*pPos)); if (nStart <= nIndex && nIndex < nEnd) { - if ( auto pFlyFrame = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) ) + if ( auto pFlyFrame = pAnchoredObj->DynCastFlyFrame() ) { RemoveFly( pFlyFrame ); pNew->AppendFly( pFlyFrame ); @@ -211,7 +222,7 @@ void sw::FlyContentPortion::Paint(const SwTextPaintInfo& rInf) const rInf.GetTextFrame()->SwitchHorizontalToVertical(aRepaintRect); if(!((m_pFly->IsCompletePaint() || - m_pFly->getFrameArea().IsOver(aRepaintRect)) && + m_pFly->getFrameArea().Overlaps(aRepaintRect)) && SwFlyFrame::IsPaint(m_pFly->GetVirtDrawObj(), m_pFly->getRootFrame()->GetCurrShell()))) return; @@ -226,7 +237,7 @@ void sw::FlyContentPortion::Paint(const SwTextPaintInfo& rInf) const // track changes: cross out the image, if it is deleted const SwFrame *pFrame = m_pFly->Lower(); - if ( IsDeleted() && pFrame ) + if ( GetAuthor() != std::string::npos && IsDeleted() && pFrame ) { SwRect aPaintRect( pFrame->GetPaintArea() ); @@ -236,7 +247,8 @@ void sw::FlyContentPortion::Paint(const SwTextPaintInfo& rInf) const const_cast<vcl::RenderContext&>(*rInf.GetOut()).SetAntialiasing(AntialiasingFlags::Enable); tools::Long startX = aPaintRect.Left( ), endX = aPaintRect.Right(); tools::Long startY = aPaintRect.Top( ), endY = aPaintRect.Bottom(); - const_cast<vcl::RenderContext&>(*rInf.GetOut()).SetLineColor(NON_PRINTING_CHARACTER_COLOR); + const_cast<vcl::RenderContext&>(*rInf.GetOut()).SetLineColor( + SwPostItMgr::GetColorAnchor(GetAuthor()) ); const_cast<vcl::RenderContext&>(*rInf.GetOut()).DrawLine(Point(startX, startY), Point(endX, endY)); const_cast<vcl::RenderContext&>(*rInf.GetOut()).DrawLine(Point(startX, endY), Point(endX, startY)); if ( bIsAntiAliasing ) @@ -270,6 +282,7 @@ void sw::DrawFlyCntPortion::Paint(const SwTextPaintInfo&) const SwFlyCntPortion::SwFlyCntPortion() : m_bMax(false) , m_bDeleted(false) + , m_nAuthor(std::string::npos) , m_eAlign(sw::LineAlign::NONE) { mnLineLength = TextFrameIndex(1); @@ -359,51 +372,20 @@ void SwFlyCntPortion::SetBase( const SwTextFrame& rFrame, const Point &rBase, aObjPositioning.CalcPosition(); } - SwFrameFormat* pShape = FindFrameFormat(pSdrObj); - const SwFormatAnchor& rAnchor(pShape->GetAnchor()); - if (rAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR) + if (auto pFormat = FindFrameFormat(pSdrObj)) { - // This is an inline draw shape, see if it has a textbox. - SwFrameFormat* pTextBox = SwTextBoxHelper::getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT); - if (pTextBox) + if (pFormat->GetOtherTextBoxFormats() + && pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR) { - // It has, so look up its text rectangle, and adjust the position - // of the textbox accordingly. - // Both rectangles are absolute, SwFormatHori/VertOrient's position - // is relative to the print area of the anchor text frame. - tools::Rectangle aTextRectangle = SwTextBoxHelper::getTextRectangle(pShape); - tools::Long nXoffs = SwTextBoxHelper::getTextRectangle(pShape, false).getX(); - - const auto aPos(pShape->GetAnchor().GetContentAnchor()); - SwFormatVertOrient aVert(pTextBox->GetVertOrient()); - SwFormatHoriOrient aHori(pTextBox->GetHoriOrient()); - - // tdf#138598 Replace vertical alignment of As_char textboxes in footer - // tdf#140158 Remove horizontal positioning of As_char textboxes, because - // the anchor moving does the same for it. - if (!aPos->nNode.GetNode().FindFooterStartNode()) - { - aVert.SetVertOrient(css::text::VertOrientation::NONE); - aVert.SetRelationOrient(css::text::RelOrientation::FRAME); - sal_Int32 const nTop = aTextRectangle.getY() - rFrame.getFrameArea().Top() - - rFrame.getFramePrintArea().Top(); - aVert.SetPos(nTop); - } - else - { - aVert.SetVertOrient(css::text::VertOrientation::NONE); - aVert.SetPos(SwTextBoxHelper::getTextRectangle(pShape, false).getY()); - } - - SwFormatAnchor aNewTxBxAnchor(pTextBox->GetAnchor()); - aNewTxBxAnchor.SetAnchor(aPos); - aHori.SetPos(nXoffs); - - pTextBox->LockModify(); - pTextBox->SetFormatAttr(aNewTxBxAnchor); - pTextBox->SetFormatAttr(aVert); - pTextBox->SetFormatAttr(aHori); - pTextBox->UnlockModify(); + // TODO: Improve security with moving this sync call to other place, + // where it works for typing but not during layout calc. + const bool bModified = pFormat->GetDoc()->getIDocumentState().IsEnableSetModified(); + pFormat->GetDoc()->getIDocumentState().SetEnableSetModified(false); + SwTextBoxHelper::synchronizeGroupTextBoxProperty(SwTextBoxHelper::changeAnchor, pFormat, + pFormat->FindRealSdrObject()); + SwTextBoxHelper::synchronizeGroupTextBoxProperty(SwTextBoxHelper::syncTextBoxSize, + pFormat, pFormat->FindRealSdrObject()); + pFormat->GetDoc()->getIDocumentState().SetEnableSetModified(bModified); } } @@ -421,14 +403,14 @@ void SwFlyCntPortion::SetBase( const SwTextFrame& rFrame, const Point &rBase, SwTwips nRelPos = aObjPositioning.GetRelPosY(); if ( nRelPos < 0 ) { - mnAscent = static_cast<sal_uInt16>(-nRelPos); + mnAscent = -nRelPos; if( mnAscent > Height() ) Height( mnAscent ); } else { mnAscent = 0; - Height( Height() + static_cast<sal_uInt16>(nRelPos) ); + Height( Height() + o3tl::narrowing<sal_uInt16>(nRelPos) ); } } else |