sw/qa/extras/layout/layout.cxx |   51 +++++++++++++++++++++++++++++++++++++++++
 sw/source/core/text/guess.cxx  |    8 ++++++
 2 files changed, 59 insertions(+)

New commits:
commit 8f25d8b610c8b8471584876ae50cd0a86a1bef8f
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Oct 22 16:53:06 2019 +0200
Commit:     Michael Stahl <michael.st...@cib.de>
CommitDate: Thu Oct 24 14:35:08 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.
    
    (cherry picked from commit dc83c34989b366a9740da062e7d7bdca73fd9890)
    
    Conflicts:
            sw/qa/extras/layout/layout.cxx
    
    Change-Id: I0af178c75bb9a1e85d9f1393f010c890cb1cbc08
    Reviewed-on: https://gerrit.libreoffice.org/81438
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@cib.de>

diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index fa3720d2a977..c4dacb049ad6 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>
@@ -25,6 +29,8 @@
 #include <edtwin.hxx>
 #include <view.hxx>
 #include <txtfrm.hxx>
+#include <frmatr.hxx>
+#include <IDocumentSettingAccess.hxx>
 
 static char const DATA_DIRECTORY[] = "/sw/qa/extras/layout/data/";
 
@@ -3157,6 +3163,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 4c0af10e54cb..10472f531894 100644
--- a/sw/source/core/text/guess.cxx
+++ b/sw/source/core/text/guess.cxx
@@ -139,6 +139,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
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to