Ok was playing a bit with DrawString on sunday trying to get string alignments to work. I've got horizontal alignments working by simply setting drawcoord.right which currently is left uninitialized and then passing DT_CENTER and DT_RIGHT as needed to DrawTextW.
So far, that worked.
However, I can't do that for vertical alignments because the code manually does the line breaking and therefore draws each line individually.
So my question is, why? Why aren't we letting DrawTextW do the line breaking and just letting it draw with the appropriate rect? Is the linebreaking different? Or does DrawTextW not have the proper support for rotations?
As it stands right now, if necessary, I can easily enough calculate the offsets myself for doing horizontal alignments instead of using DT_CENTER and DT_RIGHT.
But for vertical, this is a bit problematic. I don't know how many lines of text there are going to be until the text has already been drawn. Kind of a prerequisite for vertical alignment however.
That means that if I just want to brute force it, I'd have to duplicate the drawing loop and once only have it measure the string / count lines. That then allows me to calculate the proper offset and I could then just rerun the thing again with the new position and it'd work. A bit more better solution would be to store the line break info in a small array (indices into the string should do that tell me where each line ends) to simply the drawing loop. That would require a dynamic array though which brings me to another question, what should I use? is stuff like std::vector ok or should I use something else?
If of course there's a way we can just have DrawTextW handle the line breaking, I don't even need to care about any of the above. Can then just calculate the proper bounding rect and hand all the issues off to DrawTextW.
Thoughts?
Thanks,
Stephan
I don't know why gdiplus does its own linebreaks. I haven't really done any work in that area.
If I had to guess, I'd say it's because StringFormatFlagsNoWrap has no equivalent flag for DrawText. That probably means you can't pass it off to DrawText.
Since they'll probably have to be done differently, it's best to implement one direction at a time. When you're happy with horizontal alignment, you can send a patch for that regardless of the status of vertical alignment.
You should be able to use GdipMeasureString to get the size of the text. In fact, the alignments will need to be implemented there too, and it may be better to start there.
Vincent Povirk