diff --git a/src/ImageProcessor/Processors/Watermark.cs b/src/ImageProcessor/Processors/Watermark.cs index f5900fde9..25b449987 100644 --- a/src/ImageProcessor/Processors/Watermark.cs +++ b/src/ImageProcessor/Processors/Watermark.cs @@ -24,50 +24,50 @@ namespace ImageProcessor.Processors /// public class Watermark : IGraphicsProcessor { -/// -/// The regular expression to search strings for. -/// -private static readonly Regex QueryRegex = new Regex(@"watermark=[^&]*", RegexOptions.Compiled); - -/// -/// The regular expression to search strings for the text attribute. -/// -private static readonly Regex TextRegex = new Regex(@"text-[^/:?#\[\]@!$&'()*%\|,;=]+", RegexOptions.Compiled); - -/// -/// The regular expression to search strings for the position attribute. -/// -private static readonly Regex PositionRegex = new Regex(@"position-\d+-\d+", RegexOptions.Compiled); - -/// -/// The regular expression to search strings for the color attribute. -/// -private static readonly Regex ColorRegex = new Regex(@"color-([0-9a-fA-F]{3}){1,2}", RegexOptions.Compiled); - -/// -/// The regular expression to search strings for the font size attribute. -/// -private static readonly Regex FontSizeRegex = new Regex(@"size-\d{1,3}", RegexOptions.Compiled); - -/// -/// The regular expression to search strings for the font style attribute. -/// -private static readonly Regex FontStyleRegex = new Regex(@"style-(bold|italic|regular|strikeout|underline)", RegexOptions.Compiled); - -/// -/// The regular expression to search strings for the font family attribute. -/// -private static readonly Regex FontFamilyRegex = new Regex(@"font-[^/:?#\[\]@!$&'()*%\|,;=0-9]+", RegexOptions.Compiled); - -/// -/// The regular expression to search strings for the opacity attribute. -/// -private static readonly Regex OpacityRegex = new Regex(@"opacity-(?:100|[1-9]?[0-9])", RegexOptions.Compiled); - -/// -/// The regular expression to search strings for the shadow attribute. -/// -private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptions.Compiled); + /// + /// The regular expression to search strings for. + /// + private static readonly Regex QueryRegex = new Regex(@"watermark=[^&]*", RegexOptions.Compiled); + + /// + /// The regular expression to search strings for the text attribute. + /// + private static readonly Regex TextRegex = new Regex(@"text-[^/:?#\[\]@!$&'()*%\|,;=]+", RegexOptions.Compiled); + + /// + /// The regular expression to search strings for the position attribute. + /// + private static readonly Regex PositionRegex = new Regex(@"position-\d+-\d+", RegexOptions.Compiled); + + /// + /// The regular expression to search strings for the color attribute. + /// + private static readonly Regex ColorRegex = new Regex(@"color-([0-9a-fA-F]{3}){1,2}", RegexOptions.Compiled); + + /// + /// The regular expression to search strings for the font size attribute. + /// + private static readonly Regex FontSizeRegex = new Regex(@"size-\d{1,3}", RegexOptions.Compiled); + + /// + /// The regular expression to search strings for the font style attribute. + /// + private static readonly Regex FontStyleRegex = new Regex(@"style-(bold|italic|regular|strikeout|underline)", RegexOptions.Compiled); + + /// + /// The regular expression to search strings for the font family attribute. + /// + private static readonly Regex FontFamilyRegex = new Regex(@"font-[^/:?#\[\]@!$&'()*%\|,;=0-9]+", RegexOptions.Compiled); + + /// + /// The regular expression to search strings for the opacity attribute. + /// + private static readonly Regex OpacityRegex = new Regex(@"opacity-(?:100|[1-9]?[0-9])", RegexOptions.Compiled); + + /// + /// The regular expression to search strings for the shadow attribute. + /// + private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptions.Compiled); #region IGraphicsProcessor Members /// @@ -173,7 +173,7 @@ private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptio try { - // Dont use an object initializer here. + // Don't use an object initializer here. newImage = new Bitmap(image); newImage.Tag = image.Tag; @@ -193,12 +193,12 @@ private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptio { Point origin = textLayer.Position; + // Work out the size of the text. + SizeF textSize = graphics.MeasureString(text, font, new SizeF(image.Width, image.Height), drawFormat); + // We need to ensure that there is a position set for the watermark if (origin == Point.Empty) { - // Work out the size of the text. - SizeF textSize = graphics.MeasureString(text, font, new SizeF(image.Width, image.Height), drawFormat); - int x = (int)(image.Width - textSize.Width) / 2; int y = (int)(image.Height - textSize.Height) / 2; origin = new Point(x, y); @@ -207,6 +207,9 @@ private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptio // Set the hinting and draw the text. graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; + // Create bounds for the text. + RectangleF bounds; + if (textLayer.DropShadow) { // Shadow opacity should change with the base opacity. @@ -219,11 +222,18 @@ private static readonly Regex ShadowRegex = new Regex(@"shadow-true", RegexOptio // Magic number but it's based on artistic preference. int shadowDiff = (int)Math.Ceiling(fontSize / 24f); Point shadowPoint = new Point(origin.X + shadowDiff, origin.Y + shadowDiff); - graphics.DrawString(text, font, shadowBrush, shadowPoint, drawFormat); + + // Set the bounds so any overlapping text will wrap. + bounds = new RectangleF(shadowPoint, new SizeF(image.Width - shadowPoint.X, image.Height - shadowPoint.Y)); + + graphics.DrawString(text, font, shadowBrush, bounds, drawFormat); } } - graphics.DrawString(text, font, brush, origin, drawFormat); + // Set the bounds so any overlapping text will wrap. + bounds = new RectangleF(origin, new SizeF(image.Width - origin.X, image.Height - origin.Y)); + + graphics.DrawString(text, font, brush, bounds, drawFormat); } } } diff --git a/src/ImageProcessor/Properties/AssemblyInfo.cs b/src/ImageProcessor/Properties/AssemblyInfo.cs index 68075c37d..7e9e403f3 100644 --- a/src/ImageProcessor/Properties/AssemblyInfo.cs +++ b/src/ImageProcessor/Properties/AssemblyInfo.cs @@ -32,6 +32,6 @@ using System.Security; // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.7.0.1")] -[assembly: AssemblyFileVersion("1.7.0.1")] +[assembly: AssemblyVersion("1.7.0.2")] +[assembly: AssemblyFileVersion("1.7.0.2")] diff --git a/src/Nuget/ImageProcessor.1.7.0.2.nupkg b/src/Nuget/ImageProcessor.1.7.0.2.nupkg new file mode 100644 index 000000000..7d0ffca1c Binary files /dev/null and b/src/Nuget/ImageProcessor.1.7.0.2.nupkg differ diff --git a/src/Nuget/imageprocessor.128.png b/src/Nuget/imageprocessor.128.png index 0cea636f8..cd6f911c9 100644 --- a/src/Nuget/imageprocessor.128.png +++ b/src/Nuget/imageprocessor.128.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:594e72bfc3c1804871e083684e8927f92b9619c5b42855b8a530556ce037d356 -size 5724 +oid sha256:d4e936585d0857f7c38a3c70e9dd5d2414a84af39db30b0be698bc151d7a9225 +size 6510 diff --git a/src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml b/src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml index 2efa21511..d80616784 100644 --- a/src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml +++ b/src/TestWebsites/NET45/Test_Website_NET45/Views/Home/Index.cshtml @@ -70,7 +70,7 @@

Watermark

- +

Format