I’m trying to find a means of getting the “overflow” text from a TextNode–or another means of achieving what I have in mind.
My game has a number of in-game documents that the player can read, each potentially consisting of multiple pages. Each page may have multiple paragraphs, each of which is held in a TextNode.
Naturally, any one page will only hold so much text.
Up until now I’ve dealt with this during construction of the document by simply checking whether the current paragraph overruns the bottom of the page, and if so, shunting it onto the next page.
This works–but doesn’t look great, I feel. What I would prefer is that, when a paragraph overruns the bottom of the page, it’s split at the last “valid” line, and the remainder is placed on the next page in a new paragraph-object.
The problem, then, is how to do this.
I can, I think, find the index of the last “valid” line in an overflowing paragraph by finding out what percentage of the TextNode is within the page, and dividing that by the line-height. (And then flooring that value to get an integer.) I can also get the paragraph-text split into word-wrapped lines from the TextNode. I could perhaps separate that using “\n”-characters. But given that my text may in original form contain “\n”-characters, I’m not sure of how safe to the structure of the text it might be to attempt to reassemble it from these word-wrapped strings.
TextNode does, however, seem to have the facility to handle these matters itself: given a maximum number of rows, it will automatically cut overflowing text, and set a flag to indicate that overflow, I believe. That sounds like just what I want!
The problem is that, as far as I gather, it just throws away the overflow, and doesn’t seem to keep a record of the splitting-point.
Right now, the only idea that I have for getting that overflowed text would be to search for the contents of the TextNode in the original paragraph-string, which doesn’t sound terribly elegant…
Does anyone have any thoughts?