123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.PDFDocument;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer.PdfViewer;
- using DotNetSpeech;
- using ImTools;
- using Microsoft.Win32;
- using PDF_Master.CustomControl;
- using PDF_Master.EventAggregators;
- using PDF_Master.Helper;
- using PDF_Master.Model;
- using PDF_Master.Model.AnnotPanel;
- 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;
- using PDF_Master.Views.BOTA;
- using PDF_Master.Views.PropertyPanel.AnnotPanel;
- using PDFReader_WPF.Helper;
- using PDFSettings;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing.Imaging;
- 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 static Dropbox.Api.Paper.PaperDocPermissionLevel;
- 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();
- AnnotContainerBorderColor();
- }
- //注释容器选中边框的颜色
- private void AnnotContainerBorderColor()
- {
- var pen = new Pen(new SolidColorBrush(Color.FromArgb(0xFF, 0x17, 0x70, 0xF4)), 1);
- CommonDrawData.ActiveBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x17, 0x70, 0xF4));
- CommonDrawData.ActivePen = pen;
- }
- //事件聚合器
- 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);
- ShowOrHiddenAnnotCommand = new DelegateCommand<CustomIconToggleBtn>(ShowOrHiddenAnnot_Click);
- GlobalCommands.BookMarkCommand.RegisterCommand(AddBookMarkCommand);
- #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 ShowOrHiddenAnnot_Click(CustomIconToggleBtn annotBtn)
- {
- if (annotBtn == null || annotBtn.Tag == null) return;
- PDFViewer.SetDrawAnnot((bool)annotBtn.IsChecked);
- PDFViewer.ReloadVisibleAnnots();
- bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
- ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown = false;
- if (annotBtn.IsChecked == true)
- {
- ViewContentViewModel.IsHiddenAnnot = false;
- if (ViewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- viewModel.DisplayAnnot();
- }
- }
- else
- {
- ViewContentViewModel.IsHiddenAnnot = true;
- PDFViewer.ClearSelectAnnots();
- if (ViewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- viewModel.HiddenAnnot();
- }
- }
- //bota缩略图刷新 页面
- events.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs(App.mainWindowViewModel.SelectedItem.Unicode));
- }
- //手型工具
- private void Hand_Click()
- {
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Scroll");
- HandToolIsCheckedEvent(BtnHandIsChecked);
- if (BtnHandIsChecked)
- {
- //其余注释工具 取消选中
- StrAnnotToolChecked = "";
- BtnLinkIsChecked = false;
- BtnSelecttoolIsChecked = false;
- ViewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- }
- //手型工具按钮选中或取消
- private void HandToolIsCheckedEvent(bool isChecked)
- {
- if (isChecked == false)
- {
- if (PDFViewer == null)
- {
- return;
- }
- //鼠标框选多选注释
- 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 (PDFViewer == null || annotBtn == null || annotBtn.Tag == null) return;
- //if(viewContentViewModel.OpenBOTA==false)
- this.events.GetEvent<CleanSelectAllEvent>().Publish(new CleanSelectAllArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsCleanSelectAll = true });
- //不创建注释,属于注释模板
- Dictionary<string, bool> dictVar = new Dictionary<string, bool>();
- dictVar.Add("isTemplateAnnot", false);
- dictVar.Add("isSnapshotEdit", false);
- AnnotHandlerEventArgs annotArgs = null;
- var tag = annotBtn.Tag.ToString();
- ToolsSelectonDataTracking(tag);
- ViewContentViewModel.IsSelectedTextAddLink = false;
- if (annotBtn.IsChecked == true)
- {
- PropertyPanel.AnnotSelect = StrAnnotToolChecked;
- PropertyPanel.IsSharpAnnotSelected = true;
- PropertyPanel.IsFreeHandSelected = true;
- PropertyPanel.SaveLastAnnot();
- PDFViewer.DisableClearSelectAnnot(false);
- PDFViewer.ClearSelectAnnots();
- PDFViewer.ToolManager.DisableStickyCreate = false;
- PropertyPanel.annot = null;
- PropertyPanel.AnnotEvents = null;
- PropertyPanel.AnnotEvent = null;
- PropertyPanel.annotlists = null;
- MyToolCheckedDoing(dictVar, tag);
- FindAnnotTypeKey(tag, ref annotArgs);
- if (annotArgs != null && tag != "Stamp")
- {
- //设置点击页面会创建对应选中注释工具的注释
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- }
- else
- {
- var f = PDFViewer.MouseMode;
- //2023/4/6 设置Stamp刚进入时点击view出现空的选中方框
- //PDFViewer.SetMouseMode(MouseModes.None);
- //解决 注释 工具 图章,不选中其他注释的bug
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(new SelectToolArgs());
- }
- if (PropertyPanel.IsSelectedTextAddLink)
- {
- PropertyPanel.IsSelectedTextAddLink = false;
- PDFViewer.SelectAnnotation(PropertyPanel.annot.PageIndex, PropertyPanel.annot.AnnotIndex);
- }
- if (PropertyPanel.IsSelectedTextAddShape)
- {
- PropertyPanel.IsSelectedTextAddShape = false;
- PDFViewer.SelectAnnotation(PropertyPanel.annot.PageIndex, PropertyPanel.annot.AnnotIndex);
- }
- }
- else
- {
- UncheckAnnot();
- }
- if (dictVar["isTemplateAnnot"] == false && annotArgs == null)
- {
- //当不是注释模板,且无创建注释时,属性面板显示为空内容
- HandToolIsCheckedEvent(false);
- ViewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- else
- {
- if (dictVar["isSnapshotEdit"] == true)
- {
- ShowPropertyPanel(false);
- }
- else
- {
- ShowPropertyPanel((bool)annotBtn.IsChecked);
- }
- }
- }
- /// <summary>
- /// 工具选项卡切换埋点
- /// </summary>
- /// <param name="e"></param>
- private void ToolsSelectonDataTracking(string tag)
- {
- switch (tag)
- {
- case "SnapshotEdit":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_ContentSelection");
- break;
- case "HighLight":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Highlight");
- break;
- case "UnderLine":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Underline");
- break;
- case "Strikeout":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Strikethrough");
- break;
- case "Freehand":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Draw");
- break;
- case "Freetext":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Text");
- break;
- case "StickyNote":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Note");
- break;
- case "Rect":
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Shape");
- break;
- case "Link":
- DataTrackingHelper.SetSendInformation(DataTrackingHelper.EventType.Purchase_Annotation, DataTrackingHelper.EntryPathKeyType.SubTbr_Annotation);
- DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Home, DataTrackingHelper.SecondaryPath.Link);
- DataTrackingHelper.IsClearEntryPath = true;
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Link");
- break;
- case "Stamp":
- DataTrackingHelper.SetSendInformation(DataTrackingHelper.EventType.Purchase_Annotation, DataTrackingHelper.EntryPathKeyType.SubTbr_Annotation);
- DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Home, DataTrackingHelper.SecondaryPath.Stamp);
- DataTrackingHelper.IsClearEntryPath = true;
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Stamp");
- break;
- case "Signature":
- DataTrackingHelper.SetSendInformation(DataTrackingHelper.EventType.Purchase_Annotation, DataTrackingHelper.EntryPathKeyType.SubTbr_Annotation);
- DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Home, DataTrackingHelper.SecondaryPath.Sign);
- DataTrackingHelper.IsClearEntryPath = true;
- DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Sign");
- break;
- }
- }
- private void UncheckAnnot()
- {
- //取消选中注释工具按钮后,恢复到未编辑注释的状态
- PropertyPanel.IsAddLink = false;
- //PropertyPanel.IsLocationLink = false;
- PDFViewer.DisableClearSelectAnnot(false);
- PDFViewer.ClearSelectAnnots();
- PDFViewer.ToolManager.EnableClickCreate = false;
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- ShowPropertyPanel(false);
- if (string.IsNullOrEmpty(StrAnnotToolChecked))
- {
- events.GetEvent<LinkAnnotTipCloseEvent>().Publish(new LinkAnnotTipCloseArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode });
- }
- }
- //选中注释工具按钮时,处理的一些系列事情
- private void MyToolCheckedDoing(Dictionary<string, bool> dict, string tag)
- {
- if (BtnHandIsChecked)
- BtnHandIsChecked = false;
- //选中取消问题待优化 2023/4/4
- if (BtnSelecttoolIsChecked && tag != "SnapshotEdit")
- BtnSelecttoolIsChecked = 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 != "Link")
- {
- events.GetEvent<LinkAnnotTipCloseEvent>().Publish(new LinkAnnotTipCloseArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode });
- //if (region.Regions.ContainsRegionWithName(viewContentViewModel.TipContentRegionName))
- //{
- // var views = region.Regions[viewContentViewModel.TipContentRegionName].Views;
- // Views.TipContent.LinkAnnotTip isHas = (Views.TipContent.LinkAnnotTip)views.FindFirst(q => q is Views.TipContent.LinkAnnotTip);
- // if (isHas != null)
- // {
- // viewContentViewModel.TipVisible = System.Windows.Visibility.Collapsed;
- // (isHas.DataContext as LinkAnnotPropertyViewModel).BtnLocationIsChecked = false;
- // }
- //}
- }
- 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
- public 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>
- public 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)
- {
- ViewContentViewModel.IsSelectedTextAddLink = false;
- if (sender is MenuItem menuItem)
- {
- StrAnnotToolChecked = "";
- AnnotHandlerEventArgs annotHandler = null;
- string str = menuItem.Tag.ToString();
- ViewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- PropertyPanel.IsAddLink = false;
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- ViewContentViewModel.IsRightMenuCreateLink = false;
- IsNoSelectMenu = true;
- isRightMenuAddAnnot = false;
- if (str == AddAnnotType.AnnotFreehand.ToString())
- {
- isRightMenuAddAnnot = true;
- annotHandler = GetFreehand();
- }
- if (str == AddAnnotType.AnnotFreeText.ToString())
- {
- annotHandler = GetFreetext();
- }
- if (str == AddAnnotType.AnnotSticky.ToString())
- {
- annotHandler = GetStickyNote();
- GetCurrentAnnot = annotHandler as StickyAnnotArgs;
- customStickyPopup.GetCurrentAnnot = GetCurrentAnnot;
- customStickyPopup.GetPDFViewer = PDFViewer;
- customStickyPopup.AnnotToolContentVM = this;
- }
- 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;
- ViewContentViewModel.IsRightMenuCreateLink = true;
- annotHandler = GetLink();
- }
- if (str == AddAnnotType.AnnotStamp.ToString())
- {
- annotHandler = GetStamp();
- }
- if (str == AddAnnotType.AnnotAutograph.ToString())
- {
- annotHandler = GetSignature();
- }
- if (annotHandler != null)
- {
- //是否展开右侧面板 =>否(链接、图章、签名除外)
- if (str == AddAnnotType.AnnotLink.ToString()
- || str == AddAnnotType.AnnotStamp.ToString()
- || str == AddAnnotType.AnnotAutograph.ToString()
- )
- {
- ShowPropertyPanel(true);
- }
- else
- {
- ShowPropertyPanel(false);
- }
- annotHandler.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotHandler);
- }
- }
- }
- /// <summary>
- /// 选择文本、图片,右键菜单
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void AnnotToolMenu_Click(object sender, RoutedEventArgs e)
- {
- ViewContentViewModel.IsSelectedTextAddLink = false;
- 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.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(highlightArgs);
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- ViewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- break;
- case "UnderLine"://下划线
- TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
- underlineArgs.ClientRect = annotCommand.TextRect;
- underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(underlineArgs);
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- ViewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- break;
- case "Strikeout"://删除线
- TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
- strikeoutArgs.ClientRect = annotCommand.TextRect;
- strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(strikeoutArgs);
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- ViewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- 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"://链接
- //添加付费拦截锁
- if (!ServiceHelper.IAPBeforeFunction())
- {
- return;
- }
- 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);
- List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
- lists.Add(linkArgs);
- PropertyPanel.IsAddLink = true;
- ViewContentViewModel.IsRightMenuSelectedTextAddLink = true;
- AnnotHandlerEventArgs annotArgs = GetLink(lists);
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- ViewContentViewModel.IsPropertyOpen = true;
- //PDFViewer.SelectAnnotation(linkArgs.PageIndex, linkArgs.AnnotIndex);
- 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.Text;
- }
- #region 选择图片
- //if (string.IsNullOrEmpty(annotCommand.Text))
- //{
- // str = (annotCommand.PageIndex + 1).ToString();
- //}
- //else
- //{
- // str = annotCommand.Text;
- //}
- #endregion 选择图片
- outLineControl.AddOutlineNode(str);
- }
- break;
- case "ExportPicture":
- ExportPicture_MenuItemClick();
- break;
- }
- if (clickMenu.Tag.ToString() != "Link")
- {
- ExitAnnotationTool();
- }
- ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown = 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":
- StrAnnotToolChecked = "";
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- HandToolIsCheckedEvent(false);
- BtnHandIsChecked = false;
- ShowPropertyPanel(false);
- break;
- case "roll":
- StrAnnotToolChecked = "";
- 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 (ViewContentViewModel.mainViewModel.IsBookMode == false)
- {
- if (bOTAContentVM != null && bOTA != null)
- {
- BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
- int index = PDFViewer.CurrentIndex;
- //检测是否已存在相同数据
- if (PDFViewer.Document == null) return;
- if (PDFViewer.Document.GetBookmarkList().Count <= 0) return;
- 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;
- }
- }
- }
- else
- {
- this.events.GetEvent<DelBookMarkEvent>().Publish(new BookMarkArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsReadMode = true });
- }
- }
- 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 == false)
- {
- //if (viewContentViewModel.mainViewModel.IsBookMode)
- //{
- // this.events.GetEvent<ReadModeBOTAShowEvent>().Publish(new ReadModeBOTAShowArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsBOTAShow = true });
- //}
- if (bOTAContentVM != null && bOTA != null)
- {
- AddBookMark(bOTAContentVM, bOTA);
- }
- //if (viewContentViewModel.mainViewModel.IsBookMode)
- //{
- // AddBookMark(bOTAContentVM, bOTA);
- //}
- }
- else
- {
- this.events.GetEvent<AddBookMarkEvent>().Publish(new BookMarkArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsReadMode = true });
- }
- }
- private void AddBookMark(BOTAContentViewModel bOTAContentVM, BOTAContent bOTA)
- {
- 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)
- {
- ViewContentViewModel.IsHiddenAnnot = false;
- PDFViewer.SetDrawAnnot(true);
- PDFViewer.ReloadVisibleAnnots();
- BtnShowAnnotIsChecked = true;
- bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
- ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown = false;
- if (ViewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- viewModel.DisplayAnnot();
- }
- //bota缩略图刷新 页面
- events.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs(App.mainWindowViewModel.SelectedItem.Unicode));
- }
- private void HiddenAnnot_Click(object sender, RoutedEventArgs e)
- {
- ViewContentViewModel.IsHiddenAnnot = true;
- PDFViewer.ClearSelectAnnots();
- PDFViewer.SetDrawAnnot(false);
- PDFViewer.ReloadVisibleAnnots();
- 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();
- }
- //bota缩略图刷新 页面
- events.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs(App.mainWindowViewModel.SelectedItem.Unicode));
- }
- private void SetAddAnnotation(ItemCollection items)
- {
- var separator = items[items.Count - 4];
- InBookModeSetIsHidden(separator);
- 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()
- )
- {
- InBookModeSetIsHidden(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.MarkupContent);
- }
- }
- }
- /// <summary>
- /// 更改为当前注释属性默认值
- /// </summary>
- /// <param name="obj"></param>
- 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 textHighlight)
- {
- var color = textHighlight.Color;
- HighLightColor = new SolidColorBrush(color);
- Settings.Default.AppProperties.Annotate.HighLightColor = color;
- var hightlight = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
- hightlight.ForgoundColor = color;
- hightlight.Opacity = textHighlight.Transparency;
- SettingHelper.SetAnnotDefaultProperty(hightlight);
- if (StrAnnotToolChecked == "HighLight")
- {
- TextHighlightAnnotArgs annotArgs = new TextHighlightAnnotArgs()
- {
- Color = textHighlight.Color,
- Transparency = textHighlight.Transparency
- };
- PDFViewer.SetToolParam(annotArgs);
- }
- }
- else if (annot is TextUnderlineAnnotArgs textUnderline)
- {
- var color = textUnderline.Color;
- UnderLineColor = new SolidColorBrush(color);
- Settings.Default.AppProperties.Annotate.UnderLineColor = color;
- var Underline = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
- Underline.ForgoundColor = color;
- Underline.Opacity = textUnderline.Transparency;
- SettingHelper.SetAnnotDefaultProperty(Underline);
- if (StrAnnotToolChecked == "UnderLine")
- {
- TextUnderlineAnnotArgs annotArgs = new TextUnderlineAnnotArgs()
- {
- Color = textUnderline.Color,
- Transparency = textUnderline.Transparency
- };
- PDFViewer.SetToolParam(annotArgs);
- }
- }
- else if (annot is TextStrikeoutAnnotArgs textStrikeout)
- {
- var color = textStrikeout.Color;
- StrikeoutColor = new SolidColorBrush(color);
- Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
- var Strikeout = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
- Strikeout.ForgoundColor = color;
- Strikeout.Opacity = textStrikeout.Transparency;
- SettingHelper.SetAnnotDefaultProperty(Strikeout);
- if (StrAnnotToolChecked == "Strikeout")
- {
- TextStrikeoutAnnotArgs annotArgs = new TextStrikeoutAnnotArgs()
- {
- Color = textStrikeout.Color,
- Transparency = textStrikeout.Transparency
- };
- PDFViewer.SetToolParam(annotArgs);
- }
- }
- else if (annot is FreehandAnnotArgs freeHand)
- {
- //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);
- if (StrAnnotToolChecked == "Freehand")
- {
- FreehandAnnotArgs annotArgs = new FreehandAnnotArgs()
- {
- InkColor = freeHand.InkColor,
- Transparency = freeHand.Transparency,
- LineWidth = freeHand.LineWidth,
- LineDash = freeHand.LineDash
- };
- PDFViewer.SetToolParam(annotArgs);
- }
- }
- else if (annot is FreeTextAnnotArgs freeText)
- {
- //var freeText = annot as FreeTextAnnotArgs;
- Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
- Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontName;
- Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
- var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
- FreeTextDefalut.ForgoundColor = freeText.FontColor;
- FreeTextDefalut.FontFamily = freeText.FontName;
- FreeTextDefalut.TextAlign = freeText.Align;
- FreeTextDefalut.FontSize = freeText.FontSize;
- FreeTextDefalut.FontWeight = freeText.IsBold ? FontWeights.Bold : FontWeights.Normal;
- FreeTextDefalut.FontStyle = freeText.IsItalic ? FontStyles.Italic : FontStyles.Normal;
- FreeTextDefalut.BackgroundColor = freeText.BgColor;
- FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
- SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
- if (StrAnnotToolChecked == "Freetext")
- {
- FreeTextAnnotArgs freeTextAnnotArgs = new FreeTextAnnotArgs()
- {
- FontColor = freeText.FontColor,
- FontName = freeText.FontName,
- Align = freeText.Align,
- FontSize = freeText.FontSize,
- IsBold = freeText.IsBold,
- IsItalic = freeText.IsItalic,
- BgColor = freeText.BgColor,
- Transparency = (annot as FreeTextAnnotArgs).Transparency
- };
- PDFViewer.SetToolParam(freeTextAnnotArgs);
- }
- }
- else if (annot is StickyAnnotArgs stickyAnnotArgs)
- {
- var color = stickyAnnotArgs.Color;
- Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
- var StickyDefalut = GetAnnotDefault(AnnotArgsType.AnnotSticky);
- StickyDefalut.ForgoundColor = color;
- StickyDefalut.NoteIcon = stickyAnnotArgs.IconName;
- SettingHelper.SetAnnotDefaultProperty(StickyDefalut);
- if (StrAnnotToolChecked == "StickyNote")
- {
- StickyAnnotArgs annotArgs = new StickyAnnotArgs()
- {
- Color = stickyAnnotArgs.Color,
- IconName = stickyAnnotArgs.IconName,
- Transparency = stickyAnnotArgs.Transparency,
- Author = Settings.Default.AppProperties.Description.Author
- };
- PDFViewer.SetToolParam(annotArgs);
- }
- }
- else if (annot is SquareAnnotArgs squareAnnot)
- {
- //var square = annot as SquareAnnotArgs;
- var bgColor = squareAnnot.BgColor;
- Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
- var borderColor = squareAnnot.LineColor;
- Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
- var SquareDefalut = GetAnnotDefault(AnnotArgsType.AnnotSquare);
- SquareDefalut.BorderColor = borderColor;
- SquareDefalut.BackgroundColor = bgColor;
- SquareDefalut.Opacity = squareAnnot.Transparency;
- SquareDefalut.Thickness = squareAnnot.LineWidth;
- var isSolid = AnnotTransfer.IsSolidStyle(squareAnnot.LineDash);
- if (isSolid)
- {
- SquareDefalut.DashArray = null;
- }
- else
- {
- SquareDefalut.DashArray = new List<double>();
- foreach (var item in squareAnnot.LineDash.Dashes)
- {
- SquareDefalut.DashArray.Add(item);
- }
- }
- SettingHelper.SetAnnotDefaultProperty(SquareDefalut);
- if (PropertyPanel.SharpsAnnot == "Rect" && StrAnnotToolChecked == "Rect")
- {
- SquareAnnotArgs annotArgs = new SquareAnnotArgs()
- {
- BgColor = squareAnnot.BgColor,
- LineColor = squareAnnot.LineColor,
- Transparency = squareAnnot.Transparency,
- LineWidth = squareAnnot.LineWidth,
- LineDash = squareAnnot.LineDash
- };
- PDFViewer.SetToolParam(annotArgs);
- }
- }
- else if (annot is CircleAnnotArgs circleAnnot)
- {
- //var circle = annot as CircleAnnotArgs;
- var bgColor = circleAnnot.BgColor;
- Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
- var borderColor = circleAnnot.LineColor;
- Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
- var CircleDefalut = GetAnnotDefault(AnnotArgsType.AnnotCircle);
- CircleDefalut.BorderColor = borderColor;
- CircleDefalut.BackgroundColor = bgColor;
- CircleDefalut.Opacity = circleAnnot.Transparency;
- CircleDefalut.Thickness = circleAnnot.LineWidth;
- var isSolid = AnnotTransfer.IsSolidStyle(circleAnnot.LineDash);
- if (isSolid)
- {
- CircleDefalut.DashArray = null;
- }
- else
- {
- CircleDefalut.DashArray = new List<double>();
- foreach (var item in circleAnnot.LineDash.Dashes)
- {
- CircleDefalut.DashArray.Add(item);
- }
- }
- SettingHelper.SetAnnotDefaultProperty(CircleDefalut);
- if (PropertyPanel.SharpsAnnot == "Circle" && StrAnnotToolChecked == "Rect")
- {
- CircleAnnotArgs annotArgs = new CircleAnnotArgs()
- {
- BgColor = circleAnnot.BgColor,
- LineColor = circleAnnot.LineColor,
- Transparency = circleAnnot.Transparency,
- LineWidth = circleAnnot.LineWidth,
- LineDash = circleAnnot.LineDash
- };
- PDFViewer.SetToolParam(annotArgs);
- }
- }
- else if (annot is LineAnnotArgs lineAnnotArgs)
- {
- var color = lineAnnotArgs.LineColor;
- var lineDefalut = GetAnnotDefault(AnnotArgsType.AnnotLine);
- //箭头
- if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
- {
- Settings.Default.AppProperties.Annotate.ArrowColor = color;
- lineDefalut.HeadLineType = lineAnnotArgs.HeadLineType;
- lineDefalut.TailLineType = lineAnnotArgs.TailLineType;
- if (PropertyPanel.SharpsAnnot == "Arrow" && StrAnnotToolChecked == "Rect")
- {
- LineAnnotArgs annotArgs = new LineAnnotArgs()
- {
- LineColor = lineAnnotArgs.LineColor,
- Transparency = lineAnnotArgs.Transparency,
- LineWidth = lineAnnotArgs.LineWidth,
- LineDash = lineAnnotArgs.LineDash,
- HeadLineType = lineAnnotArgs.HeadLineType,
- TailLineType = lineAnnotArgs.TailLineType
- };
- PDFViewer.SetToolParam(annotArgs);
- }
- }
- else
- {
- Settings.Default.AppProperties.Annotate.LineColor = color;
- if (PropertyPanel.SharpsAnnot == "Line" && StrAnnotToolChecked == "Rect")
- {
- LineAnnotArgs annotArgs = new LineAnnotArgs()
- {
- LineColor = lineAnnotArgs.LineColor,
- Transparency = lineAnnotArgs.Transparency,
- LineWidth = lineAnnotArgs.LineWidth,
- LineDash = lineAnnotArgs.LineDash,
- HeadLineType = lineAnnotArgs.HeadLineType,
- TailLineType = lineAnnotArgs.TailLineType
- };
- PDFViewer.SetToolParam(annotArgs);
- }
- }
- lineDefalut.BorderColor = color;
- lineDefalut.Opacity = lineAnnotArgs.Transparency;
- lineDefalut.Thickness = lineAnnotArgs.LineWidth;
- var isSolid = AnnotTransfer.IsSolidStyle(lineAnnotArgs.LineDash);
- if (isSolid)
- {
- lineDefalut.DashArray = null;
- }
- else
- {
- lineDefalut.DashArray = new List<double>();
- foreach (var item in lineAnnotArgs.LineDash.Dashes)
- {
- lineDefalut.DashArray.Add(item);
- }
- }
- SettingHelper.SetAnnotDefaultProperty(lineDefalut);
- //if ((PropertyPanel.SharpsAnnot == "Arrow" || PropertyPanel.SharpsAnnot == "Line") && StrAnnotToolChecked == "Rect")
- //{
- // LineAnnotArgs annotArgs = new LineAnnotArgs()
- // {
- // LineColor = lineAnnotArgs.LineColor,
- // Transparency = lineAnnotArgs.Transparency,
- // LineWidth = lineAnnotArgs.LineWidth,
- // LineDash = lineAnnotArgs.LineDash,
- // HeadLineType = lineAnnotArgs.HeadLineType,
- // TailLineType = lineAnnotArgs.TailLineType
- // };
- // PDFViewer.SetToolParam(annotArgs);
- //}
- }
- Settings.Default.Save();
- PropertyPanel.annot = annot;
- PropertyPanel.SaveLastAnnot();
- }
- }
- }
- 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(), PDFViewer);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
- AnnotEvent?.UpdateAnnot();
- }
- else if (annot is FreeTextAnnotArgs)
- {
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
- 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(), PDFViewer);
- 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(), PDFViewer);
- 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(), PDFViewer);
- 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(), PDFViewer);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontName, 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(), PDFViewer);
- 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(), PDFViewer);
- 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(), PDFViewer);
- 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.DeleteModifiedAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
- }
- }
- }
- }
- }
- }
- //图章
- 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")
- {
- try
- {
- var writeStamp = annot.GetStampDrawing();
- var tempDoc = new CPDFViewer();
- tempDoc.CreateDocument();
- if (tempDoc.Document == null)
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Create PDF failed"), App.ServiceLoader.GetString("Text_ok"));
- return;
- }
- byte[] buffer = new byte[writeStamp.PixelWidth * writeStamp.PixelHeight * 4];
- writeStamp.CopyPixels(buffer, writeStamp.PixelWidth * 4, 0);
- tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
- var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
- if (result)
- {
- }
- }
- catch
- {
- }
- #region
- //之前的方法1
- //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)
- //{
- //}
- //之前的方法2
- //string imagePath = SaveImage(writeStamp);
- //if (CreateFile(imagePath, tempDoc))
- //{
- // bool result = tempDoc.Document.WriteToFilePath(dlg.FileName);
- //}
- #endregion 注释右键菜单事件
- }
- 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);
- }
- }
- CommonHelper.ExplorerFile(dlg.FileName);
- }
- }
- }
- }
- private string SaveImage(WriteableBitmap wtbBmp)
- {
- string isSave = null;
- if (wtbBmp == null)
- {
- return isSave;
- }
- try
- {
- DirectoryInfo tempfolder = new DirectoryInfo(Path.Combine(App.CurrentPath, "Temp"));
- string strpath = Path.Combine(tempfolder.FullName, DateTime.Now.ToString("yyyyMMddfff") + ".jpg");
- if (!File.Exists(tempfolder.FullName))
- {
- Directory.CreateDirectory(tempfolder.FullName);
- }
- using (FileStream stream = new FileStream(strpath, FileMode.Create))
- {
- JpegBitmapEncoder bitmapEncoder = new JpegBitmapEncoder();
- bitmapEncoder.Frames.Add(BitmapFrame.Create(wtbBmp));
- bitmapEncoder.Save(stream);
- isSave = strpath;
- }
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- isSave = null;
- }
- return isSave;
- }
- public bool CreateFile(string imagePath = null, CPDFViewer saveToPDFViewer = null)
- {
- string fileName = null;
- //saveToPDFViewer.CreateDocument();
- //if (saveToPDFViewer.Document == null)
- //{
- // AlertsMessage alertsMessage = new AlertsMessage();
- // alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Create PDF failed"), App.ServiceLoader.GetString("Text_ok"));
- // return false;
- //}
- if (string.IsNullOrEmpty(imagePath))
- {
- fileName = "Blank Page.pdf";
- //默认插入595*842 大小的页面
- saveToPDFViewer.Document.InsertPage(0, 595, 842, null);
- }
- else
- {
- fileName = imagePath.Substring(imagePath.LastIndexOf("\\") + 1, imagePath.LastIndexOf(".") - imagePath.LastIndexOf("\\") - 1) + ".pdf";
- System.Drawing.Bitmap pic = new System.Drawing.Bitmap(imagePath);
- int width = pic.Size.Width;
- int height = pic.Size.Height;
- string ex = System.IO.Path.GetExtension(imagePath);
- //其他格式或者名称中含空格的图片 在本地先转存一下
- if ((ex != ".jpg" && ex != ".jpeg") || !Uri.IsWellFormedUriString(imagePath, UriKind.Absolute))
- {
- //将其他格式图片转换成jpg
- string folderPath = Path.GetTempPath();
- if (File.Exists(folderPath))
- {
- File.Delete(folderPath);
- }
- DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
- if (!tempfolder.Exists)
- {
- tempfolder.Create();
- }
- string targetPath = System.IO.Path.Combine(folderPath, Guid.NewGuid().ToString());
- imagePath = targetPath;
- pic.Save(targetPath, ImageFormat.Jpeg);
- }
- pic.Dispose();
- var result = saveToPDFViewer.Document.InsertPage(0, width, height, imagePath);
- if (!result)
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Create PDF failed"), App.ServiceLoader.GetString("Text_ok"));
- return false;
- }
- }
- return true;
- }
- #endregion 注释右键菜单事件
- #region 快捷键
- private void ShortCut_KeyDown(object sender, KeyEventArgs e)
- {
- //之前取消逻辑
- // if (KeyEventsHelper.IsSingleKey(Key.Escape))
- // {
- // if (StrAnnotToolChecked != "Freetext")
- // {
- // ExitAnnotationTool();
- // }
- // else if (StrAnnotToolChecked == "Freetext")
- // {
- // if (PDFViewer.ToolManager.CurrentAnnotArgs is FreeTextAnnotArgs textAnnotArgs)
- // {
- // if (PDFViewer.ToolManager.HasTool)
- // {
- // PDFViewer.RemoveTool(true);
- // }
- // else
- // {
- // ExitAnnotationTool();
- // }
- // }
- // }
- // }
- //
- if (e.Key == Key.Escape)
- {
- if (PropertyPanel != null)
- {
- PropertyPanel.IsAddLink = false;
- }
- if (PDFViewer != null)
- {
- if (PDFViewer.GetSelectImageCount() > 0)
- {
- IsSelectImage = true;
- PDFViewer.ClearImage();
- }
- if (PDFViewer.MouseMode == MouseModes.AnnotCreate)
- {
- if (PDFViewer.ToolManager != null && PDFViewer.ToolManager.CurrentAnnotArgs != null)
- {
- AnnotHandlerEventArgs annotArgs = PDFViewer.ToolManager.CurrentAnnotArgs;
- switch (annotArgs.EventType)
- {
- case AnnotArgsType.AnnotErase:
- case AnnotArgsType.AnnotLine:
- case AnnotArgsType.AnnotSquare:
- case AnnotArgsType.AnnotCircle:
- //case AnnotArgsType.AnnotSticky:
- Trace.WriteLine(StrAnnotToolChecked);
- if (PDFViewer.ToolManager.HasTool)
- {
- PDFViewer.RemoveTool(false);
- IsCreateAnnot = true;
- }
- else
- {
- ExitAnnotationTool();
- }
- break;
- case AnnotArgsType.AnnotFreeText:
- if (PDFViewer.ToolManager.HasTool == false)
- {
- ExitAnnotationTool();
- }
- else
- {
- PDFViewer.RemoveTool(true);
- }
- break;
- case AnnotArgsType.AnnotSticky:
- if (PDFViewer.ToolManager.HasTool)
- {
- //PDFViewer.RemoveTool(false);
- events.GetEvent<StickyNoteEvent>().Subscribe(UnStickyNote, q => q.Unicode == Unicode);
- }
- else
- {
- ExitAnnotationTool();
- }
- break;
- case AnnotArgsType.AnnotHighlight:
- case AnnotArgsType.AnnotUnderline:
- case AnnotArgsType.AnnotStrikeout:
- case AnnotArgsType.AnnotStamp:
- case AnnotArgsType.AnnotFreehand:
- ExitAnnotationTool();
- break;
- case AnnotArgsType.AnnotLink:
- //ExitAnnotationTool();
- if (PDFViewer.ToolManager.HasTool)
- {
- PDFViewer.RemoveTool(false);
- }
- ExitAnnotationTool();
- events.GetEvent<LinkAnnotTipCloseEvent>().Publish(new LinkAnnotTipCloseArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode });
- break;
- case AnnotArgsType.AnnotSelectTool:
- //if(viewContentViewModel.mainViewModel.IsBookMode==false)
- //{
- // ExitAnnotationTool(false);
- //}
- BottomToolContent bottomTool = null;
- BottomToolContentViewModel bottomToolVM = ViewContentViewModel.GetBottomToolContentVM(ref bottomTool);
- if (bottomToolVM != null)
- {
- if (bottomToolVM.IsShowViewModular)
- {
- ExitAnnotationTool(false);
- }
- else
- {
- ExitAnnotationTool();
- }
- }
- else
- {
- ExitAnnotationTool();
- }
- break;
- }
- CleanAnnotationSelect();
- }
- }
- else
- {
- //避免编辑功能ESC快捷键冲突
- if (PDFViewer.MouseMode != MouseModes.PDFEdit)
- {
- ExitAnnotationTool();
- }
- }
- }
- }
- else if (KeyEventsHelper.IsModifierKey(ModifierKeys.Shift, Key.None))
- {
- //按住Shift等比缩放
- }
- else if (e.Key == Key.F && e.KeyboardDevice.Modifiers == ModifierKeys.Control)
- {
- if (ViewContentViewModel.OpenBOTA == false)
- {
- ViewContentViewModel.OpenBOTA = true;
- }
- bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
- if (isBook == false)
- {
- bOTAContent.TabItemSearch.IsSelected = true;
- }
- }
- AnnotToolCtrlAltKey();
- }
- private void UnStickyNote(StickyNoteArgs obj)
- {
- if (PDFViewer.MouseMode == MouseModes.AnnotCreate)
- {
- if (PDFViewer.ToolManager != null && PDFViewer.ToolManager.CurrentAnnotArgs != null)
- {
- if (string.IsNullOrEmpty(obj.Text))
- {
- PDFViewer.RemoveTool(false);
- }
- else
- {
- }
- }
- }
- }
- public void ExitAnnotationTool(bool isShow = true)
- {
- if (isShow)
- {
- ViewContentViewModel.IsReadModeShow = false;
- ViewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- ShowPropertyPanel(false);
- }
- else
- {
- ViewContentViewModel.IsReadModeShow = true;
- }
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- var annotArgs = new SelectToolArgs();
- PDFViewer.SetToolParam(annotArgs);
- //PDFViewer.SetMouseMode(MouseModes.PanTool);
- PDFViewer.DisableClearSelectAnnot(false);
- PDFViewer.ClearSelectAnnots();
- StrAnnotToolChecked = "";
- BtnHandIsChecked = false;
- }
- /// <summary>
- /// 按下Ctrl + Alt + 序列键,响应注释工具
- /// </summary>
- private void AnnotToolCtrlAltKey()
- {
- var tuple = GetCtrlAltKey();
- if (tuple != null && PDFViewer != null)
- {
- //进入快捷键时清除选中
- PDFViewer.ClearSelectAnnots();
- if (tuple.Item1 == Key.L)
- BtnLinkIsChecked = false;
- if (tuple.Item2 == "Eraser")
- {
- CreateEraseArgs();
- StrAnnotToolChecked = "Freehand";
- return;
- }
- AnnotHandlerEventArgs annotArgs = null;
- //注释 快捷键 第一次选中对应的,第二次取消选中
- if (StrAnnotToolChecked == tuple.Item2)
- {
- StrAnnotToolChecked = "";
- UncheckAnnot();
- }
- else
- {
- StrAnnotToolChecked = tuple.Item2;
- FindAnnotTypeKey(tuple.Item2, ref annotArgs);
- if (annotArgs != null && tuple.Item2 != "Stamp")
- {
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- PDFViewer.ToolManager.EnableClickCreate = false;
- }
- else
- {
- //2023/4/6 设置Stamp刚进入时点击view出现空的选中方框
- //PDFViewer.SetMouseMode(MouseModes.None);
- //解决 注释 工具 图章,不选中注释的bug
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(new SelectToolArgs());
- }
- }
- }
- }
- 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 = "RectKey";
- else if (AnnotToolDir[Key.O])
- tag = "Circle";
- else if (AnnotToolDir[Key.A])
- tag = "Arrow";
- else if (AnnotToolDir[Key.L])
- tag = "Line";
- else if (AnnotToolDir[Key.E])
- tag = "Eraser";
- }
- 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)
- {
- //链接 框 的 样式
- SolidColorBrush solidColorBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(50, 23, 112, 244));
- SolidColorBrush solidColorPen = new SolidColorBrush(System.Windows.Media.Color.FromRgb(23, 112, 244));
- CommonDrawData.LinkPen = new System.Windows.Media.Pen(solidColorPen, 0);
- CommonDrawData.LinkBrush = solidColorBrush;
- CommonDrawData.LinkAreaSelectPen = new System.Windows.Media.Pen(solidColorBrush, 0);
- CommonDrawData.LinkAreaSelectBrush = solidColorBrush;
- ViewContentViewModel viewModel;
- navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewModel);
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
- ViewContentViewModel = viewModel;
- if (ViewContentViewModel != null)
- {
- OpenFileInfo = ViewContentViewModel.OpenFileInfo;
- ViewContentViewModel.PropertyChanged -= ViewContentViewModel_PropertyChanged;
- ViewContentViewModel.PropertyChanged += ViewContentViewModel_PropertyChanged;
- }
- if (PDFViewer != null)
- {
- BindingPDFViewerHandler();
- BindingEvent();
- LoaedStickyNotePopup();
- //获取当前是否为滚动状态
- // BtnHandIsChecked = (PDFViewer.MouseMode == MouseModes.Scroll ? true : false);
- BtnHandIsChecked = false;
- HandToolIsCheckedEvent(false);
- }
- }
- #endregion Navigation
- }
- }
|