Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text that follows / clips to a shape?

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?

Example image

like image 713
Siyfion Avatar asked Nov 13 '22 12:11

Siyfion


1 Answers

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,

like image 199
Dr. Andrew Burnett-Thompson Avatar answered Nov 16 '22 03:11

Dr. Andrew Burnett-Thompson