0

I was recently developing my own GUI library. The window is created using Win32 API and then Direct2D RenderTarget was created inside. All the drawing (buttons, labels, etc.) happens inside the RenderTarget. Everything is fine except for the quality of the text. When I look at visual studio buttons for example, the text looks so clear compared to DirectWrite method DrawTextW().

Here is an image example:

image

I use DirectWrite to directly draw text. `

ID2D1SolidColorBrush* brush;
RenderTarget->CreateSolidColorBrush(D2D1::ColorF(red, green, blue, alpha), &brush);

IDWriteTextFormat* format;
HRESULT h = WriteFactory->CreateTextFormat(std::wstring(font.begin(), font.end()).c_str(), NULL, fontWeight,
    fontStyle, DWRITE_FONT_STRETCH_NORMAL, fontSize, L"", &format);

// Center the text horizontally and vertically.
format->SetTextAlignment(textAllignment);
format->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);

// Draw text
RenderTarget->DrawTextW(std::wstring(text.begin(), text.end()).c_str(), std::wstring(text.begin(), text.end()).size(), format, D2D1::RectF(xPos, yPos, xPos+width, yPos+height), brush);

brush->Release();
format->Release();

`

I was just wondering, is this something that I should just accept and move on or do I have to tweak something with DWriteFactory?

handlerFive
  • 870
  • 10
  • 23
Flare Flax
  • 61
  • 10
  • This looks like you are running Windows in HighDPI mode but your application is not [DPI aware](https://learn.microsoft.com/en-us/windows/desktop/hidpi/high-dpi-desktop-application-development-on-windows). – user7860670 Aug 26 '18 at 20:47

1 Answers1

1

It appears that you have high-DPI monitor and haven't defined proper manifest for your executable. By default Windows will think that your app is designed for old 96ppi systems and so each "pixel" will span four physical pixels if your monitor uses 192ppi for example.

Check this for how to add high-DPI awareness to your application.

In Visual Studio 2015 and above there is a flag in project settings: "Configuration Properties > Manifest Tool > Input and Output > DPI Awareness"

c-smile
  • 26,734
  • 7
  • 59
  • 86
  • Thank you very much for your reply, but I have a question. If it is a manifest file and has to be included with the project, does this mean that every time somebody would like to use my library will have to create this manifest file? – Flare Flax Aug 26 '18 at 20:37
  • "manifest file and has to be included" - that's highly desirable as this flag affects quite many things. E.g. size of window caption and buttons. Yet, common dialogs used by application, etc. You can do that programmatically but this setting is process global: https://learn.microsoft.com/en-us/windows/desktop/api/shellscalingapi/nf-shellscalingapi-setprocessdpiawareness – c-smile Aug 26 '18 at 20:49
  • Thank you for the information, I will test your solution when I get home, but it sounds like an answer :) – Flare Flax Aug 26 '18 at 20:58
  • Note that best result (fastest drawing) can be achieved if frame window (that one with desktop parent) is using WM_NOREDIRECTIONBITMAP, I've explained it here: https://sciter.com/sciter-4-2-support-of-acrylic-theming/ – c-smile Aug 26 '18 at 21:24