public static Bitmap DrawMap(IEnumerable <WordInRect> words) { var mainRect = LayoutNormalizer.GetMainRect(words); var normalizedWords = LayoutNormalizer.ShiftLayout(words, mainRect); var bitmap = new Bitmap(mainRect.Width, mainRect.Height); var graphics = Graphics.FromImage(bitmap); foreach (var word in normalizedWords) { graphics.DrawString(word.Word, word.Font, Brushes.Magenta, word.Rect, StringFormat.GenericTypographic); } return(bitmap); }
public void CalculateRectangleUnion_WhenPassedRectangleList() { var rects = new List <Rectangle>() { new Rectangle(0, 0, 10, 10), new Rectangle(-10, -10, 10, 10), new Rectangle(10, 0, 10, 10) }; Font font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular, GraphicsUnit.Pixel); var wordsInRects = rects.Select(x => new WordInRect("test", x, font)).ToList(); var expectedRect = new Rectangle(-10, -10, 30, 20); var actualRect = LayoutNormalizer.GetMainRect(wordsInRects); expectedRect.Should().Be(actualRect); }
public void ShiftLayout_WhenMainRectangleIsPassed() { var rects = new List <Rectangle>() { new Rectangle(0, 0, 10, 10), new Rectangle(-10, -10, 10, 10), new Rectangle(10, 0, 10, 10) }; var mainRectangle = new Rectangle(-10, -10, 30, 20); var expectedRects = new List <Rectangle>() { new Rectangle(10, 10, 10, 10), new Rectangle(0, 0, 10, 10), new Rectangle(20, 10, 10, 10) }; var font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular, GraphicsUnit.Pixel); var expectedWordsInRects = expectedRects.Select(x => new WordInRect("test", x, font)).ToList(); var wordsInRects = rects.Select(x => new WordInRect("test", x, font)).ToList(); var actualRects = LayoutNormalizer.ShiftLayout(wordsInRects, mainRectangle); actualRects.ShouldBeEquivalentTo(expectedWordsInRects); }