Esempio n. 1
0
            public IList <Document> ToModel()
            {
                ThemaDistribution.ForEach(pair => pair.Key.ThemaDistribution = pair.Value);
                WordsDistribution.ForEach(pair => pair.Key.WordsDistribution = pair.Value);

                return(ThemaDistribution.Keys.ToList());
            }
Esempio n. 2
0
        private void NapisTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (e.Key == Windows.System.VirtualKey.Enter)
            {
                string   textToStack  = NapisTextBox.Text;
                string[] wordsToStack = textToStack.Split(new char[] { ' ' });

                int maxHeight = (int)Math.Ceiling(MainGrid.ActualWidth);
                int maxWidth  = (int)Math.Ceiling(MainGrid.ActualHeight);

                int fontSize = 120;

                WordsDistribution distribution = CreateProperWordsDistribution(fontSize, wordsToStack, maxWidth, maxHeight);
                TextStack.Children.Clear();
                distribution.Rows.Reverse();
                foreach (string row in distribution.Rows)
                {
                    TextBlock t = new TextBlock();
                    t.FontSize = distribution.FontSize;
                    t.Text     = row;
                    //t.FontWeight = FontWeights.Bold;
                    t.TextAlignment = TextAlignment.Center;

                    LayoutTransformer lt = new LayoutTransformer();
                    lt.HorizontalAlignment = HorizontalAlignment.Stretch;
                    lt.VerticalAlignment   = VerticalAlignment.Stretch;


                    lt.Content = t;
                    RotateTransform rt = new RotateTransform();
                    rt.Angle           = 90;
                    lt.LayoutTransform = rt;
                    TextStack.Children.Add(lt);
                }


                TextStack.Visibility           = Visibility.Visible;
                NapisInputContainer.Visibility = Visibility.Collapsed;
            }
        }
Esempio n. 3
0
        private WordsDistribution CreateProperWordsDistribution(int fontSize, string[] words, int maxWidth, int maxHeight)
        {
            int            currentFontSize = fontSize;
            Queue <string> wordQueue       = new Queue <string>(words);
            List <string>  rows            = new List <string>();

            TextBlock t = new TextBlock();

            t.FontSize = currentFontSize;
            string textToRow   = String.Empty;
            int    finalHeight = 0;

            while (wordQueue.Count != 0)
            {
                string textToAppend = wordQueue.Peek();
                t.FontSize = currentFontSize;
                t.Text     = textToRow + textToAppend + " ";
                t.Measure(new Size(maxWidth, maxHeight));
                int actualWidth  = (int)Math.Ceiling(t.ActualWidth);
                int actualHeight = (int)Math.Ceiling(t.ActualHeight);

                if (actualWidth >= maxWidth)
                {
                    if (!String.IsNullOrEmpty(textToRow))
                    {
                        rows.Add(textToRow);
                    }
                    else
                    {
                        string[] check = textToAppend.Split(new char[] { ' ' });
                        if (check.Length <= 1)
                        {
                            currentFontSize -= 10;
                        }
                    }

                    textToRow    = String.Empty;
                    finalHeight += actualHeight;
                }
                else
                {
                    textToAppend = wordQueue.Dequeue();
                    textToRow   += textToAppend + " ";

                    if (wordQueue.Count == 0)
                    {
                        rows.Add(textToRow);
                        textToRow    = String.Empty;
                        finalHeight += actualHeight;
                    }
                }
            }

            if (finalHeight > maxHeight && currentFontSize > 0)
            {
                return(CreateProperWordsDistribution(currentFontSize - 10, words, maxWidth, maxHeight));
            }

            WordsDistribution wd = new WordsDistribution()
            {
                FontSize = currentFontSize,
                Rows     = rows
            };

            return(wd);
        }