Exemple #1
0
        public void invalidate()
        {
            sidebar.Strokes.Clear();
            double y = 20;
            double x = 20;

            foreach (HeadingItem heading in headings)
            {
                Rect firstText = heading.text[0].Strokes.GetBounds();
                heading.finalBounds = firstText;
                double currentY = y;
                foreach (ContextNode word in heading.text)
                {
                    StrokeCollection strokes = word.Strokes.Clone();
                    InkUtils.transposeStrokes(null, strokes, x - firstText.X, currentY - firstText.Y);
                    sidebar.Strokes.Add(strokes);
                    Rect finalBounds = strokes.GetBounds();
                    if (y < finalBounds.Y + finalBounds.Height)
                    {
                        y = finalBounds.Y + finalBounds.Height;
                    }
                    heading.finalBounds.Union(finalBounds);
                }
                y += 20;
            }
            sidebar.InvalidateVisual();
        }
Exemple #2
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);
            }
        }
Exemple #3
0
 public CorrRandWindow(double _stdev, int _window)
 {
     stdev  = _stdev;
     window = _window;
     i      = 0;
     buffer = new double[window];
     prev   = InkUtils.stdNorm() * stdev * Math.Sqrt(window);
 }
Exemple #4
0
 public Graph(IDelegate _del, Stroke b)
 {
     del                          = _del;
     box                          = b;
     bounds                       = box.GetBounds();
     box.StylusPoints             = InkUtils.xkcd(InkUtils.box(bounds));
     box.DrawingAttributes.Color  = Colors.Blue;
     analyzer                     = new InkAnalyzer();
     analyzer.ContextNodeCreated += ContextNodeCreated;
 }
Exemple #5
0
        private void InsertButton_Click(object sender, RoutedEventArgs e)
        {
            InkAnalyzer inkAnalyzer = new InkAnalyzer();

            inkAnalyzer.AddStrokes(insertionBox.InkCanvas.Strokes);
            inkAnalyzer.Analyze();
            InkUtils.MergeParagraphs(inkAnalyzer);
            insertReflow.process(inkAnalyzer);
            insertionBox.Visibility = Visibility.Collapsed;
            inserter.insertStrokes(this.inkAnalyzer, MainInkCanvas, insertionBox.InkCanvas);
        }
Exemple #6
0
        protected override void ContextNodeCreated(object sender, ContextNodeCreatedEventArgs e)
        {
            Debug.WriteLine("Holy molly! {0}", e.NodeCreated);
            InkDrawingNode n = e.NodeCreated as InkDrawingNode;

            if (n != null)
            {
                Debug.WriteLine("Yeah!");
                foreach (Stroke x in n.Strokes)
                {
                    Debug.WriteLine("Uhhhhh {0}", x);
                    analyzer.RemoveStroke(x);
                    x.StylusPoints = InkUtils.xkcd(x.StylusPoints);
                }
            }
        }
Exemple #7
0
        private void fillBar(double _x1, double _y1, double _x2, double _y2)
        {
            const double dist = 14, stdev = 4, fillGap = 0.05;
            double       x1         = Math.Min(_x1, _x2),
                         x2         = Math.Max(_x1, _x2),
                         y1         = Math.Min(_y1, _y2),
                         y2         = Math.Max(_y1, _y2);
            double d                = x1 + y1 + dist;
            StylusPointCollection r = new StylusPointCollection();
            //r.Add(new StylusPoint(x1, y1));
            bool side = false;

            while (d < x2 + y2 - dist)
            {
                if (side = !side)
                {
                    double x1_ = x1 + (x2 - x1) * Math.Abs(InkUtils.stdNorm() * fillGap);
                    double y2_ = y2 - (y2 - y1) * Math.Abs(InkUtils.stdNorm() * fillGap);
                    if (d - x1_ < y2_)
                    {
                        r.Add(new StylusPoint(x1_, d - x1_));
                    }
                    else
                    {
                        r.Add(new StylusPoint(d - y2_, y2_));
                    }
                }
                else
                {
                    double x2_ = x2 - (x2 - x1) * Math.Abs(InkUtils.stdNorm() * fillGap);
                    double y1_ = y1 + (y2 - y1) * Math.Abs(InkUtils.stdNorm() * fillGap);
                    if (d - x2_ > y1_)
                    {
                        r.Add(new StylusPoint(x2_, d - x2_));
                    }
                    else
                    {
                        r.Add(new StylusPoint(d - y1_, y1_));
                    }
                    d += Math.Abs(InkUtils.stdNorm() * stdev + dist);
                }
            }
            Stroke s = new Stroke(InkUtils.xkcd(r));

            s.DrawingAttributes.Color = colGen.nextColor();
            addStroke(s);
        }
        void ChooseSuggestion(InkCanvas canvas)
        {
            // Incase we get a double event.
            if (this.Visibility == Visibility.Collapsed)
            {
                return;
            }

            StrokeCollection newStrokes = canvas.Strokes;

            double baseline = incorrectWord.GetBaseline()[0].Y;

            InkUtils.Shift(newStrokes, InkUtils.StrokeXMin(incorrectWord.Strokes),
                           baseline - 35);

            mainWindow.MainInkCanvas.Strokes.Remove(incorrectWord.Strokes);
            mainWindow.MainInkCanvas.Strokes.Add(newStrokes);
            mainWindow.pipeline.QueueAnalysis();

            this.Visibility = Visibility.Collapsed;
        }
