notepad4
notepad4 copied to clipboard
Font "Fixedsys" Not Properly Shown
As the title says, when I choose "Fixedsys" to show, it exactly shows another font.
It works in Legacy GDI mode (Settings -> Rendering Technology), but not in Direct2D mode.
It fails on following code, where hr
is DWRITE_E_NOFONT
(_HRESULT_TYPEDEF_(0x88985002L)
):
https://github.com/zufuliu/notepad2/blob/0688888a3b5fa1c14d08f45ff542761f3895b9ee/scintilla/win32/PlatWin.cxx#L314-L316
It works in Legacy GDI mode (Settings -> Rendering Technology), but not in Direct2D mode.
It fails on following code, where
hr
isDWRITE_E_NOFONT
(_HRESULT_TYPEDEF_(0x88985002L)
):https://github.com/zufuliu/notepad2/blob/0688888a3b5fa1c14d08f45ff542761f3895b9ee/scintilla/win32/PlatWin.cxx#L314-L316
Thanks for your suggestion, but it doesn't work for me. I use Windows 11, and I downloaded exe pack directly without source code.
Hope that a new version of Notepad2 without this bug will be released soon.
It works in Legacy GDI mode (Settings -> Rendering Technology), but not in Direct2D mode.
Oh, the menu is actually under Settings -> Advanced Settings -> Rendering Technology. On my Win10 using GDI with Fixedsys, text appears same as using Windows Notepad with Fixedsys.
There maybe a limitation in Direct2D, using following C++ code, CreateFontFromLOGFONT
failed with DWRITE_E_NOFONT 0x88985002 "Indicates the specified font does not exist"
for Courier, Fixedsys, Modern, MS Sans Serif, MS Serif, Roman, System, Terminal, etc.
#include <cstdio>
#include <windows.h>
#include <commdlg.h>
#include <dwrite.h>
#ifdef _MSC_VER
#pragma comment(lib, "comdlg32.lib")
#pragma comment(lib, "dwrite.lib")
#endif
void ShowError(LPCWSTR prefix, DWORD error) {
LPWSTR lpMsgBuf;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, error,
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPWSTR)(&lpMsgBuf), 0, nullptr);
wprintf(L"%s error: 0x%08X %s\n", prefix, error, lpMsgBuf);
LocalFree(lpMsgBuf);
}
int wmain() {
LOGFONTW lf {};
// Courier, Fixedsys, Modern, MS Sans Serif, MS Serif, Roman, System, Terminal
lstrcpyW(lf.lfFaceName, L"Fixedsys");
CHOOSEFONTW cf{};
cf.lStructSize = sizeof(CHOOSEFONT);
cf.lpLogFont = &lf;
cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_NOVERTFONTS | CF_SCREENFONTS | CF_EFFECTS;
if (!ChooseFontW(&cf)) {
return 0;
}
wprintf(L"ChooseFontW lfFaceName=%s\n", lf.lfFaceName);
IDWriteFactory *factory = nullptr;
HRESULT hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory), reinterpret_cast<IUnknown**>(&factory));
if (SUCCEEDED(hr)) {
IDWriteGdiInterop *gdiInterop = nullptr;
hr = factory->GetGdiInterop(&gdiInterop);
if (SUCCEEDED(hr)) {
IDWriteFont *font = nullptr;
hr = gdiInterop->CreateFontFromLOGFONT(&lf, &font);
if (SUCCEEDED(hr)) {
wprintf(L"CreateFontFromLOGFONT OK\n");
font->Release();
} else {
ShowError(L"CreateFontFromLOGFONT", hr);
}
gdiInterop->Release();
} else {
ShowError(L"GetGdiInterop", hr);
}
factory->Release();
} else {
ShowError(L"DWriteCreateFactory", hr);
}
return 0;
}
There are also other fonts that behave abnormally in D2D mode, for example Sarasa fonts seems to be some incompatibility between Scintilla and these fonts
It works in Legacy GDI mode (Settings -> Rendering Technology), but not in Direct2D mode.
Oh, the menu is actually under Settings -> Advanced Settings -> Rendering Technology. On my Win10 using GDI with Fixedsys, text appears same as using Windows Notepad with Fixedsys.
There maybe a limitation in Direct2D, using following C++ code,
CreateFontFromLOGFONT
failed withDWRITE_E_NOFONT 0x88985002 "Indicates the specified font does not exist"
for Courier, Fixedsys, Modern, MS Sans Serif, MS Serif, Roman, System, Terminal, etc.#include <cstdio> #include <windows.h> #include <commdlg.h> #include <dwrite.h> #ifdef _MSC_VER #pragma comment(lib, "comdlg32.lib") #pragma comment(lib, "dwrite.lib") #endif void ShowError(LPCWSTR prefix, DWORD error) { LPWSTR lpMsgBuf; FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, error, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPWSTR)(&lpMsgBuf), 0, nullptr); wprintf(L"%s error: 0x%08X %s\n", prefix, error, lpMsgBuf); LocalFree(lpMsgBuf); } int wmain() { LOGFONTW lf {}; // Courier, Fixedsys, Modern, MS Sans Serif, MS Serif, Roman, System, Terminal lstrcpyW(lf.lfFaceName, L"Fixedsys"); CHOOSEFONTW cf{}; cf.lStructSize = sizeof(CHOOSEFONT); cf.lpLogFont = &lf; cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_NOVERTFONTS | CF_SCREENFONTS | CF_EFFECTS; if (!ChooseFontW(&cf)) { return 0; } wprintf(L"ChooseFontW lfFaceName=%s\n", lf.lfFaceName); IDWriteFactory *factory = nullptr; HRESULT hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast<IUnknown**>(&factory)); if (SUCCEEDED(hr)) { IDWriteGdiInterop *gdiInterop = nullptr; hr = factory->GetGdiInterop(&gdiInterop); if (SUCCEEDED(hr)) { IDWriteFont *font = nullptr; hr = gdiInterop->CreateFontFromLOGFONT(&lf, &font); if (SUCCEEDED(hr)) { wprintf(L"CreateFontFromLOGFONT OK\n"); font->Release(); } else { ShowError(L"CreateFontFromLOGFONT", hr); } gdiInterop->Release(); } else { ShowError(L"GetGdiInterop", hr); } factory->Release(); } else { ShowError(L"DWriteCreateFactory", hr); } return 0; }
I did so in my Windows 11 computer but it failed to work. I'm very sorry.
There is maybe related bug report at https://sourceforge.net/p/scintilla/bugs/2262/.
Fixdsys on my Win 10, it works in GDI (in auto-completion box), but not in editor windows (text rendered with DirectWrite).
Fixdsys on my Win 10, it works in GDI (in auto-completion box), but not in editor windows (text rendered with DirectWrite).
It's quite weird. On my Windows 11 this bug still exists.
I tried my another computer with Windows 10, and it happened again.
It works in Legacy GDI mode (Settings -> Rendering Technology), but not in Direct2D mode.
It fails on following code, where
hr
isDWRITE_E_NOFONT
(_HRESULT_TYPEDEF_(0x88985002L)
):https://github.com/zufuliu/notepad2/blob/0688888a3b5fa1c14d08f45ff542761f3895b9ee/scintilla/win32/PlatWin.cxx#L314-L316
recently I downloaded the latest release, and when I choose "设置→高级设置→渲染技术→传统GDI" the font "Fixedsys" now shows properly, but if I choose other rendering technology, the bug appears again. I still wonder how a setting change in rendering technology can have an influence on showing a kind of font anormally or not.