Line height of text

Despite numerous discussions about this topic, the answers were not clear and I don't want to necropost. So here goes, please don't hate me if it seems obvious to you.

In available text codes:
\{ Increases the text size by one step.
\} Decreases the text size by one step.
Apparently.

However:
1. does this permanently change the text size or only for that particular Show Text?
2. what if you just want to change the line height separately from the text size?

Well, there was this old solution which seemed sort of like on the right track:

Otherwise, you can copy the default function:
Code:
Window_Base.prototype.standardPadding = function() {
    return 18;
};
paste into a text file, save it as a *.js, and include it as a plugin. Then you change that number in there.

However, this apparently changes all padding and not specifically Y-position of text lines (i.e.; line height). Since it appears CSS-like code may work(?) am I correct in assuming there is something like this available?

Code:
Window_Base.prototype.lineHeight = function() {
    return 36;
};

Thanks for any tips/hints in this matter.
You might want to try this:

Window_Message.prototype.lineHeight = function() {
return 36;
};

If you want to change line height for that specific line, you'll need something else. So what do you want exactly?
1. does this permanently change the text size or only for that particular Show Text?
(ignoring you could really quickly test this 😛 ) All escape codes apply only to that Show Text event command then reset.

2. what if you just want to change the line height separately from the text size?
You can take the code that utunnels provided, paste it into a text editor, save as a *.js file and include as a plugin. Change the number 36 to the number of pixels you want.

You should also be able to do this with some number of already-made plugins, such as Yanfly's Core Engine.

Since it appears CSS-like code may work(?)
RPG Maker MV and MZ use JavaScript.
That code only affects windows size. For example if the text window has for lines, if line height is 72, the window height will be doubled.
However actual text y position is not changed by this. It is decided using the biggest font size of the text.
JavaScript:
Window_Base.prototype.calcTextHeight = function(textState, all) {
    var lastFontSize = this.contents.fontSize;
    var textHeight = 0;
    var lines = textState.text.slice(textState.index).split('\n');
    var maxLines = all ? lines.length : 1;

    for (var i = 0; i < maxLines; i++) {
        var maxFontSize = this.contents.fontSize;
        var regExp = /\x1b[\{\}]/g;
        for (;;) {
            var array = regExp.exec(lines[i]);
            if (array) {
                if (array[0] === '\x1b{') {
                    this.makeFontBigger();
                }
                if (array[0] === '\x1b}') {
                    this.makeFontSmaller();
                }
                if (maxFontSize < this.contents.fontSize) {
                    maxFontSize = this.contents.fontSize;
                }
            } else {
                break;
            }
        }
        textHeight += maxFontSize + 8;
    }

    this.contents.fontSize = lastFontSize;
    return textHeight;
};
(ignoring you could really quickly test this 😛 ) All escape codes apply only to that Show Text event command then reset.
Thank you so much. I cannot always easily boot up Steam/RPGMaker just to test things fast. Then before I am able to do that, I suddenly get some time to search the Internet or post on the forum about a topic I am researching (or asking others to research ha). I appreciate your patient response and information.

As for your latest post utunnels, is that an example script of how it's presently in the engine, or a suggestion on how to modify it (with a plugin)?

If you want to change line height for that specific line, you'll need something else. So what do you want exactly?
What I am trying to accomplish isn't too fancy, I guess. I don't need to have a plugin that changes the line height dynamically based on the font being shown.

However what would be nice is if I decide to do it with escape codes like /{ or /} (only not those, obviously because those are taken) or even with a basic script, I could choose to do so when needed.

For example, if I have to put custom script in the command editor that says

Code:
Window_Message.prototype.lineHeight = function() {
   return 36;
};

before a "normal" Show Text, and then

Code:
Window_Message.prototype.lineHeight = function() {
   return 14;
};

before a "compressed" Show Text, that would be ok.

But of course, I don't want to be too resource intensive. If it's ok to be constantly re-writing that lineHeight function every time a Show Text happens (to be sure that it's always the correct line height no matter which Show Text is called), I guess I can stick with that. But if I can write a brief plugin that parses a shortcode (and it's just the same as re-writing that function over and over, but easier to type in the Show Text command) I guess that's a slight improvement for me only, as I'm building the game.

