我正在使用DirectWrite
渲染文本。DirectWrite仅在字体大小较大时才启用y轴抗锯齿,这会使CJK字体看起来很糟糕。
如何对所有字体大小强制启用Y-Axis Antialiasing
?
在渲染目标上,将IDWriteRenderingParams
设置为使用DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC
,然后调用ID2D1RenderTarget::SetTextRenderingParams
。
ComPtr<IDWriteRenderingParams> textRenderingParams;
dwriteFactory->CreateCustomRenderingParams(
gamma,
contrast,
clearTypeLevel,
pixelGeometry,
DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC,
OUT &textRenderingParams
);
d2dRenderTarget->SetTextRenderingParams(textRenderingParams);
如果要从默认渲染参数检查现有设置,可以先调用ID2D1RenderTarget::GetTextRenderingParams
,然后创建自己的以替换默认设置。
// Get defaults for gamma, contrast, CT level, pixel geometry...
ComPtr<IDWriteRenderingParams> defaultRenderingParams;
RETURN_IF_FAILED(dwriteFactory->CreateRenderingParams(OUT &defaultRenderingParams));
// Alternately create suitable rendering params for your monitor:
// dwriteFactory->CreateMonitorRenderingParams(...)
//
// Or retrieve the existing rendering params if one was already set:
// d2dRenderTarget->GetTextRenderingParams(OUT &defaultRenderingParams);
auto gamma = defaultRenderingParams->GetGamma(); // default=1.8f
auto contrast = defaultRenderingParams->GetEnhancedContrast(); // default=0.5f
auto clearTypeLevel = defaultRenderingParams->GetClearTypeLevel(); // default=0.5f
auto pixelGeometry = defaultRenderingParams->GetPixelGeometry(); // default=RGB for most monitors
“这会使CJK字体看起来很糟。”但是请小心,因为使用6x5或8x8可能会丢失茎的精细细节。