一、实现思路
先绘制文字阴影部分,绘制阴影文本后应用3DTransform与高斯模糊特效,最后再正常绘制一次文本主体。
二、实现代码
hr = m_pDWriteFactory->CreateTextFormat(
sc_fontName,
NULL,
DWRITE_FONT_WEIGHT_NORMAL,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
sc_fontSize,
L"", //locale
&pTextFormat
);
pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
static const WCHAR sc_helloWorld[] = L"你好\nWorld!";
ID2D1SolidColorBrush *pGrayBrush = nullptr;
hr = m_pOffScreenRenderTarget->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::DarkGray),
&pGrayBrush);
hr = m_pDWriteFactory->CreateTextLayout(
sc_helloWorld,
ARRAYSIZE(sc_helloWorld) - 1,
pTextFormat,
m_width,
m_height,
&am