Пример #1
0
        void Strokes_StrokesChanged(object sender, StrokeCollectionChangedEventArgs e)
        {
            foreach (Stroke stroke in e.Added)
            {
                if (!graphAnalyzer.newStroke(stroke))
                {
                    inkAnalyzer.AddStroke(stroke);
                }

                AutocorrectHandleAddStroke(stroke);
            }

            double ymax = InkUtils.StrokeYMax(e.Added);

            if (ymax > MainInkCanvas.ActualHeight - 300.0)
            {
                MainInkCanvas.Height = ymax + 800.0;
            }

            foreach (Stroke stroke in e.Removed)
            {
                graphAnalyzer.removeStroke(stroke);
                // If we erase a word and try to replace it with autocorrect
                // suggestions, there's no good way to define the behavior
                // so just hide the suggestions.
                suggestionsBox.Visibility = Visibility.Collapsed;

                inkAnalyzer.RemoveStroke(stroke);
            }
        }
Пример #2
0
        public void SetSuggestions(InkWordNode _incorrectWord, List <String> suggestions,
                                   Dictionary <char, StylusToken> fontData)
        {
            SuggestionsStack.Children.Clear();

            incorrectWord = _incorrectWord;

            int minX = int.MaxValue;
            int maxX = int.MinValue;
            int minY = int.MaxValue;
            int maxY = int.MinValue;

            foreach (Point point in incorrectWord.GetRotatedBoundingBox())
            {
                minX = Math.Min(minX, (int)point.X);
                maxX = Math.Max(maxX, (int)point.X);
                minY = Math.Min(minY, (int)point.Y);
                maxY = Math.Max(maxY, (int)point.Y);
            }
            this.Width  = 0;
            this.Height = 0;

            var midline  = incorrectWord.GetMidline();
            var baseline = incorrectWord.GetBaseline();

            // Assume that the midline and baseline are horizontal lines
            // i.e. two points, same y coordinate.
            double wordSize = baseline[0].Y - midline[0].Y;

            // Keep the top 3 suggestions for now.
            int displayCount = Math.Min(3, suggestions.Count);

            for (int i = 0; i < displayCount; i++)
            {
                StrokeCollection strokeRepresentation =
                    GetStrokesForString(suggestions[i], fontData);

                // In the font maker, the font size is currently 30.0
                InkUtils.Scale(strokeRepresentation, wordSize / 30.0);
                InkUtils.MatchThickness(incorrectWord.Strokes, strokeRepresentation);

                InkCanvas suggestionCanvas = new InkCanvas();
                suggestionCanvas.Strokes.Add(strokeRepresentation);
                suggestionCanvas.Height       = InkUtils.StrokeYMax(strokeRepresentation) + 10;
                suggestionCanvas.Width        = InkUtils.StrokeXRange(strokeRepresentation) + 10;
                suggestionCanvas.TouchDown   += SuggestionCanvas_TouchDown;
                suggestionCanvas.StylusDown  += SuggestionCanvas_StylusDown;
                suggestionCanvas.StylusEnter += SuggestionCanvas_StylusEnter;
                suggestionCanvas.StylusLeave += SuggestionCanvas_StylusLeave;

                this.Width   = Math.Max(this.Width, suggestionCanvas.Width);
                this.Height += suggestionCanvas.Height;

                // We shouldn't be writing on this canvas, it's only for
                // display purposes.
                suggestionCanvas.EditingMode = InkCanvasEditingMode.None;

                SuggestionsStack.Children.Add(suggestionCanvas);
            }

            // Positioning.
            if (minY < this.Height)
            {
                // Show suggestions under incorrect word.
                Canvas.SetTop(this, maxY);
            }
            else
            {
                // Show suggestions above incorrect word.
                Canvas.SetTop(this, minY - this.Height);
            }
            Canvas.SetLeft(this, minX);
        }