using ComPDFKitViewer; using ComPDFKitViewer.Layer; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; namespace ComPDFKit.Tool.DrawTool { internal class AnnotSelector:BaseLayer { public CPDFViewer PDFViewer { get; set; } public List SelectAnnots { get; set; } = new List(); public Pen DrawPen { get; set; } public Brush DrawBrush { get; set; } private List ControlPoints { get; set; } = new List(); private double RectPadding = 4; public AnnotSelector() { DrawPen = new Pen(new SolidColorBrush(Color.FromArgb(255, 71, 126, 222)), 2); DrawBrush = new SolidColorBrush(Color.FromArgb(40, 119, 180, 227)); } public override void Draw() { DrawingContext drawDC = Open(); DrawOutBound(drawDC); DrawIndividual(drawDC); DrawControlPoint(drawDC); Present(); } public int GetSelectCount() { if(SelectAnnots!=null) { return SelectAnnots.Count; } return 0; } public bool AddItem(AnnotData item) { if (item == null) { return false; } List pageIndexList = SelectAnnots.Select(x => x.PageIndex).Distinct().ToList(); if(pageIndexList.Count > 1 ) { SelectAnnots.Clear(); } if( pageIndexList.Count==1 && pageIndexList[0]!=item.PageIndex) { SelectAnnots.Clear(); } if (RemoveItem(item)) { SelectAnnots.Add(item); return true; } return false; } public bool HasItem(AnnotData item) { if (item == null) { return false; } if(SelectAnnots!=null && SelectAnnots.Count > 0) { return SelectAnnots.Where(x => x.AnnotIndex == item.AnnotIndex && x.PageIndex == item.PageIndex).Count() > 0; } return false; } public bool RemoveItem(AnnotData item) { if (item == null || item.PageIndex < 0 || item.AnnotIndex < 0) { return false; } List checkList = SelectAnnots.Where(x => x.AnnotIndex == item.AnnotIndex && x.PageIndex == item.PageIndex).ToList(); if (checkList != null && checkList.Count > 0) { foreach (AnnotData removeItem in checkList) { SelectAnnots.Remove(removeItem); } } return true; } public void ClearItem() { SelectAnnots?.Clear(); } public Rect GetOutBoundRect() { if (SelectAnnots.Count > 0) { double left = 0; double top = 0; double right = 0; double bottom = 0; for (int i=0;i< SelectAnnots.Count;i++) { AnnotData checkItem= SelectAnnots[i]; if (i == 0) { left=checkItem.PaintRect.Left; top=checkItem.PaintRect.Top; right=checkItem.PaintRect.Right; bottom=checkItem.PaintRect.Bottom; continue; } left = Math.Min(left, checkItem.PaintRect.Left); top = Math.Min(top, checkItem.PaintRect.Top); right = Math.Max(right, checkItem.PaintRect.Right); bottom = Math.Max(bottom, checkItem.PaintRect.Bottom); } if(right