123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.PDFDocument.Action;
- using ComPDFKit.PDFDocument;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Master.CustomControl;
- using PDF_Master.EventAggregators;
- using PDF_Master.Helper;
- using PDF_Master.Properties;
- using PDF_Master.ViewModels.BOTA;
- using PDF_Master.Views.BOTA;
- using PDFSettings;
- 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 System.Windows.Controls.Primitives;
- using System.Windows.Media;
- using System.Diagnostics;
- using PDF_Master.Model.AnnotPanel;
- using System.Windows.Input;
- using PDF_Master.ViewModels.Tools.AnnotManager;
- using ComPDFKit.Import;
- using System.Windows.Markup;
- namespace PDF_Master.ViewModels.Tools
- {
- public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
- {
- #region 事件绑定和解绑
- private void BindingEvent()
- {
- //属性面板与注释工具栏绑定:属性面板的属性变化,会同步注释工具栏的属性值
- //比如在属性面板里更改注释颜色,会同时更新工具栏对应的工具颜色
- propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
- propertyPanel.DataChanged += AnnotPropertyPanel_DataChanged;
- propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
- propertyPanel.AnnotTypeChanged += AnnotPropertyPanel_AnnotTypeChanged;
- //快捷键
- KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
- KeyEventsHelper.KeyDown += ShortCut_KeyDown;
- }
- private void UnBindingEvent()
- {
- propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
- propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
- //快捷盘解绑
- KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
- }
- private void BindingPDFViewerHandler()
- {
- //来自PDFViewer的响应事件
- if (PDFViewer != null)
- {
- PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
- PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
- PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
- PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
- PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
- PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
- PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
- PDFViewer.SnapshotCommandHandler += PDFViewer_SnapshotCommandHandler;
- PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
- PDFViewer.PDFActionHandler += PDFViewer_PDFActionHandler;
- PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
- PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
- PDFViewer.PreviewMouseLeftButtonDown -= PDFViewer_PreviewMouseLeftButtonDown;
- PDFViewer.PreviewMouseLeftButtonDown += PDFViewer_PreviewMouseLeftButtonDown;
- }
- }
- private void UnBindingPDFViewerHandler()
- {
- if (PDFViewer != null)
- {
- PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
- PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
- PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
- PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
- PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
- PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
- PDFViewer.PreviewMouseLeftButtonDown -= PDFViewer_PreviewMouseLeftButtonDown;
- }
- }
- #endregion 事件绑定和解绑
- #region 与触发事件调用相关的函数
- //鼠标左键双击注释
- private void PDFViewer_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- if (e.ClickCount == 1)
- {
- //if (sender is CPDFViewer pDFViewer)
- //{
- // if (pDFViewer.ToolManager.CurrentAnnotArgs != null)
- // {
- // if (pDFViewer.ToolManager.CurrentAnnotArgs is FreehandAnnotArgs freehand)
- // {
- // PDFViewer.SelectAnnotation(freehand.PageIndex, freehand.AnnotIndex);
- // }
- // }
- //}
- bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemBookMark");
- if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemBookMark.IsSelected == true)
- {
- this.events.GetEvent<CleanSelectAllEvent>().Publish(new CleanSelectAllArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsCleanSelectAll = true });
- }
- }
- if (e.ClickCount == 2)
- {
- if (CurrentSelectedAnnot != null)
- {
- var type = CurrentSelectedAnnot.EventType;
- if (type != AnnotArgsType.AnnotSticky && type != AnnotArgsType.AnnotFreeText &&
- type != AnnotArgsType.AnnotHighlight && type != AnnotArgsType.AnnotUnderline && type != AnnotArgsType.AnnotStrikeout)
- {
- int dpi = DpiHelpers.Dpi;
- var rect = CurrentSelectedAnnot.ClientRect;
- rect = new Rect(
- rect.Left * PDFViewer.ZoomFactor,
- rect.Top * PDFViewer.ZoomFactor,
- rect.Width * PDFViewer.ZoomFactor,
- rect.Height * PDFViewer.ZoomFactor);
- var ui = PDFViewer.Parent as ContentControl;
- if (ui != null)
- {
- var point = e.GetPosition(ui);
- int pageIndex = 0;
- Point pagePoint = new Point(0, 0);
- //Todo:等黎总需要更新ComPDFKit.dll
- //PDFViewer.ConvertViewPointToPage(point, out pageIndex, out pagePoint);
- if (pagePoint.X >= rect.Left && pagePoint.X <= rect.Right && pagePoint.Y >= rect.Top && pagePoint.Y <= rect.Bottom)
- PopAnnotNoteText(CurrentSelectedAnnot);
- }
- }
- if (type == AnnotArgsType.AnnotSticky)
- {
- (CurrentSelectedAnnot as StickyAnnotArgs).PopupEditWnd();
- }
- }
- }
- }
- //超链接跳转
- private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
- {
- if (action == null)
- {
- return;
- }
- switch (action.ActionType)
- {
- case C_ACTION_TYPE.ACTION_TYPE_GOTO:
- if (PDFViewer != null)
- {
- CPDFGoToAction gotoAction = action as CPDFGoToAction;
- CPDFDestination dest = gotoAction.GetDestination(PDFViewer.Document);
- if (dest != null)
- {
- PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(0, 0));
- }
- }
- break;
- case C_ACTION_TYPE.ACTION_TYPE_URI:
- {
- CPDFUriAction uriAction = action as CPDFUriAction;
- string uri = uriAction.GetUri();
- try
- {
- if (!string.IsNullOrEmpty(uri))
- {
- Process.Start(uri);
- }
- }
- catch (Exception ex)
- {
- }
- }
- break;
- }
- }
- private void GetSelectedAnnots(AnnotAttribEvent e)
- {
- var annot = e.AnnotItemsList[0];
- switch (annot.EventType)
- {
- case AnnotArgsType.AnnotHighlight:
- GetHighLight(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotUnderline:
- GetUnderLine(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotStrikeout:
- GetStrikeout(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotSquiggly:
- GetSquiggly(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotFreehand:
- GetFreehand(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotFreeText:
- GetFreetext(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotSquare:
- GetRect(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotCircle:
- GetCircle(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotLine:
- bool isLine = true;
- if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
- {
- if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_NONE)
- {
- isLine = false;
- }
- }
- if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
- {
- if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_NONE)
- {
- isLine = false;
- }
- }
- if (isLine)
- GetArrowLine("Line", e.AnnotItemsList);
- else
- GetArrowLine("Arrow", e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotLink:
- //viewContentViewModel.IsCreateLink = false;
- //e.IsAnnotCreateReset= true;
- if (BtnLinkIsChecked == false)
- {
- propertyPanel.IsAddLink = false;
- }
- GetLink(e.AnnotItemsList, e);
- break;
- case AnnotArgsType.AnnotSticky:
- GetStickyNote(e.AnnotItemsList);
- customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
- customStickyPopup.GetPDFViewer = PDFViewer;
- break;
- case AnnotArgsType.AnnotStamp:
- GetStamp();
- break;
- }
- }
- private void SelectedSignature(List<AnnotHandlerEventArgs> annotlist)
- {
- if (annotlist == null || annotlist.Count == 0)
- return;
- var annot = annotlist[0];
- if (annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand)
- return;
- if (annot.PageIndex < 0 || annot.AnnotIndex < 0)
- return;
- var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
- if (signAnnot == null)
- {
- if (annot.EventType == AnnotArgsType.AnnotStamp)
- {
- StrAnnotToolChecked = "Stamp";
- }
- //else
- //{
- // StrAnnotToolChecked = "";
- //}
- }
- else
- {
- GetSignature();
- StrAnnotToolChecked = "Signature";
- }
- }
- private void AddAnnotSignature(AnnotHandlerEventArgs annot)
- {
- if ((annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand) ||
- (annot.PageIndex < 0 || annot.AnnotIndex < 0)) return;
- if (StrAnnotToolChecked == "Signature")
- {
- if (viewContentViewModel.AnnotSignatures == null)
- viewContentViewModel.AnnotSignatures = new List<Tuple<int, int>>();
- var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
- if (signAnnot == null)
- {
- viewContentViewModel.AnnotSignatures.Add(new Tuple<int, int>(annot.PageIndex, annot.AnnotIndex));
- }
- }
- }
- #endregion 与触发事件调用相关的函数
- #region PDFViewer事件
- private AnnotHandlerEventArgs CurrentSelectedAnnot = null;
- //选中和非选中注释
- private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
- {
- if (e != null)
- {
- CurrentSelectedAnnot = null;
- var annot = e.AnnotItemsList[0];
- if (annot != null)
- {
- if (e.AnnotItemsList.Count == 1)
- {
- //IsAnnotCreateReset:是否为创建注释的状态
- if (e.IsAnnotCreateReset == false)
- {
- GetSelectedAnnots(e);
- SelectedSignature(e.AnnotItemsList);
- CurrentSelectedAnnot = annot;
- if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty)
- ShowPropertyPanel(true);
- }
- else
- {
- switch (annot.EventType)
- {
- case AnnotArgsType.AnnotFreeText:
- GetFreetext(e.AnnotItemsList);
- PDFViewer.SetToolParam(annot);
- break;
- case AnnotArgsType.AnnotSticky:
- customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
- customStickyPopup.GetPDFViewer = PDFViewer;
- break;
- case AnnotArgsType.AnnotLink:
- //viewContentViewModel.IsCreateLink = false;
- GetLink(e.AnnotItemsList, e);
- PDFViewer.SetToolParam(annot);
- break;
- }
- #region //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))
- // {
- // var strLineAnnotTag = "";
- // if (e.AnnotItemsList[0] is LineAnnotArgs)
- // {
- // var lineAnnot = e.AnnotItemsList[0] as LineAnnotArgs;
- // if (lineAnnot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE && lineAnnot.TailLineType == C_LINE_TYPE.LINETYPE_NONE)
- // {
- // strLineAnnotTag = "Line";
- // }
- // else
- // {
- // strLineAnnotTag = "Arrow";
- // }
- // }
- // foreach (var item in ToolExpandDict)
- // {
- // if (item.Value == e.AnnotItemsList[0].EventType)
- // {
- // annot = null;//新建注释时,回到默认值
- // if (string.IsNullOrEmpty(strLineAnnotTag))
- // {
- // FindAnnotTypeKey(item.Key, ref annot);
- // break;
- // }
- // else
- // {
- // if (strLineAnnotTag == item.Key)
- // {
- // FindAnnotTypeKey(item.Key, ref annot);
- // break;
- // }
- // }
- // }
- // }
- // PDFViewer.SetToolParam(annot);
- // }
- //}
- //设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
- //if (isRightMenuAddAnnot && annot.EventType!=AnnotArgsType.AnnotLink)
- //{
- // ShowPropertyPanel(false);
- //}
- //else
- //{
- // ShowPropertyPanel();
- //}
- #endregion //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
- }
- }
- else
- {
- bool isDifferentAnnotTyle = AnnotTransfer.IsDifferentTypeAnnots(e.AnnotItemsList);
- if (isDifferentAnnotTyle)
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- else
- GetSelectedAnnots(e);
- }
- }
- //注释列表同步选中
- var list = e.GetPageAnnotsIndex();
- bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
- if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemAnnotation.IsSelected == true && list != null && list.Count > 0)
- {
- if (list.Keys.Count == 0)
- {
- return;
- }
- var pageindex = new List<int>(list.Keys);
- List<int> annotes = new List<int>();
- list.TryGetValue(pageindex[0], out annotes);
- int annoteindex = annotes[0];
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- if (viewModel != null)
- {
- viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
- }
- }
- }
- else
- {
- if (BtnLinkIsChecked == false)
- {
- if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
- {
- if (PDFViewer.MouseMode == MouseModes.PanTool && propertyPanel.IsAddLink == false && propertyPanel.IsLocationLink == false)
- {
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- }
- else
- {
- if (propertyPanel.IsMultiSelected)
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- }
- }
- }
- //在注释工具的状态下,右键菜单
- private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
- {
- if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
- return;
- if ((UIElement)sender != null)
- {
- //绑定命令执行前的拦截事件,对于未解密权限的文档进行复制限制
- CommandManager.AddPreviewExecutedHandler((UIElement)sender, PreviewExcute);
- }
- 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];
- PopMenuCheckedLineDash(selectedAnnot);
- PopMenuCheckedFontFamily(selectedAnnot);
- PopMenuCheckedTextAglin(selectedAnnot);
- switch (selectedAnnot.EventType)
- {
- case AnnotArgsType.AnnotHighlight:
- case AnnotArgsType.AnnotUnderline:
- case AnnotArgsType.AnnotStrikeout:
- case AnnotArgsType.AnnotSquiggly:
- if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
- {
- colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
- }
- else
- {
- colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Border);
- }
- e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotFreehand:
- e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotFreeText:
- e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotSticky:
- e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotSquare:
- case AnnotArgsType.AnnotCircle:
- ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
- ShapeAnnotPopMenu.SetVisual("ShapeFillColor", true);
- e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotLine:
- ShapeAnnotPopMenu.SetVisual("ShapeFillColor", false);
- ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
- e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotLink:
- e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotStamp:
- e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- }
- }
- else
- {
- bool isHigh = true;//是否为高亮
- foreach (var item in e.AnnotEventArgsList)
- {
- if (AnnotTransfer.IsHightAnnot(item) == false)
- {
- isHigh = false;
- break;
- }
- }
- MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
- MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
- e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);
- }
- }
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- else
- {
- if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
- {
- e.PopupMenu = SelectedTextOrImageContextMenu(sender, e);
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- else
- {
- e.PopupMenu = ViewerContextMenu(sender);
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- }
- break;
- }
- }
- private void PreviewExcute(object sender, ExecutedRoutedEventArgs e)
- {
- if (e.Command == ApplicationCommands.Copy)
- {
- VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, Model.Dialog.ToolsDialogs.SaftyDialogs.EnumPermissionsSet.StatusAllowsPrinting, dialogs);
- if (result.IsDiscryptied)
- {
- if (result.Password != null)
- {
- string filePath = PDFViewer.Document.FilePath;
- var unlockresult = PDFViewer.Document.UnlockWithPassword(result.Password);
- }
- }
- else
- {
- e.Handled = true;
- }
- }
- }
- //右键菜单,选中字体样式按钮状态
- private void PopMenuCheckedFontFamily(AnnotHandlerEventArgs annot)
- {
- if (annot != null)
- {
- if (annot.EventType == AnnotArgsType.AnnotFreeText)
- {
- var freeText = annot as FreeTextAnnotArgs;
- FreeTextAnnotPopMenu.SetIsChecked(freeText.FontFamily.ToString(), true);
- }
- }
- }
- //右键菜单,选中文本内容对齐按钮状态
- private void PopMenuCheckedTextAglin(AnnotHandlerEventArgs annot)
- {
- if (annot != null)
- {
- if (annot.EventType == AnnotArgsType.AnnotFreeText)
- {
- var freeText = annot as FreeTextAnnotArgs;
- switch (freeText.Align)
- {
- case TextAlignment.Left:
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", true);
- break;
- case TextAlignment.Center:
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", true);
- break;
- case TextAlignment.Right:
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", true);
- break;
- case TextAlignment.Justify:
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", true);
- break;
- default:
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", false);
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", false);
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", false);
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", false);
- break;
- }
- }
- }
- }
- //右键菜单,选中虚实线按钮状态
- private void PopMenuCheckedLineDash(AnnotHandlerEventArgs annot)
- {
- if (annot != null)
- {
- bool isSolidLineDash = true;
- if (annot.EventType == AnnotArgsType.AnnotFreehand)
- {
- var freeHand = annot as FreehandAnnotArgs;
- isSolidLineDash = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
- FreeHandAnnotPopMenu.SetIsChecked(isSolidLineDash ? "FreeHandSolid" : "FreeHandDash", true);
- }
- else if (annot.EventType == AnnotArgsType.AnnotSquare)
- {
- var square = annot as SquareAnnotArgs;
- isSolidLineDash = AnnotTransfer.IsSolidStyle(square.LineDash);
- ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
- }
- else if (annot.EventType == AnnotArgsType.AnnotCircle)
- {
- var circle = annot as CircleAnnotArgs;
- isSolidLineDash = AnnotTransfer.IsSolidStyle(circle.LineDash);
- ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
- }
- else if (annot.EventType == AnnotArgsType.AnnotLine)
- {
- var line = annot as LineAnnotArgs;
- isSolidLineDash = AnnotTransfer.IsSolidStyle(line.LineDash);
- ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
- }
- }
- }
- /// <summary>
- /// 内容选择工具
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
- {
- SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
- SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
- SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
- SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
- SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
- var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
- if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
- {
- e.PopupMenu = popMenu;
- e.Handle = true;
- if (popMenu != null && popMenu.Items.Count == 5)
- {
- //复制
- MenuItem menuItem = popMenu.Items[0] as MenuItem;
- menuItem.CommandTarget = PDFViewer;
- menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
- //导出
- menuItem = popMenu.Items[1] as MenuItem;
- menuItem.CommandTarget = PDFViewer;
- if (menuItem.Items.Count == 3)
- {
- MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
- menuItem1.CommandTarget = PDFViewer;
- menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
- menuItem1 = menuItem.Items[1] as MenuItem;
- menuItem1.CommandTarget = PDFViewer;
- menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
- menuItem1 = menuItem.Items[2] as MenuItem;
- menuItem1.CommandTarget = PDFViewer;
- menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
- }
- //裁剪
- menuItem = popMenu.Items[2] as MenuItem;
- menuItem.CommandTarget = PDFViewer;
- menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
- //缩放至所选区域
- menuItem = popMenu.Items[3] as MenuItem;
- menuItem.CommandTarget = PDFViewer;
- menuItem.Visibility = Visibility.Collapsed;
- //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
- //打印
- menuItem = popMenu.Items[4] as MenuItem;
- menuItem.CommandTarget = PDFViewer;
- menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
- }
- }
- }
- private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
- {
- switch (e.Key)
- {
- case "CloseSnap":
- {
- #region to do
- //var item = PDFViewerTab.SelectedItem as TabItem;
- //if (item == null)
- //{
- // ClearSelectedToolPanel();
- // return;
- //}
- //Grid grid = item.Content as Grid;
- //if (grid == null || grid.Children.Count == 0)
- //{
- // ClearSelectedToolPanel();
- // return;
- //}
- //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
- //if (pdfViewer == null)
- //{
- // ClearSelectedToolPanel();
- // return;
- //}
- #endregion to do
- switch (PDFViewer.MouseMode)
- {
- case MouseModes.SelectTextTool:
- break;
- default:
- BtnSelecttoolIsChecked = false;
- BtnHandIsChecked = true;
- PDFViewer.EnableZoom(true);
- PDFViewer.EnableScroll(true);
- break;
- }
- }
- break;
- default:
- break;
- }
- }
- private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
- {
- if (e != null && e.Count > 0)
- {
- MultipleSelectionAnnot(e);
- for (int i = 0; i < e.Count; i++)
- {
- AnnotEditEvent editEvent = e[i];
- switch (editEvent.EditAction)
- {
- case ActionType.Add:
- //BOTA
- bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
- if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- if (viewModel != null)
- {
- int pageindex = editEvent.PageIndex;
- int annotindex = editEvent.AnnotIndex;
- viewModel.UpdateAddedAnnot(pageindex, annotindex);
- }
- }
- //添加书签注释,用于未保存前跟图章手绘注释的区分
- if (StrAnnotToolChecked == "Signature")
- {
- AddAnnotSignature(editEvent.EditAnnotArgs);
- }
- if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreeText)
- {
- (editEvent.EditAnnotArgs as FreeTextAnnotArgs).LineWidth = 0;
- }
- break;
- case ActionType.Del:
- isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
- if (isTabItemAnnotation)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- 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, out AnnotationContent annotation);
- if (viewModel != null)
- {
- int pageindex = editEvent.PageIndex;
- int annotindex = editEvent.AnnotIndex;
- viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
- }
- }
- break;
- case ActionType.TextEdit:
- break;
- default:
- break;
- }
- }
- //空白处 右键菜单 添加注释 为单次添加,不连续添加
- if (IsNoSelectMenu)
- {
- IsNoSelectMenu = false;
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- }
- }
- }
- //复制多个注释,粘贴后,默认注释未选中状态
- private void MultipleSelectionAnnot(List<AnnotEditEvent> e)
- {
- bool isAdd = false;
- Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
- foreach (var item in e)
- {
- if (item.EditAction == ActionType.Add /*|| item.EditAction == ActionType.Modify*/)
- {
- var annot = item.EditAnnotArgs;
- if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
- annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText)
- {
- if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
- {
- selectAnnotDicts.Add(item.PageIndex, new List<int>());
- selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
- }
- else
- {
- selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
- }
- isAdd = true;
- }
- }
- }
- if (isAdd)
- {
- PDFViewer.ClearSelectAnnots();
- PDFViewer.SelectAnnotation(selectAnnotDicts);
- }
- }
- //阅读页悬浮相应
- private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
- {
- if (e != null && e.DrawContext != null)
- {
- Rect hoverRect = new Rect(
- e.PaintRect.Left - 2,
- e.PaintRect.Top - 2,
- e.PaintRect.Width + 4,
- e.PaintRect.Height + 4);
- Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
- hoverPen.DashStyle = DashStyles.Dash;
- e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
- //便签,显示ToolTip内容
- if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
- {
- PopAnnotToolTip(e.Annot.GetRect(), hoverRect, e.Annot.GetContent());
- return;
- }
- }
- CloseAnnotToolTip();
- }
- private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
- {
- if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
- {
- //鼠标移到注释之外,关闭ToolTip浮窗
- var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
- var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
- var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
- if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
- {
- CloseAnnotToolTip();
- }
- }
- }
- private Rect oldRect = new Rect(0, 0, 0, 0);
- private void PopAnnotToolTip(CRect placementRect, Rect hoverRect, string content)
- {
- //便签,显示ToolTip内容
- if (PDFViewer.ToolTip == null)
- {
- if (string.IsNullOrEmpty(content) == false)
- {
- ToolTip TipChild = new ToolTip();
- TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
- TipChild.MaxWidth = 246;
- TipChild.Content = content;
- TipChild.Visibility = Visibility.Visible;
- TipChild.IsOpen = true;
- TipChild.Placement = PlacementMode.Right;
- TipChild.PlacementRectangle = new Rect(placementRect.left, placementRect.top, placementRect.right, placementRect.bottom);
- TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
- TipChild.Placement = PlacementMode.MousePoint;
- PDFViewer.ToolTip = TipChild;
- oldRect = hoverRect;
- PDFViewer.MouseMove -= PDFViewer_MouseMove;
- PDFViewer.MouseMove += PDFViewer_MouseMove;
- }
- }
- }
- //关闭ToolTip
- private void CloseAnnotToolTip()
- {
- if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
- {
- ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
- oldTips.IsOpen = false;
- oldTips.Visibility = Visibility.Collapsed;
- PDFViewer.ToolTip = null;
- PDFViewer.MouseMove -= PDFViewer_MouseMove;
- oldRect = new Rect(0, 0, 0, 0);
- }
- }
- #endregion PDFViewer事件
- #region BindingEvent事件
- //同一属性面板,不同的注释类型
- private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
- {
- if (e != null)
- {
- AnnotHandlerEventArgs annotArgs = null;
- propertyPanel.SaveLastAnnot();
- foreach (AnnotArgsType argsType in e.Keys)
- {
- if (propertyPanel.annot.EventType != argsType)
- {
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- }
- switch (argsType)
- {
- case AnnotArgsType.AnnotSquare:
- annotArgs = GetRect();
- break;
- case AnnotArgsType.AnnotCircle:
- annotArgs = GetCircle();
- break;
- case AnnotArgsType.AnnotLine:
- var LineTag = e[argsType] as string;
- annotArgs = GetArrowLine(LineTag);
- break;
- }
- ShowPropertyPanel();
- if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Rect")
- {
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- return;
- }
- if (annotArgs != null)
- {
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- }
- }
- }
- }
- //来自属性面板的事件,更改颜色等属性而触发
- private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
- {
- if (e != null)
- {
- foreach (AnnotArgsType argsType in e.Keys)
- {
- switch (argsType)
- {
- case AnnotArgsType.AnnotHighlight:
- if (e[argsType] is Color)
- {
- HighLightColor = new SolidColorBrush((Color)e[argsType]);
- }
- if (e[argsType] is double)
- {
- HighLightOpacity = (double)e[argsType];
- }
- //创建注释后,修改注释属性,可用于下次创建的注释
- if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
- {
- PDFViewer.SetToolParam(propertyPanel.annot);
- }
- break;
- case AnnotArgsType.AnnotUnderline:
- if (e[argsType] is Color)
- {
- UnderLineColor = new SolidColorBrush((Color)e[argsType]);
- }
- if (e[argsType] is double)
- {
- underLineOpacity = (double)e[argsType];
- }
- //创建注释后,修改注释属性,可用于下次创建的注释
- if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
- {
- PDFViewer.SetToolParam(propertyPanel.annot);
- }
- break;
- case AnnotArgsType.AnnotSquiggly:
- if (e[argsType] is Color)
- {
- SquigglyColor = new SolidColorBrush((Color)e[argsType]);
- }
- if (e[argsType] is double)
- {
- SquigglyOpacity = (double)e[argsType];
- }
- //创建注释后,修改注释属性,可用于下次创建的注释
- if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
- {
- PDFViewer.SetToolParam(propertyPanel.annot);
- }
- break;
- case AnnotArgsType.AnnotStrikeout:
- if (e[argsType] is Color)
- {
- StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
- }
- if (e[argsType] is double)
- {
- StrikeoutOpacity = (double)e[argsType];
- }
- //创建注释后,修改注释属性,可用于下次创建的注释
- if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
- {
- PDFViewer.SetToolParam(propertyPanel.annot);
- }
- break;
- case AnnotArgsType.AnnotFreehand:
- if (e[argsType] is FreehandAnnotArgs)
- {
- var annot = e[argsType] as FreehandAnnotArgs;
- if (annot != null)
- {
- if (propertyPanel != null)
- {
- //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- propertyPanel.AnnotEvent = AnnotEvent;
- var AnnotEvents = new List<AnnotAttribEvent>();
- AnnotEvents.Add(AnnotEvent);
- propertyPanel.AnnotEvents = AnnotEvents;
- propertyPanel.annot = annot;
- //手绘注释工具按钮的属性
- // FreehandPath.Opacity = annot.Transparency;
- // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
- }
- PDFViewer.SetToolParam(annot);
- }
- }
- break;
- case AnnotArgsType.AnnotErase:
- if (e[argsType] is ToggleButton)
- {
- ToggleButton clickBtn = e[argsType] as ToggleButton;
- if (clickBtn.IsChecked == true)
- {
- if (clickBtn.Tag.ToString() == "PenBtn")
- {
- CustomIconToggleBtn btn = new CustomIconToggleBtn();
- btn.Tag = "Freehand"; btn.IsChecked = true;
- BtnMyTools_Click(btn);
- break;
- }
- CreateEraseArgs();
- }
- }
- break;
- case AnnotArgsType.AnnotSquare:
- case AnnotArgsType.AnnotCircle:
- case AnnotArgsType.AnnotLine:
- case AnnotArgsType.AnnotFreeText:
- //创建注释后,修改注释属性,可用于下次创建的注释
- if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
- {
- PDFViewer.SetToolParam(propertyPanel.annot);
- }
- break;
- }
- }
- }
- }
- private void CreateEraseArgs()
- {
- EraseArgs eraseArgs = new EraseArgs();
- eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
- eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
- eraseArgs.Thickness = 10;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
- if (annotProperty != null)
- {
- eraseArgs.Thickness = annotProperty.Thickness;
- }
- PDFViewer.ClearSelectAnnots(false);
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(eraseArgs);
- List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
- if (eraseArgs != null)
- eraseArgsList.Add(eraseArgs);
- AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
- }
- #endregion BindingEvent事件
- }
- }
|