Ejemplo n.º 1
0
 private void LimpiarCanvas()
 {
     if (inkCanvas.Strokes.Count() > 0)
     {
         m_analyzer.RemoveStrokes(inkCanvas.Strokes);
         inkCanvas.Strokes.Clear();
     }
 }
 private void ResetCanvas()
 {
     if (canvasTinta.Strokes.Count() > 0)
     {
         m_analyzer.RemoveStrokes(canvasTinta.Strokes);
         canvasTinta.Strokes.Clear();
     }
 }
Ejemplo n.º 3
0
        public static void transposeStrokes(InkAnalyzer inkAnalyzer, StrokeCollection strokes, double offsetX, double offsetY)
        {
            if (inkAnalyzer != null)
            {
                inkAnalyzer.RemoveStrokes(strokes);
            }

            Matrix transform = new Matrix();

            transform.Translate(offsetX, offsetY);
            strokes.Transform(transform, false);

            if (inkAnalyzer != null)
            {
                inkAnalyzer.AddStrokes(strokes);
            }
        }
Ejemplo n.º 4
0
 private void searchStrokes(string searchString, string imageName, InkCanvas inkCanvas)
 {
     StrokeCollection[] strokes = analyze.Search(searchString);
     foreach (StrokeCollection sc in strokes)
     {
         foreach (Stroke s in sc)
         {
             if (inkCanvas.Strokes.IndexOf(s) != -1)
             {
                 inkCanvas.Strokes.Remove(sc);
             }
             if (analyze.RootNode.Strokes.IndexOf(s) != -1)
             {
                 analyze.RemoveStrokes(sc);
             }
         }
         addImage(imageName, new Thickness(sc[0].StylusPoints[0].X, sc[0].StylusPoints[0].Y, 0, 0), inkCanvas);
     }
 }
Ejemplo n.º 5
0
        public MyInkAnalyzer(StrokeCollection strokeCollection)
        {
            if (strokeCollection.Count > 0)
            {
                _strokeCollection = strokeCollection;
                analyze           = new InkAnalyzer();
                //2052:简体中文 1033:英语
                analyze.AddStrokes(strokeCollection, GlobalValues.InkAnalyzerLanguageId);
                //analyze.BackgroundAnalyze();

                AnalysisStatus status = analyze.Analyze();

                if (status.Successful)
                {
                    analyzeResults = analyze.GetRecognizedString();
                }
                else
                {
                    analyzeResults = "Recognition Failed";
                }

                analyze.RemoveStrokes(_strokeCollection);
            }
        }
Ejemplo n.º 6
0
        private void findAndDeleteStrikethrough(InkAnalyzer inkAnalyzer, InkCanvas canvas,
                                                List <Stroke> horizontalLines, ContextNodeCollection contextNodeCollection)
        {
            List <ContextNode> deletedNodes           = new List <ContextNode>();
            List <Stroke>      removedHorizontalLines = new List <Stroke>();

            //Find things to apply gestures to
            foreach (ContextNode node in contextNodeCollection)
            {
                if (node.Strokes.Count == 0)
                {
                    continue;
                }
                Rect strikethroughBounds = node.Strokes.GetBounds();
                strikethroughBounds.Height *= 0.75d;
                if (node is InkWordNode)
                {
                    PointCollection bl = (node as InkWordNode).GetBaseline();
                    if (bl != null &&
                        bl.Count() > 0)
                    {
                        double baseline = bl[0].Y;
                        strikethroughBounds.Height = baseline - strikethroughBounds.Y;
                    }
                }

                for (int j = 0; j < horizontalLines.Count; j++)
                {
                    if (node.Strokes[0] == horizontalLines[j])
                    {
                        break;
                    }
                    Stroke horizontalLine          = horizontalLines[j];
                    Rect   horizontalLineBounds    = horizontalLine.GetBounds();
                    double sideBuffer              = (1 - Constants.LINE_WORD_OVERLAPSE_RATIO) / 2;
                    double strikethroughBoundLeft  = strikethroughBounds.X + strikethroughBounds.Width * sideBuffer;
                    double strikethroughBoundRight = strikethroughBounds.X + strikethroughBounds.Width * (1 - sideBuffer);
                    if (strikethroughBounds.IntersectsWith(horizontalLineBounds) &&
                        strikethroughBoundLeft > horizontalLineBounds.X &&
                        strikethroughBoundRight < horizontalLineBounds.X + horizontalLineBounds.Width)
                    {
                        //Delete strikethrough
                        deletedNodes.Add(node);
                        removedHorizontalLines.Add(horizontalLine);
                    }
                }
            }

            foreach (Stroke stroke in removedHorizontalLines)
            {
                horizontalLines.Remove(stroke);
                canvas.Strokes.Remove(stroke);
                inkAnalyzer.RemoveStroke(stroke);
            }

            //Final step to apply the gestures, commit changes
            for (int i = deletedNodes.Count - 1; i >= 0; i--)
            {
                ContextNode node = deletedNodes[i];
                try
                {
                    Rect        bounds   = node.Strokes.GetBounds();
                    double      nodeX    = bounds.X;
                    ContextNode parent   = node.ParentNode;
                    double      closestX = double.MaxValue;
                    foreach (ContextNode sibling in parent.SubNodes)
                    {
                        double siblingX = sibling.Strokes.GetBounds().X;
                        if (siblingX > nodeX && siblingX < closestX)
                        {
                            closestX = siblingX;
                        }
                    }
                    double dx = nodeX - closestX;
                    foreach (ContextNode sibling in parent.SubNodes)
                    {
                        //Nodes right side of current
                        if (sibling.Strokes.GetBounds().X > nodeX)
                        {
                            InkUtils.transposeStrokes(inkAnalyzer, sibling.Strokes, dx, 0d);
                        }
                    }
                    canvas.Strokes.Remove(node.Strokes);
                    inkAnalyzer.RemoveStrokes(node.Strokes);
                }
                catch (Exception e)
                {
                    //Ignore already deleted error
                }
            }
        }
