sw/qa/extras/layout/data/tdf124770.docx |binary sw/qa/extras/layout/layout.cxx | 51 ++++++++++++++++++++++++++++++++ sw/source/core/text/guess.cxx | 8 +++++ 3 files changed, 59 insertions(+)
New commits: commit dc83c34989b366a9740da062e7d7bdca73fd9890 Author: Miklos Vajna <[email protected]> AuthorDate: Tue Oct 22 16:53:06 2019 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Oct 22 20:06:35 2019 +0200 tdf#124770 sw layout: handle Word's take on italic formatting vs text break When it comes to finding out if a piece of text fits the currently line or not, Word simply measures the text width and the line width, and decides if we fit or not. This can have an effect that italic text (e.g. a "H" character) is slightly over the margin, but simplifies the layout. Writer tries to reserve a bit more space, so italic text is kept inside the margin, which leads to different layout in edge cases. This somewhat arbitrary "reserve a bit more space: decrease the usable line width by height / 12" mechanism was there since the initial import. Reuse a related compatibility flag (tab-over-margin, already set for imported-from-Word documents) to avoid this compensation to match what Word does. Change-Id: I0af178c75bb9a1e85d9f1393f010c890cb1cbc08 Reviewed-on: https://gerrit.libreoffice.org/81341 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins diff --git a/sw/qa/extras/layout/data/tdf124770.docx b/sw/qa/extras/layout/data/tdf124770.docx new file mode 100644 index 000000000000..dd354943739f Binary files /dev/null and b/sw/qa/extras/layout/data/tdf124770.docx differ diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx index 98eed78ca56a..5adaf5a54492 100644 --- a/sw/qa/extras/layout/layout.cxx +++ b/sw/qa/extras/layout/layout.cxx @@ -18,6 +18,10 @@ #include <i18nlangtag/languagetag.hxx> #include <vcl/event.hxx> #include <vcl/scheduler.hxx> +#include <editeng/lrspitem.hxx> +#include <editeng/fontitem.hxx> +#include <editeng/fhgtitem.hxx> +#include <editeng/postitem.hxx> #include <fmtanchr.hxx> #include <fmtfsize.hxx> #include <fmtcntnt.hxx> @@ -30,6 +34,8 @@ #include <sortedobjs.hxx> #include <anchoredobject.hxx> #include <ndtxt.hxx> +#include <frmatr.hxx> +#include <IDocumentSettingAccess.hxx> static char const DATA_DIRECTORY[] = "/sw/qa/extras/layout/data/"; @@ -3284,6 +3290,51 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf124601b) CPPUNIT_ASSERT_LESS(nLastCellRight, nFlyRight); } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf124770) +{ + // Enable content over margin. + SwDoc* pDoc = createDoc(); + pDoc->getIDocumentSettingAccess().set(DocumentSettingId::TAB_OVER_MARGIN, true); + + // Set page width. + SwPageDesc& rPageDesc = pDoc->GetPageDesc(0); + SwFrameFormat& rPageFormat = rPageDesc.GetMaster(); + const SwAttrSet& rPageSet = rPageFormat.GetAttrSet(); + SwFormatFrameSize aPageSize = rPageSet.GetFrameSize(); + aPageSize.SetWidth(3703); + rPageFormat.SetFormatAttr(aPageSize); + + // Set left and right margin. + SvxLRSpaceItem aLRSpace = rPageSet.GetLRSpace(); + aLRSpace.SetLeft(1418); + aLRSpace.SetRight(1418); + rPageFormat.SetFormatAttr(aLRSpace); + pDoc->ChgPageDesc(0, rPageDesc); + + // Set font to italic 20pt Liberation Serif. + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + SfxItemSet aTextSet(pWrtShell->GetView().GetPool(), + svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END - 1>{}); + SvxFontItem aFont(RES_CHRATR_FONT); + aFont.SetFamilyName("Liberation Serif"); + aTextSet.Put(aFont); + SvxFontHeightItem aHeight(400, 100, RES_CHRATR_FONTSIZE); + aTextSet.Put(aHeight); + SvxPostureItem aItalic(ITALIC_NORMAL, RES_CHRATR_POSTURE); + aTextSet.Put(aItalic); + pWrtShell->SetAttrSet(aTextSet); + + // Insert the text. + pWrtShell->Insert2("HHH"); + + xmlDocPtr pXmlDoc = parseLayoutDump(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 2 + // i.e. the italic string was broken into 2 lines, while Word kept it in a single line. + assertXPath(pXmlDoc, "/root/page/body/txt[1]/LineBreak", 1); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/guess.cxx b/sw/source/core/text/guess.cxx index c28cccfb65bc..7d2f4a3b1010 100644 --- a/sw/source/core/text/guess.cxx +++ b/sw/source/core/text/guess.cxx @@ -136,6 +136,14 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, SwTextFormatInfo &rInf, bAddItalic = false; } + if (rInf.GetTextFrame()->GetDoc().getIDocumentSettingAccess().get( + DocumentSettingId::TAB_OVER_MARGIN)) + { + // Content is allowed over the margin: in this case over-margin content caused by italic + // formatting is OK. + bAddItalic = false; + } + nItalic = bAddItalic ? nPorHeight / 12 : 0; nLineWidth -= nItalic; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
