Skip to content

Commit

Permalink
Port #45, #83 to current master branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
clangen committed Dec 30, 2022
1 parent 2481460 commit 012e3d9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
41 changes: 39 additions & 2 deletions wingui/pdcdisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,50 @@ void PDC_gotoyx(int row, int col)
}
}

int PDC_font_size = 12;
TCHAR PDC_font_name[80];
#ifndef USER_DEFAULT_SCREEN_DPI /* defined in newer versions of WinUser.h */
#define USER_DEFAULT_SCREEN_DPI 96
#endif

/* if the calling application marks itself as "DPI aware", we want to make sure
that we scale the user's font appropriately. the GetDpiForSystem call is only
available on Windows 10 and newer, so we load the DLL dynamically and find the
function address at runtime. if the method isn't available, that means we're on
and older operating system, so we just return the original value */
static LONG scale_font_for_current_dpi( LONG size)
{
typedef LONG(__stdcall *GetDpiForSystemProc)();
HMODULE user32Dll = LoadLibrary( _T("User32.dll"));

if ( user32Dll)
{
/* https://msdn.microsoft.com/en-us/library/windows/desktop/mt748623(v=vs.85).aspx */

GetDpiForSystemProc getDpiForSystem =
(GetDpiForSystemProc) GetProcAddress( user32Dll, "GetDpiForSystem");

if ( getDpiForSystem)
{
size = MulDiv( size, getDpiForSystem(), USER_DEFAULT_SCREEN_DPI);
}

FreeLibrary( user32Dll);
}

return size;
}

int PDC_font_size = -1;
TCHAR PDC_font_name[128];

static LOGFONT PDC_get_logical_font( const int font_idx)
{
LOGFONT lf;

if ( PDC_font_size < 0)
{
PDC_font_size = scale_font_for_current_dpi( 12); /* default 12 points */
}

memset(&lf, 0, sizeof(LOGFONT)); /* Clear out structure. */
lf.lfHeight = -PDC_font_size;
#ifdef PDC_WIDE
Expand Down
12 changes: 12 additions & 0 deletions wingui/pdcscrn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2216,11 +2216,23 @@ INLINE int set_up_window( void)
int PDC_scr_open(void)
{
const HMODULE hntdll = GetModuleHandle( _T("ntdll.dll"));
const HMODULE shcoredll = GetModuleHandle(_T("Shcore.dll"));

PDC_LOG(("PDC_scr_open() - called\n"));

if( hntdll)
wine_version = (wine_version_func)GetProcAddress(hntdll, "wine_get_version");

if ( shcoredll) {
typedef HRESULT *(CDECL *set_process_dpi_awareness_t)(int);
static set_process_dpi_awareness_t set_process_dpi_awareness_func;
static int ADJUST_DPI_PER_MONITOR = 2;
set_process_dpi_awareness_func = (set_process_dpi_awareness_t)GetProcAddress(shcoredll, "SetProcessDpiAwareness");
if ( set_process_dpi_awareness_func) {
set_process_dpi_awareness_func(ADJUST_DPI_PER_MONITOR);
}
}

COLORS = N_COLORS; /* should give this a try and see if it works! */
if (!SP || PDC_init_palette( ))
return ERR;
Expand Down

0 comments on commit 012e3d9

Please sign in to comment.