MZ Font Bigger / Smaller Escape Characters

Greetings, cadets-

I wonder if somebody could point me to the area in the code where the Escape Characters for making the Show Text command font bigger and smaller (\{ and \}, respectively) is actually removed from the string?

I looked at Window_Base.prototype.convertEscapeCharacters:
Window_Base.prototype.convertEscapeCharacters.png


and Window_Base.prototype.maxFontSizeInLine:
Window_Base.prototype.maxFontSizeInLine.png


But I don't see a /\x1b({|})/gi regex in .convertEscapeCharacters and while there is a /\x1b({|}|FS)(\[(\d+)])?/gi regex in .maxFontSizeInLine, it seems to be executing it to extract information to accomplish the font size change and not altering the source string?

I did a search for "
\x1b({|}" throughout the core scripts and that only resulted in .maxFontSizeInLine... so if anybody is the wiser I would appreciate the help.

Thanks and have a good rest of the weekend!
Hi there!

This happens when the Window is processing the text.

Spoiler: Short Explanation
JavaScript:
Window_Base.prototype.obtainEscapeParam = function(textState) {
    const regExp = /^\[\d+\]/;
    const arr = regExp.exec(textState.text.slice(textState.index)); // HERE
    if (arr) {
        textState.index += arr[0].length;
        return parseInt(arr[0].slice(1));
    } else {
        return "";
    }
};

Spoiler: Long Explanation:
At first, the Window creates the text state where it converts all escape characters:

JavaScript:
Window_Base.prototype.drawTextEx = function(text, x, y, width) {
    this.resetFontSettings();
    const textState = this.createTextState(text, x, y, width); // CREATE TEXTSTATE
    this.processAllText(textState); // PROCESS ALL TEXT
    return textState.outputWidth;
};

Window_Base.prototype.createTextState = function(text, x, y, width) {
    const rtl = Utils.containsArabic(text);
    const textState = {};
    textState.text = this.convertEscapeCharacters(text); // CONVERT CHARACTERS!!!
    textState.index = 0;
    textState.x = rtl ? x + width : x;
    textState.y = y;
    textState.width = width;
    textState.height = this.calcTextHeight(textState);
    textState.startX = textState.x;
    textState.startY = textState.y;
    textState.rtl = rtl;
    textState.buffer = this.createTextBuffer(rtl);
    textState.drawing = true;
    textState.outputWidth = 0;
    textState.outputHeight = 0;
    return textState;
};

Then, in the "this.processAllText", it goes in the "path" to process the escape codes like the "make font bigger/smaller":

JavaScript:
Window_Base.prototype.processAllText = function(textState) {
    while (textState.index < textState.text.length) {
        this.processCharacter(textState); // PROCESS CHARACTER
    }
    this.flushTextState(textState);
};

Window_Base.prototype.processCharacter = function(textState) {
    const c = textState.text[textState.index++];
    if (c.charCodeAt(0) < 0x20) {
        this.flushTextState(textState);
        this.processControlCharacter(textState, c); // PROCESS CONTROL CHARACTER
    } else {
        textState.buffer += c;
    }
};

Window_Base.prototype.processControlCharacter = function(textState, c) {
    if (c === "\n") {
        this.processNewLine(textState);
    }
    if (c === "\x1b") {
        const code = this.obtainEscapeCode(textState); // GET THE ESCAPE CODE
        this.processEscapeCharacter(code, textState); // PROCESS ESCAPE CODE (MAKE FONT BIGGER/SMALLER)
    }
};

Window_Base.prototype.obtainEscapeCode = function(textState) {
    const regExp = /^[$.|^!><{}\\]|^[A-Z]+/i;
    const arr = regExp.exec(textState.text.slice(textState.index));
    if (arr) {
        textState.index += arr[0].length;
        return arr[0].toUpperCase();
    } else {
        return "";
    }
};

Window_Base.prototype.processEscapeCharacter = function(code, textState) {
    switch (code) {
        case "C":
            this.processColorChange(this.obtainEscapeParam(textState));
            break;
        case "I":
            this.processDrawIcon(this.obtainEscapeParam(textState), textState);
            break;
        case "PX":
            textState.x = this.obtainEscapeParam(textState);
            break;
        case "PY":
            textState.y = this.obtainEscapeParam(textState);
            break;
        case "FS":
            this.contents.fontSize = this.obtainEscapeParam(textState);
            break;
        case "{":
            this.makeFontBigger();
            break;
        case "}":
            this.makeFontSmaller();
            break;
    }
};
I wonder if somebody could point me to the area in the code where the Escape Characters for making the Show Text command font bigger and smaller (\{ and \}, respectively) is actually removed from the string?
The difference between convertEscapeCharacter and processAllText is that converting characters is done at the beginning of the process. \V[20], \N[10] could be easily converted into string, while \{, \} needs to be removed during the runtime. So you are not going to find them in a similar manner.

If you look at the code pasted by Eliaquim.
When the system found an escape code, it simply did not register it to the textState.buffer so it won't print that particular code.

To put it simply, the workflow is like
  • Get text (from eventing)
  • Convert escape characters that could be converted into text right away (names, variables, etc)
  • "Let's see each character"
  • If <no escape cound found, yet> --> Add to buffer
  • If <escape code found> --> "Wow, hold up! lemme print all the letters I put em in the buffer first" -> Evaluate the escape code (make font bigger/smaller, pause, etc), but do not add it to the buffer.
  • Continue until it completes the evaluation.
This is the workflow for drawTextEx in Window_Base.
If you're looking at how Window_Message prints each character sequentially, then it is another story.
@Eliaquim and @TheoAllen- thank you for the explanation, the process makes much more sense now!

I was implementing my own Window_SpeechBubble and DialogueBitmap classes to replace Window_Message and Bitmap for my project's dialogue system and running into problems with empty strings being passed to the DialogueBitmap drawText function where the Font Bigger / Smaller Escape Characters were, and thanks to your help I realized that I could remedy the problem by injecting some code into the flushTextState function.

Thank you again!

Original thread: https://forums.rpgmakerweb.com/threads/font-bigger-smaller-escape-characters.141911/