1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.PDFDocument;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer.PdfViewer;
- using Microsoft.Win32;
- using PDF_Master.CustomControl;
- using PDF_Master.EventAggregators;
- using PDF_Master.Helper;
- using PDF_Master.Model;
- using PDF_Master.Model.BOTA;
- using PDF_Master.Properties;
- using PDF_Master.ViewModels.BOTA;
- using PDF_Master.ViewModels.PropertyPanel;
- using PDF_Master.ViewModels.PropertyPanel.AnnotPanel;
- using PDF_Master.ViewModels.Tools.AnnotManager;
- using PDF_Master.Views.BOTA;
- using PDF_Master.Views.PropertyPanel.AnnotPanel;
- using PDFSettings;
- using PDFSettings.Settings;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Annotations;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Forms;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using ContextMenu = System.Windows.Controls.ContextMenu;
- using KeyEventArgs = System.Windows.Input.KeyEventArgs;
- using MenuItem = System.Windows.Controls.MenuItem;
- namespace PDF_Master.ViewModels.Tools
- {
- public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
- {
- #region 初始化
- public AnnotToolContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IDialogService dialogService)
- {
- region = regionManager;
- events = eventAggregator;
- dialogs = dialogService;
- InitCommand();
- InitDefaultValue();
- InitToolDict();
- InitToolTipDict();
- InitPopMenu();
- SubscribeEvent();
- }
- //事件聚合器
- private void SubscribeEvent()
- {
- Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
- events.GetEvent<FillAndSignEvent>().Subscribe(FromFillAndSign, e => e.AppUnicode == Unicode);
- }
- private void InitPopMenu()
- {
- InitSelectHightAnnotMenu();
- InitSelectFreeHandAnnotMenu();
- InitSelectFreeTextAnnotMenu();
- InitSelectStrickNoteAnnotMenu();
- InitSelectShapeAnnotMenu();
- InitSelectLinkAnnotMenu();
- InitSelectStampAnnotMenu();
- InitSelectMultiAnnotMenu();
- }
- private void InitCommand()
- {
- MyToolsCommand = new DelegateCommand<CustomIconToggleBtn>(BtnMyTools_Click);
- SetAddAnnotationCommand = new DelegateCommand<object>(AddAnnotation_Click);
- AddBookMarkCommand = new DelegateCommand(AddBookMark_Click);
- PropertyRegionName = Guid.NewGuid().ToString();
- HandCommand = new DelegateCommand(Hand_Click);
- #region 注释 - 右键菜单
- //公共command
- AnnotDefaultValue_MenuCommand = new DelegateCommand<object>(AnnotDefaultValues_Menu);
- AnnotColorPalette_MenuCommand = new DelegateCommand<object>(AnnotColorPalette_Menu);
- AnnotAddNoteText_MenuCommand = new DelegateCommand<object>(AnnotAddNoteText_Menu);
- //高亮、下划线、删除
- HightAnnotCopyText_MenuCommand = new DelegateCommand<object>(HightAnnotCopyText_Menu);
- //手绘
- FreeHandLineStyle_MenuCommand = new DelegateCommand<object>(FreeHandLineStyle_Menu);
- //文本
- FreeTextFontFamily_MenuCommand = new DelegateCommand<object>(FreeTextFontFamily_Menu);
- FreeTextAglin_MenuCommand = new DelegateCommand<object>(FreeTextAglin_Menu);
- //便签
- StrikeNoteEditStrike_MenuCommand = new DelegateCommand<object>(StrikeNoteEditStrike_Menu);
- //形状
- ShapeLineStyle_MenuCommand = new DelegateCommand<object>(ShapeLineStyle_Menu);
- ShapeLineDirect_MenuCommand = new DelegateCommand<object>(ShapeLineDirect_Menu);
- //图章
- StampExportPicture_MenuCommand = new DelegateCommand<object>(StampExportPicture_Menu);
- //链接
- Link_MenuCommand = new DelegateCommand<object>(Link_Menu);
- #endregion 注释 - 右键菜单
- }
- #endregion 初始化
- #region 注释工具栏 -》Command实现
- //手型工具
- private void Hand_Click()
- {
- HandToolIsCheckedEvent(BtnHandIsChecked);
- if (BtnHandIsChecked)
- {
- //其余注释工具 取消选中
- StrAnnotToolChecked = "";
- BtnLinkIsChecked = false;
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- }
- //手型工具按钮选中或取消
- private void HandToolIsCheckedEvent(bool isChecked)
- {
- if (isChecked == false)
- {
- //鼠标框选多选注释
- if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
- {
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- var annotArgs = new SelectToolArgs();
- PDFViewer.SetToolParam(annotArgs);
- }
- else
- {
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- }
- }
- else
- {
- //鼠标滚动页面
- PDFViewer.SetMouseMode(MouseModes.Scroll);
- PDFViewer.SetToolParam(new AnnotHandlerEventArgs());
- }
- }
- //点击注释工具
- private void BtnMyTools_Click(CustomIconToggleBtn annotBtn)
- {
- if (annotBtn == null || annotBtn.Tag == null) return;
- //不创建注释,属于注释模板
- Dictionary<string, bool> dictVar = new Dictionary<string, bool>();
- dictVar.Add("isTemplateAnnot", false);
- dictVar.Add("isSnapshotEdit", false);
- AnnotHandlerEventArgs annotArgs = null;
- var tag = annotBtn.Tag.ToString();
- if (annotBtn.Name == "BtnShowAnnot")
- {
- //显示/隐藏注释
- PDFViewer.SetDrawAnnot((bool)annotBtn.IsChecked);
- return;
- }
- if (annotBtn.IsChecked == true)
- {
- propertyPanel.SaveLastAnnot();
- MyToolCheckedDoing(dictVar, tag);
- FindAnnotTypeKey(tag, ref annotArgs);
- if (annotArgs != null)
- {
- //设置点击页面会创建对应选中注释工具的注释
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
- //isRightMenuAddAnnot = false;
- #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
- }
- }
- else
- {
- //取消选中注释工具按钮后,恢复到未编辑注释的状态
- propertyPanel.IsAddLink = false;
- propertyPanel.IsLocationLink = false;
- PDFViewer.ToolManager.EnableClickCreate = false;
- }
- if (dictVar["isTemplateAnnot"] == false && annotArgs == null)
- {
- //当不是注释模板,且无创建注释时,属性面板显示为空内容
- HandToolIsCheckedEvent(false);
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- else
- {
- if (dictVar["isSnapshotEdit"] == true)
- {
- ShowPropertyPanel(false);
- }
- else
- {
- ShowPropertyPanel((bool)annotBtn.IsChecked);
- }
- }
- }
- //选中注释工具按钮时,处理的一些系列事情
- private void MyToolCheckedDoing(Dictionary<string, bool> dict, string tag)
- {
- if (BtnHandIsChecked)
- BtnHandIsChecked = false;
- PDFViewer.ClearSelectAnnots();
- //选中内容选择工具按钮
- if (tag == "SnapshotEdit")
- {
- dict["isSnapshotEdit"] = true;
- }
- else if (tag == "Signature" || tag == "Stamp")
- {
- //选中签名、图章工具按钮
- dict["isTemplateAnnot"] = true;
- }
- //超链接工具
- if (tag != "Link")
- BtnLinkIsChecked = false;
- else
- StrAnnotToolChecked = "Link";
- if (tag == "Rect" || tag == "Circle" || tag == "Arrow" || tag == "Line")
- {
- //新建形状注释,设置默认大小
- PDFViewer.ToolManager.EnableClickCreate = true;
- PDFViewer.ToolManager.ClickCreateWidth = 140;
- PDFViewer.ToolManager.ClickCreateHeight = 140;
- }
- else
- {
- PDFViewer.ToolManager.EnableClickCreate = false;
- }
- }
- #endregion 注释工具栏 -》Command实现
- #region BOTA
- private AnnotationContentViewModel GetAnnotationContentViewModel(BOTAContentViewModel bOTAContentViewModel, out AnnotationContent annotation)
- {
- AnnotationContentViewModel viewModel = null;
- annotation = null;
- if (bOTAContentViewModel != null)
- {
- if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
- {
- var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
- foreach (var item in views)
- {
- if (item is AnnotationContent annotation1)
- {
- annotation = annotation1;
- viewModel = annotation1.DataContext as AnnotationContentViewModel;
- break;
- }
- }
- }
- }
- return viewModel;
- }
- /// <summary>
- /// 判断Bota的TabItem是否已显示
- /// </summary>
- /// <param name="bOTAContentViewModel"></param>
- /// <param name="bOTAContent"></param>
- /// <param name="tabItemText"></param>
- /// <returns></returns>
- private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
- {
- bool isTabItem = false;
- bOTAContentViewModel = null;
- bOTAContent = null;
- if (region.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
- {
- var views = region.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;
- }
- }
- }
- return isTabItem;
- }
- 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;
- }
- }
- #endregion BOTA
- #region 阅读页右键菜单
- /// <summary>
- /// 空白处-右键菜单-添加注释
- /// </summary>
- /// <param name="sender"></param>
- private void AddAnnotation_Click(object sender)
- {
- if (sender is MenuItem menuItem)
- {
- AnnotHandlerEventArgs annotHandler = null;
- string str = menuItem.Tag.ToString();
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- propertyPanel.IsAddLink = false;
- propertyPanel.IsLocationLink = false;
- if (str == AddAnnotType.AnnotFreehand.ToString())
- {
- annotHandler = GetFreehand();
- }
- if (str == AddAnnotType.AnnotFreeText.ToString())
- {
- annotHandler = GetFreetext();
- }
- if (str == AddAnnotType.AnnotSticky.ToString())
- {
- annotHandler = GetStickyNote();
- }
- if (str == AddAnnotType.AnnotSquare.ToString())
- {
- annotHandler = GetRect();
- }
- if (str == AddAnnotType.AnnotCircle.ToString())
- {
- annotHandler = GetCircle();
- }
- if (str == AddAnnotType.AnnotArrow.ToString())
- {
- annotHandler = GetArrowLine("Arrow");
- }
- if (str == AddAnnotType.AnnotLine.ToString())
- {
- annotHandler = GetArrowLine("Line");
- }
- if (str == AddAnnotType.AnnotLink.ToString())
- {
- propertyPanel.IsAddLink = true;
- annotHandler = GetLink();
- }
- if (str == AddAnnotType.AnnotStamp.ToString())
- {
- annotHandler = GetStamp();
- }
- if (str == AddAnnotType.AnnotAutograph.ToString())
- {
- annotHandler = GetSignature();
- }
- if (annotHandler != null)
- {
- annotHandler.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotHandler);
- //是否展开右侧面板 =>否(链接、图章、签名除外)
- ShowPropertyPanel(false);
- if (str == AddAnnotType.AnnotLink.ToString()
- || str == AddAnnotType.AnnotStamp.ToString()
- || str == AddAnnotType.AnnotAutograph.ToString()
- )
- {
- ShowPropertyPanel(true);
- }
- IsNoSelectMenu = true;
- }
- }
- }
- /// <summary>
- /// 选择文本、图片,右键菜单
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void AnnotToolMenu_Click(object sender, RoutedEventArgs e)
- {
- if (sender is MenuItem clickMenu && clickMenu.CommandParameter is AnnotCommandArgs)
- {
- AnnotCommandArgs annotCommand = clickMenu.CommandParameter as AnnotCommandArgs;
- switch (clickMenu.Tag.ToString())
- {
- case "HighLight"://字体高亮
- TextHighlightAnnotArgs highlightArgs = (TextHighlightAnnotArgs)GetHighLight();
- highlightArgs.ClientRect = annotCommand.TextRect;
- highlightArgs.Content = annotCommand.Text;
- highlightArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(highlightArgs);
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- break;
- case "UnderLine"://下划线
- TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
- underlineArgs.ClientRect = annotCommand.TextRect;
- underlineArgs.Content = annotCommand.Text;
- underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(underlineArgs);
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- break;
- case "Strikeout"://删除线
- TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
- strikeoutArgs.ClientRect = annotCommand.TextRect;
- strikeoutArgs.Content = annotCommand.Text;
- strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(strikeoutArgs);
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- break;
- case "Freetext"://文本
- FreeTextAnnotArgs textArgs = (FreeTextAnnotArgs)GetFreetext();
- textArgs.ClientRect = annotCommand.TextRect;
- //textArgs.Transparency = 1;
- //textArgs.BgColor = Colors.Transparent;
- //textArgs.LineColor = Colors.Red;
- //textArgs.LineWidth = 2;
- textArgs.TextContent = annotCommand.Text;
- PDFViewer.CreatePageAnnot(annotCommand.PageIndex, textArgs);
- break;
- case "StickyNote"://便签
- StickyAnnotArgs stickyAnnotArgs = (StickyAnnotArgs)GetStickyNote();
- //stickyAnnotArgs.ClientRect = annotCommand.TextRect;
- List<TextSelectNode> textSelectNodes = PDFViewer.GetSelectTextInfo();
- //stickyAnnotArgs.ClientRect = new Rect(textSelectNodes[0].StartPoint.X, annotCommand.TextRect.Y - annotCommand.TextRect.Height, annotCommand.TextRect.Width, annotCommand.TextRect.Height);
- Rect rect = annotCommand.TextRectList[0];
- #region to do 转dpi
- //int dpi = DpiHelpers.Dpi;
- //double x = rect.X / 72D * dpi;
- //double y = (rect.Y - rect.Height) / 72D * dpi;
- //double width = rect.Width / 72D * dpi;
- //double height = rect.Height / 72D * dpi;
- #endregion to do 转dpi
- //stickyAnnotArgs.ClientRect = new Rect(x, y, width, height);
- //stickyAnnotArgs.ClientRect = new Rect(rect.X, rect.Y - rect.Height, rect.Width, rect.Height);
- stickyAnnotArgs.ClientRect = rect;
- //PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, PDFViewer);
- param.Add(ParameterNames.StickyAnnotArgs, stickyAnnotArgs);
- param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
- param.Add(ParameterNames.AnnotCommandArgs, annotCommand);
- System.Windows.Controls.ContentControl window = null;
- if (PDFViewer.Parent as ContentControl != null)
- {
- window = PDFViewer.Parent as ContentControl;
- }
- else
- {
- window = App.Current.MainWindow;
- }
- var point = Mouse.GetPosition(window);
- viewContentViewModel.NotePopupVisible = Visibility.Visible;
- viewContentViewModel.CanvasNoteLeft = point.X;
- viewContentViewModel.CanvasNoteBottom = point.Y;
- if (point.Y > window.ActualHeight / 2)
- {
- viewContentViewModel.CanvasNoteBottom = point.Y - window.ActualHeight / 2;
- }
- viewContentViewModel.IsNoteAdd = true;
- region.RequestNavigate(viewContentViewModel.NotePopupRegionName, "StickyNotePopup", param);
- //stickyAnnotArgs.Author = Settings.Default.AppProperties.Description.Author;
- //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- //PDFViewer.SetToolParam(stickyAnnotArgs);
- //PDFViewer.SetMouseMode(MouseModes.PanTool);
- break;
- case "Rect"://矩形
- SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
- squareAnnotArgs.ClientRect = annotCommand.TextRect;
- PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
- break;
- case "Circle"://圆
- CircleAnnotArgs circleAnnotArgs = (CircleAnnotArgs)GetCircle();
- circleAnnotArgs.ClientRect = annotCommand.TextRect;
- PDFViewer.CreatePageAnnot(annotCommand.PageIndex, circleAnnotArgs);
- break;
- case "Line"://线
- LineAnnotArgs lineAnnotArgs = (LineAnnotArgs)GetArrowLine(clickMenu.Tag.ToString());
- lineAnnotArgs.ClientRect = annotCommand.TextRect;
- lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Left, annotCommand.TextRect.Top));
- lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Right, annotCommand.TextRect.Bottom));
- PDFViewer.CreatePageAnnot(annotCommand.PageIndex, lineAnnotArgs);
- break;
- case "Link"://链接
- LinkAnnotArgs linkArgs = new LinkAnnotArgs();
- linkArgs.ClientRect = annotCommand.TextRect;
- linkArgs.URI = string.Empty;
- linkArgs.LinkType = LINK_TYPE.GOTO;
- linkArgs.DestIndex = annotCommand.PageIndex;
- PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
- BtnLinkIsChecked = true;
- List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
- lists.Add(linkArgs);
- propertyPanel.IsAddLink = true;
- AnnotHandlerEventArgs annotArgs = GetLink(lists);
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- viewContentViewModel.IsPropertyOpen = true;
- break;
- case "OutLine":
- bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemOutLine");
- if (isTabItemAnnotation == false)
- {
- bOTAContent.TabItemOutLine.IsSelected = true;
- }
- OutLineControlViewModel outLineControlViewModel = GetOutLineControlViewModel(bOTAContentViewModel, out OutLineControl outLineControl);
- if (outLineControlViewModel != null && outLineControl != null)
- {
- string str = null;
- if (string.IsNullOrEmpty(annotCommand.Text))
- {
- str = (annotCommand.PageIndex + 1).ToString();
- }
- else
- {
- str = annotCommand.Text;
- }
- outLineControl.AddOutlineNode(str);
- }
- break;
- case "ExportPicture":
- ExportPicture_MenuItemClick();
- break;
- }
- //ShowPropertyPanel(false);
- }
- }
- private void PageDisplay(ItemCollection items)
- {
- foreach (var item in items)
- {
- if (item is MenuItem menuItem)
- {
- menuItem.IsCheckable = false;
- menuItem.Click -= PageDisplay_Click;
- menuItem.Click += PageDisplay_Click;
- }
- }
- }
- private void PageDisplay_Click(object sender, RoutedEventArgs e)
- {
- if (sender is MenuItem menuItem)
- {
- switch (menuItem.Tag.ToString())
- {
- case "SingleView":
- PDFViewer.ChangeViewMode(ViewMode.Single);
- break;
- case "SingleContinueView":
- PDFViewer.ChangeViewMode(ViewMode.SingleContinuous);
- break;
- case "DoubleView":
- PDFViewer.ChangeViewMode(ViewMode.Double);
- break;
- case "DoubleContinueView":
- PDFViewer.ChangeViewMode(ViewMode.DoubleContinuous);
- break;
- case "BookMode":
- PDFViewer.ChangeViewMode(ViewMode.Book);
- break;
- }
- }
- }
- private void ViewZoom(ItemCollection items)
- {
- foreach (var item in items)
- {
- if (item is MenuItem menuItem)
- {
- //switch (PDFViewer.ModeFit)
- //{
- // case FitMode.FitWidth:
- // break;
- // case FitMode.FitHeight:
- // break;
- // case FitMode.FitSize:
- // break;
- // case FitMode.FitFree:
- // break;
- // default:
- // break;
- //}
- menuItem.IsCheckable = false;
- menuItem.Click -= ViewZoom_Click;
- menuItem.Click += ViewZoom_Click;
- }
- }
- }
- private void ViewZoom_Click(object sender, RoutedEventArgs e)
- {
- if (sender is MenuItem menuItem)
- {
- switch (menuItem.Tag.ToString())
- {
- case "FitWidth":
- PDFViewer.ChangeFitMode(FitMode.FitWidth);
- break;
- case "FitHeight":
- PDFViewer.ChangeFitMode(FitMode.FitHeight);
- break;
- case "FitSize":
- PDFViewer.ChangeFitMode(FitMode.FitSize);
- break;
- case "enlarge":
- double newZoom = viewContentViewModel.CheckZoomLevel((PDFViewer.ZoomFactor + 0.01), true);
- PDFViewer.Zoom(newZoom);
- break;
- case "narrow":
- newZoom = viewContentViewModel.CheckZoomLevel((PDFViewer.ZoomFactor + -0.01), false);
- PDFViewer.Zoom(newZoom);
- break;
- }
- }
- }
- private void UnReadModel_Click(object sender, RoutedEventArgs e)
- {
- viewContentViewModel.Off_ReadModel();
- }
- private void ReadModel_Click(object sender, RoutedEventArgs e)
- {
- viewContentViewModel.On_ReadMode();
- }
- private void SetToolMode(ItemCollection items)
- {
- foreach (var item in items)
- {
- if (item is MenuItem menuItem)
- {
- menuItem.IsCheckable = false;
- menuItem.Click -= ToolMode_Click;
- menuItem.Click += ToolMode_Click;
- }
- }
- }
- private void ToolMode_Click(object sender, RoutedEventArgs e)
- {
- if (sender is MenuItem menuItem)
- {
- switch (menuItem.Tag.ToString())
- {
- case "default":
- HandToolIsCheckedEvent(false);
- BtnHandIsChecked = false;
- ShowPropertyPanel(false);
- break;
- case "roll":
- HandToolIsCheckedEvent(true);
- BtnHandIsChecked = true;
- ShowPropertyPanel(false);
- break;
- case "content":
- AnnotHandlerEventArgs annotHandler = GetSnapshotEdit();
- BtnSelecttoolIsChecked = true;
- if (annotHandler != null)
- {
- annotHandler.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotHandler);
- ShowPropertyPanel(false);
- }
- break;
- default:
- break;
- }
- }
- }
- private void DelBookMark_Click(object sender, RoutedEventArgs e)
- {
- CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
- if (bOTAContentVM != null && bOTA != null)
- {
- BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
- int index = PDFViewer.CurrentIndex;
- //检测是否已存在相同数据
- CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
- if (bookmarkContentViewModel != null && bookmark != null && bOTA != null && list != null)
- {
- bookmarkContentViewModel.DeleteCommand.Execute(list);
- isAddBookMark = bookmarkContentViewModel.isAddBookMark;
- }
- }
- }
- private void CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA)
- {
- if (viewContentViewModel.OpenBOTA == false)
- {
- viewContentViewModel.OpenBOTA = true;
- }
- bool isBook = IsBOTATabItemShow(out bOTAContentVM, out bOTA, "TabItemBookMark");
- if (isBook == false)
- {
- bOTA.TabItemBookMark.IsSelected = true;
- }
- }
- private void AddBookMark_Click()
- {
- CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
- //if (viewContentViewModel.mainViewModel.IsBookMode)
- //{
- // this.events.GetEvent<ReadModeBOTAShowEvent>().Publish(new ReadModeBOTAShowArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsBOTAShow = true });
- //}
- if (bOTAContentVM != null && bOTA != null)
- {
- BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
- if (bookmarkContentViewModel != null && bookmark != null && bOTA != null)
- {
- //bookmarkContentViewModel.AddBookmarkCommand.Execute(bookmark.BookMarkListView);
- bookmark.BtnAddBookmark_Click(null, null);
- isAddBookMark = bookmarkContentViewModel.isAddBookMark;
- return;
- }
- }
- }
- private BookmarkContentViewModel GetBookmarkContentViewModel(BOTAContentViewModel bOTAContentViewModel, out BookmarkContent bookmark)
- {
- BookmarkContentViewModel viewModel = null;
- bookmark = null;
- if (bOTAContentViewModel != null)
- {
- if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
- {
- var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
- foreach (var item in views)
- {
- if (item is BookmarkContent bookmark1)
- {
- bookmark = bookmark1;
- viewModel = bookmark1.DataContext as BookmarkContentViewModel;
- break;
- }
- }
- }
- }
- return viewModel;
- }
- private OutLineControlViewModel GetOutLineControlViewModel(BOTAContentViewModel bOTAContentViewModel, out OutLineControl outLineControl)
- {
- OutLineControlViewModel viewModel = null;
- outLineControl = null;
- if (bOTAContentViewModel != null)
- {
- if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
- {
- var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
- foreach (var item in views)
- {
- if (item is OutLineControl outLineControl1)
- {
- outLineControl = outLineControl1;
- viewModel = outLineControl1.DataContext as OutLineControlViewModel;
- break;
- }
- }
- }
- }
- return viewModel;
- }
- private void DisplayAnnot_Click(object sender, RoutedEventArgs e)
- {
- PDFViewer.SetDrawAnnot(true);
- BtnShowAnnotIsChecked = true;
- bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
- if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- viewModel.DisplayAnnot();
- }
- }
- private void HiddenAnnot_Click(object sender, RoutedEventArgs e)
- {
- PDFViewer.SetDrawAnnot(false);
- BtnShowAnnotIsChecked = false;
- bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
- if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- viewModel.HiddenAnnot();
- }
- }
- private void SetAddAnnotation(ItemCollection items)
- {
- foreach (var item in items)
- {
- if (item is MenuItem menuItem)
- {
- string str = menuItem.Tag.ToString();
- //if (str == AddAnnotType.AnnotLink.ToString()
- //|| str == AddAnnotType.AnnotStamp.ToString()
- //|| str == AddAnnotType.AnnotAutograph.ToString()
- //)
- //{
- // InBookModeSetIsEnabled(menuItem);
- //}
- menuItem.CommandParameter = item;
- menuItem.Command = SetAddAnnotationCommand;
- }
- }
- }
- private void AddLink_Click(object sender, RoutedEventArgs e)
- {
- var args = PDFViewer.ToolManager.CurrentAnnotArgs;
- BtnLinkIsChecked = true;
- }
- #endregion 阅读页右键菜单
- #region 注释右键菜单事件
- //高亮、下划线、删除
- private void HightAnnotCopyText_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- if (annot != null)
- {
- System.Windows.Clipboard.SetText(annot.Content);
- }
- }
- }
- //更改为当前注释属性默认值
- private void AnnotDefaultValues_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- if (annot != null)
- {
- if (annot is TextHighlightAnnotArgs)
- {
- var color = (annot as TextHighlightAnnotArgs).Color;
- HighLightColor = new SolidColorBrush(color);
- Settings.Default.AppProperties.Annotate.HighLightColor = color;
- var hightlight = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
- hightlight.ForgoundColor = color;
- hightlight.Opacity = (annot as TextHighlightAnnotArgs).Transparency;
- SettingHelper.SetAnnotDefaultProperty(hightlight);
- }
- else if (annot is TextUnderlineAnnotArgs)
- {
- var color = (annot as TextUnderlineAnnotArgs).Color;
- UnderLineColor = new SolidColorBrush(color);
- Settings.Default.AppProperties.Annotate.UnderLineColor = color;
- var Underline = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
- Underline.ForgoundColor = color;
- Underline.Opacity = (annot as TextUnderlineAnnotArgs).Transparency;
- SettingHelper.SetAnnotDefaultProperty(Underline);
- }
- else if (annot is TextStrikeoutAnnotArgs)
- {
- var color = (annot as TextStrikeoutAnnotArgs).Color;
- StrikeoutColor = new SolidColorBrush(color);
- Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
- var Strikeout = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
- Strikeout.ForgoundColor = color;
- Strikeout.Opacity = (annot as TextStrikeoutAnnotArgs).Transparency;
- SettingHelper.SetAnnotDefaultProperty(Strikeout);
- }
- else if (annot is FreehandAnnotArgs)
- {
- var freeHand = annot as FreehandAnnotArgs;
- var color = freeHand.InkColor;
- Settings.Default.AppProperties.Annotate.FreeHandColor = color;
- var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
- FreehandDefault.ForgoundColor = color;
- FreehandDefault.Opacity = freeHand.Transparency;
- FreehandDefault.Thickness = freeHand.LineWidth;
- var isSolid = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
- if (isSolid)
- {
- FreehandDefault.DashArray = null;
- }
- else
- {
- FreehandDefault.DashArray = new List<double>();
- foreach (var item in freeHand.LineDash.Dashes)
- {
- FreehandDefault.DashArray.Add(item);
- }
- }
- SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
- }
- else if (annot is FreeTextAnnotArgs)
- {
- var freeText = annot as FreeTextAnnotArgs;
- Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
- Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
- Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
- var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
- FreeTextDefalut.ForgoundColor = freeText.FontColor;
- FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
- FreeTextDefalut.TextAlign = freeText.Align;
- FreeTextDefalut.FontSize = freeText.FontSize;
- FreeTextDefalut.FontWeight = freeText.FontWeight;
- FreeTextDefalut.FontStyle = freeText.FontStyle;
- FreeTextDefalut.BackgroundColor = freeText.BgColor;
- FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
- SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
- }
- else if (annot is StickyAnnotArgs)
- {
- var color = (annot as StickyAnnotArgs).Color;
- Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
- var StickyDefalut = GetAnnotDefault(AnnotArgsType.AnnotSticky);
- StickyDefalut.ForgoundColor = color;
- SettingHelper.SetAnnotDefaultProperty(StickyDefalut);
- }
- else if (annot is SquareAnnotArgs)
- {
- var square = annot as SquareAnnotArgs;
- var bgColor = square.BgColor;
- Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
- var borderColor = square.LineColor;
- Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
- var SquareDefalut = GetAnnotDefault(AnnotArgsType.AnnotSquare);
- SquareDefalut.BorderColor = borderColor;
- SquareDefalut.BackgroundColor = bgColor;
- SquareDefalut.Opacity = square.Transparency;
- SquareDefalut.Thickness = square.LineWidth;
- var isSolid = AnnotTransfer.IsSolidStyle(square.LineDash);
- if (isSolid)
- {
- SquareDefalut.DashArray = null;
- }
- else
- {
- SquareDefalut.DashArray = new List<double>();
- foreach (var item in square.LineDash.Dashes)
- {
- SquareDefalut.DashArray.Add(item);
- }
- }
- SettingHelper.SetAnnotDefaultProperty(SquareDefalut);
- }
- else if (annot is CircleAnnotArgs)
- {
- var circle = annot as CircleAnnotArgs;
- var bgColor = circle.BgColor;
- Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
- var borderColor = circle.LineColor;
- Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
- var CircleDefalut = GetAnnotDefault(AnnotArgsType.AnnotCircle);
- CircleDefalut.BorderColor = borderColor;
- CircleDefalut.BackgroundColor = bgColor;
- CircleDefalut.Opacity = circle.Transparency;
- CircleDefalut.Thickness = circle.LineWidth;
- var isSolid = AnnotTransfer.IsSolidStyle(circle.LineDash);
- if (isSolid)
- {
- CircleDefalut.DashArray = null;
- }
- else
- {
- CircleDefalut.DashArray = new List<double>();
- foreach (var item in circle.LineDash.Dashes)
- {
- CircleDefalut.DashArray.Add(item);
- }
- }
- SettingHelper.SetAnnotDefaultProperty(CircleDefalut);
- }
- else if (annot is LineAnnotArgs)
- {
- var line = (annot as LineAnnotArgs);
- var color = (annot as LineAnnotArgs).LineColor;
- Settings.Default.AppProperties.Annotate.LineColor = color;
- var lineDefalut = GetAnnotDefault(AnnotArgsType.AnnotLine);
- lineDefalut.BorderColor = color;
- lineDefalut.Opacity = (annot as LineAnnotArgs).Transparency;
- lineDefalut.Thickness = (annot as LineAnnotArgs).LineWidth;
- var isSolid = AnnotTransfer.IsSolidStyle(line.LineDash);
- if (isSolid)
- {
- lineDefalut.DashArray = null;
- }
- else
- {
- lineDefalut.DashArray = new List<double>();
- foreach (var item in line.LineDash.Dashes)
- {
- lineDefalut.DashArray.Add(item);
- }
- }
- SettingHelper.SetAnnotDefaultProperty(lineDefalut);
- }
- Settings.Default.Save();
- }
- }
- }
- private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
- {
- var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
- if (Annot == null)
- {
- Annot = new DefaultAnnotProperty();
- Annot.AnnotToolType = annotArgsType;
- }
- return Annot;
- }
- private System.Windows.Controls.Primitives.Popup popup = null;
- //更改颜色
- private async void AnnotColorPalette_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- if (annot != null)
- {
- var item = new ColorDropBoxPop();
- item.DataContext = menu;
- item.ColorSelected -= AnnotMenu_ColorSelected;
- item.ColorSelected += AnnotMenu_ColorSelected;
- if (popup == null)
- popup = new System.Windows.Controls.Primitives.Popup();
- ContentControl window = null;
- if (PDFViewer.Parent as ContentControl != null)
- window = PDFViewer.Parent as ContentControl;
- else
- window = App.Current.MainWindow;
- popup.Child = item;
- popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
- popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
- popup.PlacementTarget = window;
- popup.IsOpen = true;
- Window parentWnd = Window.GetWindow(App.Current.MainWindow);
- if (parentWnd != null)
- {
- parentWnd.MouseDown -= parentWnd_MouseDown;
- parentWnd.MouseDown += parentWnd_MouseDown;
- }
- while (popup.IsOpen)
- await Task.Delay(20);
- parentWnd.MouseDown -= parentWnd_MouseDown;
- popup = null;
- }
- }
- }
- private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
- {
- var ui = Mouse.DirectlyOver as FrameworkElement;
- if (ui != null)
- {
- if (popup != null)
- {
- popup.IsOpen = false;
- }
- }
- }
- private void AnnotMenu_ColorSelected(object sender, Color e)
- {
- if (sender != null)
- {
- var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
- if (menu == null) return;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- if (annot != null)
- {
- if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
- {
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
- AnnotEvent?.UpdateAnnot();
- }
- else if (annot is FreeTextAnnotArgs)
- {
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- if (menu.tag.ToString() == "FontColor")
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
- else
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
- AnnotEvent?.UpdateAnnot();
- }
- else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
- {
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- if (menu.tag.ToString() == "FillColor")
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
- else
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
- AnnotEvent?.UpdateAnnot();
- }
- else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
- {
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
- AnnotEvent?.UpdateAnnot();
- }
- }
- }
- }
- //添加笔记
- private void AnnotAddNoteText_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- PopAnnotNoteText(annot);
- }
- }
- private void PopAnnotNoteText(AnnotHandlerEventArgs annot)
- {
- if (annot != null)
- {
- AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
- args.ClientRect = annot.ClientRect;
- args.AnnotHandlerEventArgs = annot;
- args.PageIndex = annot.PageIndex;
- args.AnnotIndex = annot.AnnotIndex;
- args.EventType = annot.EventType;
- args.CreateTime = annot.CreateTime;
- args.UpdateTime = annot.UpdateTime;
- args.Content = annot.Content;
- args.MarkupContent = annot.MarkupContent;
- args.Author = annot.Author;
- args.Locked = annot.Locked;
- args.ReadOnly = annot.ReadOnly;
- args.FormField = annot.FormField;
- args.Document = PDFViewer.Document;
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.Annotation, args);
- dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
- {
- if (e.Result == ButtonResult.OK && e.Parameters != null)
- {
- PDFViewer.UndoManager.CanSave = true;
- if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
- {
- AnnotationHandlerEventArgs annotation = e.Parameters.GetValue<AnnotationHandlerEventArgs>(ParameterNames.Annotation);
- //RefreshOneListItem(annotation.AnnotHandlerEventArgs);
- events.GetEvent<RefreshAnnotEvent>().Publish(new RefreshAnnotArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, Annotation = annotation });
- }
- }
- });
- }
- }
- //手绘
- private void FreeHandLineStyle_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as FreehandAnnotArgs;
- if (annot != null)
- {
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- if (menu.tag.ToString() == "Solid")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(true));
- }
- else
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(false));
- }
- AnnotEvent?.UpdateAnnot();
- }
- }
- }
- //文本
- private void FreeTextFontFamily_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- if (annot != null)
- {
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
- AnnotEvent?.UpdateAnnot();
- }
- }
- }
- private void FreeTextAglin_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- var tag = menu.control.Tag;
- if (annot != null && tag != null)
- {
- var strTag = tag.ToString();
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- if (strTag == "Left")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
- }
- else if (strTag == "Center")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
- }
- else if (strTag == "Right")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
- }
- else if (strTag == "Justify")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
- }
- AnnotEvent?.UpdateAnnot();
- }
- }
- }
- //便签
- private void StrikeNoteEditStrike_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- if (annot != null)
- {
- var sticky = annot as StickyAnnotArgs;
- sticky.PopupEditWnd();
- #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
- //isRightMenuAddAnnot = false;
- #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
- }
- }
- }
- //形状
- private void ShapeLineStyle_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- var tag = menu.control.Tag;
- if (annot != null && tag != null)
- {
- var strTag = tag.ToString();
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- if (strTag == "Solid")
- {
- var dashStyle = AnnotTransfer.GetLineDashStyle(true);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
- }
- else
- {
- var dashStyle = AnnotTransfer.GetLineDashStyle(false);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
- }
- AnnotEvent?.UpdateAnnot();
- }
- }
- }
- private void ShapeLineDirect_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as LineAnnotArgs;
- var tag = menu.control.Tag;
- if (annot != null && tag != null)
- {
- var strTag = tag.ToString();
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- if (strTag == "Ver")
- {
- annot.SetLineVertical();
- }
- else
- {
- annot.SetLineHorizontal();
- }
- }
- }
- }
- private void Link_Menu(object obj)
- {
- if (obj is CusMenuItem menuItem)
- {
- if (menuItem.Parameter is LinkAnnotArgs linkAnnotArgs)
- {
- var result = PDFViewer.RemovePageAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
- if (result)
- {
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
- if (isTabItemAnnotation)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- if (viewModel != null)
- {
- viewModel.UpdateModifiedAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex, true);
- }
- }
- }
- }
- }
- }
- //图章
- private void StampExportPicture_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as StampAnnotArgs;
- if (annot != null)
- {
- Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
- var format = menu.tag.ToString();
- if (format == "PDF")
- dlg.Filter = "PDF|*.pdf";
- else
- dlg.Filter = format + "|*." + format.ToLower();
- dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
- dlg.FileName = PDFViewer.Document.FileName;
- if (dlg.ShowDialog() == true)
- {
- var stampPicture = dlg.FileName;
- if (menu.tag.ToString() == "PDF")
- {
- var writeStamp = annot.GetStampDrawing();
- var tempDoc = new CPDFViewer();
- tempDoc.CreateDocument();
- if (tempDoc.Document == null)
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", "创建文件失败.", "OK");
- return;
- }
- byte[] buffer;
- var encoder = new PngBitmapEncoder();
- encoder.Frames.Add(BitmapFrame.Create(writeStamp));
- using (var memoryStream = new MemoryStream())
- {
- encoder.Save(memoryStream);
- buffer = memoryStream.ToArray();
- }
- tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
- var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
- if (result)
- {
- }
- }
- else
- {
- var writeStamp = annot.GetStampDrawing();
- using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
- {
- PngBitmapEncoder encoder5 = new PngBitmapEncoder();
- encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
- encoder5.Save(stream5);
- }
- }
- }
- }
- }
- }
- #endregion 注释右键菜单事件
- #region 快捷键
- private void ShortCut_KeyDown(object sender, KeyEventArgs e)
- {
- if (KeyEventsHelper.IsSingleKey(Key.Escape))
- {
- //BtnHandIsChecked = true;
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- PDFViewer.ClearSelectAnnots();
- StrAnnotToolChecked = "";
- ShowPropertyPanel(false);
- }
- else if (KeyEventsHelper.IsModifierKey(ModifierKeys.Shift, Key.None))
- {
- //按住Shift等比缩放
- }
- AnnotToolCtrlAltKey();
- }
- /// <summary>
- /// 按下Ctrl + Alt + 序列键,响应注释工具
- /// </summary>
- private void AnnotToolCtrlAltKey()
- {
- var tuple = GetCtrlAltKey();
- if (tuple != null)
- {
- if (tuple.Item1 == Key.L)
- BtnLinkIsChecked = false;
- AnnotHandlerEventArgs annotArgs = null;
- StrAnnotToolChecked = tuple.Item2;
- FindAnnotTypeKey(tuple.Item2, ref annotArgs);
- if (annotArgs != null)
- {
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- PDFViewer.ToolManager.EnableClickCreate = false;
- }
- }
- }
- private Tuple<Key, string> GetCtrlAltKey()
- {
- Dictionary<Key, bool> AnnotToolDir = new Dictionary<Key, bool>();
- AnnotToolDir.Add(Key.H, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.H));
- AnnotToolDir.Add(Key.U, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.U));
- AnnotToolDir.Add(Key.S, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.S));
- AnnotToolDir.Add(Key.P, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.P));
- AnnotToolDir.Add(Key.E, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.E));
- AnnotToolDir.Add(Key.T, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.T));
- AnnotToolDir.Add(Key.N, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.N));
- AnnotToolDir.Add(Key.R, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.R));
- AnnotToolDir.Add(Key.O, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.O));
- AnnotToolDir.Add(Key.A, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.A));
- AnnotToolDir.Add(Key.L, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.L));
- Key key = Key.None;
- foreach (var item in AnnotToolDir.Keys)
- {
- if (AnnotToolDir[item] == true)
- {
- key = item;
- break;
- }
- }
- if (key == Key.None)
- return null;
- var tag = "";
- if (key == Key.H || key == Key.U || key == Key.S)
- {
- var str = PDFViewer.GetSelectedText();
- if (string.IsNullOrEmpty(str) == false)
- {
- if (key == Key.H)
- tag = "HighLight";
- else if (key == Key.U)
- tag = "UnderLine";
- else if (key == Key.S)
- tag = "Strikeout";
- }
- else
- {
- return null;
- }
- }
- else
- {
- if (AnnotToolDir[Key.P])
- tag = "Freehand";
- else if (AnnotToolDir[Key.T])
- tag = "Freetext";
- else if (AnnotToolDir[Key.N])
- tag = "StickyNote";
- else if (AnnotToolDir[Key.R])
- tag = "Rect";
- else if (AnnotToolDir[Key.O])
- tag = "Circle";
- else if (AnnotToolDir[Key.A])
- tag = "Arrow";
- else if (AnnotToolDir[Key.L])
- tag = "Line";
- }
- if (tag == "")
- return null;
- return new Tuple<Key, string>(key, tag);
- }
- #endregion 快捷键
- #region Navigation
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- StrAnnotToolChecked = "";
- UnBindingPDFViewerHandler();
- UnBindingEvent();
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
- if (viewContentViewModel != null)
- {
- OpenFileInfo = viewContentViewModel.OpenFileInfo;
- }
- BindingPDFViewerHandler();
- BindingEvent();
- LoaedStickyNotePopup();
- BtnHandIsChecked = (PDFViewer.MouseMode == MouseModes.Scroll ? true : false);
- }
- #endregion Navigation
- }
- }
|