简体   繁体   English

如何在 DirectWrite 中使用 Direct2D 在图像或抽象形状周围环绕文本?

[英]How to wrap text around images or abstract shapes in DirectWrite with Direct2D?

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.理想情况下,如果ID2D1HwndRenderTarget.DrawText()能让我提供多边形Geometry而不是矩形,那就太好了。

I've tried adding a Direct2D Layer with contentBounds , thinking it might skip rendering text within those layers.我尝试添加一个带有contentBounds的 Direct2D 层,认为它可能会跳过这些层中的文本渲染。 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.我还尝试将矩形区域应用于hwnd窗口本身。 It too blocked render but didn't shift text.它也阻止了渲染,但没有移动文本。

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). IDWriteTextLayout仅支持矩形布局,但 DirectWrite 支持使用低级功能(文本分析、字形测量、字形整形)您可以想到的任何形状。 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.从头开始编写自己的文本布局并非易事,但我编写了一个 Windows 7 SDK 示例,其中包含一个“FlowLayout”,它演示了一个圆形和其他一些简单的形状。 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).它不需要任意几何图形,但您可以根据自己的需要进行调整(请参阅 FlowLayoutSource::GetNextRect 以计算每条线的宽度)。

https://github.com/pauldotknopf/WindowsSDK7-Samples/tree/master/multimedia/DirectWrite/CustomLayout https://github.com/pauldotknopf/WindowsSDK7-Samples/tree/master/multimedia/DirectWrite/CustomLayout 在此处输入图片说明

DirectWrite only supports rectangular layouts, so you can't get anything more complicated automatically. DirectWrite 仅支持矩形布局,因此您无法自动获得更复杂的内容。 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.就像您已经观察到的那样,剪辑参数与文本布局无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM