summaryrefslogtreecommitdiff
path: root/sw/source/filter/ww8/rtfattributeoutput.cxx
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-26 10:11:36 +0100
commit0f149f685b9dc8fd7e53a677ce9557148be9be2a (patch)
treeffe91a3d9b73c76e538505c50075d5a182362c61 /sw/source/filter/ww8/rtfattributeoutput.cxx
parente4de3a1823f93090e12a192ebe60f786af2fa901 (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> (cherry picked from commit d6e2d624a124454fa4ac80cb30a924571a609101) Reviewed-on: https://gerrit.libreoffice.org/83665
Diffstat (limited to 'sw/source/filter/ww8/rtfattributeoutput.cxx')
-rw-r--r--sw/source/filter/ww8/rtfattributeoutput.cxx30
1 files changed, 13 insertions, 17 deletions
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 6a04e707a706..a16424b01e2e 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -2324,8 +2324,8 @@ void RtfAttributeOutput::CharCrossedOut(const SvxCrossedOutItem& rCrossedOut)
void RtfAttributeOutput::CharEscapement(const SvxEscapementItem& rEscapement)
{
- short nEsc = rEscapement.GetEsc();
- if (rEscapement.GetProportionalHeight() == DFLT_ESC_PROP)
+ short nEsc = rEscapement.GetEsc(), nProp = rEscapement.GetProportionalHeight();
+ if (DFLT_ESC_PROP == nProp || nProp < 1 || nProp > 100)
{
if (DFLT_ESC_SUB == nEsc || DFLT_ESC_AUTO_SUB == nEsc)
m_aStyles.append(OOO_STRING_SVTOOLS_RTF_SUB);
@@ -2333,14 +2333,22 @@ void RtfAttributeOutput::CharEscapement(const SvxEscapementItem& rEscapement)
m_aStyles.append(OOO_STRING_SVTOOLS_RTF_SUPER);
return;
}
+ else if (DFLT_ESC_AUTO_SUPER == nEsc)
+ {
+ nEsc = .8 * (100 - nProp);
+ }
+ else if (DFLT_ESC_AUTO_SUB == nEsc)
+ {
+ nEsc = .2 * -(100 - nProp);
+ }
const char* pUpDn;
double fHeight = m_rExport.GetItem(RES_CHRATR_FONTSIZE).GetHeight();
- if (0 < rEscapement.GetEsc())
+ if (0 < nEsc)
pUpDn = OOO_STRING_SVTOOLS_RTF_UP;
- else if (0 > rEscapement.GetEsc())
+ else if (0 > nEsc)
{
pUpDn = OOO_STRING_SVTOOLS_RTF_DN;
fHeight = -fHeight;
@@ -2348,22 +2356,10 @@ void RtfAttributeOutput::CharEscapement(const SvxEscapementItem& rEscapement)
else
return;
- short nProp = rEscapement.GetProportionalHeight() * 100;
- if (DFLT_ESC_AUTO_SUPER == nEsc)
- {
- nEsc = 100 - rEscapement.GetProportionalHeight();
- ++nProp;
- }
- else if (DFLT_ESC_AUTO_SUB == nEsc)
- {
- nEsc = -100 + rEscapement.GetProportionalHeight();
- ++nProp;
- }
-
m_aStyles.append('{');
m_aStyles.append(OOO_STRING_SVTOOLS_RTF_IGNORE);
m_aStyles.append(OOO_STRING_SVTOOLS_RTF_UPDNPROP);
- m_aStyles.append(static_cast<sal_Int32>(nProp));
+ m_aStyles.append(static_cast<sal_Int32>(nProp * 100));
m_aStyles.append('}');
m_aStyles.append(pUpDn);