I want to use DirectWrite for mixed-colour text formatting (syntax highlighting, to be precise), but can't seem to find a way to do it, either in the Layout or Typography options. The only option is passing a Brush when rendering the text, which doesn't work for me because I basically have just one Layout. Help!
How can I render mixed-colour text in DirectWrite?
2.2k Views Asked by Dmitri Nesteruk At
1
Use
IDWriteTextLayout::SetDrawingEffect
to apply drawing effects on subranges. If you're using DWrite with D2DDrawTextLayout
, which it sounds like you are, then that drawing effect would just be a brush (such asID2D1Brush
viaCreateSolidColorBrush
or one of the gradient brushes). If you have implemented your ownIDWriteTextRenderer
forIDWriteTextLayout::Draw
, then the drawing effect can be whatever you interpret it to be. In theIDWriteTextRenderer::DrawGlyphRun
callback, you then callQueryInterface
on the drawingEffect parameter, or if you are certain it is your own type, just static_cast it directly.