From 2940d1905b921d9909b08b1e32014d3c44474ef0 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Mon, 17 Feb 2020 20:20:31 +0300 Subject: tdf#80194 editeng: fix auto subscript calculations ...and auto superscript too (although not as noticably). THIS WILL CHANGE THE POSITION OF EDITENG SUBSCRIPTS AND SUPERSCRIPTS IN EXISTING DOCUMENTS! That is because they were very poorly placed before - using a formula that is very different from how Writer does it. Everyone in the bug reports indicates that Writer does it good, but Impress does it really bad. (tdf#89849, tdf#63083) FOR EXAMPLE, when the char-size is reduced to the default OF 58%, it will now be raised by 33%, not 42%. Likewise, the subscript will now be lowered by 8%, not 42%. THIS AFFECTS/FIXES Writer textboxes, Calc, Draw/Impress. "Automatic" indicates that there is not a "correct" answer, but that the computer should make it "look good", so the user should be able to accept this change in positioning, as long as it looks good. The number of documents affected might be less than one would expect. By default .uno:SuperScript does NOT set auto mode (although Format-Character does). Since most people would use the toolbar instead of the format menu to create a superscript, auto will be rare. So there will be relatively few cases where subscripts are automatic in editeng, especially since it looks so poor that most people probably turned automatic off... This patch has no effect on non-automatic escapement. It uses the same fomula that calculated DFLT_ESC_SUB (since it isn't an arbitrarily chosen value). This is an approximation of the formula that Writer uses (since Writer does exact calculations based on each font's metrics). This Writer-inspired formula was introduced in LO 6.4 for more accurate exporting to MSO word processing formats (tdf#127316). Change-Id: I0267810efe31a2b3be41bf2d39e2278ce9bc99e9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88911 Tested-by: Jenkins Reviewed-by: Ilmari Lauhakangas Reviewed-by: Justin Luth --- editeng/source/editeng/editattr.cxx | 4 +- editeng/source/editeng/editdoc.cxx | 4 +- editeng/source/editeng/impedit4.cxx | 4 +- sd/qa/unit/data/tdf80194_defaultSubscripts.fodg | 407 ++++++++++++++++++++++++ sd/qa/unit/export-tests.cxx | 17 + 5 files changed, 430 insertions(+), 6 deletions(-) create mode 100644 sd/qa/unit/data/tdf80194_defaultSubscripts.fodg diff --git a/editeng/source/editeng/editattr.cxx b/editeng/source/editeng/editattr.cxx index f000cf793560..a99e4d496f74 100644 --- a/editeng/source/editeng/editattr.cxx +++ b/editeng/source/editeng/editattr.cxx @@ -273,9 +273,9 @@ void EditCharAttribEscapement::SetFont( SvxFont& rFont, OutputDevice* ) short nEsc = static_cast(GetItem())->GetEsc(); if ( nEsc == DFLT_ESC_AUTO_SUPER ) - nEsc = 100 - nProp; + nEsc = .8 * (100 - nProp); else if ( nEsc == DFLT_ESC_AUTO_SUB ) - nEsc = sal::static_int_cast< short >( -( 100 - nProp ) ); + nEsc = .2 * -(100 - nProp); rFont.SetEscapement( nEsc ); } diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx index f3f55edf60c1..42fc1f3cc22c 100644 --- a/editeng/source/editeng/editdoc.cxx +++ b/editeng/source/editeng/editdoc.cxx @@ -2008,9 +2008,9 @@ void CreateFont( SvxFont& rFont, const SfxItemSet& rSet, bool bSearchInParent, S short nEsc = rEsc.GetEsc(); if ( nEsc == DFLT_ESC_AUTO_SUPER ) - nEsc = 100 - nProp; + nEsc = .8 * (100 - nProp); else if ( nEsc == DFLT_ESC_AUTO_SUB ) - nEsc = sal::static_int_cast< short >( -( 100 - nProp ) ); + nEsc = .2 * -(100 - nProp); rFont.SetEscapement( nEsc ); } if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_PAIRKERNING ) == SfxItemState::SET ) ) diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index 67e924653618..25d7ecc0aa8a 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -930,12 +930,12 @@ void ImpEditEngine::WriteItemAsRTF( const SfxPoolItem& rItem, SvStream& rOutput, short nEsc = static_cast(rItem).GetEsc(); if ( nEsc == DFLT_ESC_AUTO_SUPER ) { - nEsc = 100 - nProp; + nEsc = .8 * (100 - nProp); nProp100++; // A 1 afterwards means 'automatic'. } else if ( nEsc == DFLT_ESC_AUTO_SUB ) { - nEsc = sal::static_int_cast< short >( -( 100 - nProp ) ); + nEsc = .2 * -(100 - nProp); nProp100++; } // SWG: diff --git a/sd/qa/unit/data/tdf80194_defaultSubscripts.fodg b/sd/qa/unit/data/tdf80194_defaultSubscripts.fodg new file mode 100644 index 000000000000..d8028b6371c1 --- /dev/null +++ b/sd/qa/unit/data/tdf80194_defaultSubscripts.fodg @@ -0,0 +1,407 @@ + + + + 2020-02-17T15:21:21.9272561422020-02-17T16:18:41.297941901PT17M53S8LibreOfficeDev/7.0.0.0.alpha0$Linux_X86_64 LibreOffice_project/76fec020a99a41a06176307cb2c31f9494867dd0 + + + 19876 + 6602 + 3646 + 3659 + + + view1 + false + false + true + true + false + false + false + false + true + 1500 + false + Hw== + Hw== + + false + true + true + 0 + 0 + true + true + true + 4 + 0 + 20184 + 6885 + 3052 + 3063 + 1000 + 1000 + 100 + 100 + 1000 + 10 + 1000 + 10 + false + 1500 + false + false + + + + + true + $(brandbaseurl)/share/palette%3B$(userpath)/config/standard.sob + 0 + $(brandbaseurl)/share/palette%3B$(userpath)/config/standard.soc + $(brandbaseurl)/share/palette%3B$(userpath)/config/standard.sod + 1250 + true + true + false + true + false + + + en + GB + + + + + + $(brandbaseurl)/share/palette%3B$(userpath)/config/standard.sog + $(brandbaseurl)/share/palette%3B$(userpath)/config/standard.soh + false + false + true + true + false + false + true + false + false + false + $(brandbaseurl)/share/palette%3B$(userpath)/config/standard.soe + false + 3 + 4 + false + 0 + low-resolution + Boomaga + false + lwH+/0Jvb21hZ2EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQ1VQUzpCb29tYWdhAAAAAAAAAAAAAAAAAAAAAAAAAAAWAAMAuAAAAAAAAAAEAAhSAAAEdAAASm9iRGF0YSAxCnByaW50ZXI9Qm9vbWFnYQpvcmllbnRhdGlvbj1Qb3J0cmFpdApjb3BpZXM9MQpjb2xsYXRlPWZhbHNlCm1hcmdpbmRhanVzdG1lbnQ9MCwwLDAsMApjb2xvcmRlcHRoPTI0CnBzbGV2ZWw9MApwZGZkZXZpY2U9MQpjb2xvcmRldmljZT0wClBQRENvbnRleERhdGEKRHVwbGV4Ok5vbmUAUGFnZVNpemU6QTQAABIAQ09NUEFUX0RVUExFWF9NT0RFDwBEdXBsZXhNb2RlOjpPZmY= + true + false + 1 + 1 + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Subscript shouldn’t drop below decender: qp + + Superscript shouldn’t raise above ascender: dL + + + + + Text with aSubscript + Text with aSubscript + Text with aSubscript + Text with aSubscript + Text with aSubscript + Text with aSubscript + A normal line of text + A normal line of text + A normal line of text + A normal line of text + A normal line of text + A normal line of text + Text with aSubscript + Text with aSubscript + Text with aSubscript + Text with aSubscript + Text with aSubscript + Text with aSuperscript + Text with aSuperscript + Text with aSuperscript + The spacing between all of these rows should be identical. There should not be big gaps caused by default subscripts or superscripts. + + + + + + \ No newline at end of file diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx index 6446db8ddb89..fef365062ada 100644 --- a/sd/qa/unit/export-tests.cxx +++ b/sd/qa/unit/export-tests.cxx @@ -59,6 +59,7 @@ public: void testEmbeddedPdf(); void testEmbeddedText(); void testTransparenText(); + void testDefaultSubscripts(); void testTdf98477(); void testAuthorField(); void testTdf50499(); @@ -91,6 +92,7 @@ public: CPPUNIT_TEST(testEmbeddedPdf); CPPUNIT_TEST(testEmbeddedText); CPPUNIT_TEST(testTransparenText); + CPPUNIT_TEST(testDefaultSubscripts); CPPUNIT_TEST(testTdf98477); CPPUNIT_TEST(testAuthorField); CPPUNIT_TEST(testTdf50499); @@ -851,6 +853,21 @@ void SdExportTest::testTransparenText() xShell->DoClose(); } +void SdExportTest::testDefaultSubscripts() +{ + sd::DrawDocShellRef xShell + = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/tdf80194_defaultSubscripts.fodg"), FODG); + xShell = saveAndReload(xShell.get(), ODG); + + uno::Reference xPage = getPage(0, xShell); + uno::Reference xShape(xPage->getByIndex(1), uno::UNO_QUERY); + // Default subscripts were too large, enlarging the gap between the next line. + // The exact size isn't important. Was 18975, now 16604. + CPPUNIT_ASSERT(17000 > xShape->getSize().Height); + + xShell->DoClose(); +} + void SdExportTest::testTdf98477() { utl::TempFile tempFile; -- cgit