sw/qa/core/text/data/number-portion-format.odt |binary sw/qa/core/text/text.cxx | 19 +++++++++++++++++++ sw/source/core/text/txtfld.cxx | 22 ++++++++++++++++++++++ 3 files changed, 41 insertions(+)
New commits: commit cb0e1b52d68aa6d5b505f91cb4ce577f7f3b2a8f Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Oct 20 15:53:16 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Oct 20 17:02:04 2022 +0200 sw, numbering portion format: consider full-para char formats as well The bugdoc had a single paragraph with direct formatting (24pt font size), numbering enabled and a bookmark covering half of the paragraph. The numbering had default font size, not inheriting from the paragraph. Turns out that in case the bookmark is removed, then the custom font size is not an autoformat set on the whole text of the paragraph but rather a format on the paragraph level, which does influence the formatting of the numbering portion, as expected. Fix the problem by extending SwTextFormatter::NewNumberPortion(), so it looks for char props not only in the item set of the SwTextNode, but also in the hints of SwTextNode, if they cover the whole paragraph. This fixes the inconsistency that adding a bookmark to the document should not change the rendering of the portions. Interestingly DOCX import already set the font size on the SwTextNode in this case, but the ODT import created a char autofmt hint, that covered the full paragraph. Change-Id: I09ffabd84511da439bc05a6f8d134615e5dd8599 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141572 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/core/text/data/number-portion-format.odt b/sw/qa/core/text/data/number-portion-format.odt new file mode 100644 index 000000000000..3047153b63af Binary files /dev/null and b/sw/qa/core/text/data/number-portion-format.odt differ diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index d5b1761476c3..a0f7726c42b1 100644 --- a/sw/qa/core/text/text.cxx +++ b/sw/qa/core/text/text.cxx @@ -810,6 +810,25 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testRichContentControlPDF) CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount()); } +CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testNumberPortionFormat) +{ + // Given a document with a single paragraph, direct formatting asks 24pt font size for the + // numbering and the text portion: + createSwDoc(DATA_DIRECTORY, "number-portion-format.odt"); + + // When laying out that document: + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + + // Then make sure that the numbering portion has the correct font size: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 480 + // - Actual : 240 + // i.e. the numbering portion font size was 12pt, not 24pt (but only when the doc had a + // bookmark). + assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout/child::*[@type='PortionType::Number']", + "font-height", "480"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx index 22127dd30e21..e4851cc96b73 100644 --- a/sw/source/core/text/txtfld.cxx +++ b/sw/source/core/text/txtfld.cxx @@ -784,6 +784,28 @@ SwNumberPortion *SwTextFormatter::NewNumberPortion( SwTextFormatInfo &rInf ) con // Build a new numbering font basing on the current paragraph font: std::unique_ptr<SwFont> pNumFnt(new SwFont( &rInf.GetCharAttr(), pIDSA )); + const SwTextNode& rTextNode = *rInf.GetTextFrame()->GetTextNodeForParaProps(); + if (const SwpHints* pHints = rTextNode.GetpSwpHints()) + { + // Also look for a character hint that cover the entire current paragraph: + for (size_t i = 0; i < pHints->Count(); ++i) + { + const SwTextAttr* pHint = pHints->Get(i); + if (pHint->Which() == RES_TXTATR_AUTOFMT && pHint->GetStart() == 0 + && pHint->GetEnd() + && *pHint->GetEnd() == rTextNode.GetText().getLength()) + { + std::shared_ptr<SfxItemSet> pSet + = pHint->GetAutoFormat().GetStyleHandle(); + if (pSet) + { + pNumFnt->SetDiffFnt(pSet.get(), pIDSA); + break; + } + } + } + } + // #i53199# if ( !pIDSA->get(DocumentSettingId::DO_NOT_RESET_PARA_ATTRS_FOR_NUM_FONT) ) {