Hi all,I found the reason why breaking paragraphs into short lines is really slow and memory hungry: the threshold of the adjustment ratio, set to 20 at the last try, is too high and makes EVERY legal breakpoint a feasible breakpoint too. A check should be performed to avoid such situation and to choose then a better threshold.
For example, if I have a 2 columns in A4 page layout the line width is ~140000. The glue stretchability, as far as I can see in TextLM class, is often set to "3 * LineLayoutManager.DEFAULT_SPACE_WIDTH" that is equal to ~10000. When you compute the adj ratio for a line that have just one glue you get r = 140000/10000 = 14, that is lower than the threshold = 20.0, so an active node is added.
A better threshold can be chosen as follow: let idealDifference be a reasonable size we choose as good threshold. We can assume "3 * LineLayoutManager.DEFAULT_SPACE_WIDTH" as default stretchability a compute a better threshold in that way:
idealRatio = idealDifference / (3 * LineLayoutManager.DEFAULT_SPACE_WIDTH);
and bound that value:
1.0 <= idealRatio <= 20.
How to choose idealDifference? A naive solution, but probably not so
bad, can be:
idealDifference = iLineWidth / 2;
A more sophisticated, maybe too much sophisticated, solution can
choose it by looking at the average box length: we can see how many
average box can fit a line (wordsPerLine) and execute:
avgWord = avgBox + LineLayoutManager.DEFAULT_SPACE_WIDTH;
idealDifference = iLineWidth - (avgWord * (wordsPerLine / 2));
The test I've run have showed sensible performance improvement.
Comments are welcome!
Dario
autoThreshold.diff
Description: Binary data
