From 1cf69361a13d620602c71f0b5d5d26f9176f0cb2 Mon Sep 17 00:00:00 2001 From: fibref Date: Sun, 22 Feb 2026 14:29:10 +0800 Subject: [PATCH] fix MSDF font alignment --- Source/Engine/Render2D/MSDFGenerator.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Render2D/MSDFGenerator.h b/Source/Engine/Render2D/MSDFGenerator.h index 5af337d1f..e1add4dfd 100644 --- a/Source/Engine/Render2D/MSDFGenerator.h +++ b/Source/Engine/Render2D/MSDFGenerator.h @@ -114,10 +114,10 @@ public: int32 width = static_cast(Math::CeilToInt(bounds.r - bounds.l + pxRange)); int32 height = static_cast(Math::CeilToInt(bounds.t - bounds.b + pxRange)); msdfgen::Bitmap msdf(width, height); + + auto transform = msdfgen::Vector2(Math::Ceil(-bounds.l + pxRange / 2.0), Math::Ceil(-bounds.b + pxRange / 2.0)); - msdfgen::SDFTransformation t( - msdfgen::Projection(1.0, msdfgen::Vector2(-bounds.l + pxRange / 2.0, -bounds.b + pxRange / 2.0)), msdfgen::Range(pxRange) - ); + msdfgen::SDFTransformation t(msdfgen::Projection(1.0, transform), msdfgen::Range(pxRange)); correctWinding(shape, bounds); generateMTSDF(msdf, shape, t); @@ -136,7 +136,7 @@ public: } outputWidth = width; outputHeight = height; - top = static_cast(Math::CeilToInt(bounds.t + pxRange / 2.0)); - left = static_cast(Math::FloorToInt(bounds.l - pxRange / 2.0)); + top = height - static_cast(transform.y); + left = -static_cast(transform.x); } };