DirectWrite painting ligatures with multiple colors?

209 views Asked by At

I'm using Microsoft's Cascadia Code font and drawing text with DirectWrite using ID2D1RenderTarget::DrawTextLayout, with individual glyphs colored using IDWriteTextLayout::SetDrawingEffect(CreateSolidColorBrush(...)).

Cascadia Code has a ligature for "greater than or equal to" (=>) that draws as a single arrow glyph. If I have half of the glyph selected, using HitTestTextRange to paint the background highlights the correct area, but setting the selected character's drawingEffect to a different color than the unselected side doesn't work. The entire glyph is painted using the drawing effect from the second character, resulting on one side drawing as white-on-white or black-on-blue. GetClusterMetrics returns two separate clusters for it. Conversely, if I have some Arabic text like ممم, which presumably uses a substituted font, it draws as a ligature, but the individual characters within it will draw as different colors.

Notepad vs App comparison

Is implementing IDWriteTextRenderer the best way to handle this situation or is there an easier one?

Also, comparing Cascadia Code's supported ligatures in Notepad or Visual Studio Code against my app shows that most ligatures are drawn like they should be, but a handful of them aren't. -~ (minus tilde) draws as a single symbol in Notepad, VS Code, my app, and the Windows SDK's PadWrite sample app, but /\ only draws as an inverted V in the first two. The "infinite arrows" like >==>==> are similarly broken up. Is there a setting I need to use to enable all of them?

0

There are 0 answers