However, perhaps a more responsible dev question is: is there a better solution for the end user's resources? If re-writing that function each time is "fine" then ok.
Try this. Paste the below into a text editor, save as a *.js file, include as a plugin.

Code:
Window_Message.prototype.calcTextHeight = function(textState, all) {
var lastFontSize = this.contents.fontSize;
var textHeight = 0;
var lines = textState.text.slice(textState.index).split('\n');
var maxLines = all ? lines.length : 1;

for (var i = 0; i < maxLines; i++) {
    var maxFontSize = this.contents.fontSize;
    var regExp = /\x1b[\{\}]/g;
    for (;;) {
        var array = regExp.exec(lines[i]);
            if (array) {
                if (array[0] === '\x1b{')
                    this.makeFontBigger();
                if (array[0] === '\x1b}')
                    this.makeFontSmaller();
                if (maxFontSize < this.contents.fontSize)
                    maxFontSize = this.contents.fontSize;
            }
            else
                break;
    }
// Change the ID on the next line
    textHeight += maxFontSize + $gameVariables.value(2);
}
this.contents.fontSize = lastFontSize;
return textHeight;
};

Change the variable ID on the specified line from 42 to whatever you want. The value of that variable will now be the extra space added between lines of text. Remember that the default is 8.

So you can at any time do Control Variables and change the value of that variable.
Thank you so much! I have now had time to actually run RPGMaker MV and try a bunch of things.

Here's what I found out and what readers should know:

1. I've used VS_SFont to make a nice pixel perfect graphic font. Then GALV's Message Styles which sets a fontSize parameter; setting this once (such as to size 14 for my squatty font) makes everything beautiful. Once. Gamewide. But so much for dynamic changing! Because using \{ and \} on the first line treats the Show Text command as default first, then all following smaller text on the same line doesn't matter. So commands like Show Text:

\}\}\}Trying
to lay out second line
and 3rd line height \^

Results in displays like:

Code:
Trying

to lay out second line
and 3rd line height

If I disable both of these and play around with plugins, the results are like this:

2. \{ and \} still produce the first-line oddity.

3.
Code:
Window_Base.prototype.standardPadding = function() {
    return 14;
};
appears to do nothing.

