summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2019-10-05 21:23:04 +0300
committerMiklos Vajna <vmiklos@collabora.com>2019-11-25 09:08:35 +0100
commitd6e2d624a124454fa4ac80cb30a924571a609101 (patch)
tree0ec6ea3b1596965b1d3c405f1f3b7bda66766129 /sw/qa
parent51ccc0c4952d6c261a51e6a41821971013a28e8d (diff)
tdf#127316 ooxml/ww8export: DFLT_ESC_*_AUTO - use better formulas
See tdf#99602 and tdf#120412 for many fixes related to escapement. The poor formulas for AUTO style came to light in 6.3.0.1 with 6.4 commit 32262b0a537207832d7d126d8427d8949b9e821d Looking at sw/source/core/txtnode/swfont.cxx, we can see in CalcEsc() that for superscript the DFLT_ESC_SUPER_AUTO is calculated as the difference between the two ascents. Because the superscript is smaller, it has a smaller ascent, so to reach the same ascent line as the original, we can raise its baseline by fontAscent(fA) - superscriptAscent(ssA). Since the ascent is approximately 80% of the total fontheight(fH), we can calculate the Esc number (percentage * 100) as: EscHeight = fA - ssA (formula in CalcEsc) ssA = nProp/100 * fA (superscript ascent/height reduced by nProp) .8 = fA/fHeight (improvement would be to query font.GetAscent) Esc% = EscHeight / fHeight Esc% = (fA - nProp/100*fA) / fHeight Esc% = (1 - nProp/100)*fA/fHeight Esc = (100 - nProp) * 0.8 DFLT_ESC_SUB_AUTO subscript is similar with the descent(fD) being the remainding 20% of the fontHeight. EscHeight = fD - ssD (formula in CalcEsc) ssD = nProp/100 * fD (by definition of the function of nProp) .2 = fD/fHeight (an approximation - each font will be different) Esc% = (fD - nProp/100*fD) / fHeight Esc% = (1 - nProp/100)*fD/fHeight Esc = (100 - nProp) * 0.2 (in the negative direction) For RTF, I can see no reason for the ++nProp except to try and avoid nProp == 0. It is only .01% after all... Change-Id: Ia7b9f8784572193dd05cb80afa56c90540c3e676 Reviewed-on: https://gerrit.libreoffice.org/80306 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_luth@sil.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport13.cxx13
-rw-r--r--sw/qa/extras/ww8export/data/tdf127316_autoEscapement2.odtbin0 -> 14195 bytes
-rw-r--r--sw/qa/extras/ww8export/ww8export3.cxx21
3 files changed, 25 insertions, 9 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index 7294824b62ff..64c1fc6cc10a 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -224,21 +224,24 @@ DECLARE_OOXMLEXPORT_TEST(testBtlrShape, "btlr-textbox.docx")
DECLARE_OOXMLEXPORT_TEST(testTdf127316_autoEscapement, "tdf127316_autoEscapement.odt")
{
- // This should be roughly 33% of the ORIGINAL(non-reduced) size. However, during export the
+ // This should be roughly .8*35% of the ORIGINAL(non-reduced) size. However, during export the
// proportional height has to be changed into direct formatting, which then changes the relative percent.
// In this case, a 24pt font, proportional at 65% becomes roughly a 16pt font.
- // Thus an escapement of 33% (8pt) becomes roughly 50% for the 16pt font.
+ // Thus an escapement of 28% (6.72pt) becomes roughly 42% for the 16pt font.
uno::Reference<text::XTextRange> xPara = getParagraph(1);
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"), 20);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(42.f, getProperty<float>(getRun(xPara, 2), "CharEscapement"), 1);
// Subscripts are different. 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.
xPara.set(getParagraph(2));
CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.f, getProperty<float>(getRun(xPara, 1, "Normal text "), "CharEscapement"), 0);
// Negative escapements (subscripts) were decreasing by 1% every round-trip due to bad manual rounding.
- // The actual number of 52% 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?", -52.f, getProperty<float>(getRun(xPara, 2), "CharEscapement"), 2);
+ // This should be roughly .2*35% of the ORIGINAL (non-reduced) size. However, during export the
+ // proportional height has to be changed into direct formatting, which then changes the relative percent.
+ // In this case, a 24pt font, proportional at 65% becomes roughly a 16pt font.
+ // Thus an escapement of 7% (1.68pt) becomes roughly 10.5% for the 16pt font.
+ CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Subscript", -10.f, getProperty<float>(getRun(xPara, 2), "CharEscapement"), 1);
}
DECLARE_OOXMLEXPORT_TEST(testTdf99602_subscript_charStyleSize, "tdf99602_subscript_charStyleSize.docx")
diff --git a/sw/qa/extras/ww8export/data/tdf127316_autoEscapement2.odt b/sw/qa/extras/ww8export/data/tdf127316_autoEscapement2.odt
new file mode 100644
index 000000000000..d98fae0ad4d6
--- /dev/null
+++ b/sw/qa/extras/ww8export/data/tdf127316_autoEscapement2.odt
Binary files differ
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx
index 014274e98bbf..d4a65e685f4a 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -177,11 +177,24 @@ DECLARE_WW8EXPORT_TEST(testTdf127316_autoEscapement, "tdf127316_autoEscapement.o
{
uno::Reference<text::XTextRange> xPara = getParagraph(2);
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 50% 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?", -50.f, getProperty<float>(getRun(xPara, 2), "CharEscapement"), 1);
+ // This should be roughly .2*35% of the ORIGINAL (non-reduced) size. However, during export the
+ // proportional height has to be changed into direct formatting, which then changes the relative percent.
+ // In this case, a 24pt font, proportional at 65% becomes roughly a 16pt font.
+ // Thus an escapement of 7% (1.68pt) becomes roughly 10.5% for the 16pt font.
+ CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Subscript", -10.f, getProperty<float>(getRun(xPara, 2), "CharEscapement"), 1);
+}
+
+DECLARE_WW8EXPORT_TEST(testTdf127316_autoEscapement2, "tdf127316_autoEscapement2.odt")
+{
+ uno::Reference<text::XTextRange> xPara = getParagraph(1);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.f, getProperty<float>(getRun(xPara, 1, "Base1"), "CharEscapement"), 0);
+ // Font is 80% of 40pt or 32pt, original escapement is 6.4pt, so round-trip escapement is 20%.
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(20.f, getProperty<float>(getRun(xPara, 2,"AutoSuperscript"), "CharEscapement"), 1);
+ xPara.set( getParagraph(3) );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.f, getProperty<float>(getRun(xPara, 1, "Base3"), "CharEscapement"), 0);
+ // font is 20% of 40pt or 8pt, original escapement is 25.6pt, so round-trip escapement is 320%.
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(320.f, getProperty<float>(getRun(xPara, 2,"AutoSuperscript"), "CharEscapement"), 3);
}
DECLARE_WW8EXPORT_TEST(testTdf120412_proportionalEscapement, "tdf120412_proportionalEscapement.odt")