0

I created a very simple c++ win32 application, and I'm trying to draw some text using the following font settings:

charset = OEM_CHARSET
pitch = FIXED_PITCH
name = L"System"

I create the font like this:

CreateFont(16, 0, 0, 0, FW_REGULAR, false, false, false, OEM_CHARSET, OUT_RASTER_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH, L"System");

and I draw the text in WM_PAINT like this:

PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);

SelectObject(hdc, font);
TextOut(hdc, 100, 200, L"wiw", 3);

EndPaint(hWnd, &ps);

However, the text that is drawn is in the Consolas font, not the System font. The thing is, if I change OEM_CHARSET to DEFAULT_CHARSET, then the text is drawn using the correct font System.

Here is the text drawn with OEM_CHARSET (ie not working): not working example

Here is the text drawn without OEM_CHARSET (ie working, but I need OEM_CHARSET set): working example

The reason I need OEM_CHARSET set is because I'm attempting to replicate this, and the answer states that OEM_CHARSET, FIXED_PITCH and System are required.

My questions are:

  1. Why does OEM_CHARSET render System font with a different font altogether?
  2. What does OEM_CHARSET even do? The documentation just states it maps the characters differently, but I'm using plain ascii, so why would that matter?
  3. Does my version of windows matter? I'm using Windows 10 x64.
  • You don't need `OEM_CHARSET`. The referenced Q&A states the intended purpose: To get a mono-spaced font. – IInspectable May 01 '21 at 21:13
  • @IInspectable Thanks! However, if I remove `OEM_CHARSET`, is the font still monospaced? I specified `FIXED_PITCH` so it should be right? – IWatchCowsEat123 May 01 '21 at 23:07
  • So long as you pick a font that is mono-spaced (like "Cascadia Mono"). Just don't use "System", it's [a font that nobody uses any more](https://devblogs.microsoft.com/oldnewthing/20050707-00/?p=35013). – IInspectable May 02 '21 at 07:57

1 Answers1

0

The System font is a proportional one, so font mapper has hard time to find FIXED_PITCH font with name System. Because FIXED_PITCH has higher priority than font name, font mapper tries to substitute another one that at least partially meets stated requirements and it chooses some fixed pitch font.

To resolve this, specify name for fixed pitch font e.g. FixedSys *, Terminal *, Lucida Console, Courier *, Courier New etc. or not specify name at all. Fonts marked with * are raster fonts (bitmapped). Depending on your use case it could be good or bad.

1
I'm not sure how exactly OEM_CHARSET plays int this case, but font mapper tries to choose font that covers characters from given charset, so it probably limits suitable font substitutions, and gives you different results.

2
I think in polish locale where default code page is CP1250, OEM_CHARSET selects CP852 with more DOS-like charset (e.g. box drawing characters).

3
It could depend on Windows version, but is more affected by installed fonts extending possible font substitutions.

Daniel Sęk
  • 2,504
  • 1
  • 8
  • 17
  • The system responsible for matching a font against user-supplied requirements is called *"font mapper"*, not *"font manager"*. – IInspectable May 02 '21 at 09:04