diff options
author | László Németh <nemeth@numbertext.org> | 2021-05-11 18:40:18 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2021-05-12 08:44:00 +0200 |
commit | 1610eeef6f2312616fe5d3535475f27f7896bef8 (patch) | |
tree | 7a96cee804a2b28be68dc834494aff4aded0284f /sw | |
parent | 5d7251c7121cee8885fa9f2387c4a0625dd4ecee (diff) |
tdf#142196 sw: crossing out images anchored to character
Follow-up to commit d845b91bcc6eb885c55494d4d4fab4ec09577e1d
(tdf#78864 sw track changes: cross out deleted images).
Change-Id: I3daa772ac80f777e1badc58a424f98b1d655acba
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115442
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/uiwriter/data/tdf142196.fodt | 30 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter2.cxx | 47 | ||||
-rw-r--r-- | sw/source/core/inc/flyfrm.hxx | 3 | ||||
-rw-r--r-- | sw/source/core/layout/fly.cxx | 1 | ||||
-rw-r--r-- | sw/source/core/layout/paintfrm.cxx | 10 | ||||
-rw-r--r-- | sw/source/core/text/porlay.cxx | 44 |
6 files changed, 127 insertions, 8 deletions
diff --git a/sw/qa/extras/uiwriter/data/tdf142196.fodt b/sw/qa/extras/uiwriter/data/tdf142196.fodt new file mode 100644 index 000000000000..b184ba22e67f --- /dev/null +++ b/sw/qa/extras/uiwriter/data/tdf142196.fodt @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:styles> + <style:style style:name="Standard" style:family="paragraph" style:class="text"/> + <style:default-style style:family="paragraph"> + <style:text-properties fo:language="en" fo:country="US"/> + </style:default-style> + </office:styles> + <office:body> + <office:text> + <text:tracked-changes text:track-changes="false"> + <text:changed-region xml:id="ct94146400887392" text:id="ct94146400887392"> + <text:deletion> + <office:change-info> + <dc:creator>X</dc:creator> + <dc:date>2021-05-07T17:32:23</dc:date> + </office:change-info> + </text:deletion> + </text:changed-region> + </text:tracked-changes> + <text:p text:style-name="Standard"><text:change-start text:change-id="ct94146400887392"/>Lorem <draw:frame text:anchor-type="char" svg:width="10.663cm" svg:height="5.415cm" draw:z-index="1"><draw:image draw:mime-type="image/png"> + <office:binary-data>iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAAAmJLR0QA/4ePzL8AAAAJcEhZ + cwAACxMAAAsTAQCanBgAAAAHdElNRQflBQYKGR4LTuGQAAAACklEQVQI12M4DwAA0QDQfVbA + HQAAAABJRU5ErkJggg== + </office:binary-data> + </draw:image> + </draw:frame>ipsum <text:change-end text:change-id="ct94146400887392"/>dolor sit amet.</text:p> + </office:text> + </office:body> +</office:document> diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index b2c5a71e1164..02d8163cc95e 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -2194,9 +2194,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf142130) xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile); CPPUNIT_ASSERT(pXmlDoc); - // This was 6 (crossing out of the first, not deleted image) - // (4 lines = 2 lines for crossing out of the second image, 2 lines for the - // vertical lines before the two lines) + // This was 6 (bad crossing out of the first, not deleted image) + // (4 lines = 2 lines for crossing out of the second image + 2 lines = + // vertical "changed line" indicator before the two paragraph lines) assertXPath(pXmlDoc, "/metafile/push/push/push/line", 4); // reject deletion of the second image @@ -2209,6 +2209,47 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf142130) assertXPath(pXmlDoc2, "/metafile/push/push/push/line", 0); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf142196) +{ + load(DATA_DIRECTORY, "tdf142196.fodt"); + + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + + //turn on red-lining and show changes + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete + | RedlineFlags::ShowInsert); + CPPUNIT_ASSERT_MESSAGE("redlining should be on", + pDoc->getIDocumentRedlineAccess().IsRedlineOn()); + CPPUNIT_ASSERT_MESSAGE( + "redlines should be visible", + IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags())); + + // Dump the rendering of the first page as an XML file. + SwDocShell* pShell = pTextDoc->GetDocShell(); + std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile(); + MetafileXmlDump dumper; + + xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile); + CPPUNIT_ASSERT(pXmlDoc); + + // This was 1 (missing crossing out of the deleted image) + // (2 lines = crossing out of the deleted image + 1 line for the + // vertical "changed line" indicator before the paragraph line) + assertXPath(pXmlDoc, "//line", 3); + + // reject deletion of the image + IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess()); + rIDRA.AcceptAllRedline(false); + + xMetaFile = pShell->GetPreviewMetaFile(); + xmlDocUniquePtr pXmlDoc2 = dumpAndParse(dumper, *xMetaFile); + + // no crossing out and vertical "changed line" indicator + assertXPath(pXmlDoc2, "//line", 0); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf139120) { SwDoc* pDoc = createDoc("tdf54819.fodt"); diff --git a/sw/source/core/inc/flyfrm.hxx b/sw/source/core/inc/flyfrm.hxx index 6072d7a4d033..399bbbe913fe 100644 --- a/sw/source/core/inc/flyfrm.hxx +++ b/sw/source/core/inc/flyfrm.hxx @@ -130,6 +130,7 @@ protected: ///< or RndStdIds::FLY_AT_CHAR bool m_bLayout :1; ///< RndStdIds::FLY_AT_PAGE, RndStdIds::FLY_AT_FLY, at page or at frame bool m_bAutoPosition :1; ///< RndStdIds::FLY_AT_CHAR, anchored at character + bool m_bDeleted :1; ///< Anchored to a tracked deletion friend class SwNoTextFrame; // is allowed to call NotifyBackground @@ -214,6 +215,8 @@ public: bool IsFlyFreeFrame() const { return m_bAtCnt || m_bLayout; } bool IsFlyLayFrame() const { return m_bLayout; } bool IsFlyAtContentFrame() const { return m_bAtCnt; } + bool IsDeleted() const { return m_bDeleted; } + void SetDeleted(bool bDeleted) { m_bDeleted = bDeleted; } bool IsNotifyBack() const { return m_bNotifyBack; } void SetNotifyBack() { m_bNotifyBack = true; } diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx index 688c1b6503e7..bf01c3b1dc7a 100644 --- a/sw/source/core/layout/fly.cxx +++ b/sw/source/core/layout/fly.cxx @@ -87,6 +87,7 @@ SwFlyFrame::SwFlyFrame( SwFlyFrameFormat *pFormat, SwFrame* pSib, SwFrame *pAnch m_bAtCnt( false ), m_bLayout( false ), m_bAutoPosition( false ), + m_bDeleted (false ), m_bValidContentPos( false ) { mnFrameType = SwFrameType::Fly; diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx index 01fe03594ba9..9e5cd3a16c05 100644 --- a/sw/source/core/layout/paintfrm.cxx +++ b/sw/source/core/layout/paintfrm.cxx @@ -4221,6 +4221,16 @@ void SwFlyFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect const& PaintDecorators(); + // crossing out for tracked deletion + if ( IsDeleted() ) + { + tools::Long startX = aRect.Left( ), endX = aRect.Right(); + tools::Long startY = aRect.Top( ), endY = aRect.Bottom(); + rRenderContext.SetLineColor(NON_PRINTING_CHARACTER_COLOR); + rRenderContext.DrawLine(Point(startX, startY), Point(endX, endY)); + rRenderContext.DrawLine(Point(startX, endY), Point(endX, startY)); + } + rRenderContext.Pop(); if ( gProp.pSProgress && pNoText ) diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx index be984e137b99..3d26e990c50c 100644 --- a/sw/source/core/text/porlay.cxx +++ b/sw/source/core/text/porlay.cxx @@ -58,6 +58,8 @@ #include <IDocumentContentOperations.hxx> #include <IDocumentFieldsAccess.hxx> #include <IMark.hxx> +#include <sortedobjs.hxx> +#include <dcontact.hxx> using namespace ::com::sun::star; using namespace i18n::ScriptType; @@ -359,7 +361,7 @@ void SwLineLayout::CalcLine( SwTextFormatter &rLine, SwTextFormatInfo &rInf ) bool bHasBlankPortion = false; bool bHasOnlyBlankPortions = true; - bool bHasFlyContentPortion = false; + bool bHasFlyPortion = false; if( mpNextPortion ) { @@ -446,8 +448,8 @@ void SwLineLayout::CalcLine( SwTextFormatter &rLine, SwTextFormatInfo &rInf ) SetHanging(true); rInf.GetParaPortion()->SetMargin(); } - else if( !bHasFlyContentPortion && pPos->IsFlyCntPortion() ) - bHasFlyContentPortion = true; + else if( !bHasFlyPortion && ( pPos->IsFlyCntPortion() || pPos->IsFlyPortion() ) ) + bHasFlyPortion = true; // To prevent that a paragraph-end-character does not change // the line height through a Descent and thus causing the line @@ -627,8 +629,8 @@ void SwLineLayout::CalcLine( SwTextFormatter &rLine, SwTextFormatInfo &rInf ) } SetRedline( bHasRedline ); - // set redline for as-char anchored portions - if ( bHasFlyContentPortion ) + // redlining: set crossing out for deleted anchored objects + if ( bHasFlyPortion ) { SwLinePortion *pPos = mpNextPortion; TextFrameIndex nLineLength; @@ -636,6 +638,7 @@ void SwLineLayout::CalcLine( SwTextFormatter &rLine, SwTextFormatInfo &rInf ) { TextFrameIndex const nPorSttIdx = rInf.GetLineStart() + nLineLength; nLineLength += pPos->GetLen(); + // anchored as characters if( pPos->IsFlyCntPortion() ) { bool bDeleted = false; @@ -653,6 +656,37 @@ void SwLineLayout::CalcLine( SwTextFormatter &rLine, SwTextFormatInfo &rInf ) } static_cast<SwFlyCntPortion*>(pPos)->SetDeleted(bDeleted); } + // anchored to characters + else if ( pPos->IsFlyPortion() ) + { + const IDocumentRedlineAccess& rIDRA = + rInf.GetTextFrame()->GetDoc().getIDocumentRedlineAccess(); + SwSortedObjs *pObjs = rInf.GetTextFrame()->GetDrawObjs(); + if ( pObjs && IDocumentRedlineAccess::IsShowChanges( rIDRA.GetRedlineFlags() ) ) + { + for ( size_t i = 0; rInf.GetTextFrame()->GetDrawObjs() && i < pObjs->size(); ++i ) + { + SwAnchoredObject* pAnchoredObj = (*rInf.GetTextFrame()->GetDrawObjs())[i]; + if ( auto pFly = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) ) + { + bool bDeleted = false; + const SwFormatAnchor& rAnchor = pAnchoredObj->GetFrameFormat().GetAnchor(); + if ( rAnchor.GetAnchorId() == RndStdIds::FLY_AT_CHAR ) + { + SwPosition aAnchor = *rAnchor.GetContentAnchor(); + const SwPaM aPam(aAnchor, aAnchor); + if ( rIDRA.HasRedline( aPam, RedlineType::Delete, + /*bStartOrEndInRange=*/false) ) + { + bDeleted = true; + } + } + pFly->SetDeleted(bDeleted); + } + + } + } + } pPos = pPos->GetNextPortion(); } } |