Ejemplo n.º 7
0
        public static void transposeStrokes(InkAnalyzer inkAnalyzer, StrokeCollection strokes, double offsetX, double offsetY)
        {
            if(inkAnalyzer != null)
            {
                inkAnalyzer.RemoveStrokes(strokes);
            }

            Matrix transform = new Matrix();
            transform.Translate(offsetX, offsetY);
            strokes.Transform(transform, false);

            if(inkAnalyzer != null)
            {
                inkAnalyzer.AddStrokes(strokes);
            }
        }
Ejemplo n.º 8
0
        private void findAndDeleteStrikethrough(InkAnalyzer inkAnalyzer, InkCanvas canvas,
            List<Stroke> horizontalLines, ContextNodeCollection contextNodeCollection)
        {
            List<ContextNode> deletedNodes = new List<ContextNode>();
            List<Stroke> removedHorizontalLines = new List<Stroke>();

            //Find things to apply gestures to
            foreach (ContextNode node in contextNodeCollection)
            {
                if (node.Strokes.Count == 0)
                {
                    continue;
                }
                Rect strikethroughBounds = node.Strokes.GetBounds();
                strikethroughBounds.Height *= 0.75d;
                if (node is InkWordNode)
                {
                    PointCollection bl = (node as InkWordNode).GetBaseline();
                    if (bl != null
                        && bl.Count() > 0)
                    {
                        double baseline = bl[0].Y;
                        strikethroughBounds.Height = baseline - strikethroughBounds.Y;
                    }
                }

                for (int j = 0; j < horizontalLines.Count; j++)
                {
                    if (node.Strokes[0] == horizontalLines[j])
                    {
                        break;
                    }
                    Stroke horizontalLine = horizontalLines[j];
                    Rect horizontalLineBounds = horizontalLine.GetBounds();
                    double sideBuffer = (1 - Constants.LINE_WORD_OVERLAPSE_RATIO) / 2;
                    double strikethroughBoundLeft = strikethroughBounds.X + strikethroughBounds.Width * sideBuffer;
                    double strikethroughBoundRight = strikethroughBounds.X + strikethroughBounds.Width * (1 - sideBuffer);
                    if (strikethroughBounds.IntersectsWith(horizontalLineBounds) &&
                        strikethroughBoundLeft > horizontalLineBounds.X &&
                        strikethroughBoundRight < horizontalLineBounds.X + horizontalLineBounds.Width)
                    {
                        //Delete strikethrough
                        deletedNodes.Add(node);
                        removedHorizontalLines.Add(horizontalLine);
                    }
                }
            }

            foreach (Stroke stroke in removedHorizontalLines)
            {
                horizontalLines.Remove(stroke);
                canvas.Strokes.Remove(stroke);
                inkAnalyzer.RemoveStroke(stroke);
            }

            //Final step to apply the gestures, commit changes
            for (int i = deletedNodes.Count - 1; i >= 0; i--)
            {
                ContextNode node = deletedNodes[i];
                try
                {
                    Rect bounds = node.Strokes.GetBounds();
                    double nodeX = bounds.X;
                    ContextNode parent = node.ParentNode;
                    double closestX = double.MaxValue;
                    foreach (ContextNode sibling in parent.SubNodes)
                    {
                        double siblingX = sibling.Strokes.GetBounds().X;
                        if (siblingX > nodeX && siblingX < closestX)
                        {
                            closestX = siblingX;
                        }
                    }
                    double dx = nodeX - closestX;
                    foreach (ContextNode sibling in parent.SubNodes)
                    {
                        //Nodes right side of current
                        if (sibling.Strokes.GetBounds().X > nodeX)
                        {
                            InkUtils.transposeStrokes(inkAnalyzer, sibling.Strokes, dx, 0d);
                        }
                    }
                    canvas.Strokes.Remove(node.Strokes);
                    inkAnalyzer.RemoveStrokes(node.Strokes);
                }
                catch (Exception e)
                {
                    //Ignore already deleted error
                }
            }
        }