Friday, January 11, 2008
Wrapped Text with GDIPlusX

I was recently asked if it was possible to do "Wrapped Text" with GDIPlusX. I wasn’t sure what they meant at first, but found out they wanted a text string to render in the form a circle, instead of a straight line. While there is nothing built into the library that can do this, I knew it was possible to write your own code to get this functionality.

I dug around and found an excellent article written by Sjaak Priester. He came up with a very interesting technique. By using the FlattenPath method of a GraphicsPath and some straight forward geometry, he was able to not only get a text string to render in a circle, but to get a text string to render in any shape by using a GraphicsPath as a guide. He developed a very nice little C++ class to handle this. I was impressed by the simple yet powerful technique he was using, I decided to try it using the GDIPlusX library.

The results are attached. A relatively straight forward, 300+ line class that takes a GraphicsPath guide, a String of text and a Font and fills a second GraphicsPath with the rendered string, following the specified path. Once you have this rendered path, you can do all kinds of cools stuff with it (check out some of the text effect samples with the GDIPlusX samples download).

Included in this download is the WrappedText class, a demo form as well as the 1.10 version of the GDIPlusX library (compiled into an app). To run the demo, issue a:

DO FORM WRAPPEDTEXTDEMO

WrappedTextDemo.zip (210.63 KB)


Friday, January 11, 2008 7:56:52 AM (Eastern Standard Time, UTC-05:00)  #    Comments [2]  

Sunday, January 13, 2008 12:46:09 AM (Eastern Standard Time, UTC-05:00)
Cool demo, also shows how the system.app greatly simplifies deployment/inclusion of GDIPlusX - great job Bo.
Friday, January 18, 2008 2:58:01 PM (Eastern Standard Time, UTC-05:00)
Great demo, but upon running the form wrappedtextdemo.scx, Image control was always empty, after studying the code decided to modify it a little to fix the issue, added the following line at the end of drawwrappedtext method:

Thisform.Image1.PictureVal = ThisForm.bmp.GetPictureValfromHBitmap()

and voila!
I don't know if I'm the only one experiencing this issue...
Just wanted to share this bit of info...
Excellent demo, GDIplusX rocks!

Thank you very much for sharing it.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: )  

Enter the code shown (prevents robots):