sw/qa/extras/tiledrendering/data/format-insert-list.docx |binary sw/qa/extras/tiledrendering/tiledrendering.cxx | 42 ++++++++++++++- sw/source/core/doc/extinput.cxx | 15 +---- 3 files changed, 44 insertions(+), 13 deletions(-)
New commits: commit 6b21c4af3d896ac7293483a21944162afff3c4db Author: Jaume Pujantell <jaume.pujant...@collabora.com> AuthorDate: Tue Oct 8 09:29:51 2024 +0200 Commit: Jaume Pujantell <jaume.pujant...@collabora.com> CommitDate: Fri Oct 11 09:47:31 2024 +0200 cool#6382 lok: sw: text wrong format on inserted text When inserting text at the beginning of a list item the incorrect font is used. It used default style instead of the font applied to the item text. Added a test to avoid this regression, and also modified the test testIMEFormattingAtEndOfParagraph to better catch regressions there. This reverts some changes from: lok: IME: preserve formatting when inserting at the end of paragraph bf96d1f23e5c12f9263643dfdab94fd1361bb098 lok: IME: directly copy formatting for inserted text d8dbd123bfa7f39489ceb15ac83142635531fd43 tdf#146728 lok: IME: preset formatting in the new paragraph 218acb48df79101392c2cc3a030ddb5dcee878c7 Change-Id: I60071e06ff448b2e7c2d5a628a344fbfd15b30af Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174657 Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> Reviewed-by: Jaume Pujantell <jaume.pujant...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sw/qa/extras/tiledrendering/data/format-insert-list.docx b/sw/qa/extras/tiledrendering/data/format-insert-list.docx new file mode 100644 index 000000000000..25104af81860 Binary files /dev/null and b/sw/qa/extras/tiledrendering/data/format-insert-list.docx differ diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index a6e07bd7220d..a2c804d20aee 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -35,6 +35,7 @@ #include <vcl/virdev.hxx> #include <vcl/filter/PngImageWriter.hxx> #include <editeng/editview.hxx> +#include <editeng/fontitem.hxx> #include <editeng/outliner.hxx> #include <editeng/wghtitem.hxx> #include <svl/srchitem.hxx> @@ -2738,6 +2739,21 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testIMEFormattingAtEndOfParagraph) // check the content CPPUNIT_ASSERT_EQUAL(OUString("bab"), pShellCursor->GetPoint()->GetNode().GetTextNode()->GetText()); + + // check the actual weight format of the text + SvxWeightItem aBoldWeightItem(WEIGHT_BOLD, RES_CHRATR_WEIGHT); + SfxItemSet aSet(pXTextDocument->GetDocShell()->GetDoc()->GetAttrPool(), svl::Items<RES_CHRATR_WEIGHT, RES_CHRATR_WEIGHT>); + pShellCursor->GetPoint()->GetNode().GetTextNode()->GetParaAttr(aSet, 0, 1); + SfxPoolItem const* pPoolItem = aSet.GetItem(RES_CHRATR_WEIGHT); + CPPUNIT_ASSERT(*pPoolItem != aBoldWeightItem); // b not bold + aSet.ClearItem(); + pShellCursor->GetPoint()->GetNode().GetTextNode()->GetParaAttr(aSet, 1, 2); + pPoolItem = aSet.GetItem(RES_CHRATR_WEIGHT); + CPPUNIT_ASSERT(*pPoolItem == aBoldWeightItem); // a bold + aSet.ClearItem(); + pShellCursor->GetPoint()->GetNode().GetTextNode()->GetParaAttr(aSet, 2, 3); + pPoolItem = aSet.GetItem(RES_CHRATR_WEIGHT); + CPPUNIT_ASSERT(*pPoolItem != aBoldWeightItem); // b not bold } CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testIMEFormattingAfterHeader) @@ -4601,7 +4617,7 @@ public: CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testAnyInput) { - // Given a document with 3 pages, the first page is visible: + // Given a document with 3 pages, the first page is visible:f SwXTextDocument* pXTextDocument = createDoc(); CPPUNIT_ASSERT(pXTextDocument); ViewCallback aView; @@ -4660,6 +4676,30 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testSignatureState) CPPUNIT_ASSERT_EQUAL(SignatureState::NOTVALIDATED, eState); } +CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testFormatInsertStartList) +{ + // Given a document containing a list where the text has a changed font + SwXTextDocument* pXTextDocument = createDoc("format-insert-list.docx"); + CPPUNIT_ASSERT(pXTextDocument); + VclPtr<vcl::Window> pDocWindow = pXTextDocument->getDocWindow(); + SwView* pView = dynamic_cast<SwView*>(SfxViewShell::Current()); + assert(pView); + + // Insert a string at the begining of a list item + pDocWindow->PostExtTextInputEvent(VclEventId::ExtTextInput, "a"); + pDocWindow->PostExtTextInputEvent(VclEventId::EndExtTextInput, ""); + Scheduler::ProcessEventsToIdle(); + + // The inserted text should have the same font as the rest + std::unique_ptr<SvxFontItem> pFontItem; + pView->GetViewFrame().GetBindings().QueryState(SID_ATTR_CHAR_FONT, pFontItem); + CPPUNIT_ASSERT(pFontItem); + CPPUNIT_ASSERT_EQUAL(u"Calibri"_ustr, pFontItem->GetFamilyName()); + // Without the accompanying fix in place, this test fails with: + // - Expected: Calibri + // - Actual : MS Sans Serif +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/extinput.cxx b/sw/source/core/doc/extinput.cxx index c8563facbd85..7ea91125b876 100644 --- a/sw/source/core/doc/extinput.cxx +++ b/sw/source/core/doc/extinput.cxx @@ -107,20 +107,12 @@ SwExtTextInput::~SwExtTextInput() } else { - // 1. Insert text at start position with EMPTYEXPAND to use correct formatting - // ABC<NEW><OLD> - // 2. Then remove old (not tracked) content - // ABC<NEW> - - sal_Int32 nLenghtOfOldString = nEndCnt - nSttCnt; + pTNd->EraseText( rPtPos, nEndCnt - nSttCnt ); if( m_bInsText ) { - rPtPos.SetContent(nSttCnt); - rDoc.getIDocumentContentOperations().InsertString( *this, sText, SwInsertFlags::EMPTYEXPAND ); + rDoc.getIDocumentContentOperations().InsertString(*this, sText); } - - pTNd->EraseText( rPtPos, nLenghtOfOldString ); } if (!bWasIME) { @@ -202,8 +194,7 @@ void SwExtTextInput::SetInputData( const CommandExtTextInputData& rData ) pTNd->EraseText( aIdx, nEndCnt - nSttCnt ); } - // NOHINTEXPAND so we can use correct formatting in destructor when we finish composing - pTNd->InsertText( rNewStr, aIdx, SwInsertFlags::NOHINTEXPAND ); + pTNd->InsertText(rNewStr, aIdx); if( !HasMark() ) SetMark(); }