From e9d12dbe4e85d167869a16e99cdc4b72c3ce53ef Mon Sep 17 00:00:00 2001 From: Robin Krom Date: Tue, 23 Mar 2021 09:05:46 +0100 Subject: [PATCH] When moving from graphics.DrawString to TextRenderer.DrawText, to fix #283, the line wrapping was broken. This should fix it. (#297) --- Greenshot/Drawing/TextContainer.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Greenshot/Drawing/TextContainer.cs b/Greenshot/Drawing/TextContainer.cs index fda883f16..9d3838580 100644 --- a/Greenshot/Drawing/TextContainer.cs +++ b/Greenshot/Drawing/TextContainer.cs @@ -598,9 +598,15 @@ namespace Greenshot.Drawing DrawText(graphics, rect, lineThickness, lineColor, drawShadow, _stringFormat, text, _font); } + /// + /// Convert the StringFormat information into a TextFormatFlags + /// This is important for the rending to work, have it aligned to the correct place + /// + /// StringFormat + /// TextFormatFlags private static TextFormatFlags ConvertStringFormat(StringFormat stringFormat) { - TextFormatFlags flags = TextFormatFlags.Default; + var flags = TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak; if (stringFormat == null) { return flags; @@ -683,14 +689,7 @@ namespace Greenshot.Drawing drawingRectange.Inflate(-textOffset, -textOffset); } - if (stringFormat != null) - { - TextRenderer.DrawText(graphics, text, font, drawingRectange, fontColor, ConvertStringFormat(stringFormat)); - } - else - { - TextRenderer.DrawText(graphics, text, font, drawingRectange, fontColor); - } + TextRenderer.DrawText(graphics, text, font, drawingRectange, fontColor, ConvertStringFormat(stringFormat)); } public override bool ClickableAt(int x, int y)