public IList<WordIntPair> GetFontSizes(IList<WordIntPair> wordsAndFreqs, InputOptions options) { int minCount = wordsAndFreqs.Min(t => t.Number); int maxCount = wordsAndFreqs.Max(t => t.Number); return wordsAndFreqs.Select(tuple => new WordIntPair( tuple.Word, CountFont(tuple.Number, options.MaxFont, options.MinFont, minCount, maxCount))) .ToList(); }
private static void DrawTextOnBitmap(System.Drawing.Bitmap objBmpImage, Graphics objGraphics, string text, Font objFont, InputOptions options) { objGraphics = Graphics.FromImage(objBmpImage); objGraphics.Clear(ColorTranslator.FromHtml(options.BackgroundColor)); objGraphics.SmoothingMode = SmoothingMode.AntiAlias; objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias; objGraphics.DrawString(text, objFont, new SolidBrush(ColorTranslator.FromHtml(options.TextColor)), 0, 0); objGraphics.Flush(); }
public override System.Drawing.Bitmap GetBitmap(IList<WordIntPair> fonts, InputOptions options) { var textImages = BitmapMethods.GetTextImages(fonts, options).ToList(); CountVariables(textImages); var resultImage = new System.Drawing.Bitmap( sumWidth, maxHeight); FillBackgroundColor(resultImage, options.BackgroundColor); FillImagesWithWordsImages(resultImage, textImages); return BitmapMethods.ResizeImage(resultImage, options.Width, options.Height); }
public static System.Drawing.Bitmap CreateBitmapImage(string text, int size, InputOptions options) { System.Drawing.Bitmap objBmpImage = new System.Drawing.Bitmap(1, 1); Font objFont = new Font(options.FontName, size, FontStyle.Bold, GraphicsUnit.Pixel); Graphics objGraphics = Graphics.FromImage(objBmpImage); int width = (int)objGraphics.MeasureString(text, objFont).Width; int height = (int)objGraphics.MeasureString(text, objFont).Height; objBmpImage = new System.Drawing.Bitmap(objBmpImage, new Size(width, height)); DrawTextOnBitmap(objBmpImage, objGraphics, text, objFont, options); return (objBmpImage); }
public InputOptionsValidator(InputOptions options) { Options = options; RulesAndErrorMessages = new Dictionary<Func<bool>, string> { { CheckHeight, "Validation Error: Wrong height" }, { CheckWidth, "Validation Error: Wrong width" }, { CheckMaxFont, "Validation Error: Font size error" }, { CheckMinFont, "Validation Error: Font size error" }, { CheckInputFile, "Validation Error: File doesn't exists" }, { CheckTextColor, "Validation Error: Cannot recognize this text color" }, { CheckBackgroundColor, "Validation Error: Cannot recognize background color"}, { CheckAlgorithm, "Validation Error: Unknown Algorithm" } }; }
public void Init() { fonts = new List<WordIntPair> { new WordIntPair("a", 10) }; options = new InputOptions { Width = 100, Height = 100, FontName = "Arial", MinFont = 10, MaxFont = 40, BackgroundColor = "Red", TextColor = "Yellow" }; algorithm = new LineAlgorithm(); }
public void GetFonts_on_equal_freqs_should_return_equal_fonts_sizes() { var proc = new FontProcessor(); var data = new List<WordIntPair> { new WordIntPair("A", 10), new WordIntPair("B", 10), new WordIntPair("C", 10) }; var settings = new InputOptions { MinFont = 20, MaxFont = 20 }; var expected = new List<WordIntPair> { new WordIntPair("A", 20), new WordIntPair("B", 20), new WordIntPair("C", 20) }; var result = proc.GetFontSizes(data, settings).ToList(); CollectionAssert.AreEqual(expected, result); }
public TagCloudGenerator(InputOptions options) { this.options = options; }
public static IEnumerable<System.Drawing.Bitmap> GetTextImages(IList<WordIntPair> fonts, InputOptions options) { var mixedFonts = fonts.OrderBy(e => Guid.NewGuid()); return mixedFonts.Select(tuple => CreateBitmapImage(tuple.Word, tuple.Number, options)); }
public void Init() { options = new InputOptions { Width = 200, Height = 100, FontName = "Arial", MinFont = 10, MaxFont = 40, BackgroundColor = "Red", TextColor = "Yellow", InputFile = "test", OutputFile = "result.png", AlgorithmName = "Column" }; Program.AppKernel = new StandardKernel(new BindingModule()); var reader = Substitute.For<IFileReader>(); reader.GetRawText("test").Returns("test text"); Program.AppKernel.Unbind<IFileReader>(); Program.AppKernel.Bind<IFileReader>().ToConstant(reader); generator = new TagCloudGenerator(options); }
public abstract System.Drawing.Bitmap GetBitmap(IList<WordIntPair> fonts, InputOptions options);