private Rectangle ShiftRectangleToImageCenter(TagsCloud tagsCloud, Rectangle rectangle, Size imageSize) { var newX = rectangle.X + tagsCloud.Center.X + imageSize.Width / 2; var newY = rectangle.Y + tagsCloud.Center.Y + imageSize.Height / 2; return(new Rectangle(newX, newY, rectangle.Width, rectangle.Height)); }
private Result <None> DrawTags(IImageSettings imageSettings, TagsCloud tagsCloud, Graphics graphics, int tagsCount) { graphics.FillRectangle(new SolidBrush(imageSettings.BackgroundColor), 0, 0, imageSettings.Width, imageSettings.Height); var imageSize = new Size(imageSettings.Width, imageSettings.Height); foreach (var tag in tagsCloud.Tags.Take(tagsCount)) { var shiftedRectangle = ShiftRectangleToImageCenter( tagsCloud, tag.Rectangle, imageSize); if (!RectangleIsInImageRange(shiftedRectangle, imageSize)) { return(Result.Fail <None>("Tag cloud are out of image, enlarge image size or reduce tags count")); } graphics.DrawString(tag.Text, tag.Font, new SolidBrush(imageSettings.ForegroundColor), shiftedRectangle); } return(Result.Ok()); }