4.
Code:
Window_Message.prototype.lineHeight = function() {
   return 14;
};
appears to do nothing. (Whereas with GALV's Message Styles plugin activated it seems to cut lines of text in half. Maybe is this because of what utunnels said in post #4 that it doesn't actually change y position and it conflicts with GALV's text handling?)

5. Using the code from post #4 (https://forums.rpgmakerweb.com/index.php?threads/line-height-of-text.173147/post-1480988) appears to do nothing. With or without plugins activated.

6. Using the code from post #6 (https://forums.rpgmakerweb.com/index.php?threads/line-height-of-text.173147/post-1481167) appears to do nothing. With or without plugins activated.

So I guess there's either another plugin somehow messing with things preventing those post #4 and #6 from doing anything. Here is my list of plugins at the moment. The last one is the code from post #6 which I'm turning on and off to play with things.

Conclusion:
This is unsolved. GALV's Message Styles controls line height beautifully, but only for one universal font that cannot dynamically switch. I may have to dig in and attempt to modify the plugin if that's allowed (can't remember, have to check if that's ok with GALV's distribution parameters).

Also, I find it strange that \{ and \} generally are causing the first line to always have a different line height even if every displayed character is smaller than default. Anyone else notice this in their games?
The code not working was simply a misplaced closing bracket - I've corrected it above.

As a tip, when code/a plugin isn't working as expected, a first troubleshooting step should be to press F8 and go to the Console tab - you would've seen an error was preventing the plugin from being loaded.
The code not working was simply a misplaced closing bracket - I've corrected it above.

As a tip, when code/a plugin isn't working as expected, a first troubleshooting step should be to press F8 and go to the Console tab - you would've seen an error was preventing the plugin from being loaded.
Wow, you did it! Awesome sauce. Thank you so much; now my game can have more than one pixel font size with those plugins. Amazing! You solved the crap out of this.

Just for fun I set it to -20 and sure enough it crammed three lines of text into an oblivion with only the bottom line peeking out. This is a powerful little plugin you wrote thanks to your understanding of the game mechanics. Thanks for sharing! And the many tips!

Sorry for the delay; I've hadn't the time to check on it for a bit and I know the forum is sensitive about extraneous posts like "Cool, let me check this out soon" lol

EDIT: Oh, is it alright with you if I credit you in some way?
Sorry for the delay; I've hadn't the time to check on it for a bit and I know the forum is sensitive about extraneous posts like "Cool, let me check this out soon" lol
There's no need to apologize - no one cares if you respond to a thread within a day or whatever 😛

I don't think the "forum is sensitive" so much as it's not really necessary. And then we wouldn't know when you actually tried it unless you double posted.

So I'm glad it worked and you can implement what you wanted. Good luck with your project!
Okay, one thing I found difficult to handle is how the line height change was not making message windows smaller to size. So I decided to try to fix that. And I ended up with code that seems way too complex.

Code:
/*:
 * @plugindesc Custom Message Window Height Plugin
 * @param customFontSize
 * @desc Set the custom font size for the message window.
 * @default 28
 * @help This plugin adjusts the message window height based on a custom font size if no face graphic is requested.
 */

(function() {
    var parameters = PluginManager.parameters('CustomMessageWindowHeight');
    var customFontSize = Number(parameters['customFontSize'] || 28);
    var _Window_Message_fittingHeight = Window_Message.prototype.fittingHeight;

    // Hook into the message setup phase to detect face graphic presence
    var _Game_Message_setFaceImage = Game_Message.prototype.setFaceImage;
    Game_Message.prototype.setFaceImage = function(faceName, faceIndex) {
        this._isFaceGraphicPresent = faceName && faceName !== '';
        _Game_Message_setFaceImage.call(this, faceName, faceIndex);
    };

    // Ensure isFaceGraphicPresent is checked at the start of each message
    var _Window_Message_startMessage = Window_Message.prototype.startMessage;
    Window_Message.prototype.startMessage = function() {
        $gameMessage._isFaceGraphicPresent = $gameMessage.faceName() && $gameMessage.faceName() !== '';
        _Window_Message_startMessage.call(this);
    };

    // fittingHeight toggle between custom font size and core logic
    Window_Message.prototype.fittingHeight = function(numLines) {
        if ($gameMessage._isFaceGraphicPresent) {
            // Use the default fittingHeight if a face graphic is requested
            return _Window_Message_fittingHeight.call(this, numLines);
        } else {
            // Use the custom fittingHeight if no face graphic is requested
            return numLines * customFontSize + $gameVariables.value(100);
        }
    };

    Window_Message.prototype.resetFontSettings = function() {
        this.contents.fontSize = customFontSize;
    };

    // override for ensuring proper handling of face graphics
    var _Window_Message_newPage = Window_Message.prototype.newPage;
    Window_Message.prototype.newPage = function(textState) {
        this.contents.clear();
        this.resetFontSettings();
        this.clearFlags();
        this.loadMessageFace();
        textState.x = this.newLineX();
        textState.y = 0;
        textState.left = this.newLineX();
        textState.height = this.calcTextHeight(textState, false);
        _Window_Message_newPage.call(this, textState);
    };

    // handle face graphic presence and loading
    var _Window_Message_updateLoading = Window_Message.prototype.updateLoading;
    Window_Message.prototype.updateLoading = function() {
        if (this._faceBitmap) {
            if (this._faceBitmap.isReady()) {
                this.drawMessageFace();
                this._faceBitmap = null;
                return false;
            } else {
                return true;
            }
        } else {
            return _Window_Message_updateLoading.call(this);
        }
    };
})();

I know I can solve this with a simple switch that replaces the $gameMessage._isFaceGraphicPresent concept but I am just trying so hard to make it automated so I don't have to choose a "no face" graphic for a Show Text AND turn the switch on before doing so.

All it really needs to do is see that "ah you selected None as a face, I will adjust the line heights" or "you selected a face, I will do the RPGMaker default thing". All I am trying to do is check immediately when a message is called and right now what happens is the _isFaceGraphicPresent gets triggered after the first portrait instead of before.

So the first portrait is shown cut off because it thinks the window is just lines of text. Then the subsequent messages with portraits work properly.

Can anyone help with this?

Original thread: https://forums.rpgmakerweb.com/threads/line-height-of-text.173147/