【发布时间】:2019-02-01 10:35:52
【问题描述】:
我最近正在开发自己的 GUI 库。该窗口是使用 Win32 API 创建的,然后在其中创建 Direct2D RenderTarget。所有绘图(按钮、标签等)都发生在 RenderTarget 内。一切都很好,除了文字质量。例如,当我查看 Visual Studio 按钮时,与 DirectWrite 方法 DrawTextW() 相比,文本看起来非常清晰。
这是一个图像示例:
我使用 DirectWrite 直接绘制文本。 `
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();
`
我只是想知道,这是我应该接受并继续前进的事情,还是我必须使用 DWriteFactory 进行一些调整?
【问题讨论】:
-
这看起来您正在以 HighDPI 模式运行 Windows,但您的应用程序不是 DPI aware。
标签: c++ direct2d directwrite