Example #1
0
 private void GenerateClick(object sender, EventArgs e)
 {
     Cloud.Controls.Clear();
     var genCloudSysPath = RootPath + @"\Cloud.png";
     var tags = Words.Lines.Select(
         line => line.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries))
         .Where(splits => splits.Length == 2)
         .ToDictionary(splits => splits[0], splits => int.Parse(splits[1]));
     var tagCloudService = new TagCloudService(tags, int.Parse(Width.Text), int.Parse(Height.Text))
                               {
                                   MaximumFontSize = float.Parse(MaxFontSize.Text),
                                   MinimumFontSize = float.Parse(MinFontSize.Text),
                               };
     if (!String.IsNullOrEmpty(Angle.Text)) tagCloudService.Angle = int.Parse(Angle.Text);
     if (!String.IsNullOrEmpty(Margin.Text)) tagCloudService.Margin = int.Parse(Margin.Text);
     if (null != FontsCombo.SelectedItem)
         tagCloudService.SelectedFont = service.AvailableFonts[FontsCombo.SelectedItem.ToString()];
     if (null != StrategyCombo.SelectedItem)
         tagCloudService.DisplayChoice = DisplayStrategy.Get(
             (TagDisplayStrategy) Enum.Parse(typeof (TagDisplayStrategy), StrategyCombo.SelectedItem.ToString()));
     var bgfgScheme = null != BgfgStrategyCombo.SelectedItem
                          ? (Theme) Enum.Parse(typeof (Theme), BgfgStrategyCombo.SelectedItem.ToString())
                          : Theme.LightBgDarkFg;
     var fgScheme = null != FgStrategyCombo.SelectedItem
                        ? (Style) Enum.Parse(typeof (Style), FgStrategyCombo.SelectedItem.ToString())
                        : Style.Varied;
     tagCloudService.ColorChoice = ColorStrategy.Get(bgfgScheme, fgScheme, bg, fg);
     tagCloudService.VerticalTextRight = VerticalTextRight.Checked;
     tagCloudService.ShowWordBoundaries = ShowBoundaries.Checked;
     tagCloudService.Crop = Cropper.Checked;
     Dictionary<string, RectangleF> borders;
     var bitmap = tagCloudService.Construct(out borders);
     Skipped.Text = string.Join("; ", tagCloudService.WordsSkipped.Select(x => x.Key));
     bitmap.Save(genCloudSysPath, ImageFormat.Png);
     Cloud.Image = bitmap;
     borders.Values.ToList().ForEach(x => Cloud.Controls.Add(GetBorder(x)));
 }