MV drawTextEX - Text being cut off

Hello, I am working on a plugin and running into a strange problem. I am using drawTextEX to try and display a large amount of text inside of a scrollable window. The problem, however, is that only a small portion of the text is being displayed in game.

While debugging the code, I can see that drawTextEX is actually processing through every character in the testState but at some point the characters are no longer being drawn to the window. I will put my text and code snippet for my overridden drawTextEX and the function that calls it that processes the text from the plugin settings. I should note that if I comment out my override and use the drawTextEX from Window_Base that the same issue happens.




Founded in 305AG, the Felgarin Empire started out its life as a small meritocracy that depended on trade. As the decades wore on Felgarin began to expand until a man, x, had the audacious idea of conglomerating the various maeritime companies under one incorporaiton. This action led to a massive accumulation of wealth by x and his cohorts. They purchased large tracts of land from the Republic of Dunslor and expanded northward, forging the northern boundries of today\'s Felgarin. In 520AG the populace voted to form a representitive government where a quorum of a representitive from each city was formed in Shig, which would become the capitol city. The decision was to not only pool the resources from across the nation for everyone\\'s benefit but also to handle trade route disputs in a more civilized manner than in the past. This experiment was short lived, however. Seven years after its formation, the quorum voted to install a grand chancellor that would have the power to implement or overrule its decisions. In return, the quorum members were granted seats on a cabinet when it was disbanded and given greater powers over specific areas of governance. While these individuals were still representitve and chosen by each town, they now had an appointment term of ten years while the grand chancellor was a lifetime position until death or resignation. Power and wealth began to amass around this new form of government and it wasn't long before corruption began seeping into it in the form of bribes, assasinations to obtain a seat on the cabinet, and election tampering. In 620AG, the high chancellor announcemeed the formation of an aristocracy with a king who would ascend to the throne. Naturally, the king would be the high chancellor. Those on the cabinet who did not agree were executed while those that facilitated this power grab were granted immense wealth and power. This would be the basis for the present day Empire.

In game, the text stops at "pool the resources from across the nation for"

codexplugin_textissue.JPG



Code:
Window_EntryData.prototype.drawCodexInfo = function() {
    this.getCodexEntry();

    if (!isEmptyObject(this._codexEntry)){
        var fmt = JSON.parse(genTxFmt || '');

        if (fmt !== ''){
            var bEnableWordwrap = fmt.match(/<(?:WordWrap)>/i);
            var title = this._codexEntry.title.replace(/\\I\[(\d+)\]/gi, '').trim();
            var desc = this._codexEntry.text;
            var text = fmt.format(title,desc);
            var textState = { index: 0 };
            textState.originalText = text;
            textState.text = this.convertEscapeCharacters(text);
            this._allTextHeight = this.calcTextHeight(textState, true);
            this._allTextHeight *= (bEnableWordwrap) ? 10 : 1;
            this.createContents();
            this.drawTextEx(text, 0, 0);
        }
    }
}
 
Window_EntryData.prototype.drawTextEx = function(txt, x, y) {
  if (txt) {
      var textState = { index: 0, x: x, y: y, left: x};
      
    textState.text = this.convertEscapeCharacters(txt);
      textState.height = this.calcTextHeight(textState, false);
    this.resetFontSettings();
    
    while (textState.index < textState.text.length) {
      this.processCharacter(textState);
    }
    
    this._allTextHeight = textState.y - y + this.lineHeight();
    return textState.x - x;
  } else {
    return 0;
  }
};
you said it was a scrollable window right? might I suggest actually looking at that part of the code instead, if your text is getting cut off your issue is probably coming from their and not the characters themselves. or at the very least it'd be a good place to start. otherwise I think a bit more information is needed, try experimenting with the text box in game, see if it stops at a certain line or a certain number of characters dialog wise.
Maybe the \\' in everyone\\'s is throwing off the wordwrap in some way. It should be \', or you could use "double quotes" to avoid having to escape the apostrophes in the first place. 🙂

Also note that by default calcTextHeight determines the height of the first line of text, not the overallHeight of a multi-line text block (I assume you've made an off-stage edit to that method in which you reference the _allTextHeight property). I notice you've passed it an extra argument, though, so I'm not sure what's going on there. 😅

Also, in this line:
JavaScript:
            this._allTextHeight *= (bEnableWordwrap) ? 10 : 1;
...you've added in an arbitrary x10 multiplier for word-wrapped text, which seems to have given you 20 (?) lines in your window. I'm not sure how your word-wrapping works; you may need to "pre-wrap" the text first to determine the total wrapped height, then set the window height based on that. 😴
Maybe the \\' in everyone\\'s is throwing off the wordwrap in some way. It should be \', or you could use "double quotes" to avoid having to escape the apostrophes in the first place. 🙂

Also note that by default calcTextHeight determines the height of the first line of text, not the overallHeight of a multi-line text block (I assume you've made an off-stage edit to that method in which you reference the _allTextHeight property). I notice you've passed it an extra argument, though, so I'm not sure what's going on there. 😅

Also, in this line:
JavaScript:
            this._allTextHeight *= (bEnableWordwrap) ? 10 : 1;
...you've added in an arbitrary x10 multiplier for word-wrapped text, which seems to have given you 20 (?) lines in your window. I'm not sure how your word-wrapping works; you may need to "pre-wrap" the text first to determine the total wrapped height, then set the window height based on that. 😴


Thanks Caethyril, you got me looking at the right area. It was the ternary on allTextHeight. It needs to be higher or I need to figure out a better way, as you mentioned, to get the total height. I changed the 10 to 20 and now more of the text is being displayed.

As for the question on the bool argument for calcTextHeight, it has a bool argument called All used to determine the value assigned to maxLines.


-----Update

Here is what I came up with, this seems to be working as expected as I copy pasted the text from my op three times into the plugin param used for this section and all of the text is showing (although it takes 2 seconds to load D: )

JavaScript:
if (bEnableWordwrap) {
    var txtLen = desc.length;
    var multi = Math.ceil((txtLen * 10) / (Graphics.width - (this.windowWidth() + 10)));

    this._allTextHeight *= multi;
} else {
    this._allTextHeight  = 1;
}
Yay! 😂

And whoops, I was looking at MZ's core scripts by mistake, which defines calcTextHeight differently. 😴
seems the forum put my code block in a new post; don't know why 🤣

Original thread: https://forums.rpgmakerweb.com/threads/drawtextex-text-being-cut-off.128494/