Exemple #9
0
        public override bool takeStroke(Stroke s)
        {
            InkUtils.depressurize(s.StylusPoints);
            StylusPointCollection col = InkUtils.toPolyline(s.StylusPoints);

            if (xAxis == null || yAxis == null)
            {
                if (col.Count == 2)
                {
                    StylusPoint p1 = col[0];
                    StylusPoint p2 = col[1];
                    if (xAxis == null && Math.Abs(p2.X - p1.X) > 100 && Math.Abs((p2.Y - p1.Y) / (p2.X - p1.X)) < 0.3)
                    {
                        if (yAxis == null)
                        {
                            if (p1.X < p2.X)
                            {
                                origin = new Point(p1.X, p1.Y);
                                xEnd   = new Point(p2.X, p1.Y);
                            }
                            else
                            {
                                origin = new Point(p2.X, p2.Y);
                                xEnd   = new Point(p1.X, p2.Y);
                            }
                        }
                        else if (InkUtils.distSquared(p2, InkUtils.sp(origin)) < 20 * 20)
                        {
                            xEnd = new Point(p1.X, origin.Y);
                        }
                        else if (InkUtils.distSquared(p1, InkUtils.sp(origin)) < 20 * 20)
                        {
                            xEnd = new Point(p2.X, origin.Y);
                        }
                        else
                        {
                            goto notX;
                        }
                        xAxis          = s;
                        s.StylusPoints = InkUtils.xkcd(new StylusPointCollection(new Point[] { origin, xEnd }));
                        return(true);
                    }
notX:
                    if (yAxis == null && Math.Abs(p2.Y - p1.Y) > 100 && Math.Abs((p2.X - p1.X) / (p2.Y - p1.Y)) < 0.3)
                    {
                        if (xAxis == null)
                        {
                            if (p1.Y > p2.Y)
                            {
                                origin = new Point(p1.X, p1.Y);
                                yEnd   = new Point(p1.X, p2.Y);
                            }
                            else
                            {
                                origin = new Point(p2.X, p2.Y);
                                yEnd   = new Point(p2.X, p1.Y);
                            }
                        }
                        else if (InkUtils.distSquared(p2, InkUtils.sp(origin)) < 20 * 20)
                        {
                            yEnd = new Point(origin.X, p1.Y);
                        }
                        else if (InkUtils.distSquared(p1, InkUtils.sp(origin)) < 20 * 20)
                        {
                            yEnd = new Point(origin.X, p2.Y);
                        }
                        else
                        {
                            goto notY;
                        }
                        yAxis          = s;
                        s.StylusPoints = InkUtils.xkcd(new StylusPointCollection(new Point[] { origin, yEnd }));
                        return(true);
                    }
                    notY : { }
                }
            }
            else
            {
                StylusPoint spOrigin = InkUtils.sp(origin), spXEnd = InkUtils.sp(xEnd), spYEnd = InkUtils.sp(yEnd);
                // Support bars
                if (col.Count == 4
                    // Vertical bars
                    && InkUtils.isVertical(col[0], col[1])
                    //&& InkUtils.isHorizontal(col[1], col[2])
                    && InkUtils.isVertical(col[2], col[3]) &&
                    InkUtils.similar(Math.Sqrt(InkUtils.distSquared(col[0], col[1])),
                                     Math.Sqrt(InkUtils.distSquared(col[2], col[3]))) &&
                    InkUtils.lineDistSquared(spOrigin, spXEnd, col[0]) < 400 &&
                    InkUtils.lineDistSquared(spOrigin, spXEnd, col[3]) < 400)
                {
                    double x1 = (col[0].X + col[1].X) / 2;
                    double x2 = (col[2].X + col[3].X) / 2;
                    double y  = (col[1].Y + col[2].Y) / 2;
                    s.StylusPoints = InkUtils.xkcd(new StylusPointCollection(new Point[] {
                        new Point(x1, origin.Y),
                        new Point(x1, y),
                        new Point(x2, y),
                        new Point(x2, origin.Y)
                    }));
                    fillBar(x1, origin.Y, x2, y);
                }
                else if (col.Count == 4
                         // Horizontal bars
                         && InkUtils.isHorizontal(col[0], col[1])
                         //&& InkUtils.isVertical(col[1], col[2])
                         && InkUtils.isHorizontal(col[2], col[3]) &&
                         InkUtils.similar(Math.Sqrt(InkUtils.distSquared(col[0], col[1])),
                                          Math.Sqrt(InkUtils.distSquared(col[2], col[3]))) &&
                         InkUtils.lineDistSquared(spOrigin, spYEnd, col[0]) < 400 &&
                         InkUtils.lineDistSquared(spOrigin, spYEnd, col[3]) < 400)
                {
                    double y1 = (col[0].Y + col[1].Y) / 2;
                    double y2 = (col[2].Y + col[3].Y) / 2;
                    double x  = (col[1].X + col[2].X) / 2;
                    s.StylusPoints = InkUtils.xkcd(new StylusPointCollection(new Point[] {
                        new Point(origin.X, y1),
                        new Point(x, y1),
                        new Point(x, y2),
                        new Point(origin.X, y2)
                    }));
                    fillBar(origin.X, y1, x, y2);
                }
                // Maybe it's inside the graph itself?
                else if (s.HitTest(new Rect(xEnd, yEnd), 80))
                {
                    s.StylusPoints = InkUtils.xkcd(s.StylusPoints);
                }
            }

            curves.Add(s);
//            s.StylusPoints = InkUtils.xkcd(col);

            //analyzer.AddStroke(s);
            //analyzer.Analyze();
            return(true);
        }
        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);
        }
Exemple #11
0
 public double next()
 {
     prev = prev + (buffer[(i + 1) % window] = InkUtils.stdNorm() * stdev) - buffer[i % window];
     ++i;
     return(prev);
 }
Exemple #12
0
 public double next()
 {
     prev = prev * preserve + InkUtils.stdNorm() * stdev;
     return(prev);
 }