From b437ff98b0c61bf7ecdbe57d759917d1eb92a94f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 20 Jun 2012 17:54:46 +0000 Subject: [PATCH] Fix text extent computation in wxMSW wxGraphicsContext. The results were incorrect for italic or bold fonts as we hardcoded FontStyleRegular instead of using the real font style. Closes #14421. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71821 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/msw/graphics.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 27c00e708c..f3b5245289 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -592,6 +592,7 @@ MSW: - Fix code compilation with wxUSE_UNICODE_UTF8 (Kolya Kosenko). - Fix crash in wxTreeCtrl when calling GetSelection() from selection changed event handler under Vista and later (sbrowne). +- Fix text extent computation in wxGraphicsContext (juria90). OSX: diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index 54f0c33e67..112e2d43f9 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -1770,12 +1770,15 @@ void wxGDIPlusContext::GetTextExtent( const wxString &str, wxDouble *width, wxDo REAL factorY = m_fontScaleRatio; - REAL rDescent = ffamily.GetCellDescent(FontStyleRegular) * - f->GetSize() / ffamily.GetEmHeight(FontStyleRegular); - REAL rAscent = ffamily.GetCellAscent(FontStyleRegular) * - f->GetSize() / ffamily.GetEmHeight(FontStyleRegular); - REAL rHeight = ffamily.GetLineSpacing(FontStyleRegular) * - f->GetSize() / ffamily.GetEmHeight(FontStyleRegular); + // Notice that we must use the real font style or the results would be + // incorrect for italic/bold fonts. + const INT style = f->GetStyle(); + REAL rDescent = ffamily.GetCellDescent(style) * + f->GetSize() / ffamily.GetEmHeight(style); + REAL rAscent = ffamily.GetCellAscent(style) * + f->GetSize() / ffamily.GetEmHeight(style); + REAL rHeight = ffamily.GetLineSpacing(style) * + f->GetSize() / ffamily.GetEmHeight(style); if ( height ) *height = rHeight * factorY; -- 2.45.2