How can I render mixed-colour text in DirectWrite?

天大地大妈咪最大 提交于 2019-12-04 07:40:10

Use IDWriteTextLayout::SetDrawingEffect to apply drawing effects on subranges. If you're using DWrite with D2D DrawTextLayout, which it sounds like you are, then that drawing effect would just be a brush (such as ID2D1Brush via CreateSolidColorBrush or one of the gradient brushes). If you have implemented your own IDWriteTextRenderer for IDWriteTextLayout::Draw, then the drawing effect can be whatever you interpret it to be. In the IDWriteTextRenderer::DrawGlyphRun callback, you then call QueryInterface on the drawingEffect parameter, or if you are certain it is your own type, just static_cast it directly.

// ... create the colored brushes and determine where to draw ...
wchar_t const* text = L"Red Green";
dwriteFactory->CreateTextLayout(....., OUT &textLayout);

DWRITE_TEXT_RANGE textRange1 = {0,3}, textRange2 = {4,5};

textLayout->SetDrawingEffect(redBrush,  textRange1);
textLayout->SetDrawingEffect(greenBrush, textRange2);

renderer->DrawTextLayout(point, textLayout, defaultBrush);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!