diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2024-06-13 15:46:31 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2024-06-24 16:36:55 +0200 |
commit | 3f3b3e1888a3d0d5a1f0fd051fb6b9aa6478621f (patch) | |
tree | 6740aa36b3da8127dda1f29eb464ea99a13d2525 | |
parent | 1e4af581d64c7d29e571e979899fa8625c3f969f (diff) |
tdf#158658 sw: text formatting: make TabOverMargin even more crazy
... to better match Word's formatting.
The bugdoc has a special case where a right-aligned tab is positioned at
the right margin exactly, which causes the bFull condition in
SwTabPortion::PreFormat() to be true.
An obvious change to replace rInf.Width() - rInf.X() with
rInf.GetLineWidth() in the condition makes no difference because
m_pLastTab was already reset previously; instead, pass in the last tab
from Format(), which indicates that the right edge position of the
previous text portion was found via that tab.
Additionally, change the condition that checks for TabOverMargin to also
allow equal positions, i.e., exactly at the end of the paragraph.
Change-Id: I5d3b1c13eca0bffa640745d7c5f4113699f79cad
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168823
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
(cherry picked from commit 69d873e1c46f3cc8c524e18ac5a307a8d32ddd0f)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168864
Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
-rw-r--r-- | sw/qa/extras/layout/data/tdf158658c.rtf | 26 | ||||
-rw-r--r-- | sw/qa/extras/layout/layout3.cxx | 22 | ||||
-rw-r--r-- | sw/source/core/text/portab.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/text/txttab.cxx | 9 |
4 files changed, 54 insertions, 5 deletions
diff --git a/sw/qa/extras/layout/data/tdf158658c.rtf b/sw/qa/extras/layout/data/tdf158658c.rtf new file mode 100644 index 000000000000..4148eb6d9a51 --- /dev/null +++ b/sw/qa/extras/layout/data/tdf158658c.rtf @@ -0,0 +1,26 @@ +{\rtf1\adeflang1025\ansi\ansicpg1250\uc1\adeff31507\deff0\stshfdbch31506\stshfloch31506\stshfhich31506\stshfbi31507\deflang1038\deflangfe1038\themelang1038\themelangfe0\themelangcs0
+{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2 Times New Roman;}
+{\fhiminor\f31506\fbidi \fswiss\fcharset0\fprq2 Calibri;}
+{\fbiminor\f31507\fbidi \froman\fcharset0\fprq2 Times New Roman;}
+}
+{\*\defchp \f31506\fs22\lang1038\langfe1033\langfenp1033 }{\*\defpap \ql \li0\ri0\sa160\sl259\slmult1
+\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 }\noqfpromote
+{\stylesheet{\ql \li0\ri0\sa160\sl259\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025
+\ltrch\fcs0 \f31506\fs22\lang1038\langfe1033\cgrid\langnp1038\langfenp1033 \snext0 \sqformat \spriority0 Normal;}
+{\s15\ql \li0\ri0\widctlpar\tqc\tx4513\tqr\tx9026\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1038\langfe1033\cgrid\langnp1038\langfenp1033
+\sbasedon0 \snext15 \slink16 \sunhideused header;}}
+\paperw11906\paperh16838\margl1440\margr1440\margt1440\margb1440\gutter0\ltrsect
+\deftab708\widowctrl\ftnbj\aenddoc\hyphhotz425\trackmoves0\trackformatting1\donotembedsysfont1\relyonvml0\donotembedlingdata0\grfdocevents0\validatexml1\showplaceholdtext0\ignoremixedcontent0\saveinvalidxml0
+\showxmlerrors1\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\formshade\horzdoc\dgmargin\dghspace180\dgvspace180\dghorigin1440\dgvorigin1440\dghshow1\dgvshow1
+\jexpand\viewkind1\viewscale100\pgbrdrhead\pgbrdrfoot\splytwnine\ftnlytwnine\htmautsp\nolnhtadjtbl\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl\snaptogridincell\allowfieldendsel\wrppunct
+\asianbrkrule\newtblstyruls\nogrowautofit\usenormstyforlist\noindnmbrts\felnbrelev\nocxsptable\indrlsweleven\noafcnsttbl\afelev\utinl\hwelev\spltpgpar\notcvasp\notbrkcnstfrctbl\notvatxbx\krnprsnet\cachedcolbal \nouicompat \fet0
+\nofeaturethrottle1\ilfomacatclnup0
+\ltrpar \sectd \ltrsect\linex0\headery708\footery708\colsx708\endnhere\sectlinegrid360\sectdefaultcl\sftnbj {\headerr \ltrpar \pard\plain \ltrpar\s15\ql \li0\ri0\widctlpar
+\tqc\tx4513\tqr\tx9026\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1038\langfe1033\cgrid\langnp1038\langfenp1033 {\rtlch\fcs1 \af31507 \ltrch\fcs0 Hello
+\tab World\tab Here come some tabs:\tab \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab \tab
+\par }}
+\pard\plain \ltrpar\ql \li0\ri0\sa160\sl259\slmult1
+\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1038\langfe1033\cgrid\langnp1038\langfenp1033 {\rtlch\fcs1 \af31507 \ltrch\fcs0 Main body here}{
+\rtlch\fcs1 \af31507 \ltrch\fcs0
+\par }
+}
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx index 2fc4bf2cb10a..b96b66992cef 100644 --- a/sw/qa/extras/layout/layout3.cxx +++ b/sw/qa/extras/layout/layout3.cxx @@ -453,6 +453,28 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf158658b) 0); } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf158658c) +{ + createSwDoc("tdf158658c.rtf"); + xmlDocUniquePtr pXmlDoc = parseLayoutDump(); + + // Word 2013 puts all tabs into one line, the last 17 of them are off the page + assertXPath(pXmlDoc, "/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout"_ostr, 1); + assertXPath( + pXmlDoc, + "/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabCenter']"_ostr, + 1); + // the right tab is exactly at the margin of the paragraph + assertXPath( + pXmlDoc, + "/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabRight']"_ostr, + 1); + assertXPath( + pXmlDoc, + "/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/child::*[@type='PortionType::TabLeft']"_ostr, + 20); +} + CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf155177) { createSwDoc("tdf155177-1-min.odt"); diff --git a/sw/source/core/text/portab.hxx b/sw/source/core/text/portab.hxx index 9ffe7be50651..42c21204c7b7 100644 --- a/sw/source/core/text/portab.hxx +++ b/sw/source/core/text/portab.hxx @@ -27,7 +27,7 @@ class SwTabPortion : public SwFixPortion const bool m_bAutoTabStop; // Format() branches either into PreFormat() or PostFormat() - bool PreFormat( SwTextFormatInfo &rInf ); + bool PreFormat(SwTextFormatInfo &rInf, SwTabPortion const*); public: SwTabPortion( const sal_uInt16 nTabPos, const sal_Unicode cFill, const bool bAutoTab = true ); virtual void Paint( const SwTextPaintInfo &rInf ) const override; diff --git a/sw/source/core/text/txttab.cxx b/sw/source/core/text/txttab.cxx index 3f72f5375000..c34692e0024a 100644 --- a/sw/source/core/text/txttab.cxx +++ b/sw/source/core/text/txttab.cxx @@ -345,7 +345,7 @@ bool SwTabPortion::Format( SwTextFormatInfo &rInf ) return PostFormat( rInf ); if( pLastTab ) pLastTab->PostFormat( rInf ); - return PreFormat( rInf ); + return PreFormat(rInf, pLastTab); } void SwTabPortion::FormatEOL( SwTextFormatInfo &rInf ) @@ -354,7 +354,7 @@ void SwTabPortion::FormatEOL( SwTextFormatInfo &rInf ) PostFormat( rInf ); } -bool SwTabPortion::PreFormat( SwTextFormatInfo &rInf ) +bool SwTabPortion::PreFormat(SwTextFormatInfo &rInf, SwTabPortion const*const pLastTab) { OSL_ENSURE( rInf.X() <= GetTabPos(), "SwTabPortion::PreFormat: rush hour" ); @@ -396,7 +396,8 @@ bool SwTabPortion::PreFormat( SwTextFormatInfo &rInf ) // 1. Minimal width does not fit to line anymore. // 2. An underflow event was called for the tab portion. bool bFull = ( bTabCompat && rInf.IsUnderflow() ) || - ( rInf.Width() <= rInf.X() + PrtWidth() && rInf.X() <= rInf.Width() ) ; + (rInf.Width() <= rInf.X() + PrtWidth() && rInf.X() <= rInf.Width() + && (!bTabOverMargin || !pLastTab)); // #95477# Rotated tab stops get the width of one blank const Degree10 nDir = rInf.GetFont()->GetOrientation( rInf.GetTextFrame()->IsVertical() ); @@ -420,7 +421,7 @@ bool SwTabPortion::PreFormat( SwTextFormatInfo &rInf ) { // handle this case in PostFormat if ((bTabOverMargin || bTabOverSpacing) && GetTabPos() > rInf.Width() - && (!m_bAutoTabStop || rInf.X() > rInf.Width())) + && (!m_bAutoTabStop || rInf.Width() <= rInf.X())) { if (bTabOverMargin || GetTabPos() < nTextFrameWidth) { |