我想使用DirectWrite进行混合颜色的文本格式化(准确地说,语法突出显示),但似乎找不到一种方法,无论是在布局还是排版选项中。唯一的选择是在渲染文本时传递一个Brush,这对我来说是行不通的,因为我基本上只有一个布局。帮助!
发布于 2011-09-10 15:54:09
使用IDWriteTextLayout::SetDrawingEffect对子区域应用绘图效果。如果您正在使用DWrite和D2D DrawTextLayout,那么绘制效果将只是一个画笔(例如通过CreateSolidColorBrush的ID2D1Brush或其中一个渐变画笔)。如果您已经为IDWriteTextLayout::Draw实现了自己的IDWriteTextRenderer,那么绘制效果可以是您所解释的任何效果。在IDWriteTextRenderer::DrawGlyphRun回调中,您可以在drawingEffect参数上调用QueryInterface,或者如果您确定它是您自己的类型,只需直接static_cast它。
// ... 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);https://stackoverflow.com/questions/1656014
复制相似问题