Endofline in canvas?

I rarely deal with long text (paragraphs) in canvases and was suprised to see that g.drawstring does not respect “endofline”. Is there a special trick to drawing text with endoflines in them? I could have sworn a few years ago I was drawing endofline in canvases just fine… :slight_smile:

Have a look at the third parameter of the drawstring function: http://documentation.xojo.com/index.php/Graphics.DrawString

Actually you mean the fourth parameter Wrapwidth :wink:

Ah yes. Counting is harder than it seems :stuck_out_tongue:

While currently working on a project which uses EndOfLine in a DrawString for a Canvas, I can confirm it still works as expected in Xojo like it did in RS. WrapWidth just does this automatically for you.

I’m rather wondering how to wrap text using StringShapes…

@Alex von Siebenthal: Indeed, line breaks are not supported in StringShapes. I wonder too…

Got it working :slight_smile: I can post an example if desired.

Solutions are always welcome. So, yes, post yours. Others will be thankful, when stumbling across this matter.

I can wrap text, that is not the issue. I can’t get endofline or line breaks to work in canvases. Here’s a screenshot of what happens. I copied some text from CNN, paste it into a textfield (with styledtext turned off) and have them rendered on a canvas: http://koualo.com/beta/eofissueoncanvas.png

All of those little diamonds with the ? in them are line breaks or endoflines. I even manually put “hello” + endofline + endofline + “world.” and still get the little black diamond.

I would certainly love to see how you are doing it because it is not working for me.

Perhaps there’s a better way to create dynamically sized “listboxes” (height-wise) than faking it with a canvas?

[quote=11607:@[deleted]]
I would certainly love to see how you are doing it because it is not working for me.[/quote]

To handle drawing multiline strings I wrote code that handled wrapping myself. It first splits the text into paragraphs at linebrakes, then wraps the lines for each paragraph and returns the physical lines as a string array…

(all this assume a unstyled text)

Once you have that array, using g.textheight you know how tall it needs to be and can easily draw it…

I use the same approach when dealing with stringshapes

This approach lets me control line spacing and justification… and for list box use I also have it add an ellipsis if the wrapped text won’t fit in a specified rectangle.

If you copy text from elsewhere it may not have the right EndOfLine format for your platform. That’s the reason.

Indeed, make sure you use ReplaceLineEndings(), otherwise I do it exactly as Karen described.

Funy, I actually thought of doing that but I just became very lazy last night. But this morning, I was thinking that maybe it would be much simpler for me to use a HTML Viewer instead of a canvas to “fake” a dynamic listbox…

I also said that I entered directly into the paint event: “hello” + endofline + endofline + “world.” – and same thing happened. :wink:

I think the only solution to this canvas issue is to use a split and then manually calculate the next position of the text in the split array. I wish that canvas would just support endofline natively.

Then something else must be wrong. As I stated above, it works for me. (tested)

Whew, figured it out. I forgot to .DefineEncoding(Encodings.UTF8) when retreiving from the sqlite db.

Thank you everyone, for helping me figure this out.