From 4091fb78c5559b856aa7d4140051aad388caf8c0 Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sat, 21 Feb 2026 15:46:03 +0100 Subject: [PATCH] Center each text line individually when drawing on image Updated text rendering logic to center each line horizontally based on its estimated width, ensuring multi-line text is visually centered. Previously, all lines were drawn at a fixed horizontal position. Both shadow and main text now use the calculated centered position. --- MaddoShared/ImageCreatorAlternate.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/MaddoShared/ImageCreatorAlternate.cs b/MaddoShared/ImageCreatorAlternate.cs index ecbe6ac..476b9be 100644 --- a/MaddoShared/ImageCreatorAlternate.cs +++ b/MaddoShared/ImageCreatorAlternate.cs @@ -271,8 +271,16 @@ public class ImageCreatorAlternate : IImageCreator // Ensure we're drawing inside the canvas vertically if (y + finalFont.Size < 0 || y > working.Height) continue; - ctx.DrawText(line, finalFont, shadowColor, new SixLabors.ImageSharp.PointF(originX + 1, y + 1)); - ctx.DrawText(line, finalFont, textColor, new SixLabors.ImageSharp.PointF(originX, y)); + // Center each line individually so multi-line (vertical) text is justified to center + var approxWidthLine = finalFont.Size * (line?.Length ?? 0) * 0.6f; + if (approxWidthLine > working.Width) + approxWidthLine = working.Width * 0.95f; + + var x = xCenterOfImg - (approxWidthLine / 2f); + x = Math.Max(0, Math.Min(x, working.Width - approxWidthLine)); + + ctx.DrawText(line, finalFont, shadowColor, new SixLabors.ImageSharp.PointF(x + 1, y + 1)); + ctx.DrawText(line, finalFont, textColor, new SixLabors.ImageSharp.PointF(x, y)); } }); }