MV Choice align text + Furigana plugin incompatibility help (addon? alternatives?)

Hello. I have a compatibility problem with some plugins, so I will explain the setup and include a demo folder. I think there are two solutions here... one would be to use a different plugin for one of the features (that's the easy one, if anyone knows such a plugin x'D) and the other would be to make an addon plugin that fixes this (that's the hard one).



I am currently translating my game to Japanese. For that, I'm using Torigoya_TextRuby, a plugin that lets me add furigana. Furigana is small text that is displayed on top of some kanji (Japanese characters), so that the player is able to phonetically read the character. This is helpful for difficult words, or for any word if the player is young (or a Japanese learner, like me). This plugin is non-negotiable, as I've tried looking for alternatives and none work for me (they all have other, different problems).

Since the instructions are in Japanese, I will summarize them here:
Code:
\ruby[kanji](furigana)
This will work in any game message. The example in the demo is this:
Code:
\ruby[猫](ねこ)

Then, I am also using a plugin for changing the alignment of text in choice lists. It is MPP_ChoiceAlign. It's a simple plugin that works with plugin commands: by writing SetChoiceAlign 2 in a command, I can align text to the right. (1 is center, 0 is left). I will note that this problem I'm having happens whether I use the command or not, just by having the plugin ON.

The problem is this: whenever furigana is added to any choice, this little text will appear on the bottom corner of the choice window, as you can see in the image.

Additionally, I am using a plugin I made called BF_Choicelist (included in the demo) that makes each choice's height taller (to account for p, q... in the font and size I'm using in my main project). However, if I turn this plugin off, the problem doesn't go away, so I don't think this is the issue.

In a different project, turning off YEP_MessageCore did "solve" the issue, but that is one of my other essential plugins, and this problem also happened in a fresh project without MessageCore added, so I believe it's best to solve it from this side.


Anyway... as I said, I am open to suggestions to replace that plugin that changes choice text alignment, haha. Back when I found it, I remember searching quite a bit for plugins that had that feature and didn't add anything else. It's fine if they add more things, but only if I can turn them off, as this feature is the only one I need.

The other option is making some sort of addon that could fix this. I tried looking into the code, but I can't understand much of what is happening. Why is furigana appearing double? Also, if you make all options have furigana, they will all appear at the same time in the same place. It's truly a mess.

Here is the demo for whoever feels like looking into it x') (Is it okay to share it as a Google Drive link?)

problem.png
I found the cause of the bug. In rpg_windows.js, line 3907:
JavaScript:
Window_ChoiceList.prototype.textWidthEx = function(text) {
    return this.drawTextEx(text, 0, this.contents.height);
};

Spoiler: Explanation of the incompatibility
So how does your game know how wide "\ruby[猫](ねこ)" is going to turn out? Just like writing in pencil/pen, the only way to find out is your game to draw the entire text to find out the text's final "landing spot". It must process all its escape characters, and it can only draw the text from right to left.

Your game has to draw "\ruby[猫](ねこ)" three times to render your choice message. The first time is done as part of the core scripts to measure the width of every choice option to know how wide the choice option window must be. The second time is done by one of your problem plugins, MPP_ChoiceAlign so that plugin knows how wide each choice option is, so it can then draw the choice option a third time, knowing its true width, and when it draws the entire text, its landing spot is exactly where it is to produce your desired text align.

Why those plugins are not compatible is because when the core scripts draws text to measure text width, it draws it outside of the expected window. Problem is, your Torigoya_TextRuby plugin draws additional stuff on top so when it measures your text width, it accidentally bleeds into the window contents.

So basically your fix would look something like this, to guarantee that the furigana won't bleed into your window:

JavaScript:
Window_ChoiceList.prototype.textWidthEx = function(text) {
    return this.drawTextEx(text, 0, this.contents.height * 2);
};
So basically your fix would look something like this, to guarantee that the furigana won't bleed into your window:

JavaScript:
Window_ChoiceList.prototype.textWidthEx = function(text) {
    return this.drawTextEx(text, 0, this.contents.height * 2);
};
I already replied in Discord (this was discussed in paralell in r/RPGMaker Discord, lol) but I want to thank you here too! It works perfectly, not just in my demo, but also in my other project with all the other plugins. Thank you very much, my life is saved. And so fast, too, whoa. I have to ask more.

Good that it's posted here too, for other people... who may... use these exact two plugins too? Outside of a Japanese forum? I find that pretty unlikely, but you never know XD. This thread can be closed, thank you again.

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/choice-align-text-furigana-plugin-incompatibility-help-addon-alternatives.181341/