跟随/剪辑到形状的文本?
好的,所以我知道如何将文本剪辑到特定的几何形状,但是文本不会根据剪辑自动换行,那么假设您有“勾号”,如何实现类似于下图所示的效果作为几何/路径?
是否是手动添加适合每一行的文本框,然后根据适合/不适合的内容分割文本?
Ok, so I know how to clip text to a particular geometry, however the text doesn't automatically wrap based on the clip so how does one go about achieving an effect similar to the one shown below, given that you have the "tick" as a geometry / path?
Is it a case of manually adding text boxes that fit for each line and then splitting the text based on what will / will not fit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能想到的唯一方法是创建一个自定义控件并重写 OnRender。该自定义控件将具有定义其剪辑区域的几何图形和字符串类型的“文本”属性。它还具有 int 类型的 lineheight 属性。
在 OnRender 中,您可以测量要在当前 X、Y 位置绘制的文本(从剪辑几何体的左上角开始)。一次测量一个单词,看看该单词的边界框是否完全在剪辑内这可以使用 Geometry 的 HitTest API 来实现,并测试单词边界矩形的所有四个点是否在几何图形内。如果是,则绘制该单词,如果不是,则将 X 增加一个字母间距并再次测量。如果你到达了边缘控制,将 X 重置为零并增加 Y 一行空间并重复,使用类似于电视绘制像素的方式的扫描线方法
基本上,您想要做的是创建自己的带有文本换行的 WrapPanel 或 TextBlock 如果可以的话。会调用 WPF 框架上的 Reflector 或 ILSpy 来查看 WrapPanel / TextBlock 中的代码,或者搜索有关“使用文本换行编写自定义 WrapPanel”/“TextBlock”/“RichTextControl”的文章 这不是一件容易的任务。任何想象力都可以,但上述方法将为您提供所需的基本信息。
此致,
The only way I can think of to do this would be to create a custom control and override OnRender. This custom control would have a Geometry defining its clip area and a "Text" property of type string. It would also have a lineheight property of type int.
In OnRender you could measure the text about to be drawn at the current X,Y location (starting at top left of the clip geometry. Measure this text one word at a time and see if the bounding box of the word is entirely within the clip geometry. This is possible using the HitTest API of Geometry, and testing that all four points of the bounding rect of the word are within the geometry. If so, draw that word, if not, increment X by one letter spacing and measure again. If you reach the edge of the control, reset X to zero and increment Y by one line space and repeat, using a Scanline approach similar to how TV draws its pixels.
Basically what you are trying to do is create your own WrapPanel or TextBlock with text wrapping. If you can I would invoke Reflector or ILSpy on the WPF Framework to see the code within WrapPanel / TextBlock, or search for articles on "Coding a custom WrapPanel" / "TextBlock" / "RichTextControl" with text wrapping. Its not an easy task by any stretch of the imagination but the above method will give you the bare bones of what you require.
Best regards,