Improve multi-line text, logo, and version display
- Enhance ImageCreatorAlternate to support multi-line text rendering with correct sizing, spacing, and shadow for each line. - Only draw logos on non-thumbnail images to match GDI behavior. - Add a status bar to MainWindow showing the app version at runtime. - Upgrade MinVer to 7.0.0 and adjust versioning to avoid WPF/XAML assembly identity issues. - Refactor XAML layout to accommodate the new status bar.
This commit is contained in:
parent
8db7ee8075
commit
f4893a39e9
4 changed files with 70 additions and 23 deletions
|
|
@ -171,15 +171,22 @@ public class ImageCreatorAlternate : IImageCreator
|
|||
var maxTextWidth = working.Width * 0.95f;
|
||||
var maxTextHeight = working.Height * 0.15f;
|
||||
|
||||
var chosenSize = FindBestFontSize(text, font.Name, Math.Max(6, baseSize), maxTextWidth, maxTextHeight);
|
||||
// Support multi-line text: measure using the longest line when choosing font size
|
||||
var normalizedText = text.Replace("\r", string.Empty);
|
||||
var lines = normalizedText.Split(new[] { '\n' }, StringSplitOptions.None);
|
||||
var longestLine = lines.OrderByDescending(l => l.Length).FirstOrDefault() ?? string.Empty;
|
||||
|
||||
var chosenSize = FindBestFontSize(longestLine, font.Name, Math.Max(6, baseSize), maxTextWidth, maxTextHeight);
|
||||
|
||||
// Use final font
|
||||
var finalFont = SixLabors.Fonts.SystemFonts.CreateFont(font.Name, chosenSize);
|
||||
if (!isThumbnail) imgState.DimensioneStandard = (int)Math.Round(chosenSize);
|
||||
|
||||
// Approximate measured size since TextMeasurer/RendererOptions may not be available in this Fonts version
|
||||
var approxWidth = finalFont.Size * text.Length * 0.6f;
|
||||
var approxHeight = finalFont.Size * 1.0f;
|
||||
var approxWidth = finalFont.Size * longestLine.Length * 0.6f;
|
||||
// Account for multiple lines: height = font size * lineCount * lineSpacing
|
||||
var lineSpacing = 1.1f; // small extra spacing between lines
|
||||
var approxHeight = finalFont.Size * lines.Length * lineSpacing;
|
||||
|
||||
// Compute horizontal position based on alignment
|
||||
float xCenterOfImg;
|
||||
|
|
@ -228,16 +235,26 @@ public class ImageCreatorAlternate : IImageCreator
|
|||
originX = Math.Max(0, Math.Min(originX, working.Width - approxWidth));
|
||||
originY = Math.Max(0, Math.Min(originY, working.Height - approxHeight));
|
||||
|
||||
// Draw shadow then text
|
||||
// Draw shadow then text; handle multiple lines
|
||||
var lineHeight = finalFont.Size * lineSpacing;
|
||||
working.Mutate(ctx =>
|
||||
{
|
||||
ctx.DrawText(text, finalFont, shadowColor, new SixLabors.ImageSharp.PointF(originX + 1, originY + 1));
|
||||
ctx.DrawText(text, finalFont, textColor, new SixLabors.ImageSharp.PointF(originX, originY));
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
var line = lines[i];
|
||||
var y = originY + i * lineHeight;
|
||||
// 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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Draw logo if provided
|
||||
if (logo != null && _picSettings.LogoAggiungi)
|
||||
// Draw logo if provided. For compatibility with the original GDI implementation,
|
||||
// do not draw the logo on thumbnails (ImageCreatorSharp only draws logos on big images).
|
||||
if (logo != null && _picSettings.LogoAggiungi && !isThumbnail)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue