Beispiel #1
0
        void AutocorrectInit()
        {
            using (Stream stream = new FileStream("rudi_hand_font.txt", FileMode.Open))
            {
                var serializer = new DataContractJsonSerializer(typeof(Dictionary <char, DataStylusToken>));
                var data       = (Dictionary <char, DataStylusToken>)serializer.ReadObject(stream);

                foreach (var token in data)
                {
                    StrokeCollection strokes = token.Value.Representation();

                    // We made our characters in 100x100 boxes.
                    StylusToken stylusToken = new StylusToken(strokes);
                    stylusToken.Normalize();
                    fontData.Add(token.Key, stylusToken);
                }
            }

            spellchecker.Add("hackathon");

            // To display autocorrect stuff.
            suggestionsBox = new SuggestionsBox(this);

            OverlayCanvas.Children.Add(suggestionsBox);
            Grid.SetRow(suggestionsBox, 0);
            Grid.SetColumn(suggestionsBox, 0);
            suggestionsBox.Background = new SolidColorBrush(Colors.LightGray);
            suggestionsBox.Visibility = Visibility.Collapsed;
        }
Beispiel #2
0
        void AutocorrectInit()
        {
            using (Stream stream = new FileStream("rudi_hand_font.txt", FileMode.Open))
            {
                var serializer = new DataContractJsonSerializer(typeof(Dictionary<char, DataStylusToken>));
                var data = (Dictionary<char, DataStylusToken>)serializer.ReadObject(stream);

                foreach (var token in data)
                {
                    StrokeCollection strokes = token.Value.Representation();

                    // We made our characters in 100x100 boxes.
                    StylusToken stylusToken = new StylusToken(strokes);
                    stylusToken.Normalize();
                    fontData.Add(token.Key, stylusToken);
                }
            }

            spellchecker.Add("hackathon");

            // To display autocorrect stuff.
            suggestionsBox = new SuggestionsBox(this);

            OverlayCanvas.Children.Add(suggestionsBox);
            Grid.SetRow(suggestionsBox, 0);
            Grid.SetColumn(suggestionsBox, 0);
            suggestionsBox.Background = new SolidColorBrush(Colors.LightGray);
            suggestionsBox.Visibility = Visibility.Collapsed;
        }
        // Generates a collection of strokes representing an entire word.
        StrokeCollection GetStrokesForString(string text,
                                             Dictionary <char, StylusToken> fontData)
        {
            double currentX = 0.0;

            StrokeCollection stringStrokes = new StrokeCollection();

            for (int i = 0; i < text.Length; i++)
            {
                char c = text[i];

                if (fontData.Keys.Contains(c))
                {
                    StylusToken token = fontData[c];

                    double kerningLeft = 2.0;
                    if (i > 0 && Char.ToLower(text[i - 1]) == text[i - 1] &&
                        Char.ToLower(c) == c)
                    {
                        kerningLeft += token.width * 0.14;
                    }

                    double kerningRight = 2.0;
                    if (i < text.Length - 1 && Char.ToLower(text[i + 1]) == text[i + 1] &&
                        Char.ToLower(c) == c)
                    {
                        kerningRight += token.width * 0.14;
                    }

                    foreach (Stroke stroke in token.strokes)
                    {
                        StylusPointCollection newPoints = new StylusPointCollection();
                        foreach (StylusPoint point in stroke.StylusPoints)
                        {
                            newPoints.Add(new StylusPoint(
                                              point.X + currentX + kerningLeft, point.Y));
                        }
                        stringStrokes.Add(new Stroke(newPoints));
                    }

                    currentX += token.width + kerningLeft + kerningRight;
                }
            }

            return(stringStrokes);
        }