I noticed that possibly any sort of text, and actor faces, can(!) be extremely blurry sometimes due to non-integer coordinates. It depends on screen resolution, the exact dialog, and it's way more visible when disabling the final canvas scaling smoothing like this (not part of the fix, just to help you look at it if you're curious):
I have managed to fix almost all blurriness with the following plugin code which should also be a helpful guide where in the corescript all these things need to be fixed. This code should be considered public domain, and I would be very happy if the MZ developers looked at this to see how it needs to be fixed. No credit of any kind is required, I just want this fixed for as many games as possible. (Because once you notice how blurry some fonts and faces are, it'll annoy you too!)
It would be really lovely if this could be fixed in the core script. Because I want to play random people's games without blurry fonts! So please take all of this you need, devs anywhere, and make this issue go away.
JavaScript:
/* USE THIS ONLY TO HELP YOU SEE THE ISSUE OF BLURRINESS, NOT MEANT AS A "FIX" / TO BE INTEGRATED */
(() => {
const _orig_Graphics_createCanvas = Graphics._createCanvas;
Graphics._createCanvas = function() {
let result = _orig_Graphics_createCanvas.apply(
this, arguments
);
this._canvas.style["image-rendering"] = "pixelated";
return result;
};
})();
I have managed to fix almost all blurriness with the following plugin code which should also be a helpful guide where in the corescript all these things need to be fixed. This code should be considered public domain, and I would be very happy if the MZ developers looked at this to see how it needs to be fixed. No credit of any kind is required, I just want this fixed for as many games as possible. (Because once you notice how blurry some fonts and faces are, it'll annoy you too!)
JavaScript:
(() => {
Window_Base.prototype.drawFace = function(
faceName, faceIndex, x, y, width, height
) {
// FIX: drawFace doesn't round sx/sy coordinates here,
// which may cause them to be blurry at some sizes.
// This is a copy of the original code with two lines fixed as marked below:
width = width || ImageManager.faceWidth;
height = height || ImageManager.faceHeight;
const bitmap = ImageManager.loadFace(faceName);
const pw = ImageManager.faceWidth;
const ph = ImageManager.faceHeight;
const sw = Math.min(width, pw);
const sh = Math.min(height, ph);
const dx = Math.floor(x + Math.max(width - pw, 0) / 2);
const dy = Math.floor(y + Math.max(height - ph, 0) / 2);
const sx = Math.round((faceIndex % 4) * pw + (pw - sw) / 2); // FIXED.
const sy = Math.round(Math.floor(faceIndex / 4) * ph + (ph - sh) / 2); // FIXED.
this.contents.blt(bitmap, sx, sy, sw, sh, dx, dy);
};
const _Bitmap_measureTextWidth = Bitmap.prototype.measureTextWidth;
Bitmap.prototype.measureTextWidth = function(text) {
// FIX: this function is used in 99% of cases for UI placement.
// Not all UI placement rounds this number before using it,
// which results in lots of corner cases with blurry elements.
// Since nothing seems to rely on it returning the exact float,
// I think this should be changed to just always return rounded ints.
let result = _Bitmap_measureTextWidth.apply(this, arguments);
return Math.round(result);
};
const _orig_Graphics_centerElement = Graphics._centerElement;
Graphics._centerElement = function(element) {
// FIX: canvas element should be sized to rounded
// integers, or all the canvas contents can be extra blurry.
// The original code doesn't ensure this after applying the
// floating point scaler named this._realScale internally.
let result = _orig_Graphics_centerElement.apply(
this, arguments
);
const width = Math.max(0, // FIXED COMPUTATION based on original one
Math.floor(element.width * this._realScale)
);
const height = Math.max(0,
Math.floor(element.height * this._realScale)
);
element.style.width = width + "px";
element.style.height = height + "px";
return result;
};
const _orig_Bitmap_drawText = Bitmap.prototype.drawText;
Bitmap.prototype.drawText = function(text, x, y, maxWidth, lineHeight, align) {
// FIX: force drawText to always draw at integer coordinates!
// The original code will happily draw blurry text at floating
// point coordinates. I think the original function should be changed
// to just always round the coordinates it gets passed.
try {
x = Math.round(x);
y = Math.round(y);
maxWidth = Math.round(maxWidth);
lineHeight = Math.round(lineHeight);
} catch (e) {
//
}
return _orig_Bitmap_drawText.apply(
this, [text, x, y, maxWidth, lineHeight, align]
);
}
Window_MenuStatus.prototype.drawItemStatus = function(index) {
// FIX: drawItemStatus should round the y coordinate, due to the 1.5 float spacer:
const actor = this.actor(index);
const rect = this.itemRect(index);
const x = rect.x + 180;
const y = Math.round( // FIXED
rect.y + rect.height / 2 - this.lineHeight() * 1.5
);
this.drawActorSimpleStatus(actor, x, y);
};
const _orig_Scene_Base_createWindowLayer = (
Scene_Base.prototype.createWindowLayer
);
Scene_Base.prototype.createWindowLayer = function() {
// FIX: windowLayer needs to be on integer coordinates always,
// or all the windows inside will be blurry. The original code
// doesn't ensure this especially with uneven UI area resolutions.
let result = _orig_Scene_Base_createWindowLayer.apply(
this, arguments
);
this._windowLayer.x = Math.round(
(Graphics.width - Graphics.boxWidth) / 2
);
this._windowLayer.y = Math.round(
(Graphics.height - Graphics.boxHeight) / 2
);
return result;
};
const _orig_Scene_Options_optionsWindowRect = (
Scene_Options.prototype.optionsWindowRect
);
Scene_Options.prototype.optionsWindowRect = function() {
// FIX: the options window rect must be integer sized,
// or it will be rendered blurry. The original code doesn't
// ensure this especially with uneven UI area resolutions.
let rect = _orig_Scene_Options_optionsWindowRect.apply(
this, arguments
);
rect.x = Math.round(rect.x);
rect.y = Math.round(rect.y);
rect.width = Math.round(rect.width);
rect.height = Math.round(rect.height);
return rect;
};
})();
It would be really lovely if this could be fixed in the core script. Because I want to play random people's games without blurry fonts! So please take all of this you need, devs anywhere, and make this issue go away.