mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-11 21:03:05 +08:00
+ fix: DPI Awareness & Fractional Font Size
This commit is contained in:
parent
8bcc67f692
commit
df01605acf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -31,7 +31,13 @@
|
||||
</compatibility>
|
||||
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
|
||||
<dpiAware>true</dpiAware>
|
||||
<dpiAware>true/PM</dpiAware>
|
||||
</asmv3:windowsSettings>
|
||||
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
|
||||
<dpiAwareness>PerMonitorV2,PerMonitor</dpiAwareness>
|
||||
</asmv3:windowsSettings>
|
||||
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">
|
||||
<gdiScaling>false</gdiScaling>
|
||||
</asmv3:windowsSettings>
|
||||
</asmv3:application>
|
||||
</assembly>
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<assemblyIdentity
|
||||
name="Notepad3"
|
||||
processorArchitecture="*"
|
||||
version="4.18.607.1004"
|
||||
version="4.18.802.1034"
|
||||
type="win32"
|
||||
/>
|
||||
<description>Notepad3 X_MUI</description>
|
||||
|
||||
@ -2239,6 +2239,7 @@ INT_PTR CALLBACK SelectDefEncodingDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPAR
|
||||
if (g_hDlgIcon) { SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)g_hDlgIcon); }
|
||||
|
||||
hbmp = LoadImage(g_hInstance,MAKEINTRESOURCE(IDB_ENCODING),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
|
||||
hbmp = ResizeImageForCurrentDPI(hbmp);
|
||||
|
||||
himl = ImageList_Create(16,16,ILC_COLOR32|ILC_MASK,0,0);
|
||||
ImageList_AddMasked(himl,hbmp,CLR_DEFAULT);
|
||||
@ -2364,6 +2365,8 @@ INT_PTR CALLBACK SelectEncodingDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM
|
||||
hwndLV = GetDlgItem(hwnd,IDC_ENCODINGLIST);
|
||||
|
||||
hbmp = LoadImage(g_hInstance,MAKEINTRESOURCE(IDB_ENCODING),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
|
||||
hbmp = ResizeImageForCurrentDPI(hbmp);
|
||||
|
||||
himl = ImageList_Create(16,16,ILC_COLOR32|ILC_MASK,0,0);
|
||||
ImageList_AddMasked(himl,hbmp,CLR_DEFAULT);
|
||||
DeleteObject(hbmp);
|
||||
|
||||
@ -43,6 +43,7 @@
|
||||
extern HINSTANCE g_hInstance;
|
||||
extern HMODULE g_hLngResContainer;
|
||||
extern LANGID g_iPrefLngLocID;
|
||||
extern UINT g_uCurrentDPI;
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
@ -300,6 +301,70 @@ DWORD GetLastErrorToMsgBox(LPWSTR lpszFunction, DWORD dwErrID)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// GetCurrentDPI()
|
||||
//
|
||||
UINT GetCurrentDPI(HWND hwnd) {
|
||||
UINT dpi = 0;
|
||||
if (IsWin10()) {
|
||||
FARPROC pfnGetDpiForWindow = GetProcAddress(GetModuleHandle(L"user32.dll"), "GetDpiForWindow");
|
||||
if (pfnGetDpiForWindow) {
|
||||
dpi = (UINT)pfnGetDpiForWindow(hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
if (dpi == 0 && IsWin81()) {
|
||||
HMODULE hShcore = LoadLibrary(L"shcore.dll");
|
||||
if (hShcore) {
|
||||
FARPROC pfnGetDpiForMonitor = GetProcAddress(hShcore, "GetDpiForMonitor");
|
||||
if (pfnGetDpiForMonitor) {
|
||||
HMONITOR hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
|
||||
UINT dpiX = 0, dpiY = 0;
|
||||
if (pfnGetDpiForMonitor(hMonitor, 0 /* MDT_EFFECTIVE_DPI */, &dpiX, &dpiY) == S_OK) {
|
||||
dpi = dpiX;
|
||||
}
|
||||
}
|
||||
FreeLibrary(hShcore);
|
||||
}
|
||||
}
|
||||
|
||||
if (dpi == 0) {
|
||||
// FIXME: seems always get 96
|
||||
HDC hDC = GetDC(hwnd);
|
||||
dpi = GetDeviceCaps(hDC, LOGPIXELSX);
|
||||
ReleaseDC(hwnd, hDC);
|
||||
}
|
||||
|
||||
dpi = max(dpi, USER_DEFAULT_SCREEN_DPI);
|
||||
return dpi;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// ResizeImageForCurrentDPI()
|
||||
//
|
||||
HBITMAP ResizeImageForCurrentDPI(HBITMAP hbmp)
|
||||
{
|
||||
if (hbmp) {
|
||||
BITMAP bmp;
|
||||
if (g_uCurrentDPI > USER_DEFAULT_SCREEN_DPI && GetObject(hbmp, sizeof(BITMAP), &bmp)) {
|
||||
int width = MulDiv(bmp.bmWidth, g_uCurrentDPI, USER_DEFAULT_SCREEN_DPI);
|
||||
int height = MulDiv(bmp.bmHeight, g_uCurrentDPI, USER_DEFAULT_SCREEN_DPI);
|
||||
HBITMAP hCopy = CopyImage(hbmp, IMAGE_BITMAP, width, height, LR_COPYRETURNORG | LR_COPYDELETEORG);
|
||||
if (hCopy) {
|
||||
hbmp = hCopy;
|
||||
}
|
||||
}
|
||||
}
|
||||
return hbmp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// PrivateIsAppThemed()
|
||||
@ -952,6 +1017,7 @@ void MakeBitmapButton(HWND hwnd,int nCtlId,HINSTANCE hInstance,UINT uBmpId)
|
||||
BITMAP bmp;
|
||||
BUTTON_IMAGELIST bi;
|
||||
HBITMAP hBmp = LoadImage(hInstance,MAKEINTRESOURCE(uBmpId),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
|
||||
hBmp = ResizeImageForCurrentDPI(hBmp);
|
||||
GetObject(hBmp,sizeof(BITMAP),&bmp);
|
||||
bi.himl = ImageList_Create(bmp.bmWidth,bmp.bmHeight,ILC_COLOR32|ILC_MASK,1,0);
|
||||
ImageList_AddMasked(bi.himl,hBmp,CLR_DEFAULT);
|
||||
@ -962,6 +1028,7 @@ void MakeBitmapButton(HWND hwnd,int nCtlId,HINSTANCE hInstance,UINT uBmpId)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// MakeColorPickButton()
|
||||
@ -1033,11 +1100,14 @@ void DeleteBitmapButton(HWND hwnd,int nCtlId)
|
||||
//
|
||||
// SendWMSize()
|
||||
//
|
||||
LRESULT SendWMSize(HWND hwnd)
|
||||
LRESULT SendWMSize(HWND hwnd, RECT* rc)
|
||||
{
|
||||
RECT rc;
|
||||
GetClientRect(hwnd, &rc);
|
||||
return (SendMessage(hwnd, WM_SIZE, SIZE_RESTORED, MAKELPARAM(rc.right, rc.bottom)));
|
||||
if (!rc) {
|
||||
RECT _rc;
|
||||
GetClientRect(hwnd, &_rc);
|
||||
return (SendMessage(hwnd, WM_SIZE, SIZE_RESTORED, MAKELPARAM(_rc.right, _rc.bottom)));
|
||||
}
|
||||
return (SendMessage(hwnd, WM_SIZE, SIZE_RESTORED, MAKELPARAM(rc->right, rc->bottom)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -28,7 +28,6 @@
|
||||
|
||||
extern WCHAR g_wchIniFile[MAX_PATH];
|
||||
|
||||
|
||||
// ============================================================================
|
||||
|
||||
#define STRGFY(X) L##(X)
|
||||
@ -132,6 +131,9 @@ DWORD GetLastErrorToMsgBox(LPWSTR lpszFunction, DWORD dwErrID);
|
||||
|
||||
bool SetClipboardTextW(HWND, LPCWSTR);
|
||||
|
||||
UINT GetCurrentDPI(HWND hwnd);
|
||||
HBITMAP ResizeImageForCurrentDPI(HBITMAP hbmp);
|
||||
|
||||
bool PrivateIsAppThemed();
|
||||
HRESULT PrivateSetCurrentProcessExplicitAppUserModelID(PCWSTR);
|
||||
bool IsElevated();
|
||||
@ -174,7 +176,7 @@ LONG StatusCalcPaneWidth(HWND,LPCWSTR);
|
||||
int Toolbar_GetButtons(HWND,int,LPWSTR,int);
|
||||
int Toolbar_SetButtons(HWND,int,LPCWSTR,void*,int);
|
||||
|
||||
LRESULT SendWMSize(HWND);
|
||||
LRESULT SendWMSize(HWND, RECT*);
|
||||
|
||||
bool IsCmdEnabled(HWND, UINT);
|
||||
|
||||
|
||||
@ -67,6 +67,7 @@ HWND g_hwndReBar = NULL;
|
||||
HWND hwndEditFrame = NULL;
|
||||
HWND hwndNextCBChain = NULL;
|
||||
HICON g_hDlgIcon = NULL;
|
||||
UINT g_uCurrentDPI = USER_DEFAULT_SCREEN_DPI;
|
||||
|
||||
bool g_bExternalBitmap = false;
|
||||
|
||||
@ -1414,6 +1415,10 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
|
||||
MsgThemeChanged(hwnd,wParam,lParam);
|
||||
break;
|
||||
|
||||
case WM_DPICHANGED:
|
||||
MsgDPIChanged(hwnd, wParam, lParam);
|
||||
break;
|
||||
|
||||
// update Scintilla colors
|
||||
case WM_SYSCOLORCHANGE:
|
||||
UpdateLineNumberWidth();
|
||||
@ -1710,6 +1715,8 @@ LRESULT MsgCreate(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
||||
|
||||
HINSTANCE hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
|
||||
|
||||
g_uCurrentDPI = GetCurrentDPI(hwnd);
|
||||
|
||||
// Setup edit control
|
||||
g_hwndEdit = CreateWindowEx(
|
||||
WS_EX_CLIENTEDGE,
|
||||
@ -1870,6 +1877,7 @@ void CreateBars(HWND hwnd,HINSTANCE hInstance)
|
||||
if (!SearchPath(NULL,g_tchToolbarBitmap,L".bmp",COUNTOF(szTmp),szTmp,NULL))
|
||||
StringCchCopy(szTmp,COUNTOF(szTmp),g_tchToolbarBitmap);
|
||||
hbmp = LoadImage(NULL,szTmp,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
|
||||
hbmp = ResizeImageForCurrentDPI(hbmp);
|
||||
}
|
||||
|
||||
if (hbmp) {
|
||||
@ -1878,8 +1886,10 @@ void CreateBars(HWND hwnd,HINSTANCE hInstance)
|
||||
else {
|
||||
LPWSTR toolBarIntRes = (iHighDpiToolBar > 0) ? MAKEINTRESOURCE(IDR_MAINWNDTB2) : MAKEINTRESOURCE(IDR_MAINWNDTB);
|
||||
hbmp = LoadImage(hInstance, toolBarIntRes, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
|
||||
hbmp = ResizeImageForCurrentDPI(hbmp);
|
||||
hbmpCopy = CopyImage(hbmp, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
|
||||
}
|
||||
|
||||
GetObject(hbmp,sizeof(BITMAP),&bmp);
|
||||
if (!IsXP())
|
||||
BitmapMergeAlpha(hbmp,GetSysColor(COLOR_3DFACE));
|
||||
@ -1896,6 +1906,7 @@ void CreateBars(HWND hwnd,HINSTANCE hInstance)
|
||||
StringCchCopy(szTmp,COUNTOF(szTmp),g_tchToolbarBitmapHot);
|
||||
|
||||
hbmp = LoadImage(NULL, szTmp, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);
|
||||
hbmp = ResizeImageForCurrentDPI(hbmp);
|
||||
if (hbmp)
|
||||
{
|
||||
GetObject(hbmp,sizeof(BITMAP),&bmp);
|
||||
@ -1914,6 +1925,7 @@ void CreateBars(HWND hwnd,HINSTANCE hInstance)
|
||||
StringCchCopy(szTmp,COUNTOF(szTmp),g_tchToolbarBitmapDisabled);
|
||||
|
||||
hbmp = LoadImage(NULL, szTmp, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);
|
||||
hbmp = ResizeImageForCurrentDPI(hbmp);
|
||||
if (hbmp)
|
||||
{
|
||||
GetObject(hbmp,sizeof(BITMAP),&bmp);
|
||||
@ -2092,6 +2104,46 @@ void MsgEndSession(HWND hwnd, UINT umsg)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// MsgDPIChanged() - Handle WM_DPICHANGED
|
||||
//
|
||||
//
|
||||
void MsgDPIChanged(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
g_uCurrentDPI = HIWORD(wParam);
|
||||
DocPos const pos = SciCall_GetCurrentPos();
|
||||
|
||||
HINSTANCE hInstance = (HINSTANCE)(INT_PTR)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
|
||||
|
||||
#if 0
|
||||
char buf[64];
|
||||
sprintf_s(buf, COUNTOF(buf), "WM_DPICHANGED: dpi=%u\n", g_uCurrentDPI);
|
||||
SendMessage(g_hwndEdit, SCI_INSERTTEXT, 0, (LPARAM)buf);
|
||||
#endif
|
||||
|
||||
Style_ResetCurrentLexer(g_hwndEdit);
|
||||
SciCall_GotoPos(pos);
|
||||
|
||||
// recreate toolbar and statusbar
|
||||
Toolbar_GetButtons(g_hwndToolbar, IDT_FILE_NEW, g_tchToolbarButtons, COUNTOF(g_tchToolbarButtons));
|
||||
|
||||
DestroyWindow(g_hwndToolbar);
|
||||
DestroyWindow(g_hwndReBar);
|
||||
DestroyWindow(g_hwndStatus);
|
||||
CreateBars(hwnd, hInstance);
|
||||
|
||||
RECT* const rc = (RECT*)lParam;
|
||||
SendWMSize(hwnd, rc);
|
||||
|
||||
UpdateUI();
|
||||
UpdateToolbar();
|
||||
UpdateStatusbar(true);
|
||||
UpdateLineNumberWidth();
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// MsgThemeChanged() - Handle WM_THEMECHANGED
|
||||
@ -2147,7 +2199,7 @@ void MsgThemeChanged(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
||||
DestroyWindow(g_hwndStatus);
|
||||
CreateBars(hwnd,hInstance);
|
||||
|
||||
SendWMSize(hwnd);
|
||||
SendWMSize(hwnd, NULL);
|
||||
|
||||
EditFinalizeStyling(g_hwndEdit, -1);
|
||||
|
||||
@ -4816,7 +4868,7 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
UpdateToolbar();
|
||||
ShowWindow(g_hwndReBar,SW_SHOW);
|
||||
}
|
||||
SendWMSize(hwnd);
|
||||
SendWMSize(hwnd, NULL);
|
||||
break;
|
||||
|
||||
|
||||
@ -4840,7 +4892,7 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
UpdateStatusbar(false);
|
||||
ShowWindow(g_hwndStatus,SW_SHOW);
|
||||
}
|
||||
SendWMSize(hwnd);
|
||||
SendWMSize(hwnd, NULL);
|
||||
break;
|
||||
|
||||
|
||||
@ -8225,9 +8277,16 @@ void UpdateLineNumberWidth()
|
||||
else {
|
||||
SciCall_SetMarginWidthN(MARGIN_SCI_LINENUM, 0);
|
||||
}
|
||||
|
||||
int const widthBM = g_bShowSelectionMargin ? MulDiv(16, g_uCurrentDPI, USER_DEFAULT_SCREEN_DPI) : 0;
|
||||
SciCall_SetMarginWidthN(MARGIN_SCI_BOOKMRK, widthBM);
|
||||
|
||||
int const widthCF = (g_bCodeFoldingAvailable && g_bShowCodeFolding) ? MulDiv(13, g_uCurrentDPI, USER_DEFAULT_SCREEN_DPI) : 0;
|
||||
SciCall_SetMarginWidthN(MARGIN_SCI_FOLDING, widthCF);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// UpdateSettingsCmds()
|
||||
|
||||
@ -172,6 +172,7 @@ LRESULT MsgCreate(HWND, WPARAM, LPARAM);
|
||||
void MsgEndSession(HWND, UINT);
|
||||
void CreateBars(HWND, HINSTANCE);
|
||||
void MsgThemeChanged(HWND, WPARAM, LPARAM);
|
||||
void MsgDPIChanged(HWND, WPARAM, LPARAM);
|
||||
void MsgSize(HWND, WPARAM, LPARAM);
|
||||
void MsgDropFiles(HWND, WPARAM, LPARAM);
|
||||
LRESULT MsgCopyData(HWND, WPARAM, LPARAM);
|
||||
|
||||
18
src/Styles.c
18
src/Styles.c
@ -50,6 +50,7 @@ extern HICON g_hDlgIcon;
|
||||
extern HWND g_hwndMain;
|
||||
extern HWND g_hwndDlgCustomizeSchemes;
|
||||
extern EDITFINDREPLACE g_efrData;
|
||||
extern UINT g_uCurrentDPI;
|
||||
|
||||
extern int g_iSciFontQuality;
|
||||
extern const int FontQuality[4];
|
||||
@ -5566,6 +5567,14 @@ bool Style_SelectColor(HWND hwnd,bool bForeGround,LPWSTR lpszStyle,int cchStyle,
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
|
||||
inline static int _GetDPIAwareFractFontSize(float fFontSize)
|
||||
{
|
||||
return MulDiv((int)(fFontSize + 0.5), (SC_FONT_SIZE_MULTIPLIER * g_uCurrentDPI), USER_DEFAULT_SCREEN_DPI);
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Style_SetStyles()
|
||||
@ -5631,13 +5640,10 @@ void Style_SetStyles(HWND hwnd, int iStyle, LPCWSTR lpszStyle, bool bInitDefault
|
||||
}
|
||||
|
||||
// Size values are relative to BaseFontSize/CurrentFontSize
|
||||
POINT dpi = GetSystemDpi();
|
||||
float fBaseFontSize = _GetCurrentFontSize();
|
||||
fBaseFontSize = (float)max(0.0, fBaseFontSize);
|
||||
if (Style_StrGetSize(lpszStyle, &fBaseFontSize)) {
|
||||
fBaseFontSize = (float)max(0.0, fBaseFontSize);
|
||||
fBaseFontSize = (float)MulDiv((int)fBaseFontSize, (dpi.x + dpi.y)/2, USER_DEFAULT_SCREEN_DPI);
|
||||
//SendMessage(hwnd, SCI_STYLESETSIZE, iStyle, (int)fBaseFontSize);
|
||||
SendMessage(hwnd, SCI_STYLESETSIZEFRACTIONAL, iStyle, (LPARAM)((int)(fBaseFontSize * SC_FONT_SIZE_MULTIPLIER + 0.5)));
|
||||
SendMessage(hwnd, SCI_STYLESETSIZEFRACTIONAL, iStyle, (LPARAM)_GetDPIAwareFractFontSize(fBaseFontSize));
|
||||
if (iStyle == STYLE_DEFAULT) {
|
||||
if (bInitDefault) {
|
||||
_SetBaseFontSize(fBaseFontSize);
|
||||
@ -5647,7 +5653,7 @@ void Style_SetStyles(HWND hwnd, int iStyle, LPCWSTR lpszStyle, bool bInitDefault
|
||||
}
|
||||
else if (bInitDefault) {
|
||||
//SendMessage(hwnd, SCI_STYLESETSIZE, STYLE_DEFAULT, (LPARAM)((int)fBaseFontSize));
|
||||
SendMessage(hwnd, SCI_STYLESETSIZEFRACTIONAL, STYLE_DEFAULT, (LPARAM)((int)(fBaseFontSize * SC_FONT_SIZE_MULTIPLIER + 0.5)));
|
||||
SendMessage(hwnd, SCI_STYLESETSIZEFRACTIONAL, STYLE_DEFAULT, (LPARAM)_GetDPIAwareFractFontSize(fBaseFontSize));
|
||||
}
|
||||
|
||||
// Character Set
|
||||
|
||||
Loading…
Reference in New Issue
Block a user