Hi
I have a grid and I need to know in advance what the grid height will be . The cells height are Auto Height and the grid column widths are fixed.
By default the grid adjusts the height of the cells according to the width and the amount of text . That is Ok but I want to know in advance what the height of each cell is going to be , and for that I need to know how many lines of text are going to be in the cell. I tried measuring the text on a canvas for each cell and then dividing by the width of the cell, but the problem is that the cell (or the IText not sure who ) does word wrap , so sometimes the height will actually be more becuase it tries not to break up the words and for that it sometimes uses more lines.
I already asked a question on how to remove the Word Wrap feature , but I would also like to know how I can calculate the actual height with word wrap . What is the algorithm it used to calculate how to break up the text into different lines. If there is an easy way for me to find out how many lines of text there are in each cell then I think that would be the best solution.
Thanks.
I'm not sure that there's an easy way to do this. The Documents engine does its measuring in several passes, and is also dependant on the parent/sibling elements and how much space they take up. Since the Documents engine will not break apart words when wrapping, what you could do is measure each word, and if there isn't enough space for that word, you know it's on the next line, so you could continue your measuring that way. There is a static private method in the GraphicsProxy class in the Documents assembly called BuildMultiLineString that you could take a look at that basically does this, taking into account spaces and newlines.
-Matt
Hi Matt
I had a look and I also did some debugging into the Text.cs to see what happens. The answer is more or less in the methods ComposeUnits where they create word units from the text and ComposeBody where the body.ActiveHeight is calculated. Each time they add a new word and check the total against the available width and see if it fits in , if not it adds more height. didnt go into exact details but it looks pretty straigth forward. at the end they adjust the body.ActiveHeight.