summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2020-03-14 14:45:39 +0300
committerMiklos Vajna <vmiklos@collabora.com>2020-04-03 10:04:56 +0200
commit0f29d36aa9e6ac7d0914a6e1749c16ecec216904 (patch)
tree1d4fe8dde667d5caffad571a88a5322aacb91b81 /editeng
parent730c5317a968f4e99d4d2d28499b1d6204a07285 (diff)
tdf#80194 autoEsc: use fontmetrics in calculation
This replaces the previous 7.0 patch in commit 2940d1905b921d9909b08b1e32014d3c44474ef0 where the following is still true: 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). Instead of using the previous patch's 80%/20% generalization, copy Writer's use of the actual ascent and descent of the font to determine the best position for the subscript or superscript. Change-Id: I0f10f6174b0709f3bc3b9acdc54b7b1fd59c5ee2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90489 Reviewed-by: Justin Luth <justin_luth@sil.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Justin Luth <justin_luth@sil.org>
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/editeng/editattr.cxx8
-rw-r--r--editeng/source/editeng/editdoc.cxx6
-rw-r--r--editeng/source/editeng/impedit4.cxx14
-rw-r--r--editeng/source/items/svxfont.cxx31
4 files changed, 46 insertions, 13 deletions
diff --git a/editeng/source/editeng/editattr.cxx b/editeng/source/editeng/editattr.cxx
index a99e4d496f74..e48445c27c30 100644
--- a/editeng/source/editeng/editattr.cxx
+++ b/editeng/source/editeng/editattr.cxx
@@ -266,17 +266,13 @@ EditCharAttribEscapement::EditCharAttribEscapement( const SvxEscapementItem& rAt
assert(rAttr.Which() == EE_CHAR_ESCAPEMENT);
}
-void EditCharAttribEscapement::SetFont( SvxFont& rFont, OutputDevice* )
+void EditCharAttribEscapement::SetFont( SvxFont& rFont, OutputDevice* pOutDev )
{
sal_uInt16 const nProp = static_cast<const SvxEscapementItem*>(GetItem())->GetProportionalHeight();
rFont.SetPropr( static_cast<sal_uInt8>(nProp) );
short nEsc = static_cast<const SvxEscapementItem*>(GetItem())->GetEsc();
- if ( nEsc == DFLT_ESC_AUTO_SUPER )
- nEsc = .8 * (100 - nProp);
- else if ( nEsc == DFLT_ESC_AUTO_SUB )
- nEsc = .2 * -(100 - nProp);
- rFont.SetEscapement( nEsc );
+ rFont.SetNonAutoEscapement( nEsc, pOutDev );
}
diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx
index 42fc1f3cc22c..9e9eb17e6177 100644
--- a/editeng/source/editeng/editdoc.cxx
+++ b/editeng/source/editeng/editdoc.cxx
@@ -2007,11 +2007,7 @@ void CreateFont( SvxFont& rFont, const SfxItemSet& rSet, bool bSearchInParent, S
rFont.SetPropr( static_cast<sal_uInt8>(nProp) );
short nEsc = rEsc.GetEsc();
- if ( nEsc == DFLT_ESC_AUTO_SUPER )
- nEsc = .8 * (100 - nProp);
- else if ( nEsc == DFLT_ESC_AUTO_SUB )
- nEsc = .2 * -(100 - nProp);
- rFont.SetEscapement( nEsc );
+ rFont.SetNonAutoEscapement( nEsc );
}
if ( bSearchInParent || ( rSet.GetItemState( EE_CHAR_PAIRKERNING ) == SfxItemState::SET ) )
rFont.SetKerning( rSet.Get( EE_CHAR_PAIRKERNING ).GetValue() ? FontKerning::FontSpecific : FontKerning::NONE );
diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx
index 25d7ecc0aa8a..050eed8667f4 100644
--- a/editeng/source/editeng/impedit4.cxx
+++ b/editeng/source/editeng/impedit4.cxx
@@ -69,6 +69,7 @@
#include <unotools/textsearch.hxx>
#include <comphelper/processfactory.hxx>
#include <vcl/help.hxx>
+#include <vcl/metric.hxx>
#include <svtools/rtfkeywd.hxx>
#include <editeng/edtdlg.hxx>
@@ -928,14 +929,23 @@ void ImpEditEngine::WriteItemAsRTF( const SfxPoolItem& rItem, SvStream& rOutput,
sal_uInt16 const nProp = static_cast<const SvxEscapementItem&>(rItem).GetProportionalHeight();
sal_uInt16 nProp100 = nProp*100; // For SWG-Token Prop in 100th percent.
short nEsc = static_cast<const SvxEscapementItem&>(rItem).GetEsc();
+ const FontMetric& rFontMetric = GetRefDevice()->GetFontMetric();
+ double fFontHeight = rFontMetric.GetAscent() + rFontMetric.GetDescent();
+ double fAutoAscent = .8;
+ double fAutoDescent = .2;
+ if ( fFontHeight )
+ {
+ fAutoAscent = rFontMetric.GetAscent() / fFontHeight;
+ fAutoDescent = rFontMetric.GetDescent() / fFontHeight;
+ }
if ( nEsc == DFLT_ESC_AUTO_SUPER )
{
- nEsc = .8 * (100 - nProp);
+ nEsc = fAutoAscent * (100 - nProp);
nProp100++; // A 1 afterwards means 'automatic'.
}
else if ( nEsc == DFLT_ESC_AUTO_SUB )
{
- nEsc = .2 * -(100 - nProp);
+ nEsc = fAutoDescent * -(100 - nProp);
nProp100++;
}
// SWG:
diff --git a/editeng/source/items/svxfont.cxx b/editeng/source/items/svxfont.cxx
index a8792df4c729..f6ff6cf92681 100644
--- a/editeng/source/items/svxfont.cxx
+++ b/editeng/source/items/svxfont.cxx
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <vcl/metric.hxx>
#include <vcl/outdev.hxx>
#include <vcl/print.hxx>
#include <tools/debug.hxx>
@@ -55,6 +56,36 @@ SvxFont::SvxFont( const SvxFont &rFont )
SetLanguage(rFont.GetLanguage());
}
+void SvxFont::SetNonAutoEscapement(short nNewEsc, const OutputDevice* pOutDev)
+{
+ nEsc = nNewEsc;
+ if ( abs(nEsc) == DFLT_ESC_AUTO_SUPER )
+ {
+ double fAutoAscent = .8;
+ double fAutoDescent = .2;
+ if ( pOutDev )
+ {
+ const FontMetric& rFontMetric = pOutDev->GetFontMetric();
+ double fFontHeight = rFontMetric.GetAscent() + rFontMetric.GetDescent();
+ if ( fFontHeight )
+ {
+ fAutoAscent = rFontMetric.GetAscent() / fFontHeight;
+ fAutoDescent = rFontMetric.GetDescent() / fFontHeight;
+ }
+ }
+
+ if ( nEsc == DFLT_ESC_AUTO_SUPER )
+ nEsc = fAutoAscent * (100 - nPropr);
+ else //DFLT_ESC_AUTO_SUB
+ nEsc = fAutoDescent * -(100 - nPropr);
+ }
+
+ if ( nEsc > MAX_ESC_POS )
+ nEsc = MAX_ESC_POS;
+ else if ( nEsc < -MAX_ESC_POS )
+ nEsc = -MAX_ESC_POS;
+}
+
void SvxFont::DrawArrow( OutputDevice &rOut, const tools::Rectangle& rRect,
const Size& rSize, const Color& rCol, bool bLeft )
{