Exemplo n.º 1
0
 public void PutNextRectangle_ShouldReturnRectangleWithSameSize_WhenSomeSizesAdded()
 {
     foreach (var size in SizesGenerator.GenerateSizes(5, minSize, maxSize, seed:128))
     {
         layouter.PutNextRectangle(size).GetValueOrThrow().Size.Should().BeEquivalentTo(size);
     }
 }
Exemplo n.º 2
0
 public void UseRectangleLayouter_ForPuttingWords()
 {
     var words = new[] {new MeasuredWord("a", 5), new MeasuredWord("b", 1), new MeasuredWord("c", 3)};
     layouter.CreateCloud(words);
     A.CallTo(() => rectLayouter.PutNextRectangle(A<Size>.Ignored))
         .MustHaveHappened(Repeated.Exactly.Times(words.Length));
 }
Exemplo n.º 3
0
        private void DrawTag(TagInfo tag)
        {
            var font = GetFont(tag);
            var occupiedRectangle = layouter.PutNextRectangle(MeasureStringSize(tag.Value, font));

            FillRectangle(occupiedRectangle, settings.ForegroundColor);
            DrawString(tag.Value, font, occupiedRectangle.Location, GetFontColor());
        }
 private static void FillLayoutWithSomeRectangles(IRectangleLayouter layouter,
                                                  IEnumerable <Size> rectangleSizes)
 {
     foreach (var size in rectangleSizes)
     {
         layouter.PutNextRectangle(size);
     }
 }
Exemplo n.º 5
0
        private Result <WordImageInfo> GetImageInfo(FontFamily fontFamily, int fontMultiplier, WordInfo wordInfo)
        {
            var font   = new Font(fontFamily, wordInfo.Occurrences * fontMultiplier);
            var size   = TextRenderer.MeasureText(wordInfo.Word, font);
            var result = rectangleLayouter.PutNextRectangle(size);

            return(result
                   .Then(rectangle => new WordImageInfo(wordInfo.Word, font, rectangle, wordInfo.Frequency)));
        }
Exemplo n.º 6
0
        private Tag GetNextTag(WeightedWord weightedWord, int minWeight, int maxWeight)
        {
            var fontSize  = GetFontSize(weightedWord.Weight, minWeight, maxWeight);
            var font      = new Font(fontSettings.FontFamily, fontSize);
            var frameSize = TextRenderer.MeasureText(weightedWord.Word, font);
            var frame     = rectangleLayouter.PutNextRectangle(frameSize);

            return(new Tag(weightedWord.Word, frame, font));
        }
Exemplo n.º 7
0
        private static List <Rectangle> FillLayoutWithSomeRectangles(IRectangleLayouter layouter,
                                                                     IEnumerable <Size> rectangleSizes)
        {
            var result = new List <Rectangle>();

            foreach (var size in rectangleSizes)
            {
                result.Add(layouter.PutNextRectangle(size).GetValueOrThrow());
            }
            return(result);
        }
Exemplo n.º 8
0
 private Result <None> PlaceAndDrawTag(TagInfo tag, Font font)
 {
     return(layouter
            .PutNextRectangle(MeasureStringSize(tag.Value, font))
            .Then(FitRectangleInBorders)
            .Then(rectangle =>
     {
         FillRectangle(rectangle, settings.ForegroundColor);
         DrawString(tag.Value, font, rectangle.Location, GetFontColor());
     }));
 }
Exemplo n.º 9
0
 public void DrawWords(Graphics graphics, IEnumerable <CloudTag> words, IRectangleLayouter layouter)
 {
     graphics.Clear(config.BackgroundColor);
     foreach (var word in words)
     {
         var wordFontSize = Math.Max(10, (int)(config.Font.Size * word.Weight));
         var font         = new Font(config.Font.FontFamily, wordFontSize);
         var size         = TextRenderer.MeasureText(word.Text, font);
         var area         = layouter.PutNextRectangle(size);
         graphics.DrawString(word.Text, font, config.Brush, area);
     }
 }
Exemplo n.º 10
0
        public ITagsCloud CreateCloud(IEnumerable <MeasuredWord> measuredWords)
        {
            var wordsArray = measuredWords as MeasuredWord[] ?? measuredWords.ToArray();
            var maxWeight  = wordsArray.Max(w => w.Weight);

            return(new TagsCloud(wordsArray.Select(word =>
            {
                var font = new Font(fontSettings.FontFamily, CalcFontSize(word.Weight, maxWeight, fontSettings));
                var size = TextRenderer.MeasureText(word.Value, font);
                var rect = layouter.PutNextRectangle(size);
                return new Tag(rect, word.Value, font);
            })));
        }
Exemplo n.º 11
0
        public Image Create(TagsCloudSettings settings)
        {
            var words = processors.Aggregate(wordReader.ReadAllWords(settings.WordsPath),
                                             (current, processor) => processor.Process(current)).ToArray();
            var tags = WordCounter.Count(words)
                       .Select(word =>
            {
                var(font, size) = wordMeasurer.Measure(word);
                return(new Tag(word.Value, font, layouter.PutNextRectangle(size)));
            })
                       .ToArray();

            return(visualizer.Visualize(painter.Colorize(tags)));
        }
Exemplo n.º 12
0
        private Bitmap Visualize(Dictionary <string, int> tags)
        {
            var drawer = Graphics.FromImage(tagCloud);

            drawer.Clear(cloudDesign.BackgroundColor);

            foreach (var tag in tags)
            {
                var word      = tag.Key;
                var weight    = tag.Value;
                var font      = cloudDesign.GetFont(weight);
                var textSize  = Size.Ceiling(drawer.MeasureString(word, font));
                var rectangle = layouter.PutNextRectangle(textSize);
                var br        = cloudDesign.GetStringBrush();
                drawer.DrawString(word, font, br, rectangle);
            }

            return(tagCloud);
        }
Exemplo n.º 13
0
 private Result <Tag> CreateTag(Word word)
 {
     return(wordMeasurer.Measure(word)
            .SelectMany(tuple => layouter.PutNextRectangle(tuple.size),
                        (tuple, rectangle) => new Tag(word.Value, tuple.font, rectangle)));
 }