notepad4 icon indicating copy to clipboard operation
notepad4 copied to clipboard

Font "Fixedsys" Not Properly Shown

Open hTp34r opened this issue 2 years ago • 11 comments

As the title says, when I choose "Fixedsys" to show, it exactly shows another font.

hTp34r avatar Sep 17 '22 08:09 hTp34r

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

zufuliu avatar Sep 17 '22 09:09 zufuliu

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

Thanks for your suggestion, but it doesn't work for me. I use Windows 11, and I downloaded exe pack directly without source code.

hTp34r avatar Sep 17 '22 09:09 hTp34r

Hope that a new version of Notepad2 without this bug will be released soon.

hTp34r avatar Sep 18 '22 12:09 hTp34r

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;
}

zufuliu avatar Sep 19 '22 11:09 zufuliu

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

PNBRQK avatar Sep 19 '22 12:09 PNBRQK

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;
}

I did so in my Windows 11 computer but it failed to work. I'm very sorry.

hTp34r avatar Sep 20 '22 14:09 hTp34r

There is maybe related bug report at https://sourceforge.net/p/scintilla/bugs/2262/.

zufuliu avatar Sep 23 '22 10:09 zufuliu

Fixdsys on my Win 10, it works in GDI (in auto-completion box), but not in editor windows (text rendered with DirectWrite).

Fixdsys

zufuliu avatar Sep 28 '22 23:09 zufuliu

Fixdsys on my Win 10, it works in GDI (in auto-completion box), but not in editor windows (text rendered with DirectWrite).

Fixdsys

It's quite weird. On my Windows 11 this bug still exists.

hTp34r avatar Sep 29 '22 06:09 hTp34r

I tried my another computer with Windows 10, and it happened again.

hTp34r avatar Sep 30 '22 11:09 hTp34r

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

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.

hTp34r avatar Feb 03 '23 12:02 hTp34r