1

I couldn't find an example of a block of text not rendered to a rectangular area.

Ideally, it would be nice if ID2D1HwndRenderTarget.DrawText() would let me provide a polygon Geometry instead of a rectangle.

I've tried adding a Direct2D Layer with contentBounds, thinking it might skip rendering text within those layers. It didn't work as expected, it just blocked render to the area still emulating text underneath.

I've also tried applying a rectangular area to hwnd window itself. It too blocked render but didn't shift text.

McMaster
  • 11
  • 1

2 Answers2

2

IDWriteTextLayout only supports rectangular layouts, but DirectWrite supports any shape you can think of by using the lower level functions (text analysis, glyph measurement, glyph shaping). It's no easy task to write your own text layout from scratch, but I wrote a Windows 7 SDK sample containing a "FlowLayout" that demonstrates a circle and a few other simple shapes. It doesn't take arbitrary geometry, but you may be able to adapt it to your needs (see FlowLayoutSource::GetNextRect for computing the width of each line).

https://github.com/pauldotknopf/WindowsSDK7-Samples/tree/master/multimedia/DirectWrite/CustomLayoutenter image description here

Dwayne Robinson
  • 2,034
  • 1
  • 24
  • 39
0

DirectWrite only supports rectangular layouts, so you can't get anything more complicated automatically. You'll have to implement layout functionality yourself if you want it to work differently. Clipping arguments, like you already observed, have nothing to do with text layout.

bunglehead
  • 1,104
  • 1
  • 14
  • 22
  • Do you suggest I create a separate window for each line of text? – McMaster Jan 28 '20 at 13:32
  • No, windows don't have much to do with that. You'll need to access lower level of shaped glyphs (see GetGlyphs), and arrange them yourself into lines, with any constraints that are suitable for you. It's complicated, so you might look at using some layout library that supports rendering with DirectWrite. – bunglehead Jan 28 '20 at 13:44