/// <summary> /// Checks if two ink annotations are matched by comparing their colors and ink points. /// </summary> /// <param name="loadedInk">The ink annotation in the pdf file.</param> /// <param name="appInk">The ink annotation constructed by the app.</param> /// <returns>If the two annotations are matched, true. Otherwise false.</returns> private bool MatchInkAnnotations(PdfLoadedInkAnnotation loadedInk, PdfInkAnnotation appInk) { // Color if (loadedInk.Color.R != appInk.Color.R || loadedInk.Color.G != appInk.Color.G || loadedInk.Color.B != appInk.Color.B) { return(false); } // Points List <float> points1 = loadedInk.InkList; List <float> points2 = appInk.InkList; if (points1.Count != points2.Count) { return(false); } for (int i = 0; i < points1.Count; i++) { double threshold = 0.5; if (Math.Abs(points1[i] - points2[i]) > threshold) { return(false); } } return(true); }
/// <summary> /// Converts an ink annotation (from the PDF file) to an ink stroke (to be displayed on the screen). /// </summary> /// <param name="inkAnnotation"></param> /// <param name="mapping"></param> /// <returns></returns> public InkStroke InkAnnotation2InkStroke(PdfLoadedInkAnnotation inkAnnotation) { List <float> strokePoints = inkAnnotation.InkList; InkStrokeBuilder builder = new InkStrokeBuilder(); List <Point> InkPoints = new List <Point>(); // Construct ink points for (int i = 0; i < strokePoints.Count; i = i + 2) { if ((i + 1) >= strokePoints.Count) { // TODO: Something must be wrong. break; } double X = 0, Y = 0; float W = strokePoints[i]; float Z = strokePoints[i + 1]; switch (Rotation) { case 0: // No rotation { X = W; Y = PageSize.Height - Z; break; } case 1: // 90-degree rotation { X = Z; Y = W; break; } case 2: // 180-degree rotation { X = PageSize.Width - W; Y = Z; break; } case 3: // 270-degree rotation { X = PageSize.Width - Z; Y = PageSize.Height - W; break; } } double pointX = (X - Offset.X) / ScaleRatio; double pointY = (Y - Offset.Y) / ScaleRatio; InkPoints.Add(new Point(pointX, pointY)); } InkStroke stroke = builder.CreateStroke(InkPoints); Windows.UI.Color color = ColorToUI(inkAnnotation.Color); double width = inkAnnotation.BorderWidth; if (width < InkingPreference.MIN_PEN_SIZE) { width = InkingPreference.MIN_PEN_SIZE; } width = width / ScaleRatio; Size size = new Size(width, width); if (inkAnnotation.Opacity == InkingManager.HighlighterOpacity) { stroke.DrawingAttributes = InkingManager.HighlighterDrawingAttributes(color, size); } else { stroke.DrawingAttributes = InkingManager.PencilDrawingAttributes(color, size); } return(stroke); }