last day (16 days later) » 

21:58
0
Q: C# split text by rectangle

TayabI have a requirement. I need to split a string by fitting it into a Rectangle object. I have the string's Font, the regionSize (of size 1780x880), and a default StringFormat object. Here's my code: // file 1 public static class Utils { public static List<string> SplitByRect(string...

TaW
TaW
For this kind of thing try to add the typographic parmater to the measurestring call. I don't quite follow the code: do you add any spaces to the lines to fill them up? This will be necessary. I would consider not using regular spaces for this but n-space charcters. They are wider and can be removed if necessary.
@TaW I'll try to do that. However I don't understand what you mean by adding spaces to lines to fill them up..
TaW
TaW
Words will not accidentally fill lines properly. so you need to add extra spaces between them to achive block alignment.
@TaW In that case no, I haven't done anything to add extra spaces. The text is as it is.
TaW
TaW
OK, for this result you actually don't need any code at all; you could use the drawstring overload that take a target rectangle. But for justified output you need a more elaborate code that calulates how many white space characters are missing and them adds them between words.. - (Professional software also sometimes uses extra thin spaces between letters..)
21:58
Also I couldn't figure out how to 'add the typographic parmater to the measurestring call' :/
Also, why are empty chars needed to be added? Doesn't draw string calculate the string size with the white spaces in between words?
TaW
TaW
Yes it does but that usually will not add up to the full line length. bibendum is too long so it goes to the next line, leaving the previous one short. Or don't you aim at block alignment?? - The param is called StringFormat.GenericTypographic
Using StringFormat.GenericTypographic now makes my method return my input text in one line :/
Also, as for what you're saying it's frankly just flying over my head. It's some complex stuff
TaW
TaW
Hm, maybe I didn't get your question right. Are you maybe not talking about the tight border but about the bottom space??
The border is fine. It's the bottom space that needs to be filled. The full image has a size of 1920x1080 however, there's a margin of 100 pixels for the text.
I should've mentioned that I realize now, sorry :/
TaW
TaW
Here is what you could do: MeasureString returns a Rectangle when you feed in the maximum width. Then you can compare its height with your target height and if it is too low you can increase the font and repeat.
22:09
are you asking how to justify your text in your question?
TaW
TaW
He wants to fill to the bottom, not to the right.
 
2 hours later…
23:54
@Taw that is what I'm doing in this scenario tho. Although I'm supplying a Size instance instead of just the width. So it should work... But the problem is it isn't.

  last day (16 days later) »