[Libreoffice-commits] core.git: sw/qa sw/source
Justin Luth (via logerrit)
logerrit at kemper.freedesktop.org
Thu Oct 31 07:53:16 UTC 2019
sw/qa/extras/ww8export/ww8export3.cxx | 8 ++++++--
sw/source/filter/ww8/rtfattributeoutput.cxx | 8 +++-----
sw/source/filter/ww8/ww8atr.cxx | 9 ++++-----
3 files changed, 13 insertions(+), 12 deletions(-)
New commits:
commit aaa242a33b01e87c41f19fca871cafa857fe71dd
Author: Justin Luth <justin.luth at collabora.com>
AuthorDate: Fri Oct 4 14:41:19 2019 +0300
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Oct 31 08:52:38 2019 +0100
related tdf#99602 ww8/rtfoutput: fix incorrect rounding on subscripts
Adding .5 is a poor mans version of rounding which works fine with
unsigned numbers, but not with negative numbers. Perhaps use the
exotic round() function instead?
In addition, the font size isn't necessarily an integer,
so that should have been a float.
The result of bad rounding was losing a percentage of the subscript
every round-trip.
Change-Id: I9093f7bfcd0b87249b42562668e45480dcb59f53
Reviewed-on: https://gerrit.libreoffice.org/80218
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth at sil.org>
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx
index cb4caa351b98..7a4dc17d4ede 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -176,8 +176,12 @@ DECLARE_WW8EXPORT_TEST(testTdf120225_textControlCrossRef, "tdf120225_textControl
DECLARE_WW8EXPORT_TEST(testTdf127316_autoEscapement, "tdf127316_autoEscapement.odt")
{
uno::Reference<text::XTextRange> xPara = getParagraph(2);
- CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.f, getProperty<float>(getRun(xPara, 1), "CharEscapement"), 0);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(-33.f, getProperty<float>(getRun(xPara, 2), "CharEscapement"), 3);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.f, getProperty<float>(getRun(xPara, 1, "Normal text "), "CharEscapement"), 0);
+ // Automatic escapement SHOULD BE limited by the font bottom line(?)
+ // and so the calculations ought to be different. There is room for a lot of export improvement here.
+ // Negative escapements (subscripts) were decreasing by 1% every round-trip due to bad manual rounding.
+ // The actual number of 33% isn't so important here, but test that it is stable across multiple round-trips.
+ CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Did you fix or break me?", -33.f, getProperty<float>(getRun(xPara, 2), "CharEscapement"), 1);
}
DECLARE_WW8EXPORT_TEST(testTdf121111_fillStyleNone, "tdf121111_fillStyleNone.docx")
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 078f9dc94dd6..70ba0dd85115 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -2306,14 +2306,14 @@ void RtfAttributeOutput::CharEscapement(const SvxEscapementItem& rEscapement)
const char* pUpDn;
- SwTwips nH = m_rExport.GetItem(RES_CHRATR_FONTSIZE).GetHeight();
+ double fHeight = m_rExport.GetItem(RES_CHRATR_FONTSIZE).GetHeight();
if (0 < rEscapement.GetEsc())
pUpDn = OOO_STRING_SVTOOLS_RTF_UP;
else if (0 > rEscapement.GetEsc())
{
pUpDn = OOO_STRING_SVTOOLS_RTF_DN;
- nH = -nH;
+ fHeight = -fHeight;
}
else
return;
@@ -2344,9 +2344,7 @@ void RtfAttributeOutput::CharEscapement(const SvxEscapementItem& rEscapement)
* ----------------------- = ------------
* 100% Escapement
*/
-
- m_aStyles.append(static_cast<sal_Int32>((long(nEsc) * nH) + 500) / 1000);
- // 500 to round !!
+ m_aStyles.append(static_cast<sal_Int32>(round(fHeight * nEsc / 1000)));
}
void RtfAttributeOutput::CharFont(const SvxFontItem& rFont)
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 040153b65bdd..17780b0e0efb 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -1396,6 +1396,7 @@ void WW8AttributeOutput::CharEscapement( const SvxEscapementItem& rEscapement )
else if ( DFLT_ESC_SUPER == nEsc || DFLT_ESC_AUTO_SUPER == nEsc )
b = 1;
}
+ // FIXME: these need a better formula. See rtfAttributeOutput
else if ( DFLT_ESC_AUTO_SUPER == nEsc )
nEsc = DFLT_ESC_SUPER;
else if ( DFLT_ESC_AUTO_SUB == nEsc )
@@ -1410,17 +1411,15 @@ void WW8AttributeOutput::CharEscapement( const SvxEscapementItem& rEscapement )
if ( 0 == b || 0xFF == b )
{
- long nHeight = m_rWW8Export.GetItem( RES_CHRATR_FONTSIZE ).GetHeight();
+ double fHeight = m_rWW8Export.GetItem( RES_CHRATR_FONTSIZE ).GetHeight();
m_rWW8Export.InsUInt16( NS_sprm::sprmCHpsPos );
- m_rWW8Export.InsUInt16( static_cast<short>(( nHeight * nEsc + 500 ) / 1000 ));
+ m_rWW8Export.InsUInt16(static_cast<short>( round(fHeight * nEsc / 1000) ));
if( 100 != nProp || !b )
{
m_rWW8Export.InsUInt16( NS_sprm::sprmCHps );
-
- m_rWW8Export.InsUInt16(
- msword_cast<sal_uInt16>((nHeight * nProp + 500 ) / 1000));
+ m_rWW8Export.InsUInt16(msword_cast<sal_uInt16>( round(fHeight * nProp / 1000) ));
}
}
}
More information about the Libreoffice-commits
mailing list