[REQUEST] Plugin to utilize furigana

I was wondering if there is anyone willing to write a plugin to implement furigana in a project that I'm working in Japanese.

For those that don't know what furigana is:

Furigana (Japanese: 振り仮名), often alternatively referred to as ruby text, is a phonetic gloss that appears above the base text (when writing horizontally) or to the right (when writing vertically). It is usually in hiragana and indicates how the base text should be read. For example, a term from a light novel series I'm writing has the base text "古いシステムの解放者", which is normally read as 'furui shisutemu no kaihōsha', but has "システム・リベレータ" which is read as 'shisutemu riberēta', indicating that it should be read as 'System Liberator' instead of 'Liberator of the Old System'. Again this explanation was for those who don't know what furigana is. Now you know.

Now that I've briefly explained what furigana is, I need a plugin that will let me input furigana, especially when introducing new characters.

If anyone doesn't want to take up this request, I perfectly understand.

Many thanks in advance!
Hi, I have made something. However, it is in no way perfect. I am not too experienced in changing the message system yet.
I have only done a few tests and it seem to work. Something to notice is that I have made it so there is more space between each line. This means that 3 lines takes up 4 lines of space.

The plugin is relatively easy to use just add the text code \furi[BASETEXT, FURIGANA] to add the furigana to be above the base text. I hope I have done it right as I am not completely sure about the rules for furigana.

If you encounter any problems with the plugin feel free to message me 🙂

Code:
//=============================================================================
// Furigana
// MRP_Furigana.js
// By Magnus0808 || Magnus Rubin Peterson
//=============================================================================

/*:
 * @plugindesc Adds Furigana Utilization.
 * @author Magnus0808
 *
 * @help Use the Text Code \furi[BASETEXT, FURIGANA] to add the furigana above
 * the base text.
 *
 
 */
 
 var Imported = Imported || {};
 Imported.MRP_Furigana = true;
 
 var MRP = MRP || {};
 MRP.Furigana = MRP.Furigana ||{};
 
(function() {
       
    //-----------------------------------------------------------------------------
    // Window_Base
    //
    // Changes to Window_Base
   
    Window_Base.prototype.processNewLine = function(textState) {
        textState.x = textState.left;
        var arr = /^\n((?!\n).)*(\x1bfuri).*?/.exec(textState.text.slice(textState.index));
        if(arr) {
            textState.y += textState.height * 1.5;          
        } else {
            textState.y += textState.height;      
        }
        textState.height = this.calcTextHeight(textState, false);
       
        textState.index++;
    };
   
    MRP.Furigana.Window_Base_processEscapeCharacter = Window_Base.prototype.processEscapeCharacter;
    Window_Base.prototype.processEscapeCharacter = function(code, textState) {
        console.log("process");
        MRP.Furigana.Window_Base_processEscapeCharacter.call(this, code, textState);
        switch (code) {
        case 'FURI':
            var arr = this.obtainFuriParam(textState);
            var normText = arr[0];
            var furiText = arr[1];
           
            var w = this.textWidth(normText);
           
            this.makeFontSmaller();
            var furiW = this.textWidth(furiText);
            var spaceLength = (w - furiW)/(furiText.length + 1);
           
            var furiStart = textState.x + spaceLength;
            for(var i = 0; i < furiText.length; i++){
                var c = furiText.charAt(i);
                this.contents.drawText(c, furiStart + spaceLength * i, textState.y - textState.height/1.5, w * 2, textState.height);
                furiStart += furiW/furiText.length;
            }
           
            this.makeFontBigger();
            this.contents.drawText(normText, textState.x, textState.y, w * 2, textState.height);
            textState.x += w;
            break;
        }
    };
   
    Window_Base.prototype.obtainFuriParam = function(textState) {
        var arr = /^\[(.+?), *(.+?)\]/.exec(textState.text.slice(textState.index));
        if (arr) {
            textState.index += arr[0].length;
            return arr.slice(1);
        } else {
            return '';
        }
    };
   
    //-----------------------------------------------------------------------------
    // Window_Message
    //
    // Changes to Window_Message
   
    MRP.Furigana.Window_Message_newPage = Window_Message.prototype.newPage
    Window_Message.prototype.newPage = function(textState) {
        MRP.Furigana.Window_Message_newPage.call(this, textState);
        var arr = /^((?!\n).)*(\x1bfuri).*?/.exec(textState.text.slice(textState.index));
        if(arr) {
            textState.y = textState.height * 0.5;          
        } else {
            textState.y = 0;      
        }
    };
   
})();
Unfortunately, I do have a problem.

For some reason that I can't explain, the text code "\furi" isn't doing what you and I hoped it would do. I'll have a screenshot for you shortly.

Spoiler: The screenshot I mentioned.
open

Here's a gander at the event page. The event in question is already highlighted.

Spoiler: Event page
open

[EDIT]
kuso~. How do I keep the images from appearing like they didn't load properly?
Edited 2019/4/17, 07:42 JST.
[/EDIT]

And about the rules for furigana... unfortunately the rules governing it's usage are rather complicated (there are things about it I don't quite understand either, so don't feel bad.) Although, I don't think I can provide an explanation that is easy to understand... sorry.
Hi, I did encounter a bug myself that I am currently trying to fix. (If the furigana is on the first line it does not work correctly).
Could you try to upload the screenshots again? All I can see is IMG
Okay... give me a moment.

Spoiler: Screenshot of the problem
考え物.png

Spoiler: The event in question (the highlighted part is the part giving me the problem)
イベント019.png

I didn't notice the "Upload a file" button, so my bad about that. Hopefully these help😅!?
Okay try it now. I have fixed some bugs. I even made it so it only uses extra space if the next line contains furigana (hopefully that works correctly).
The bug you encounted yourself occured because I forgot to make a regex lazy... so \furi[a, b] \furi[c, d] was seen as a = "a" and b = "b] \furi[c, d"...
Well I have fixed it now. I have updated my original reply
Unfortunately, it still isn't working. I don't know if it's something that we're overlooking or if it's MV being a pain (which I doubt, but is possible), and I even tried it without Yanfly's Message Core turned on.

Spoiler: This problem is not wanting to be fixed, is it?
考え物 (1).png

Spoiler: The event page that I'm using to test it.
イベント019 (1).png

I'm sure this problem is getting on your nerves, being the one actually writing the code (I'm still having trouble with JavaScript myself, I wouldn't know what would be the best way to make a plugin.), while it most certainly getting on my nerves because I'm testing it (not saying you're bad at what you do, because I think you might be better at it than I ever would be (^_^).) I just hope it isn't something we're overlooking...

[EDIT]
Also, you wouldn't mind if I start addressing you as "Magnus-san", would you? I don't want to sound rude or anything of the sort by never referring to you by name. (-san is actually a very common honorific in Japanese; also, referring the person you're speaking with using 'you' often carries a accusatory connotation in Japanese, so sorry if I sounded rude by asking.
Edited 2019/4/17, 09:02 JST
[/EDIT]

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/request-plugin-to-utilize-furigana.108051/