From 3d3454e92d10c490d22854fad43a0f491aae0da3 Mon Sep 17 00:00:00 2001 From: dazedanon Date: Mon, 27 Oct 2025 01:53:04 -0500 Subject: [PATCH] Superior AI will fix wrap for me --- www/js/plugins/SceneGlossary.js | 50 ++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/www/js/plugins/SceneGlossary.js b/www/js/plugins/SceneGlossary.js index 267b4e4..413812d 100644 --- a/www/js/plugins/SceneGlossary.js +++ b/www/js/plugins/SceneGlossary.js @@ -2289,7 +2289,7 @@ function Window_GlossaryComplete() { }; Window_Glossary.prototype.standardFontSize = function() { - return param.FontSize ? param.FontSize : Window_Base.prototype.standardFontFace(); + return param.FontSize ? param.FontSize - 2 : Window_Base.prototype.standardFontFace(); }; Window_Glossary.prototype.calcMaxPages = function(index) { @@ -2640,14 +2640,62 @@ function Window_GlossaryComplete() { Window_Glossary.prototype.processNormalCharacter = function(textState) { var c = textState.text[textState.index]; + // If starting a new line, ensure line start index is tracked + if (typeof textState._lineStartIndex === 'undefined') { + textState._lineStartIndex = 0; + } + // If this char starts a word (previous is space or at line start) and + // the upcoming full word would not fit on this line, break before it. + // This avoids breaking English words in the middle. + var isWhitespace = function(ch) { + return ch === ' ' || ch === '\n' || ch === '\f' || ch === '\t'; + }; + var prevChar = textState.index > 0 ? textState.text[textState.index - 1] : '\n'; + var startsWord = !isWhitespace(c) && (textState.index === textState._lineStartIndex || isWhitespace(prevChar)); + if (startsWord) { + // Collect full word until next whitespace or control (escape) char + var j = textState.index; + while (j < textState.text.length) { + var ch = textState.text[j]; + if (ch === '\x1b' || ch === '\n' || ch === '\f' || ch === ' ' || ch === '\t') break; + j++; + } + if (j > textState.index) { + var word = textState.text.substring(textState.index, j); + var wordWidth = this.textWidth(word); + var remain = this.contentsWidth() - textState.x; + // If the whole word fits on an empty line but not in the remaining space, + // move it to the next line. If the word itself is wider than the line, + // allow normal mid-word breaking. + if (wordWidth <= this.contentsWidth() && wordWidth > remain) { + // Start new line before the word. Window_Base.processNewLine + // increments textState.index (it assumes a literal '\n' was consumed), + // so decrement it here so the current character isn't skipped. + this.processNewLine(textState); + textState.index--; + // After adjusting index, mark the start of the new line + textState._lineStartIndex = textState.index; + } + } + } + // Default drawing of single character var w = this.textWidth(c); if (textState.x + w > this.contentsWidth()) { + // If still overflows (e.g., long word), break line normally this.processNewLine(textState); textState.index--; + // Reset line start index after manual break + textState._lineStartIndex = textState.index + 1; } Window_Base.prototype.processNormalCharacter.apply(this, arguments); }; + Window_Glossary.prototype.processNewLine = function(textState) { + // Call base implementation then track character index at new line start + Window_Base.prototype.processNewLine.call(this, textState); + textState._lineStartIndex = textState.index; + }; + Window_Glossary.prototype.drawPicture = function(bitmap, text, y) { if (!bitmap) return; var item = this._itemData;