[Libreoffice-commits] core.git: sw/CppunitTest_sw_core_text.mk sw/qa sw/source

2023-08-16 Thread Miklos Vajna (via logerrit)
 sw/CppunitTest_sw_core_text.mk |1 
 sw/qa/core/text/data/floattable-leftover-para-portion.docx |binary
 sw/qa/core/text/porrst.cxx |   57 +
 sw/source/core/text/porrst.cxx |2 
 4 files changed, 59 insertions(+), 1 deletion(-)

New commits:
commit 1cf29168840f84c2e946e2678b99988e83503c96
Author: Miklos Vajna 
AuthorDate: Wed Aug 16 09:34:49 2023 +0200
Commit: Miklos Vajna 
CommitDate: Wed Aug 16 10:43:46 2023 +0200

tdf#156682 sw floattable: fix missing del of master anchor para por on split

Pressing "enter" at the end of B1 in the bugdoc resulted in a split
floating table, which had the anchor text duplicated (both on page 1 and
page2).

What happened is that the master anchor frame didn't have its paragraph
portion cleared, the follow anchor frame had a correct frame offset (of
0).

Fix the problem in SwTextFrame::FormatEmpty(), similar to what commit
00b9b4791079c2dc26b1ed4c123450cabf7d (sw: call FormatEmpty() in
SwTextFrame::Format() for split fly masters, 2023-02-09), did; here what
we want to avoid is setting some properties on the paragraph preventing
the deletion of non-last anchor paragraph portions.

As a side effect, this also fixes the hang from the bugreport, after
pressing "enter" 5 times at the end of B1.

Change-Id: I16e6d786f02ad503a0fdff465ecf7716c1c5f8b7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155732
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/sw/CppunitTest_sw_core_text.mk b/sw/CppunitTest_sw_core_text.mk
index 477e25b91612..37b2fa566094 100644
--- a/sw/CppunitTest_sw_core_text.mk
+++ b/sw/CppunitTest_sw_core_text.mk
@@ -17,6 +17,7 @@ $(eval $(call 
gb_CppunitTest_add_exception_objects,sw_core_text, \
 sw/qa/core/text/frmform \
 sw/qa/core/text/itratr \
 sw/qa/core/text/itrform2 \
+sw/qa/core/text/porrst \
 sw/qa/core/text/text \
 ))
 
