1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108 |
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Office.Model;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using PDF_Office.ViewModels.Tools;
- using ComPDFKitViewer;
- using PDF_Office.Helper;
- using PDF_Office.Properties;
- using PDFSettings;
- using System.Windows.Media;
- using ComPDFKit.PDFDocument.Action;
- using ComPDFKit.PDFDocument;
- using System.Diagnostics;
- using ComPDFKit.PDFAnnotation;
- using PDF_Office.ViewModels.BOTA;
- using PDF_Office.Views.BOTA;
- using System.Windows.Forms;
- using Control = System.Windows.Controls.Control;
- using Microsoft.Office.Interop.Word;
- using Point = System.Windows.Point;
- using System.Windows.Ink;
- using PDF_Office.EventAggregators;
- using System.Management.Instrumentation;
- using Prism.Events;
- using System.Windows.Input;
- using ContextMenu = System.Windows.Controls.ContextMenu;
- using MenuItem = System.Windows.Controls.MenuItem;
- using System.Drawing;
- using Color = System.Windows.Media.Color;
- using Brush = System.Windows.Media.Brush;
- using FontFamily = System.Windows.Media.FontFamily;
- namespace PDF_Office.ViewModels.FillAndSign
- {
- public class FillAndSignContentViewModel : BindableBase, INavigationAware
- {
- #region
- private CPDFViewer PDFViewer;
- private AnnotPropertyPanel propertyPanel = new AnnotPropertyPanel();
- private ViewContentViewModel viewContentViewModel;
- private bool isRightMenuAddAnnot = false;
- private IEventAggregator events;
- public List<List<Point>> ShapePoints = new List<List<Point>>();
- private string Shape = "HookShape";
- private PopMenu FreeHandAnnotPopMenu;
- private PopMenu MultiAnnotPopMenu;
- private IRegionManager regions { get; set; }
- private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
- public static bool IsEdit = false;
- public Brush SelectColor = new SolidColorBrush(Colors.GreenYellow);
- public double FillOpacity = 1;
- public double LineWidth = 1;
- public double LineWidthMultiple = 1;
- #endregion
- #region Command
- public DelegateCommand<RoutedEventArgs> CheckCommand { get; set; }
- /// <summary>
- /// 按钮名称和属性面板映射字典
- /// </summary>
- public Dictionary<string, string> btnToProperty = new Dictionary<string, string>();
- #endregion
- public FillAndSignContentViewModel(IRegionManager regionManager, IEventAggregator events)
- {
- regions = regionManager;
- this.events = events;
- CheckCommand = new DelegateCommand<RoutedEventArgs>(CheckedEvent);
- ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
- InitDictionary();
- InitSelectFreeHandAnnotMenu();
- }
- private void CheckedEvent(RoutedEventArgs e)
- {
- IsEdit = false;
- var control = e.OriginalSource as Control;
- //NavigateToProperty(control.Name);
- //不创建注释,属于注释模板
- bool isTemplateAnnot = false;
- bool isSnapshotEdit = false;
- AnnotHandlerEventArgs annotArgs = null;
- var tag = control.Name;
- FindAnnotTypeKey(control.Name, ref annotArgs);
- if (control.Name == "RbtnSign") { isTemplateAnnot = true; }
- if (tag == "SnapshotEdit")
- {
- isSnapshotEdit = true;
- }
- else if (tag == "Signature" || tag == "Stamp")
- {
- isTemplateAnnot = true;
- }
- if (annotArgs != null)
- {
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- isRightMenuAddAnnot = false;
- }
- //当不是注释模板,且无创建注释时,属性面板显示为空内容
- if (isTemplateAnnot == false && annotArgs == null)
- {
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- else
- {
- if (isSnapshotEdit == true)
- {
- ShowPropertyPanel(false);
- isSnapshotEdit = false;
- }
- else
- {
- ShowPropertyPanel(true);
- }
- }
- }
- //注释工具
- private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
- {
- LineWidthMultiple = 1;
- switch (tag)
- {
- case "RbtnDate":
- case "RbtnText"://文本
- annotArgs = GetFreetext();
- break;
- case "Freetext"://文本
- annotArgs = GetFreetext();
- break;
- case "RbtnSign"://签名
- annotArgs = GetSignature();
- PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
- break;
- case "RbtnTick"://勾
- Shape = "HookShape";
- ShapePoints = new List<List<Point>> { new List<Point> { new Point(0.599976, 7.0286), new Point(5.57775, 11.8), new Point(13.4, 1.40002) } };
- annotArgs = GetStamp();
- break;
- case "RbtnFork"://叉
- Shape = "ForkShape";
-
- ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(12.8, 12.8) }, new List<Point> { new Point(12.8, 3.20001), new Point(3.20005, 12.8) } };
- annotArgs = GetStamp();
- break;
- case "RbtnRectangle"://矩形
- Shape = "RectShape";
- ShapePoints = new List<List<Point>> { new List<Point> { new Point(0.19995, 5), new Point(28, 5), new Point(28, 27), new Point(0.19995, 27), new Point(0.19995, 5) } };
- annotArgs = GetStamp();
- break;
- case "RbtnLine"://下划线
- Shape = "LineShape";
- ShapePoints = new List<List<Point>> { new List<Point> { new Point(12.19995, 10), new Point(36, 10) } };
- annotArgs = GetStamp();
- break;
- case "RbtnPoint":
- Shape = "DotShape";
- ShapePoints = new List<List<Point>> { new List<Point> { new Point(12.19995, 10), new Point(12.19995, 10) } };
- LineWidthMultiple = 4;
- annotArgs = GetStamp();
- break;
- default://图章
- break;
- }
- }
- /// <summary>
- /// 签名
- /// </summary>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetSignature()
- {
- AddToPropertyPanel("SignatureAnnotProperty");
- return null;
- }
- /// <summary>
- /// 图章
- /// </summary>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetStamp(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
- stampAnnotArgs.SetInkData(ShapePoints, LineWidth* LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
- //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- //PDFViewer.SetToolParam(stampArgs);
- //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
- //stampAnnotArgs.Opacity = 1;
- //stampAnnotArgs.StampText = "APPROVED";
- //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
- // stampAnnotArgs.Type = StampType.STANDARD_STAMP;
- stampAnnotArgs.IsContinueMode = true;
-
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
- List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
- if (stampAnnotArgs != null)
- stampAnnotArgsList.Add(stampAnnotArgs);
- //if (selectedArgs != null) {
- //var annot = selectedArgs[0];
- //if (annot != null)
- //{
- // foreach (var item in selectedArgs)
- // {
- // selectedArgs[selectedArgs.IndexOf(item)] = stampAnnotArgs;
- // }
- // AddToPropertyPanel("ShapFillProperty", "", selectedArgs, annotAttribsList);
- // return stampAnnotArgs;
- //}
- // }
- AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
- return stampAnnotArgs;
- }
- public void SetStamp()
- {
- StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
- stampAnnotArgs.SetInkData(ShapePoints, LineWidth* LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
- //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- //PDFViewer.SetToolParam(stampArgs);
- //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
- //stampAnnotArgs.Opacity = 1;
- //stampAnnotArgs.StampText = "APPROVED";
- //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
- stampAnnotArgs.IsContinueMode = true;
- stampAnnotArgs.Opacity = FillOpacity;
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
- List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
- if (stampAnnotArgs != null)
- stampAnnotArgsList.Add(stampAnnotArgs);
- AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
- bool isTemplateAnnot = false;
- bool isSnapshotEdit = false;
- AnnotHandlerEventArgs annotArgs = stampAnnotArgs;
- if (annotArgs != null)
- {
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- isRightMenuAddAnnot = false;
- }
- //当不是注释模板,且无创建注释时,属性面板显示为空内容
- if (isTemplateAnnot == false && annotArgs == null)
- {
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- else
- {
- if (isSnapshotEdit == true)
- {
- ShowPropertyPanel(false);
- isSnapshotEdit = false;
- }
- else
- {
- ShowPropertyPanel(true);
- }
- }
- }
- /// <summary>
- /// 手绘
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- List<AnnotHandlerEventArgs> newSelectedArgs= new List<AnnotHandlerEventArgs>();
- FreehandAnnotArgs freehandArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- freehandArgs = new FreehandAnnotArgs();
-
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null)
- {
- freehandArgs.InkColor = annotate.FreeHandColor;
- }
- else
- {
- freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
- }
- freehandArgs.RawPointList= new List<List<Point>> { new List<Point> { new Point(0.599976, 7.0286), new Point(5.57775, 11.8), new Point(13.4, 1.40002) } };
- freehandArgs.Transparency = 1;
- freehandArgs.LineWidth = 2;
- if (freehandArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(freehandArgs);
- }
- }
- else
- {
- freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
- foreach (var item in selectedArgs)
- {
-
- //if (ListPoint((item as FreehandAnnotArgs).RawPointList, ShapePoints)){
- foreach (var point in viewContentViewModel.FillAndSign)
- {
- if ((item as FreehandAnnotArgs).PageIndex == point.X && (item as FreehandAnnotArgs).AnnotIndex == point.Y)
- {
- newSelectedArgs.Add(item);
- }
- }
- }
- freehandArgs.RawPointList = ShapePoints;
- freehandArgs.InkColor = (SelectColor as SolidColorBrush).Color;
- freehandArgs.Transparency = 1;
- freehandArgs.LineWidth = LineWidth;
- annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
- annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
- annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
- annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
- annotAttribsList[AnnotAttrib.Path]= freehandArgs.RawPointList;
- AddToPropertyPanel("ShapFillProperty", "Freehand", newSelectedArgs, annotAttribsList);
- //GetStamp();
- return freehandArgs;
- }
- //annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
- //annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
- //annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
- //annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
- //AddToPropertyPanel("ShapFillProperty", "Freehand", selectedArgs, annotAttribsList);
- return freehandArgs;
- }
- private bool ListPoint(List<List<Point>> leftpoints, List<List<Point>> rightpoints)
- {
- if (leftpoints.Count == rightpoints.Count)
- {
- if (leftpoints[0][0].X == rightpoints[0][0].X) { return true; }
- }
- return false;
- }
- /// <summary>
- /// 文本
- /// </summary>
- /// <param name="selectedfreetextArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- FreeTextAnnotArgs freetextArgs = null;
- TextAlignment textAlignment;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- freetextArgs = new FreeTextAnnotArgs();
-
- freetextArgs.Align = TextAlignment.Left;
- freetextArgs.BgColor = Colors.Transparent;
- freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
- freetextArgs.FontColor = Colors.Black;
- freetextArgs.FontSize = 14;
- freetextArgs.Transparency = 1;
- freetextArgs.LineColor = Colors.Black;
- freetextArgs.LineWidth = 0;
- freetextArgs.TextContent = string.Empty;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
- if (annotProperty != null)
- {
- freetextArgs.Align = annotProperty.TextAlign;
- freetextArgs.BgColor = annotProperty.BackgroundColor;
- freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
- freetextArgs.FontColor = annotProperty.ForgoundColor;
- freetextArgs.FontSize = annotProperty.FontSize;
- freetextArgs.Transparency = annotProperty.Opacity;
- freetextArgs.LineColor = annotProperty.BorderColor;
- freetextArgs.LineWidth = annotProperty.Thickness;
- freetextArgs.TextContent = annotProperty.NoteText;
- freetextArgs.FontWeight = annotProperty.FontWeight;
- freetextArgs.FontStyle = annotProperty.FontStyle;
- }
- int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
- if (align == 0)
- textAlignment = TextAlignment.Left;
- else if (align == 1)
- textAlignment = TextAlignment.Center;
- else
- textAlignment = TextAlignment.Right;
- if (freetextArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(freetextArgs);
- }
- }
- else
- {
- freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
- textAlignment = freetextArgs.Align;
- }
- annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
- annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
- annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
- annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
- annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
- annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
- annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
- annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
- annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
- annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
- annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
- annotAttribsList[AnnotAttrib.Text] = freetextArgs.TextContent;
- AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs, annotAttribsList);
- return freetextArgs;
- }
- /// <summary>
- /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
- /// </summary>
- /// <param name="viewContent">对应的注释面板</param>
- /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
- /// <param name="annot">注释</param>
- /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
- private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null, bool isUpData = false)
- {
- if (annots != null&& annots.Count!=0)
- {
- propertyPanel.annotlists = annots;
- propertyPanel.annot = annots[0];
- }
- else
- {
- propertyPanel.annotlists = null;
- propertyPanel.annot = null;
- return;
- }
- if (annotAttribsList != null && annotAttribsList.Count != 0)
- {
- if (annots.Count > 1)
- {
- if (propertyPanel.AnnotEvents == null)
- propertyPanel.AnnotEvents = new List<AnnotAttribEvent>();
- propertyPanel.AnnotEvents.Clear();
- foreach (var itemAnnot in annots)
- {
- var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, annotAttribsList);
- propertyPanel.AnnotEvents.Add(eventitem);
- }
- }
- propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annots[0], annotAttribsList);
- if (annots[0] is LinkAnnotArgs && annotAttribEvent != null)
- {
- propertyPanel.AnnotEvent = annotAttribEvent;
- }
- }
- if (toolTag == "Freetext")
- {
- propertyPanel.SetIsTextFill(true);
- }
- else
- {
- propertyPanel.SetIsTextFill(false);
- }
- if (string.IsNullOrEmpty(viewContent) == false)
- {
- if (isUpData) { return; }
- if (viewContent == "ShapFillProperty") { NavigateToProperty(viewContent, propertyPanel); return; }
- viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
- }
- }
- private void NavigateToProperty(string btnName, AnnotPropertyPanel annotPropertyPanel)
- {
- NavigationParameters values = new NavigationParameters();
- values.Add(ParameterNames.PDFViewer, PDFViewer);
- values.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
- values.Add("Shape", Shape);
- values.Add("FillAndSignContentViewModel", this);
- regions.RequestNavigate(RegionNames.PropertyRegionName, btnName, values);
- viewContentViewModel.IsPropertyOpen = true;
- }
- /// <summary>
- /// 初始化按钮名称-属性面板字典
- /// </summary>
- private void InitDictionary()
- {
- btnToProperty["RbtnText"] = "TextFillProperty";
- btnToProperty["RbtnTick"] = "ShapFillProperty";
- btnToProperty["RbtnFork"] = "ShapFillProperty";
- btnToProperty["RbtnRectangle"] = "ShapFillProperty";
- btnToProperty["RbtnLine"] = "ShapFillProperty";
- btnToProperty["RbtnPoint"] = "ShapFillProperty";
- btnToProperty["RbtnDate"] = "DateFillProperty";
- btnToProperty["RbtnSign"] = "";
- }
- /// <summary>
- /// 手绘
- /// </summary>
- private void InitSelectFreeHandAnnotMenu()
- {
- var popMenu = new ContextMenu();
- PopMenu pop = new PopMenu(popMenu);
- var menuItem = new MenuItem();
- menuItem.Name = "FreeHandCopy";
- menuItem.Header = "复制";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
- menuItem = new MenuItem();
- menuItem.Name = "FreeHandCut";
- menuItem.Header = "剪切";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
- menuItem = new MenuItem();
- menuItem.Name = "FreeHandPaste";
- menuItem.Header = "粘贴";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
- menuItem = new MenuItem();
- menuItem.Name = "FreeHandDelete";
- menuItem.Header = "删除";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
- pop.AddItem(GetSeparator());
- FreeHandAnnotPopMenu = pop;
- }
- private Separator GetSeparator()
- {
- Separator separator = new Separator();
- separator.Height = 1;
- separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
- separator.BorderThickness = new Thickness(1);
- return separator;
- }
- private void BindingPDFViewerHandler()
- {
- //来自PDFViewer的响应事件
- if (PDFViewer != null)
- {
- PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
- PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
- PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
- PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
- PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
- PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
- }
- }
- private void UnBindingPDFViewerHandler()
- {
- if (PDFViewer != null)
- {
- PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
- PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
- PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
- }
- }
- //在注释工具的状态下,右键菜单
- private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
- {
- if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
- return;
- switch (e.CommandType)
- {
- case CommandType.Context:
- if (e.AnnotEventArgsList.Count > 0)
- {
- if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
- {
- //绑定标记密文处右键菜单
- events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
- }
- else
- {
- if (e.AnnotEventArgsList.Count == 1)
- {
- var selectedAnnot = e.AnnotEventArgsList[0];
- switch (selectedAnnot.EventType)
- {
-
- case AnnotArgsType.AnnotFreehand:
- e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- }
- }
- else
- {
- bool isHigh = true;//是否为高亮
- foreach (var item in e.AnnotEventArgsList)
- {
- if (isHightAnnot(item) == false)
- {
- isHigh = false;
- break;
- }
- }
- MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
- MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
- e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
- }
- }
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- else
- {
- if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
- {
-
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- else
- {
- e.PopupMenu = ViewerContextMenu();
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- }
- break;
- }
- }
- private ContextMenu ViewerContextMenu()
- {
- ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
-
- ViewerContextMenu_Loaded(contextMenu, null);
- return contextMenu;
- }
- private void ViewerContextMenu_Loaded(object sender, RoutedEventArgs e,Visibility visibility =Visibility.Collapsed)
- {
- ContextMenu contextMenu = sender as ContextMenu;
- if (contextMenu.Items.Count > 0)
- {
- int index = PDFViewer.CurrentIndex;
- //检测是否已存在相同数据
- CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
- foreach (var item in contextMenu.Items)
- {
- if (item is Separator separator) {
-
- separator.Visibility = visibility;
- }
- if (item is MenuItem menuItem1)
- {
- //if (menuItem1.Tag.ToString() == "DisplayAnnot" || menuItem1.Tag.ToString() == "HiddenAnnot")
- //{
- // SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
- //}
-
- switch (menuItem1.Tag.ToString())
- {
- case "Copy":
- //粘贴
- //if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
- //{
- // menuItem1.IsEnabled = false;
- // menuItem1.Opacity = 0.5;
- //}
- //else
- //{
- // menuItem1.IsEnabled = true;
- // menuItem1.Opacity = 1;
- //}
- menuItem1.CommandTarget = (UIElement)PDFViewer;
- menuItem1.Command = ApplicationCommands.Paste;
- break;
- case "AddAnnotation":
- menuItem1.Visibility = visibility;
-
- break;
- case "HiddenAnnot":
- menuItem1.Visibility = visibility;
-
- break;
- case "DisplayAnnot":
- menuItem1.Visibility = visibility;
-
- break;
- case "AddBookMark":
- menuItem1.Visibility = visibility;
-
- break;
- case "DelBookMark":
- menuItem1.Visibility = visibility;
-
- break;
- case "ToolMode":
- menuItem1.Visibility = visibility;
-
- break;
- case "ReadModel":
- menuItem1.Visibility = visibility;
-
- break;
- case "UnReadModel":
- menuItem1.Visibility = visibility;
-
- break;
- case "ViewZoom":
- menuItem1.Visibility = visibility;
-
- break;
- case "PageDisplay":
- menuItem1.Visibility = visibility;
-
- break;
- case "Select":
- menuItem1.Click -= Select_Click;
- menuItem1.Click += Select_Click;
- break;
- case "Print":
- menuItem1.Command = viewContentViewModel.PrintCommand;
- break;
- }
- }
- }
- }
- }
- private void Select_Click(object sender, RoutedEventArgs e)
- {
- if (viewContentViewModel.OpenBOTA == false)
- {
- viewContentViewModel.OpenBOTA = true;
- }
- bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
- if (isBook == false)
- {
- bOTAContent.TabItemSearch.IsSelected = true;
- }
- }
- private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
- {
- bool isTabItem = false;
- bOTAContentViewModel = null;
- bOTAContent = null;
- if (regions.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
- {
- var views = regions.Regions[viewContentViewModel.BOTARegionName].Views;
- var model = views.FirstOrDefault(q => q is BOTAContent);
- if (model is BOTAContent bOTAContent1)
- {
- bOTAContent = bOTAContent1;
- bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
- if (bOTAContentViewModel.CurrentBar == tabItemText)
- {
- isTabItem = true;
- }
- }
- //foreach (var item in views)
- //{
- // if (item is BOTAContent bOTAContent1)
- // {
- // bOTAContent = bOTAContent1;
- // bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
- // if (bOTAContentViewModel.CurrentBar == tabItemText)
- // {
- // isTabItem = true;
- // break;
- // }
- // }
- //}
- }
- return isTabItem;
- }
- private 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;
- }
- }
- private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
- {
- if (e != null && e.Count > 0)
- {
- for (int i = 0; i < e.Count; i++)
- {
- AnnotEditEvent editEvent = e[i];
- switch (editEvent.EditAction)
- {
- case ActionType.Add:
- int pageindex = editEvent.PageIndex;
- int annotindex = editEvent.AnnotIndex;
- viewContentViewModel.FillAndSign.Add(new Point(pageindex, annotindex));
- break;
- }
- }
- }
- }
- //选中和非选中注释,右键菜单
- private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
- {
- if (e != null)
- {
- var annot = e.AnnotItemsList[0];
- if (annot != null)
- {
- if (e.AnnotItemsList.Count == 1)
- {
- //IsEdit = false;
- //IsAnnotCreateReset:是否为创建注释的状态
- if (e.IsAnnotCreateReset == false)
- {
-
- GetSelectedAnnots(e);
- //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
- //PDFViewer.SetToolParam(annot);
- }
- else
- {
- //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
- if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
- annot.EventType != AnnotArgsType.AnnotUnderline &&
- annot.EventType != AnnotArgsType.AnnotHighlight &&
- annot.EventType != AnnotArgsType.AnnotSquiggly &&
- annot.EventType != AnnotArgsType.AnnotLink &&
- annot.EventType != AnnotArgsType.AnnotFreehand &&
- annot.EventType != AnnotArgsType.AnnotSticky
- )
- {
- if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
- {
- foreach (var item in ToolExpandDict)
- {
- if (item.Value == e.AnnotItemsList[0].EventType)
- {
- annot = null;//新建注释时,回到默认值
- FindAnnotTypeKey(item.Key, ref annot);
- break;
- }
- }
- }
- }
- //else
- //PDFViewer.SetToolParam(annot);
- //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
- if (isRightMenuAddAnnot)
- {
- ShowPropertyPanel(false);
- }
- else
- {
- ShowPropertyPanel();
- }
- }
- }
- else
- {
- bool isDifferentAnnotTyle = false;
- var lastAnnot = annot;
- foreach (var item in e.AnnotItemsList)
- {
- if (lastAnnot.EventType != item.EventType)
- {
- if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
- {
- lastAnnot = item;
- continue;
- }
- lastAnnot = item;
- isDifferentAnnotTyle = true;
- break;
- }
- }
- if (isDifferentAnnotTyle)
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- else
- GetSelectedAnnots(e);
- }
- }
- }
- else
- {
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- }
- //private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
- //{
- // if (e != null && e.Count > 0)
- // {
- // for (int i = 0; i < e.Count; i++)
- // {
- // AnnotEditEvent editEvent = e[i];
- // switch (editEvent.EditAction)
- // {
- // case ActionType.Add:
- // // bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
- // if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
- // {
- // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
- // if (viewModel != null)
- // {
- // int pageindex = editEvent.PageIndex;
- // int annotindex = editEvent.AnnotIndex;
- // viewModel.UpdateAddedAnnot(pageindex, annotindex);
- // }
- // }
- // break;
- // case ActionType.Del:
- // //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
- // if (isTabItemAnnotation)
- // {
- // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
- // if (viewModel != null)
- // {
- // int pageindex = editEvent.PageIndex;
- // int annotindex = editEvent.AnnotIndex;
- // viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
- // }
- // }
- // break;
- // case ActionType.Modify:
- // isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
- // if (bOTAContent.TabItemAnnotation.IsSelected)
- // {
- // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
- // if (viewModel != null)
- // {
- // int pageindex = editEvent.PageIndex;
- // int annotindex = editEvent.AnnotIndex;
- // viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
- // }
- // }
- // break;
- // case ActionType.TextEdit:
- // break;
- // default:
- // break;
- // }
- // }
- // }
- //}
- private bool isShapAnnot(AnnotHandlerEventArgs annot)
- {
- if (annot.EventType == AnnotArgsType.AnnotCircle ||
- annot.EventType == AnnotArgsType.AnnotSquare ||
- annot.EventType == AnnotArgsType.AnnotLine
- )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- private void GetSelectedAnnots(AnnotAttribEvent e)
- {
- IsEdit = true;
- var annot = e.AnnotItemsList[0];
- switch (annot.EventType)
- {
- case AnnotArgsType.AnnotFreeText:
- GetFreetext(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotFreehand:
- GetFreehand(e.AnnotItemsList);
- break;
- }
- }
- private void ShowPropertyPanel(bool show = true)
- {
- viewContentViewModel.IsPropertyOpen = show;
- }
- #region Navigation
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- UnBindingPDFViewerHandler();
- ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
- ViewerContextMenu_Loaded(contextMenu, null,Visibility.Visible);
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
- BindingPDFViewerHandler();
- IsEdit = false;
- }
- #endregion
- }
- }
|