[PATCH] Use GetOutlineTextMetrics instead of GetTextMetrics

Khaled Hosny khaledhosny at eglug.org
Fri Sep 2 01:24:16 PDT 2011


Follow up of commit 3364fef

GetOutlineTextMetrics returns an OUTLINETEXTMETRIC struct containing
typographic ascent/descent among other font metrics.

The CKJ external leading hack have been removed as well.
---
 vcl/win/source/gdi/salgdi3.cxx |   51 +++++++++++-----------------------------
 1 files changed, 14 insertions(+), 37 deletions(-)

diff --git a/vcl/win/source/gdi/salgdi3.cxx b/vcl/win/source/gdi/salgdi3.cxx
index fdb9296..ad8dbe0 100644
--- a/vcl/win/source/gdi/salgdi3.cxx
+++ b/vcl/win/source/gdi/salgdi3.cxx
@@ -1764,24 +1764,24 @@ void WinSalGraphics::GetFontMetric( ImplFontMetricData* pMetric, int nFallbackLe
         pMetric->maName = reinterpret_cast<const sal_Unicode*>(aFaceName);
 
     // get the font metric
-    TEXTMETRICA aWinMetric;
-    const bool bOK = GetTextMetricsA( mhDC, &aWinMetric );
+    OUTLINETEXTMETRICA aWinMetric;
+    const bool bOK = GetOutlineTextMetricsA( mhDC, &aWinMetric );
     // restore the HDC to the font in the base level
     SelectFont( mhDC, hOldFont );
     if( !bOK )
         return;
 
     // device independent font attributes
-    pMetric->meFamily       = ImplFamilyToSal( aWinMetric.tmPitchAndFamily );;
-    pMetric->mbSymbolFlag   = (aWinMetric.tmCharSet == SYMBOL_CHARSET);
-    pMetric->meWeight       = ImplWeightToSal( aWinMetric.tmWeight );
-    pMetric->mePitch        = ImplMetricPitchToSal( aWinMetric.tmPitchAndFamily );
-    pMetric->meItalic       = aWinMetric.tmItalic ? ITALIC_NORMAL : ITALIC_NONE;
+    pMetric->meFamily       = ImplFamilyToSal( aWinMetric.otmTextMetrics.tmPitchAndFamily );;
+    pMetric->mbSymbolFlag   = (aWinMetric.otmTextMetrics.tmCharSet == SYMBOL_CHARSET);
+    pMetric->meWeight       = ImplWeightToSal( aWinMetric.otmTextMetrics.tmWeight );
+    pMetric->mePitch        = ImplMetricPitchToSal( aWinMetric.otmTextMetrics.tmPitchAndFamily );
+    pMetric->meItalic       = aWinMetric.otmTextMetrics.tmItalic ? ITALIC_NORMAL : ITALIC_NONE;
     pMetric->mnSlant        = 0;
 
     // device dependend font attributes
-    pMetric->mbDevice       = (aWinMetric.tmPitchAndFamily & TMPF_DEVICE) != 0;
-    pMetric->mbScalableFont = (aWinMetric.tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE)) != 0;
+    pMetric->mbDevice       = (aWinMetric.otmTextMetrics.tmPitchAndFamily & TMPF_DEVICE) != 0;
+    pMetric->mbScalableFont = (aWinMetric.otmTextMetrics.tmPitchAndFamily & (TMPF_VECTOR|TMPF_TRUETYPE)) != 0;
     if( pMetric->mbScalableFont )
     {
         // check if there are kern pairs
@@ -1798,34 +1798,11 @@ void WinSalGraphics::GetFontMetric( ImplFontMetricData* pMetric, int nFallbackLe
     }
 
     // transformation dependend font metrics
-    pMetric->mnWidth        = static_cast<int>( mfFontScale[nFallbackLevel] * aWinMetric.tmAveCharWidth );
-    pMetric->mnIntLeading   = static_cast<int>( mfFontScale[nFallbackLevel] * aWinMetric.tmInternalLeading );
-    pMetric->mnExtLeading   = static_cast<int>( mfFontScale[nFallbackLevel] * aWinMetric.tmExternalLeading );
-    pMetric->mnAscent       = static_cast<int>( mfFontScale[nFallbackLevel] * aWinMetric.tmAscent );
-    pMetric->mnDescent      = static_cast<int>( mfFontScale[nFallbackLevel] * aWinMetric.tmDescent );
-
-    // #107888# improved metric compatibility for Asian fonts...
-    // TODO: assess workaround below for CWS >= extleading
-    // TODO: evaluate use of aWinMetric.sTypo* members for CJK
-    if( mpWinFontData[nFallbackLevel] && mpWinFontData[nFallbackLevel]->SupportsCJK() )
-    {
-        pMetric->mnIntLeading += pMetric->mnExtLeading;
-
-        // #109280# The line height for Asian fonts is too small.
-        // Therefore we add half of the external leading to the
-        // ascent, the other half is added to the descent.
-        const long nHalfTmpExtLeading = pMetric->mnExtLeading / 2;
-        const long nOtherHalfTmpExtLeading = pMetric->mnExtLeading - nHalfTmpExtLeading;
-
-        // #110641# external leading for Asian fonts.
-        // The factor 0.3 has been confirmed with experiments.
-        long nCJKExtLeading = static_cast<long>(0.30 * (pMetric->mnAscent + pMetric->mnDescent));
-        nCJKExtLeading -= pMetric->mnExtLeading;
-        pMetric->mnExtLeading = (nCJKExtLeading > 0) ? nCJKExtLeading : 0;
-
-        pMetric->mnAscent   += nHalfTmpExtLeading;
-        pMetric->mnDescent  += nOtherHalfTmpExtLeading;
-    }
+    pMetric->mnWidth      =  static_cast<int>( mfFontScale[nFallbackLevel] * aWinMetric.otmTextMetrics.tmAveCharWidth );
+    pMetric->mnExtLeading =  static_cast<int>( mfFontScale[nFallbackLevel] * aWinMetric.otmLineGap );
+    pMetric->mnAscent     =  mfFontScale[nFallbackLevel] * aWinMetric.otmAscent;
+    pMetric->mnDescent    = -mfFontScale[nFallbackLevel] * aWinMetric.otmDescent;
+    pMetric->mnIntLeading =  pMetric->mnAscent + pMetric->mnDescent - ( mfFontScale[nFallbackLevel] * aWinMetric.otmEMSquare );
 
     pMetric->mnMinKashida = GetMinKashidaWidth();
 }
-- 
1.7.0.4


--YiEDa0DAkWCtVeE4--


More information about the LibreOffice mailing list