using ComPDFKit.PDFAnnotation;
using ComPDFKitViewer;
using ComPDFKitViewer.AnnotEvent;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace PDF_Master.ViewModels.Tools.AnnotManager
{
///
/// 注释面板与外部(如注释工具)关联
///
public class AnnotTransfer
{
public event EventHandler> DataChanged;
public event EventHandler> AnnotTypeChanged;
public bool IsAddLink = false;
public bool IsLocationLink = false;
public AnnotAttribEvent AnnotEvent { get; set; }
public List AnnotEvents = new List();
public AnnotHandlerEventArgs annot;
public List annotlists;
public Dictionary LastAnnotDict = new Dictionary();
public AnnotHandlerEventArgs LastArrowAnnot = null;
//是否为填写与签名的日期文本
public bool IsTextFill { get; private set; }
public void SetIsTextFill(bool isTextFill)
{
IsTextFill = isTextFill;
}
public bool IsMultiSelected
{ get { return (annotlists != null && annotlists.Count > 1); } }
public AnnotTransfer()
{
LastAnnotDict.Add(AnnotArgsType.AnnotHighlight, null);
LastAnnotDict.Add(AnnotArgsType.AnnotUnderline, null);
LastAnnotDict.Add(AnnotArgsType.AnnotStrikeout, null);
LastAnnotDict.Add(AnnotArgsType.AnnotFreehand, null);
LastAnnotDict.Add(AnnotArgsType.AnnotFreeText, null);
LastAnnotDict.Add(AnnotArgsType.AnnotSticky, null);
LastAnnotDict.Add(AnnotArgsType.AnnotSquare, null);
LastAnnotDict.Add(AnnotArgsType.AnnotCircle, null);
LastAnnotDict.Add(AnnotArgsType.AnnotLine, null);
}
public void SaveLastAnnot()
{
if (annot == null)
{
return;
}
if (annot.EventType == AnnotArgsType.AnnotLine)
{
var lineAnnotArgs = annot as LineAnnotArgs;
if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
{
LastArrowAnnot = annot;
return;
}
}
LastAnnotDict[annot.EventType] = annot;
}
#region 静态
//是否为形状注释
public static bool IsShapAnnot(AnnotHandlerEventArgs annot)
{
if (annot.EventType == AnnotArgsType.AnnotCircle ||
annot.EventType == AnnotArgsType.AnnotSquare ||
annot.EventType == AnnotArgsType.AnnotLine
)
{
return true;
}
else
{
return false;
}
}
//是否为高亮注释
public static bool IsHightAnnot(AnnotHandlerEventArgs annot)
{
if (annot.EventType == AnnotArgsType.AnnotUnderline ||
annot.EventType == AnnotArgsType.AnnotSquiggly ||
annot.EventType == AnnotArgsType.AnnotHighlight ||
annot.EventType == AnnotArgsType.AnnotStrikeout
)
{
return true;
}
else
{
return false;
}
}
//判断注释列表是否有不同种类的注释
public static bool IsDifferentTypeAnnots(List annotlists)
{
//如高亮、下划线、删除线,是属于同一种类的注释
bool isDifferentAnnotTyle = false;
var annot = annotlists[0];
var lastAnnot = annot;
foreach (var item in annotlists)
{
if (lastAnnot.EventType != item.EventType)
{
if ((AnnotTransfer.IsShapAnnot(annot) == true && AnnotTransfer.IsShapAnnot(item) == true) || (AnnotTransfer.IsHightAnnot(annot) == true && AnnotTransfer.IsHightAnnot(item) == true))
{
lastAnnot = item;
continue;
}
lastAnnot = item;
isDifferentAnnotTyle = true;
break;
}
}
return isDifferentAnnotTyle;
}
//外部UI控件选中状态
public static bool IsSolidStyle(DashStyle LineDash)
{
bool isSolid = true;
if (LineDash == null || LineDash.Dashes.Count == 0)
{
return isSolid;
}
foreach (var item in LineDash.Dashes)
{
if (item > 0)
{
isSolid = false;
break;
}
}
return isSolid;
}
public static DashStyle GetLineDashStyle(bool isSolid)
{
DashStyle newDash = new DashStyle();
if (isSolid == false)
{
newDash.Dashes.Add(2);
newDash.Dashes.Add(2);
}
else
{
newDash = DashStyles.Solid;
}
return newDash;
}
#endregion 静态
//单个属性更改
public void UpdateAnnotAAttrib(AnnotAttrib annotAttrib, object obj)
{
if (annotlists != null && annotlists.Count > 1)
{
foreach (var itemevent in AnnotEvents)
{
itemevent?.UpdateAttrib(annotAttrib, obj);
itemevent?.UpdateAnnot();
}
}
else
{
AnnotEvent?.UpdateAttrib(annotAttrib, obj);
AnnotEvent?.UpdateAnnot();
//this.annot = AnnotEvent.AnnotItemsList[0];
}
}
//多个属性更改
public void UpdateAnnotAllAttribs(Dictionary AnnotAttribDir)
{
if (annotlists != null && annotlists.Count > 1)
{
foreach (var itemevent in AnnotEvents)
{
foreach (var item in AnnotAttribDir)
{
itemevent?.UpdateAttrib(item.Key, item.Value);
}
itemevent?.UpdateAnnot();
}
}
else
{
foreach (var item in AnnotAttribDir)
{
AnnotEvent?.UpdateAttrib(item.Key, item.Value);
}
AnnotEvent?.UpdateAnnot();
//this.annot = AnnotEvent.AnnotItemsList[0];
}
}
//是否为多选
#region Invoke
///
/// 更新多个属性,触发到工具栏注释工具,改变工具图标下的颜色值
///
public void InvokeToMyTools(object sender, Dictionary keyValues)
{
DataChanged?.Invoke(sender, keyValues);
}
///
/// 更新单个属性
///
public void InvokeToMyTools(AnnotArgsType argsType, object obj)
{
Dictionary changeData = new Dictionary();
changeData[argsType] = obj;
DataChanged?.Invoke(null, changeData);
}
//同一属性面板,切换注释工具
public void AnnotTypeChangedInvoke(object sender, Dictionary keyValues)
{
AnnotTypeChanged?.Invoke(sender, keyValues);
}
#endregion Invoke
}
}