Merge branch 'msw-font-dpi'

Various wxFont-related fixes and refactorings in preparation for adding
per-monitor DPI support.

Closes https://github.com/wxWidgets/wxWidgets/pull/1408
This commit is contained in:
Vadim Zeitlin
2019-07-12 18:53:24 +02:00
12 changed files with 83 additions and 78 deletions

View File

@@ -40,6 +40,7 @@
#include "wx/wxcrtvararg.h"
#endif
#include "wx/fontutil.h"
#include "wx/scopedptr.h"
#include "wx/stack.h"
#include "wx/sysopt.h"
@@ -2829,14 +2830,13 @@ bool wxTextCtrl::MSWSetCharFormat(const wxTextAttr& style, long start, long end)
CFM_ITALIC | CFM_BOLD | CFM_UNDERLINE | CFM_STRIKEOUT;
// fill in data from LOGFONT but recalculate lfHeight because we need
// the real height in twips and not the negative number which
// wxFillLogFont() returns (this is correct in general and works with
// the real height in twips and not the negative number used inside
// LOGFONT returns (this is correct in general and works with
// the Windows font mapper, but not here)
wxFont font(style.GetFont());
LOGFONT lf;
wxFillLogFont(&lf, &font);
LOGFONT lf = font.GetNativeFontInfo()->lf;
cf.yHeight = 20*font.GetPointSize(); // 1 pt = 20 twips
cf.bCharSet = lf.lfCharSet;
cf.bPitchAndFamily = lf.lfPitchAndFamily;
@@ -3126,8 +3126,9 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
LOGFONT lf;
// Convert the height from the units of 1/20th of the point in which
// CHARFORMAT stores it to pixel-based units used by LOGFONT.
const wxCoord ppi = wxClientDC(this).GetPPI().y;
lf.lfHeight = -MulDiv(cf.yHeight/20, ppi, 72);
// Note that RichEdit seems to always use standard DPI of 96, even when the
// window is a monitor using a higher DPI.
lf.lfHeight = wxNativeFontInfo::GetLogFontHeightAtPPI(cf.yHeight/20.0f, 96);
lf.lfWidth = 0;
lf.lfCharSet = ANSI_CHARSET; // FIXME: how to get correct charset?
lf.lfClipPrecision = 0;
@@ -3160,7 +3161,7 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
else
lf.lfWeight = FW_NORMAL;
wxFont font = wxCreateFontFromLogFont(& lf);
wxFont font(lf);
if (font.IsOk())
{
style.SetFont(font);