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::SetDrawingEffectto 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 asID2D1BrushviaCreateSolidColorBrushor one of the gradient brushes). If you have implemented your ownIDWriteTextRendererforIDWriteTextLayout::Draw, then the drawing effect can be whatever you interpret it to be. In theIDWriteTextRenderer::DrawGlyphRuncallback, you then callQueryInterfaceon the drawingEffect parameter, or if you are certain it is your own type, just static_cast it directly.