1

I'm rendering text using DirectWrite.
DirectWrite only enable y-axis antialiasing when font size is large, which makes CJK fonts looks bad.

How to force enable Y-Axis Antialiasing for all font size?

Zz Tux
  • 600
  • 1
  • 5
  • 18

1 Answers1

0

On your render target, set your IDWriteRenderingParams to use DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC, and then call ID2D1RenderTarget::SetTextRenderingParams.

ComPtr<IDWriteRenderingParams> textRenderingParams;
dwriteFactory->CreateCustomRenderingParams(
    gamma,
    contrast,
    clearTypeLevel,
    pixelGeometry,
    DWRITE_RENDERING_MODE_NATURAL_SYMMETRIC,
    OUT &textRenderingParams
    );
d2dRenderTarget->SetTextRenderingParams(textRenderingParams);

If you want to inspect the existing settings from the default rendering params, you can call ID2D1RenderTarget::GetTextRenderingParams first, and then create your own to replace the default one.

// 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

"which makes CJK fonts looks bad." Careful though, as using 6x5 or 8x8 can lose the fine details of the stems.

Dwayne Robinson
  • 2,034
  • 1
  • 24
  • 39