Beispiel #1
0
        public Result <None> RenderIntoFile(ImageSettings imageSettings, IColorManager colorManager,
                                            ITagsCloud tagsCloud)
        {
            if (imageSettings.AutoSize)
            {
                return(RenderIntoFileAutoSize(imageSettings, colorManager, tagsCloud));
            }


            var wordsColors = colorManager.GetWordsColors(tagsCloud.AddedWords.ToList());


            var btm = new Bitmap(imageSettings.ImageSize.Width, imageSettings.ImageSize.Height);

            using (var obj = Graphics.FromImage(btm))
            {
                foreach (var tagsCloudWord in tagsCloud.AddedWords)
                {
                    DrawWord(obj, tagsCloudWord, wordsColors[tagsCloudWord], FontFamily.GenericMonospace);
                }

                btm.Save(imageSettings.OutputPath);
            }

            return(CheckCloudPlaceability(tagsCloud, imageSettings.ImageSize).RefineError("Rendering error"));
        }
Beispiel #2
0
        private Result <None> RenderIntoFileAutoSize(ImageSettings imageSettings, IColorManager colorManager,
                                                     ITagsCloud tagsCloud)
        {
            var words             = tagsCloud.AddedWords.Select(x => x.Word).ToList();
            var shiftedRectangles =
                ShiftRectanglesToMainQuarter(tagsCloud.AddedWords.Select(x => x.Rectangle).ToList());
            var tagsCloudWords = words.Zip(shiftedRectangles, (word, rectangle) => (new TagsCloudWord(word, rectangle)))
                                 .ToList();
            var tagsCloudToDraw = new TagsCloud(tagsCloudWords);
            var wordsColors     = colorManager.GetWordsColors(tagsCloudToDraw.AddedWords.ToList());

            var pictureSize = GetPictureSize(tagsCloudToDraw);

            var btm = new Bitmap(pictureSize.Width, pictureSize.Height);

            using (var obj = Graphics.FromImage(btm))
            {
                foreach (var tagsCloudWord in tagsCloudToDraw.AddedWords)
                {
                    DrawWord(obj, tagsCloudWord, wordsColors[tagsCloudWord], FontFamily.GenericMonospace);
                }

                btm.Save(imageSettings.OutputPath);
            }

            return(new Result <None>());
        }
Beispiel #3
0
        public CircularCloudLayouter(Point center)
        {
            TagsCloud = new TagsCloud(center);
            const double coefficients   = 0.5;
            const double spiralStep     = 0.05;
            var          geometryObject = new ArchimedeanSpiral(center, coefficients, spiralStep);

            geometryEnumerator = geometryObject.GetEnumerator();
        }
Beispiel #4
0
 public CircularCloudLayouter(Point center)
 {
     if (center.X < 0 || center.Y < 0)
     {
         throw new ArgumentException("Coordinates of the center must be positive numbers");
     }
     this.center     = center;
     spiralGenerator = new SpiralGenerator(this.center);
     TagsCloud       = new TagCloud();
 }
Beispiel #5
0
        private Result <None> CheckCloudPlaceability(ITagsCloud tagsCloud, Size imageSize)
        {
            if (tagsCloud.AddedWords.Select(x => x.Rectangle).Any(x => IsInside(x.Location, imageSize)))
            {
                return(Result.Fail <None>(
                           $"The cloud does not fit in the image with size {imageSize.Width}x{imageSize.Height}"));
            }

            return(new Result <None>());
        }
Beispiel #6
0
        public void RenderIntoFile(string filePath, ITagsCloud tagsCloud, Size pictureSize)
        {
            var btm = new Bitmap(pictureSize.Width, pictureSize.Height);
            var obj = Graphics.FromImage(btm);

            foreach (var r in tagsCloud.AddedRectangles)
            {
                obj.DrawRectangle(new Pen(Color.Brown), r);
            }

            btm.Save(filePath);
        }
Beispiel #7
0
        public void RenderIntoFile(string filePath, ITagsCloud tagsCloud)
        {
            var shiftedRectangles = ShiftRectanglesToMainQuarter(tagsCloud.AddedRectangles);
            var tagCloudToDraw    = new TagsCloud(tagsCloud.Center, shiftedRectangles);
            var pictureSize       = GetPictureSize(tagCloudToDraw);
            var btm = new Bitmap(pictureSize.Width, pictureSize.Height);
            var obj = Graphics.FromImage(btm);

            foreach (var r in tagCloudToDraw.AddedRectangles)
            {
                obj.DrawRectangle(new Pen(Color.Brown), r);
            }

            btm.Save(filePath);
        }
Beispiel #8
0
        private Size GetPictureSize(ITagsCloud tagsCloud)
        {
            var rectangles = tagsCloud.AddedWords.Select(x => x.Rectangle).ToList();
            var maxX       = rectangles.Max(x => x.Right);
            var minX       = rectangles.Min(x => x.X);
            var maxY       = rectangles.Max(x => x.Top);
            var minY       = rectangles.Min(x => x.Bottom);

            if (minY < 0 || minX < 0)
            {
                throw new ArgumentException("Rectangles must have positive coordinates");
            }

            return(new Size(maxX - minX + Math.Abs(minX * 2),
                            maxY - minY + Math.Abs(minY * 2)));
        }
Beispiel #9
0
        public Bitmap Render(ITagsCloud cloud)
        {
            var bitmap = new Bitmap(Settings.Width, Settings.Height);

            using (var graphics = Graphics.FromImage(bitmap))
            {
                graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                foreach (var tag in cloud.Tags)
                {
                    graphics.DrawRectangle(new Pen(Settings.Palette.SecondaryColor), tag.Rectangle);
                    var boundingRect = new Rectangle(tag.Rectangle.Location,
                                                     tag.Rectangle.Size + new Size(Settings.BorderSize, Settings.BorderSize));
                    graphics.DrawString(tag.Word, tag.Font, new SolidBrush(Settings.Palette.PrimaryColor), boundingRect);
                }
            }
            return(bitmap);
        }
Beispiel #10
0
        public CircularCloudLayouter(ITagsCloud tagsCloud)
        {
            if (!tagsCloud.Rectangles.Any())
            {
                throw new ArgumentException("Tags cloud could not be empty");
            }

            var firstRectangle = tagsCloud.Rectangles.First();

            var firstRectangleCenter = firstRectangle.GetRectangleCenter();

            if (firstRectangleCenter.X < 0 || firstRectangleCenter.Y < 0)
            {
                throw new ArgumentException("Coordinates of the center must be positive numbers");
            }
            this.center     = firstRectangleCenter;
            this.TagsCloud  = tagsCloud;
            spiralGenerator = new SpiralGenerator(this.center);
        }
Beispiel #11
0
        public void RenderIntoFile(ImageSettings imageSettings, IColorManager colorManager, ITagsCloud tagsCloud)
        {
            if (imageSettings.AutoSize)
            {
                RenderIntoFileAutoSize(imageSettings, colorManager, tagsCloud);
                return;
            }

            var wordsColors = colorManager.GetWordsColors(tagsCloud.AddedWords.ToList());


            var btm = new Bitmap(imageSettings.ImageSize.Width, imageSettings.ImageSize.Height);

            using (var obj = Graphics.FromImage(btm))
            {
                foreach (var tagsCloudWord in tagsCloud.AddedWords)
                {
                    DrawWord(obj, tagsCloudWord, wordsColors[tagsCloudWord], FontFamily.GenericMonospace);
                }

                btm.Save(imageSettings.OutputPath);
            }
        }