12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253 |
- 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 / 72D * dpi,
- // rect.Top / 72D * dpi,
- // rect.Width / 72D * dpi,
- // rect.Height / 72D * dpi);
- var ui = PDFViewer.Parent as ContentControl;
- if (ui != null)
- {
- var point = e.GetPosition(ui);
- double x = point.X / 72D * dpi;
- double y = point.Y / 72D * dpi;
- point = new Point(x, y);
- //if (rect.Contains(point))
- //{
- PopAnnotNoteText(CurrentSelectedAnnot);
- //}
- //if (rect.Left <= x && rect.Right >= x && rect.Top <= y && rect.Bottom >= y)
- ////if (rect.Left < x && rect.Top > y && (rect.Width + rect.X) >= x && (rect.Height + rect.Y) >= y)
- //{
- // 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.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);
- }
- }
- }
- }
- }
- //在注释工具的状态下,右键菜单
- 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;
- }
- 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);
- }
- }
- 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;
- }
- }
- }
- }
- #endregion BindingEvent事件
- }
- }
|