diff --git a/sw/qa/core/text/data/floattable-leftover-para-portion.docx 
b/sw/qa/core/text/data/floattable-leftover-para-portion.docx
new file mode 100644
index ..51eee56cf003
Binary files /dev/null and 
b/sw/qa/core/text/data/floattable-leftover-para-portion.docx differ
diff --git a/sw/qa/core/text/porrst.cxx b/sw/qa/core/text/porrst.cxx
new file mode 100644
index ..1c343dc0d9f2
--- /dev/null
+++ b/sw/qa/core/text/porrst.cxx
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace
+{
+/// Covers sw/source/core/text/porrst.cxx fixes.
+class Test : public SwModelTestBase
+{
+public:
+Test()
+: SwModelTestBase("/sw/qa/core/text/data/")
+{
+}
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testFloattableLeftoverParaPortion)
+{
+// Given a document with a multi-page floating table, the anchor of the 
table has some text:
+createSwDoc("floattable-leftover-para-portion.docx");
+
+// When laying out that document:
+calcLayout();
+
+// Then make sure all anchor text goes to the second page:
+SwDoc* pDoc = getSwDoc();
+SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+auto pPage = dynamic_cast(pLayout->Lower());
+CPPUNIT_ASSERT(pPage);
+SwFrame* pBody = pPage->FindBodyCont();
+SwFrame* pPara1 = pBody->GetLower();
+auto pPara2 = pPara1->GetNext()->DynCastTextFrame();
+CPPUNIT_ASSERT(pPara2);
+// Without the accompanying fix in place, this test would have failed, the 
first page's anchor
+// also had some (duplicated) anchor text.
+CPPUNIT_ASSERT(!pPara2->GetPara());
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/porrst.cxx b/sw/source/core/text/porrst.cxx
index 255318119f87..5c6ea428c1db 100644
--- a/sw/source/core/text/porrst.cxx
+++ b/sw/source/core/text/porrst.cxx
@@ -413,7 +413,7 @@ bool SwTextFrame::FormatEmpty()
 // Split fly frames: non-last parts of the anchor want this optimization 
to clear the old
 // content.
 bool bHasNonLastSplitFlyDrawObj = HasNonLastSplitFlyDrawObj();
-if ((HasFollow() && !bHasNonLastSplitFlyDrawObj) || GetMergedPara() || 
GetTextNodeFirst()->GetpSwpHints() ||
+if ((HasFollow() && !bHasNonLastSplitFlyDrawObj) || GetMergedPara() || 
(GetTextNodeFirst()->GetpSwpHints() && !bHasNonLastSplitFlyDrawObj) ||
 nullptr != GetTextNodeForParaProps()->GetNumRule() ||
 GetTextNodeFirst()->HasHiddenCharAttribute(true) ||
  IsInFootnote() || ( HasPara() && GetPara

[Libreoffice-commits] core.git: sw/CppunitTest_sw_core_text.mk sw/qa sw/source

2023-07-14 Thread Miklos Vajna (via logerrit)
 sw/CppunitTest_sw_core_text.mk   |1 
 sw/qa/core/text/data/floattable-wrap-empty-para.docx |binary
 sw/qa/core/text/itrform2.cxx |   59 +++
 sw/source/core/text/itrform2.cxx |   13 +++-
 4 files changed, 70 insertions(+), 3 deletions(-)

New commits:
commit 8bd30999098567b3bdb84a6ca65c071952192932
Author: Miklos Vajna 
AuthorDate: Fri Jul 14 08:28:32 2023 +0200
Commit: Miklos Vajna 
CommitDate: Fri Jul 14 11:00:30 2023 +0200

tdf#120262 sw floattable: don't wrap text around fly when no content would 
fit

The document has 2 pages with 2 floating tables, but instead Writer had
a single page with 2 overlapping floating tables.

What happened is that most of the horizontal space on page 1 was used by
the floating table, but out of the 10466 twips body width, 11 remained
(after accounting for the floating table and its margin. Considering
that the empty paragraph needs no space, the paragraph marker was
shifted up, next to the floating table, leading to losing page 2 and
overlapping floating tables.

Fix the problem by checking if the remaining space has some minimal
size: if it has no space to host any actual content, then shift the
paragraph marker down (in compat mode), similar to what Word >= 2013
does.

Note this only fixes the "DOCX, Word >= 2013" version, the original
bug DOC file still needs more work.

Change-Id: I00864d9b3ae662cdf19fa63e004da1ee1cc7be7c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154409
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/sw/CppunitTest_sw_core_text.mk b/sw/CppunitTest_sw_core_text.mk
index a04824e08e07..477e25b91612 100644
--- a/sw/CppunitTest_sw_core_text.mk
+++ b/sw/CppunitTest_sw_core_text.mk
@@ -16,6 +16,7 @@ $(eval $(call 
gb_CppunitTest_use_common_precompiled_header,sw_core_text))
 $(eval $(call gb_CppunitTest_add_exception_objects,sw_core_text, \
 sw/qa/core/text/frmform \
 sw/qa/core/text/itratr \
+sw/qa/core/text/itrform2 \
 sw/qa/core/text/text \
 ))
 
diff --git a/sw/qa/core/text/data/floattable-wrap-empty-para.docx 
b/sw/qa/core/text/data/floattable-wrap-empty-para.docx
new file mode 100644
index ..91e8a141c15a
Binary files /dev/null and 
b/sw/qa/core/text/data/floattable-wrap-empty-para.docx differ
diff --git a/sw/qa/core/text/itrform2.cxx b/sw/qa/core/text/itrform2.cxx
new file mode 100644
index ..066a8fb331a6
--- /dev/null
+++ b/sw/qa/core/text/itrform2.cxx
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+namespace
+{
+/// Covers sw/source/core/text/itrform2.cxx fixes.
+class Test : public SwModelTestBase
+{
+public:
+Test()
+: SwModelTestBase("/sw/qa/core/text/data/")
+{
+}
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testFloattableWrapEmptyParagraph)
+{
+// Given a document with 2 pages, a floating table on both pages:
+createSwDoc("floattable-wrap-empty-para.docx");
+
+// When calculating the layout:
+calcLayout();
+
+// Then make sure that each page has exactly 1 floating table:
+SwDoc* pDoc = getSwDoc();
+SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+auto pPage = dynamic_cast(pLayout->Lower());
+CPPUNIT_ASSERT(pPage);
+CPPUNIT_ASSERT(pPage->GetSortedObjs());
+const SwSortedObjs& rPageObjs = *pPage->GetSortedObjs();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 2
+// i.e. both tables were on page 1, leading to an overlap.
+CPPUNIT_ASSERT_EQUAL(static_cast(1), rPageObjs.size());
+auto pPage2 = dynamic_cast(pPage->GetNext());
+CPPUNIT_ASSERT(pPage2);
+CPPUNIT_ASSERT(pPage2->GetSortedObjs());
+const SwSortedObjs& rPageObjs2 = *pPage2->GetSortedObjs();
+CPPUNIT_ASSERT_EQUAL(static_cast(1), rPageObjs2.size());
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 51c3a49f2062..5895825bf668 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -2714,11 +2714,11 @@ void SwTextFormatter::CalcFlyWidth( SwTextFormatInfo 
&rInf )
 SwRect aLine( rInf.X() + nLeftMin, nTop, rInf.RealWidth() - rInf.X()
   + nLeftMar - nLeftMin , nHeight );
 
+bool bWordFlyWrap = 
GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(DocumentSettingId::ADD_VERTICAL_FLY_OFFSETS);
 // tdf#116486: consider also the u

[Libreoffice-commits] core.git: sw/CppunitTest_sw_core_text.mk sw/qa sw/source

2023-07-03 Thread Miklos Vajna (via logerrit)
 sw/CppunitTest_sw_core_text.mk  |1 
 sw/qa/core/text/data/floattable-negative-vert-offset-empty.docx |binary
 sw/qa/core/text/itratr.cxx  |   58 
++
 sw/source/core/inc/txtfrm.hxx   |4 
 sw/source/core/text/frmform.cxx |9 +
 sw/source/core/text/itratr.cxx  |   41 +++
 sw/source/core/text/porrst.cxx  |7 +
 sw/source/core/text/widorp.cxx  |   25 
 8 files changed, 124 insertions(+), 21 deletions(-)

New commits:
commit 16b5b21d36da87be9b50235acbbb8008ed23b8bb
Author: Miklos Vajna 
AuthorDate: Mon Jul 3 08:30:21 2023 +0200
Commit: Miklos Vajna 
CommitDate: Mon Jul 3 10:12:49 2023 +0200

sw floattable: fix negative vert offset with on page boundary without anch 
text

The bugdoc has 3 floating tables on page 1, and the anchor of the last
floating table goes to page 2. All anchors are empty (no text), apart
from serving as an anchor for the floating tables. The last floating
table goes to page 2 in Writer, but not in Word.

The problem is quite similar to what commit
2d0a4ef1d83b8de6cb133970c2c35ae706fb058e (sw floattable: fix negative
vertical offset handling on page boundary, 2023-06-20) fixed already,
but here the anchor of the floating table is empty, and there it had
some text, which is a different codepath.

Fix the problem by first requesting a frame split in
SwTextFrame::FormatAdjust() even for empty paragraphs with flys (so the
fly part can go to page 1 and the empty paragraph can go to page 2) and
second disabling the SwTextFrame::FormatEmpty() optimization that would
assume no split is needed, while a split is required for a correct
layout here.

With this, the DOCX version of the original bnc#816603 document finally
renders without overlaps (4 pages, 11 floating tables).

Change-Id: Ie64ce92bf19b3dee8059fa14294d7599b41cc53f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153866
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/sw/CppunitTest_sw_core_text.mk b/sw/CppunitTest_sw_core_text.mk
index 79ac4a0320bf..a04824e08e07 100644
--- a/sw/CppunitTest_sw_core_text.mk
+++ b/sw/CppunitTest_sw_core_text.mk
@@ -15,6 +15,7 @@ $(eval $(call 
gb_CppunitTest_use_common_precompiled_header,sw_core_text))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,sw_core_text, \
 sw/qa/core/text/frmform \
+sw/qa/core/text/itratr \
 sw/qa/core/text/text \
 ))
 
diff --git a/sw/qa/core/text/data/floattable-negative-vert-offset-empty.docx 
b/sw/qa/core/text/data/floattable-negative-vert-offset-empty.docx
new file mode 100644
index ..132fde553825
Binary files /dev/null and 
b/sw/qa/core/text/data/floattable-negative-vert-offset-empty.docx differ
diff --git a/sw/qa/core/text/itratr.cxx b/sw/qa/core/text/itratr.cxx
new file mode 100644
index ..6913d0037dbd
--- /dev/null
+++ b/sw/qa/core/text/itratr.cxx
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace
+{
+/// Covers sw/source/core/text/itratr.cxx fixes.
+class Test : public SwModelTestBase
+{
+public:
+Test()
+: SwModelTestBase("/sw/qa/core/text/data/")
+{
+}
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testFloattableNegativeVertOffsetEmptyAnchor)
+{
+// Given a document with 3 floating tables, all of them on page 1, but the 
anchor of the last
+// floating table is on page 2, but that anchor has no own text:
+createSwDoc("floattable-negative-vert-offset-empty.docx");
+
+// When laying out that document:
+calcLayout();
+
+// Then make sure the that 3rd floating table is not shifted to page 2:
+SwDoc* pDoc = getSwDoc();
+SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+auto pPage1 = dynamic_cast(pLayout->Lower());
+CPPUNIT_ASSERT(pPage1);
+CPPUNIT_ASSERT(pPage1->GetSortedObjs());
+const SwSortedObjs& rPage1Objs = *pPage1->GetSortedObjs();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 3
+// - Actual  : 2
+// i.e. the last floating table was shifted to page 2, which lead to 
overlapping text in the
+// original document.
+CPPUNIT_ASSERT_EQUAL(static_cast(3), rPage1Objs.size());
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/sou

[Libreoffice-commits] core.git: sw/CppunitTest_sw_core_text.mk sw/qa sw/source

2023-06-19 Thread Miklos Vajna (via logerrit)
 sw/CppunitTest_sw_core_text.mk|1 
 sw/qa/core/text/data/floattable-negative-vert-offset.docx |binary
 sw/qa/core/text/frmform.cxx   |   64 ++
 sw/source/core/text/frmform.cxx   |8 +
 4 files changed, 72 insertions(+), 1 deletion(-)

New commits:
commit 01eff4a68b05dd494bc4b3b018059efa60d4
Author: Miklos Vajna 
AuthorDate: Mon Jun 19 08:34:56 2023 +0200
Commit: Miklos Vajna 
CommitDate: Mon Jun 19 09:50:13 2023 +0200

sw floattable: avoid layout loop for negative vert offset in MakePos()

The bugdoc has 2 paragraphs and a floating table between them. The
floating table has a large enough negative vertical offset so it "pushes
down" the paragraph that is before the table in the doc model. Our
layout didn't push the first paragraph down, the second paragraph
overlapped with the table and the whole layout process was just stopped
by the layout loop control.

What happened is that we realized that we have to push down the first
paragraph, so an SwFlyPortion was created for it. Then we made an
UnlockPosition() in SwTextFrame::MakePos(), so it could be calculated
again. This lead to an oscillation, and the calculated vertical position
of the floating table's fly changed between 964 (good) and 2990 (bad)
twips.

Fix the problem by limiting when SwTextFrame::MakePos() calls
UnlockPosition(). The general strategy is that flys are only positioned
once during a layout pass. The exception from this is when the fly moved
to a new page and it's not yet positioned. So if we unlock when the fly
only has the page frame top left position, then we keep the original
use-case working, but fix the layout loop.

Regression from commit 12a9009a1c19ee26c65fb44fc90f3432c88ab6a5 (sw
floattable: fix bad position of follow fly if anchor is positioned late,
2023-03-23), where I didn't realize how dangerous UnlockPosition() is.

Change-Id: I0aa0a52db712a464105e8040497fd429e0604309
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153245
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/sw/CppunitTest_sw_core_text.mk b/sw/CppunitTest_sw_core_text.mk
index 1d8db3e6eeb1..79ac4a0320bf 100644
--- a/sw/CppunitTest_sw_core_text.mk
+++ b/sw/CppunitTest_sw_core_text.mk
@@ -14,6 +14,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,sw_core_text))
 $(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_core_text))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,sw_core_text, \
+sw/qa/core/text/frmform \
 sw/qa/core/text/text \
 ))
 
diff --git a/sw/qa/core/text/data/floattable-negative-vert-offset.docx 
b/sw/qa/core/text/data/floattable-negative-vert-offset.docx
new file mode 100644
index ..688b5b8c1188
Binary files /dev/null and 
b/sw/qa/core/text/data/floattable-negative-vert-offset.docx differ
diff --git a/sw/qa/core/text/frmform.cxx b/sw/qa/core/text/frmform.cxx
new file mode 100644
index ..3c1a16a99444
--- /dev/null
+++ b/sw/qa/core/text/frmform.cxx
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace
+{
+/// Covers sw/source/core/text/frmform.cxx fixes.
+class Test : public SwModelTestBase
+{
+public:
+Test()
+: SwModelTestBase("/sw/qa/core/text/data/")
+{
+}
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testFloattableNegativeVertOffset)
+{
+// Given a document with 2 paragraphs, floating table is between the two 
(so anchored to the
+// 2nd) and with a negative vertical offset:
+createSwDoc("floattable-negative-vert-offset.docx");
+
+// When laying out that document:
+calcLayout();
+
+// Then make sure that the negative vertical offset shifts both paragraphs 
down:
+SwDoc* pDoc = getSwDoc();
+SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+auto pPage = dynamic_cast(pLayout->Lower());
+CPPUNIT_ASSERT(pPage);
+CPPUNIT_ASSERT(pPage->GetSortedObjs());
+const SwSortedObjs& rPageObjs = *pPage->GetSortedObjs();
+CPPUNIT_ASSERT_EQUAL(static_cast(1), rPageObjs.size());
+SwAnchoredObject* pPageObj = rPageObjs[0];
+const SwRect& rFlyRect = pPageObj->GetObjRectWithSpaces();
+SwFrame* pBody = pPage->FindBodyCont();
+SwFrame* pPara1 = pBody->GetLower();
+SwFrame* pPara2 = pPara1->GetNext();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected less than: 993
+// - Actual  : 2709
+// i.e. the expectation that 

[Libreoffice-commits] core.git: sw/CppunitTest_sw_core_text.mk sw/qa sw/source

2022-04-29 Thread Miklos Vajna (via logerrit)
 sw/CppunitTest_sw_core_text.mk  |1 
 sw/qa/core/text/text.cxx|   44 +++-
 sw/source/core/text/frmform.cxx |   18 
 3 files changed, 62 insertions(+), 1 deletion(-)

New commits:
commit 515bf5d4afa3a8ed413fd6f17f66fa98b6dbf29e
Author: Miklos Vajna 
AuthorDate: Fri Apr 29 12:10:13 2022 +0200
Commit: Miklos Vajna 
CommitDate: Fri Apr 29 20:59:50 2022 +0200

tdf#148683 sw: fix crash on deleting text with redlining enabled, but hidden

Regression from commit 32902f66e7749b2d06d13f50416be5323a0c0ea9
(sw_redlinehide: make layout based Show/Hide mode the default,
2018-11-30), deleting some text in the middle of the paragraph with the
bugdoc results in an assertion failure in the SwDrawTextInfo ctor.

Normally this doesn't happen on text deletion as we already have a
mechanism for truncating no longer needed lines in
SwTextFrame::Format_(), though that only checks the length of the
current line.

Fix the problem by extending this mechanism to also check the remaining
lines: if change tracking is on and the total of all line lengths is
more than the string length of the text frame, then time to
re-calculate.

It seems this is not needed in practice when redlining is disabled,
though we might want to enable this for the non-redline case as well in
the future.

Change-Id: Iede03e11daceb3c2b614a301e21560b075a60c01
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133620
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/sw/CppunitTest_sw_core_text.mk b/sw/CppunitTest_sw_core_text.mk
index 19d8cd422edc..c3025f007a9a 100644
--- a/sw/CppunitTest_sw_core_text.mk
+++ b/sw/CppunitTest_sw_core_text.mk
@@ -21,6 +21,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_core_text, \
 comphelper \
 cppu \
 cppuhelper \
+editeng \
 sal \
 sfx \
 svl \
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index f847df9c5e56..f6c4023af944 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -24,13 +24,14 @@
 #include 
 #include 
 #include 
-
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
 
 constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/text/data/";
 
@@ -428,6 +429,47 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, 
testAsCharImageDocModelFromViewPoint)
 CPPUNIT_ASSERT_EQUAL(aGraphicNode, pShellCursor->GetMark()->nNode);
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testRedlineDelete)
+{
+// Given a document with A4 paper size, some text, redlining on, but 
hidden:
+SwDoc* pDoc = createSwDoc();
+SwDocShell* pDocShell = pDoc->GetDocShell();
+SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+{
+// Set page size to A4.
+size_t nCurIdx = pWrtShell->GetCurPageDesc();
+SwPageDesc aPageDesc(pWrtShell->GetPageDesc(nCurIdx));
+SwFrameFormat& rMaster = aPageDesc.GetMaster();
+SwFormatFrameSize aSize(SwFrameSize::Fixed);
+aSize.SetSize(Size(11906, 16838));
+rMaster.SetFormatAttr(aSize);
+pWrtShell->ChgPageDesc(nCurIdx, aPageDesc);
+}
+OUString aBefore("a aa aa aa aa ");
+OUString aDelete("delete eee ee eee ee ee");
+pWrtShell->Insert(aBefore + " " + aDelete
+  + " zz zzz z zzz   z zz zzz 
zzz zzz");
+// Enable redlining.
+pDocShell->SetChangeRecording(/*bActivate=*/true);
+// Hide redlining.
+pWrtShell->StartAllAction();
+pWrtShell->GetLayout()->SetHideRedlines(true);
+pWrtShell->EndAllAction();
+
+// When deleting content in the middle of the paragraph:
+pWrtShell->SttEndDoc(/*bStt=*/true);
+pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 
/*nCount=*/aBefore.getLength(),
+ /*bBasicCall=*/false);
+pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 
/*nCount=*/aDelete.getLength(),
+ /*bBasicCall=*/false);
+// Without the accompanying fix in place, this test would have crashed:
+pWrtShell->Delete();
+
+// Then make sure that the redline is created:
+CPPUNIT_ASSERT_EQUAL(static_cast(1),
+ 
pDoc->getIDocumentRedlineAccess().GetRedlineTable().size());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/frmform.cxx b/sw/source/core/text/frmform.cxx
index 861d143dc96a..e2bff47bd305 100644
--- a/sw/source/core/text/frmform.cxx
+++ b/sw/source/core/text/frmform.cxx
@@ -1620,8 +1620,26 @@ void SwTextFrame::Format_( SwTextFormatter &rLine, 
SwTextFormatInfo &rInf,
 // If we're finished formatting the text and we still
 // have other line objects left, these are superfluous
 // now because the text has gotten shorter.
+bool bTruncLines = false;
 if( rLine

[Libreoffice-commits] core.git: sw/CppunitTest_sw_core_text.mk sw/qa sw/source

2022-04-26 Thread Miklos Vajna (via logerrit)
 sw/CppunitTest_sw_core_text.mk  |1 
 sw/qa/core/text/text.cxx|   46 
 sw/source/core/text/itrcrsr.cxx |4 ++-
 3 files changed, 50 insertions(+), 1 deletion(-)

New commits:
commit 651527b4efe9700c8c8dff58ce5aa86ad5681f16
Author: Miklos Vajna 
AuthorDate: Tue Apr 26 15:40:44 2022 +0200
Commit: Miklos Vajna 
CommitDate: Tue Apr 26 17:02:15 2022 +0200

sw: fix double-click opening frame dialog, not graphic dialog on images

The user-visible problem was that once a user clicks on an image a lot
(e.g. 5 times), then the slot ID dispatched on double-click in
SwEditWin::MouseButtonDown() is no longer FN_FORMAT_GRAFIC_DLG, but it's
FN_FORMAT_FRAME_DLG.

This is already inconsistent, but it's especially problematic in case an
UNO client intercepts only the first UNO command, but not the second
one.

The other inconsistency is that in practice this only happens for
as-char images, at-char anchored images work fine.

The reason for this seems to be how we get the doc model position for a
twips view point. At-char anchored images are handled at
lcl_GetModelPositionForViewPoint_Objects(), and there we return the
SwGrfNode in case the view point is inside the frame of the matching fly
frame. SwTextCursor::GetModelPositionForViewPoint() restricted the same
to as-char fly frames which have text or layout frame children.

Fix the problem by allowing non-text frame children for as-char images.

Change-Id: If08e7dd2a72f46ebcfb8c6ddf110703eaeb7df6d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133443
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/sw/CppunitTest_sw_core_text.mk b/sw/CppunitTest_sw_core_text.mk
index 6f19ff690f5a..19d8cd422edc 100644
--- a/sw/CppunitTest_sw_core_text.mk
+++ b/sw/CppunitTest_sw_core_text.mk
@@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_core_text, \
 cppuhelper \
 sal \
 sfx \
+svl \
 sw \
swqahelper \
 test \
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 8ad0d230bebc..f847df9c5e56 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -28,6 +28,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/text/data/";
 
@@ -382,6 +385,49 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, 
testClearingLineBreakHeader)
 assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout[1]", "height", "276");
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testAsCharImageDocModelFromViewPoint)
+{
+// Given a document with an as-char image:
+SwDoc* pDoc = createSwDoc();
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xTextGraphic(
+xFactory->createInstance("com.sun.star.text.TextGraphicObject"), 
uno::UNO_QUERY);
+// Only set the anchor type, the actual bitmap content is not interesting.
+xTextGraphic->setPropertyValue("AnchorType",
+   
uno::makeAny(text::TextContentAnchorType_AS_CHARACTER));
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xBodyText = xTextDocument->getText();
+uno::Reference xCursor(xBodyText->createTextCursor());
+uno::Reference xTextContent(xTextGraphic, 
uno::UNO_QUERY);
+xBodyText->insertTextContent(xCursor, xTextContent, false);
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+SwRootFrame* pRootFrame = pWrtShell->GetLayout();
+SwFrame* pPageFrame = pRootFrame->GetLower();
+SwFrame* pBodyFrame = pPageFrame->GetLower();
+SwFrame* pTextFrame = pBodyFrame->GetLower();
+const SwSortedObjs& rSortedObjs = *pTextFrame->GetDrawObjs();
+const SwAnchoredObject* pAnchoredObject = rSortedObjs[0];
+// The content points to the start node, the next node is the graphic node.
+SwNodeIndex aGraphicNode = 
*pAnchoredObject->GetFrameFormat().GetContent().GetContentIdx();
+++aGraphicNode;
+tools::Rectangle aFlyFrame = 
pAnchoredObject->GetDrawObj()->GetLastBoundRect();
+Point aDocPos = aFlyFrame.Center();
+
+// When translating the view point to the model position:
+pWrtShell->SttCursorMove();
+pWrtShell->CallSetCursor(&aDocPos, /*bOnlyText=*/false);
+pWrtShell->EndCursorMove();
+
+// Then make sure that we find the graphic node, and not its anchor:
+SwShellCursor* pShellCursor = pWrtShell->getShellCursor(/*bBlock=*/false);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: SwNodeIndex (node 6)
+// - Actual  : SwNodeIndex (node 12)
+// i.e. the cursor position was the text node hosting the as-char image, 
not the graphic node of
+// the image.
+CPPUNIT_ASSERT_EQUAL(aGraphicNode, pShellCursor->GetMark()->nNode);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab

[Libreoffice-commits] core.git: sw/CppunitTest_sw_core_text.mk sw/qa sw/source

2021-09-13 Thread Miklos Vajna (via logerrit)
 sw/CppunitTest_sw_core_text.mk   |1 
 sw/qa/core/text/data/ruby.fodt   |   25 +
 sw/qa/core/text/text.cxx |   46 +++
 sw/source/core/text/porlay.hxx   |2 -
 sw/source/core/text/pormulti.cxx |2 -
 5 files changed, 74 insertions(+), 2 deletions(-)

New commits:
commit 0c3e47cc2f0570a7cd8ff4889763991a86b29f26
Author: Miklos Vajna 
AuthorDate: Mon Sep 13 19:27:48 2021 +0200
Commit: Miklos Vajna 
CommitDate: Tue Sep 14 08:19:07 2021 +0200

tdf#144305 sw: fix rendering of ruby portions with non-default ruby 
alignment

Regression from 301278b656e76b6f42af5cf8a6f5c6c02acfffeb (sw: allow the
height of a line to be larger than 65536 twips, 2021-05-20), the problem
was that changing from sal_uInt16 to sal_uInt32 broke
SwRubyPortion::Adjust_(), which relied on integer promotion rules to
have a negative diff.

Old storage size was smaller than int, so got promoted to signed int, so
the result could be a small negative number.

New storage size is an unsigned int, so no promotion happens, so the new
result was a large positive number.

Fix this by casting to signed int explicitly.

Change-Id: I8778c1bd0d62e27c99d4ceb1bb7bc6107a179803
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122048
Tested-by: Jenkins
Reviewed-by: Miklos Vajna 

diff --git a/sw/CppunitTest_sw_core_text.mk b/sw/CppunitTest_sw_core_text.mk
index cb4801accac9..6f19ff690f5a 100644
--- a/sw/CppunitTest_sw_core_text.mk
+++ b/sw/CppunitTest_sw_core_text.mk
@@ -40,6 +40,7 @@ $(eval $(call gb_CppunitTest_use_externals,sw_core_text,\
 $(eval $(call gb_CppunitTest_set_include,sw_core_text,\
 -I$(SRCDIR)/sw/inc \
 -I$(SRCDIR)/sw/source/core/inc \
+-I$(SRCDIR)/sw/source/core/text \
 -I$(SRCDIR)/sw/source/uibase/inc \
 -I$(SRCDIR)/sw/qa/inc \
 $$(INCLUDE) \
diff --git a/sw/qa/core/text/data/ruby.fodt b/sw/qa/core/text/data/ruby.fodt
new file mode 100644
index ..b5a0e23d2c53
--- /dev/null
+++ b/sw/qa/core/text/data/ruby.fodt
@@ -0,0 +1,25 @@
+
+
+  
+  
+  
+  
+  
+
+  
+
+
+  
+
+
+  
+
+  
+  
+  
+  
+
+  Ruby test: base textruby (left) base 
textruby (center) 
base 
textruby 
(right)
+
+  
+
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index be6406f6b654..6832ad2cb436 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -21,6 +21,12 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
 
 constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/text/data/";
 
@@ -170,6 +176,46 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testLineWidth)
 CPPUNIT_ASSERT_GREATER(static_cast(65536), nNewLeft - nOldLeft);
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testRuby)
+{
+// Given a document with multiple ruby portions:
+SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "ruby.fodt");
+
+// When laying out that document:
+SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+
+// Then make sure that no unwanted margin portions are created, making the 
actual text
+// invisible:
+SwFrame* pPageFrame = pLayout->GetLower();
+SwFrame* pBodyFrame = pPageFrame->GetLower();
+SwFrame* pFrame = pBodyFrame->GetLower();
+CPPUNIT_ASSERT(pFrame->IsTextFrame());
+auto pTextFrame = static_cast(pFrame);
+SwParaPortion* pPara = pTextFrame->GetPara();
+bool bFirst = true;
+for (SwLinePortion* pPor = pPara->GetFirstPortion(); pPor; pPor = 
pPor->GetNextPortion())
+{
+// Look for multi-portions in the only paragraph of the document.
+if (pPor->GetWhichPor() != PortionType::Multi)
+{
+continue;
+}
+
+if (bFirst)
+{
+bFirst = false;
+continue;
+}
+
+// The second multi-portion has two lines, check the start of the 
second line.
+auto pMulti = static_cast(pPor);
+// Without the accompanying fix in place, this test would have failed, 
as the portion was a
+// margin portion, not a text portion. The margin was so large that 
the actual text portion was
+// hidden. No margin is needed here at all.
+
CPPUNIT_ASSERT(pMulti->GetRoot().GetNext()->GetFirstPortion()->IsTextPortion());
+}
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/porlay.hxx b/sw/source/core/text/porlay.hxx
index 3a3d458f2cf8..f7d775e23fed 100644
--- a/sw/source/core/text/porlay.hxx
+++ b/sw/source/core/text/porlay.hxx
@@ -77,7 +77,7 @@ public:
 
 /// Collection of SwLinePortion instances, representing one line of text.
 /// Typically owned by an SwParaPortion.
-class SwLineLayout : public SwTextPortion
+class SW_DLLPUBLIC SwLineLayout : public SwTextPortion
 {
 private:
 SwLineLayout *m_pNext;// The ne

[Libreoffice-commits] core.git: sw/CppunitTest_sw_core_text.mk sw/qa sw/source

2020-01-07 Thread Miklos Vajna (via logerrit)
 sw/CppunitTest_sw_core_text.mk |1 
 sw/qa/core/text/text.cxx   |   32 +
 sw/source/core/text/inftxt.cxx |   75 +
 3 files changed, 108 insertions(+)

New commits:
commit bf540873f5e258452fed5006f65a403c95e7872a
Author: Miklos Vajna 
AuthorDate: Mon Jan 6 20:35:08 2020 +0100
Commit: Miklos Vajna 
CommitDate: Tue Jan 7 09:26:47 2020 +0100

sw: add rendering for semi-transparent text

I considered passing the text color's alpha value down to the various
vcl backends, but this would need changes everywhere (cairo, opengl, pdf
export, etc). It's much easier to go via DrawTransparent(), that's how
semi-transparent text in Draw/Impress already works.

Change-Id: I96f15e6764c3c88ba67dd72dc8708414d7c6050c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86294
Tested-by: Jenkins
Reviewed-by: Miklos Vajna 

diff --git a/sw/CppunitTest_sw_core_text.mk b/sw/CppunitTest_sw_core_text.mk
index 9fe4fadbf357..cb901fde29f2 100644
--- a/sw/CppunitTest_sw_core_text.mk
+++ b/sw/CppunitTest_sw_core_text.mk
@@ -27,6 +27,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_core_text, \
 test \
 unotest \
 utl \
+vcl \
 ))
 
 $(eval $(call gb_CppunitTest_use_externals,sw_core_text,\
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 8074cbc9f45e..4e6d4fcdb14e 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -8,6 +8,9 @@
  */
 
 #include 
+
+#include 
+
 #include 
 
 static char const DATA_DIRECTORY[] = "/sw/qa/core/text/data/";
@@ -46,6 +49,35 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testFootnoteConnect)
 pWrtShell->DelLeft();
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testSemiTransparentText)
+{
+// Create an in-memory empty document.
+loadURL("private:factory/swriter", nullptr);
+
+// Set text to half-transparent and type a character.
+uno::Reference xParagraph(getParagraph(1), 
uno::UNO_QUERY);
+CPPUNIT_ASSERT(xParagraph.is());
+sal_Int16 nTransparence = 50;
+xParagraph->setPropertyValue("CharTransparence", 
uno::makeAny(nTransparence));
+uno::Reference xTextRange(xParagraph, uno::UNO_QUERY);
+CPPUNIT_ASSERT(xTextRange.is());
+xTextRange->setString("x");
+
+// Render the document to a metafile.
+SwXTextDocument* pTextDoc = 
dynamic_cast(mxComponent.get());
+CPPUNIT_ASSERT(pTextDoc);
+SwDocShell* pDocShell = pTextDoc->GetDocShell();
+CPPUNIT_ASSERT(pDocShell);
+std::shared_ptr xMetaFile = pDocShell->GetPreviewMetaFile();
+CPPUNIT_ASSERT(xMetaFile);
+
+// Make sure that DrawTransparent() was used during rendering.
+MetafileXmlDump dumper;
+xmlDocPtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
+CPPUNIT_ASSERT(pXmlDoc);
+assertXPath(pXmlDoc, "//floattransparent");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx
index 9fc9116fe1e4..efe9d54e1222 100644
--- a/sw/source/core/text/inftxt.cxx
+++ b/sw/source/core/text/inftxt.cxx
@@ -64,6 +64,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::linguistic2;
@@ -552,6 +555,71 @@ static bool lcl_IsDarkBackground( const SwTextPaintInfo& 
rInf )
 return pCol->IsDark();
 }
 
+namespace
+{
+/**
+ * Context class that captures the draw operations on rDrawInf's output device 
for transparency
+ * purposes.
+ */
+class SwTransparentTextGuard
+{
+ScopedVclPtrInstance m_aContentVDev;
+GDIMetaFile m_aContentMetafile;
+MapMode m_aNewMapMode;
+SwRect m_aPorRect;
+SwTextPaintInfo& m_rPaintInf;
+SwDrawTextInfo& m_rDrawInf;
+
+public:
+SwTransparentTextGuard(const SwLinePortion& rPor, SwTextPaintInfo& 
rPaintInf,
+   SwDrawTextInfo& rDrawInf);
+~SwTransparentTextGuard();
+};
+
+SwTransparentTextGuard::SwTransparentTextGuard(const SwLinePortion& rPor,
+   SwTextPaintInfo& rPaintInf, 
SwDrawTextInfo& rDrawInf)
+: m_aNewMapMode(rPaintInf.GetOut()->GetMapMode())
+, m_rPaintInf(rPaintInf)
+, m_rDrawInf(rDrawInf)
+{
+rPaintInf.CalcRect(rPor, &m_aPorRect);
+rDrawInf.SetOut(*m_aContentVDev);
+m_aContentVDev->SetMapMode(rPaintInf.GetOut()->GetMapMode());
+m_aContentMetafile.Record(m_aContentVDev.get());
+m_aContentVDev->SetLineColor(rPaintInf.GetOut()->GetLineColor());
+m_aContentVDev->SetFillColor(rPaintInf.GetOut()->GetFillColor());
+m_aContentVDev->SetFont(rPaintInf.GetOut()->GetFont());
+m_aContentVDev->SetDrawMode(rPaintInf.GetOut()->GetDrawMode());
+m_aContentVDev->SetSettings(rPaintInf.GetOut()->GetSettings());
+m_aContentVDev->SetRefPoint(rPaintInf.GetOut()->GetRefPoint());
+}
+
+SwTransparentTextGuard::~SwTransparentTextGuard()
+{
+m_aContentMetafile.Stop();
+m_aContentMetafile