diff options
author | Mark Hung <marklh9@gmail.com> | 2015-10-21 22:34:08 +0800 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-11-10 11:48:53 +0000 |
commit | f5ed3a29e995152b80bf1adc888094d735a0882c (patch) | |
tree | 741fe067abd30c6b95305432408f182d9111c124 /vcl | |
parent | 610e6fddbc19dd2ac23b6a6cf4d8cbfb0dcf589a (diff) |
tdf#81144 Chinese full-width punctuation does not align properly
Ideographic fullstop and comma in most Chinese fonts are centered,
while those in Japanese fonts align closer to the left. Original
compression algorithm trimed right side of the punctuation, making
fullwidth fullstop or comma in Chinese font visually unbalanced.
In worst case, it crowds together with the followed compressed
punctuation.
This patch fix the situation in the folowing way
1) make compression less stronger.
2) Trim space according to glyph bearing to font height ratio.
3) fix a memory access violation issue
Reviewed-on: https://gerrit.libreoffice.org/19517
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Norbert Thiebaud <nthiebaud@gmail.com>
Conflicts:
sw/source/core/txtnode/fntcache.cxx
Change-Id: Icff215064e6c442fd36eac8e01b01fb6acb27594
Reviewed-on: https://gerrit.libreoffice.org/19764
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/impfont.hxx | 3 | ||||
-rw-r--r-- | vcl/inc/outfont.hxx | 1 | ||||
-rw-r--r-- | vcl/source/gdi/metric.cxx | 5 | ||||
-rw-r--r-- | vcl/source/outdev/font.cxx | 19 |
4 files changed, 27 insertions, 1 deletions
diff --git a/vcl/inc/impfont.hxx b/vcl/inc/impfont.hxx index 3a02b1d9483a..afa1a3b479ff 100644 --- a/vcl/inc/impfont.hxx +++ b/vcl/inc/impfont.hxx @@ -103,7 +103,7 @@ private: sal_uInt16 mnMiscFlags; // Misc Flags sal_uInt32 mnRefCount; // Reference Counter - enum { DEVICE_FLAG=1, SCALABLE_FLAG=2, LATIN_FLAG=4, CJK_FLAG=8, CTL_FLAG=16 }; + enum { DEVICE_FLAG=1, SCALABLE_FLAG=2, LATIN_FLAG=4, CJK_FLAG=8, CTL_FLAG=16, FULLSTOP_CENTERED_FLAG=32 }; public: ImplFontMetric(); @@ -116,6 +116,7 @@ public: long GetExtLeading() const { return mnExtLeading; } long GetLineHeight() const { return mnLineHeight; } long GetSlant() const { return mnSlant; } + bool IsFullstopCentered() const { return ((mnMiscFlags & FULLSTOP_CENTERED_FLAG ) != 0); } bool IsDeviceFont() const { return ((mnMiscFlags & DEVICE_FLAG) != 0); } bool IsScalable() const { return ((mnMiscFlags & SCALABLE_FLAG) != 0); } diff --git a/vcl/inc/outfont.hxx b/vcl/inc/outfont.hxx index 78e1a8f65c63..107f10cb3b7d 100644 --- a/vcl/inc/outfont.hxx +++ b/vcl/inc/outfont.hxx @@ -187,6 +187,7 @@ public: // TODO: hide members behind accessor methods bool mbDevice; // Flag for Device Fonts bool mbScalableFont; bool mbKernableFont; + bool mbFullstopCentered; // font metrics that are usually derived from the measurements long mnUnderlineSize; // Lineheight of Underline diff --git a/vcl/source/gdi/metric.cxx b/vcl/source/gdi/metric.cxx index 5ed467ef912e..05630c63f895 100644 --- a/vcl/source/gdi/metric.cxx +++ b/vcl/source/gdi/metric.cxx @@ -151,6 +151,11 @@ long FontMetric::GetSlant() const return mpImplMetric->GetSlant(); } +bool FontMetric::IsFullstopCentered() const +{ + return mpImplMetric->IsFullstopCentered(); +} + FontMetric& FontMetric::operator =( const FontMetric& rMetric ) { vcl::FontInfo::operator=( rMetric ); diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx index 1e4632939f63..bce865190815 100644 --- a/vcl/source/outdev/font.cxx +++ b/vcl/source/outdev/font.cxx @@ -215,6 +215,8 @@ FontMetric OutputDevice::GetFontMetric() const aMetric.mpImplMetric->mnMiscFlags |= ImplFontMetric::DEVICE_FLAG; if( pMetric->mbScalableFont ) aMetric.mpImplMetric->mnMiscFlags |= ImplFontMetric::SCALABLE_FLAG; + if ( pMetric->mbFullstopCentered) + aMetric.mpImplMetric->mnMiscFlags |= ImplFontMetric::FULLSTOP_CENTERED_FLAG; aMetric.mpImplMetric->mnAscent = ImplDevicePixelToLogicHeight( pMetric->mnAscent+mnEmphasisAscent ); aMetric.mpImplMetric->mnDescent = ImplDevicePixelToLogicHeight( pMetric->mnDescent+mnEmphasisDescent ); aMetric.mpImplMetric->mnIntLeading = ImplDevicePixelToLogicHeight( pMetric->mnIntLeading+mnEmphasisAscent ); @@ -1731,6 +1733,7 @@ ImplFontMetricData::ImplFontMetricData( const FontSelectPattern& rFontSelData ) , mnMinKashida( 0 ) , meFamilyType(FAMILY_DONTKNOW) , mbScalableFont(false) + , mbFullstopCentered(false) , mnUnderlineSize( 0 ) , mnUnderlineOffset( 0 ) , mnBUnderlineSize( 0 ) @@ -1775,6 +1778,7 @@ ImplFontMetricData::ImplFontMetricData( const FontSelectPattern& rFontSelData ) } } + void ImplFontMetricData::ImplInitTextLineSize( const OutputDevice* pDev ) { long nDescent = mnDescent; @@ -1857,6 +1861,21 @@ void ImplFontMetricData::ImplInitTextLineSize( const OutputDevice* pDev ) mnDStrikeoutSize = n2LineHeight; mnDStrikeoutOffset1 = nStrikeoutOffset - n2LineDY2 - n2LineHeight; mnDStrikeoutOffset2 = mnDStrikeoutOffset1 + n2LineDY + n2LineHeight; + + const vcl::Font& rFont ( pDev->GetFont() ); + bool bCentered = true; + if (MsLangId::isCJK(rFont.GetLanguage())) + { + const OUString sFullstop( sal_Unicode( 0x3001 ) ); // Fullwidth fullstop + Rectangle aRect; + pDev->GetTextBoundRect( aRect, sFullstop ); + const sal_uInt16 nH = rFont.GetSize().Height(); + const sal_uInt16 nB = aRect.Left(); + // Use 18.75% as a threshold to define a centered fullwidth fullstop. + // In general, nB/nH < 5% for most Japanese fonts. + bCentered = (nB > (((nH >> 1)+nH)>>3)) ? true : false; + } + mbFullstopCentered = bCentered ; } void ImplFontMetricData::ImplInitAboveTextLineSize() |