123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- 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
- {
- /// <summary>
- /// 注释面板与外部(如注释工具)关联
- /// </summary>
- public class AnnotTransfer
- {
- public event EventHandler<Dictionary<AnnotArgsType, object>> DataChanged;
- public event EventHandler<Dictionary<AnnotArgsType, object>> AnnotTypeChanged;
- public bool IsAddLink = false;
- public bool IsLocationLink = false;
- public AnnotAttribEvent AnnotEvent { get; set; }
- public List<AnnotAttribEvent> AnnotEvents = new List<AnnotAttribEvent>();
- public AnnotHandlerEventArgs annot;
- public List<AnnotHandlerEventArgs> annotlists;
- public Dictionary<AnnotArgsType, AnnotHandlerEventArgs> LastAnnotDict = new Dictionary<AnnotArgsType, AnnotHandlerEventArgs>();
- 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<AnnotHandlerEventArgs> 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<AnnotAttrib, object> 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
- /// <summary>
- /// 更新多个属性,触发到工具栏注释工具,改变工具图标下的颜色值
- /// </summary>
- public void InvokeToMyTools(object sender, Dictionary<AnnotArgsType, object> keyValues)
- {
- DataChanged?.Invoke(sender, keyValues);
- }
- /// <summary>
- /// 更新单个属性
- /// </summary>
- public void InvokeToMyTools(AnnotArgsType argsType, object obj)
- {
- Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
- changeData[argsType] = obj;
- DataChanged?.Invoke(null, changeData);
- }
- //同一属性面板,切换注释工具
- public void AnnotTypeChangedInvoke(object sender, Dictionary<AnnotArgsType, object> keyValues)
- {
- AnnotTypeChanged?.Invoke(sender, keyValues);
- }
- #endregion Invoke
- }
- }
|