123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776 |
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Office.Model;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using PDF_Office.ViewModels.Tools;
- using ComPDFKitViewer;
- using PDF_Office.Helper;
- using PDF_Office.Properties;
- using PDFSettings;
- using System.Windows.Media;
- using ComPDFKit.PDFDocument.Action;
- using ComPDFKit.PDFDocument;
- using System.Diagnostics;
- using ComPDFKit.PDFAnnotation;
- using PDF_Office.ViewModels.BOTA;
- using PDF_Office.Views.BOTA;
- using System.Windows.Forms;
- using Control = System.Windows.Controls.Control;
- using Microsoft.Office.Interop.Word;
- using Point = System.Windows.Point;
- using System.Windows.Ink;
- using PDF_Office.EventAggregators;
- using System.Management.Instrumentation;
- using Prism.Events;
- using System.Windows.Input;
- using ContextMenu = System.Windows.Controls.ContextMenu;
- using MenuItem = System.Windows.Controls.MenuItem;
- using System.Drawing;
- using Color = System.Windows.Media.Color;
- using Brush = System.Windows.Media.Brush;
- using FontFamily = System.Windows.Media.FontFamily;
- using ToolTip = System.Windows.Controls.ToolTip;
- using ContentControl = System.Windows.Controls.ContentControl;
- using MouseEventArgs = System.Windows.Input.MouseEventArgs;
- using Pen = System.Windows.Media.Pen;
- using PDF_Office.Model.PropertyPanel.AnnotPanel;
- using RadioButton = System.Windows.Controls.RadioButton;
- using Style = System.Windows.Style;
- using PDF_Office.CustomControl;
- using System.Windows.Controls.Primitives;
- using Window = System.Windows.Window;
- using Task = System.Threading.Tasks.Task;
- using Size = System.Windows.Size;
- using System.Windows.Markup;
- using Prism.Services.Dialogs;
- using PDF_Office.ViewModels.Tools.AnnotManager;
- using PDF_Office.Model.FillAndSign;
- namespace PDF_Office.ViewModels.FillAndSign
- {
- public class FillAndSignContentViewModel : BindableBase, INavigationAware
- {
- #region
- public CPDFViewer PDFViewer;
- private AnnotTransfer propertyPanel = new AnnotTransfer();
- public ViewContentViewModel viewContentViewModel;
- private bool isRightMenuAddAnnot = false;
- private IEventAggregator events;
- public List<List<Point>> ShapePoints = new List<List<Point>>();
- public string Shape = "HookShape";
- private bool IsFillAndSign { get;
-
- set; } = true;
- private PopMenu FreeHandAnnotPopMenu;
- private PopMenu FreeTextAnnotPopMenu;
- private PopMenu MultiAnnotPopMenu;
- public bool isFirst = true;
- private IRegionManager regions { get; set; }
- private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
- public static bool IsEdit = false;
- public static bool IsSignPoint = false;
- public Brush SelectColor = new SolidColorBrush(Colors.GreenYellow);
- public double FillOpacity = 1;
- public double LineWidth = 2;
- public double LineWidthMultiple = 1;
- private string DateOrText = "";
- private bool _HookShapeIsCheck = false;
- public bool HookShapeIsCheck
- {
- get { return _HookShapeIsCheck; }
- set { SetProperty(ref _HookShapeIsCheck, value); }
- }
- #endregion
- public DelegateCommand<object> AnnotDefaultValue_MenuCommand { get; set; }
- public DelegateCommand<object> FreeTextFontFamily_MenuCommand { get; set; }
- public DelegateCommand<object> AnnotColorPalette_MenuCommand { get; set; }
- public DelegateCommand<object> FreeTextAglin_MenuCommand { get; set; }
- #region Command
- public DelegateCommand<object> CheckCommand { get; set; }
- /// <summary>
- /// 按钮名称和属性面板映射字典
- /// </summary>
- public Dictionary<string, string> btnToProperty = new Dictionary<string, string>();
- private IDialogService dialogs;
- #endregion
- string Unicode = "";
- public FillAndSignContentViewModel(IRegionManager regionManager, IEventAggregator events) { }
- public FillAndSignContentViewModel(IRegionManager regionManager, IEventAggregator events, IDialogService dialogService)
- {
- dialogs = dialogService;
- regions = regionManager;
- this.events = events;
- Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
- CheckCommand = new DelegateCommand<object>(CheckedEvent);
- ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
- InitDictionary();
- AnnotDefaultValue_MenuCommand = new DelegateCommand<object>(AnnotDefaultValues_Menu);
- AnnotColorPalette_MenuCommand = new DelegateCommand<object>(AnnotColorPalette_Menu);
- FreeTextFontFamily_MenuCommand = new DelegateCommand<object>(FreeTextFontFamily_Menu);
- FreeTextAglin_MenuCommand = new DelegateCommand<object>(FreeTextAglin_Menu);
- InitSelectFreeHandAnnotMenu();
- InitSelectFreeTextAnnotMenu();
- InitSelectMultiAnnotMenu();
- SubscribeEvent();
- }
- #region 事件聚合器(来自AnnotToolContentViewModel)
- private void SubscribeEvent()
- {
- events.GetEvent<FillAndSignEvent>().Subscribe(FromFillAndSign, e => e.AppUnicode == Unicode);
- }
- private void FromFillAndSign(FillAndSigntEventArgs obj)
- {
- if (obj != null)
- {
- if (string.IsNullOrEmpty(obj.Action) == false)
- {
- if (obj.Action == "Clear")
- {
- viewContentViewModel.FillAndSign.Clear();
- }
- else
- {
- if (obj.Annots != null && obj.Annots.Count > 0)
- {
- if (obj.Annots[0].EventType == AnnotArgsType.AnnotFreehand)
- {
- IsFillAndSign = false;
- GetFreehand(obj.Annots);
-
- }
- else if (obj.Annots[0].EventType == AnnotArgsType.AnnotFreeText)
- {
- GetFreetext(obj.Annots);
- }
- }
- }
- }
- }
- }
- #endregion 事件聚合器
- private void InitFillAndSignProperty()
- {
- var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand, "FillAndSign");
- SelectColor = new SolidColorBrush(FreehandDefault.BorderColor != Color.FromArgb(0, 0, 0, 0) ? FreehandDefault.BorderColor : Colors.GreenYellow);
- FillOpacity = FreehandDefault.Opacity > 0 ? FreehandDefault.Opacity : 1;
- LineWidth = FreehandDefault.Thickness > 0 ? FreehandDefault.Thickness : 2;
- }
- 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 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 parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
- {
- var ui = Mouse.DirectlyOver as FrameworkElement;
- if (ui != null)
- {
- if (popup != null)
- {
- popup.IsOpen = false;
- }
- }
- }
- 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 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 FreehandAnnotArgs)
- {
- var freeHand = annot as FreehandAnnotArgs;
- var color = freeHand.InkColor;
- //Settings.Default.AppProperties.Annotate.FreeHandColor = color;
- var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand, "FillAndSign");
- FreehandDefault.BorderColor = color;
- FreehandDefault.Opacity = freeHand.Transparency;
- FreehandDefault.Thickness = freeHand.LineWidth;
- FreehandDefault.SaveKey = "FillAndSign";
- 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);
- }
- }
- }
- }
- private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType, string savaKey = "")
- {
- var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType, savaKey);
- if (Annot == null)
- {
- Annot = new DefaultAnnotProperty();
- Annot.AnnotToolType = annotArgsType;
- }
- return Annot;
- }
- private void CheckedEvent(object e)
- {
- var control = e as Control;
- IsEdit = false;
- //NavigateToProperty(control.Name);
- //不创建注释,属于注释模板
- bool isTemplateAnnot = false;
- bool isSnapshotEdit = false;
- AnnotHandlerEventArgs annotArgs = null;
- //付费锁
- if (!App.IsLogin)
- {
- dialogs.ShowDialog(DialogNames.IAPCompareDialog);
- return;
- }
- var tag = control.Name;
- FindAnnotTypeKey(control.Name, ref annotArgs);
- if (control.Name == "RbtnSign") { isTemplateAnnot = true; }
- if (tag == "SnapshotEdit")
- {
- isSnapshotEdit = true;
- }
- else if (tag == "Signature" || tag == "Stamp")
- {
- isTemplateAnnot = true;
- }
- if (annotArgs != null)
- {
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- isRightMenuAddAnnot = false;
- }
- //当不是注释模板,且无创建注释时,属性面板显示为空内容
- if (isTemplateAnnot == false && annotArgs == null)
- {
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- else
- {
- if (isSnapshotEdit == true)
- {
- ShowPropertyPanel(false);
- isSnapshotEdit = false;
- }
- else
- {
- ShowPropertyPanel(true);
- }
- }
- }
- private void InitCheckedEvent(string e)
- {
- IsEdit = false;
- //NavigateToProperty(control.Name);
- //不创建注释,属于注释模板
- bool isTemplateAnnot = false;
- bool isSnapshotEdit = false;
- AnnotHandlerEventArgs annotArgs = null;
- var tag = e;
- FindAnnotTypeKey(e, ref annotArgs);
- if (e == "RbtnSign") { isTemplateAnnot = true; }
- if (tag == "SnapshotEdit")
- {
- isSnapshotEdit = true;
- }
- else if (tag == "Signature" || tag == "Stamp")
- {
- isTemplateAnnot = true;
- }
- if (annotArgs != null)
- {
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- isRightMenuAddAnnot = false;
- }
- //当不是注释模板,且无创建注释时,属性面板显示为空内容
- if (isTemplateAnnot == false && annotArgs == null)
- {
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- else
- {
- if (isSnapshotEdit == true)
- {
- ShowPropertyPanel(false);
- isSnapshotEdit = false;
- }
- else
- {
- ShowPropertyPanel(true);
- }
- }
- }
- //注释工具
- private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
- {
- LineWidthMultiple = 1;
- IsSignPoint = false;
- Shape = "None";
- switch (tag)
- {
- case "RbtnDate":
- DateOrText = "Freetext";
- annotArgs = GetFreetext();
- break;
- case "RbtnText"://文本
- DateOrText = "";
- annotArgs = GetFreetext();
- break;
- case "Freetext"://文本
- annotArgs = GetFreetext();
- break;
- case "RbtnSign"://签名
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- annotArgs = GetSignature();
- //清空其他注释
- break;
- case "RbtnTick"://勾
- Shape = "HookShape";
- ShapePoints = new List<List<Point>> { new List<Point> { new Point(0.599976, 7.0286), new Point(5.57775, 11.8), new Point(13.4, 1.40002) } };
- annotArgs = GetStamp();
- break;
- case "RbtnFork"://叉
- Shape = "ForkShape";
- ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(12.8, 12.8) }, new List<Point> { new Point(12.8, 3.20001), new Point(3.20005, 12.8) } };
- annotArgs = GetStamp();
- break;
- case "RbtnRectangle"://矩形
- Shape = "RectShape";
- ShapePoints = new List<List<Point>> { new List<Point> { new Point(5, 5), new Point(28, 5) }, new List<Point> { new Point(28, 5), new Point(28, 27) }, new List<Point> { new Point(28, 27), new Point(5, 27) }, new List<Point> { new Point(5, 27), new Point(5, 5) } };
- annotArgs = GetStamp();
- break;
- case "RbtnLine"://下划线
- Shape = "LineShape";
- ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(28, 3.20001) } };
- annotArgs = GetStamp();
- break;
- case "RbtnPoint":
- IsSignPoint = true;
- Shape = "DotShape";
- ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.19995), new Point(3.19995, 3.19995) } };
- LineWidthMultiple = 5;
- annotArgs = GetStamp();
- break;
- default://图章
- break;
- }
- }
- /// <summary>
- /// 签名
- /// </summary>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetSignature()
- {
- AddToPropertyPanel("SignatureAnnotProperty");
- return null;
- }
- /// <summary>
- /// 图章
- /// </summary>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetStamp(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
- stampAnnotArgs.SetInkData(ShapePoints, LineWidth * LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
- //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- //PDFViewer.SetToolParam(stampArgs);
- //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
- //stampAnnotArgs.Opacity = 1;
- //stampAnnotArgs.StampText = "APPROVED";
- //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
- // stampAnnotArgs.Type = StampType.STANDARD_STAMP;
- stampAnnotArgs.IsContinueMode = true;
- stampAnnotArgs.IsSignPoint = IsSignPoint;
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
- List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
- if (stampAnnotArgs != null)
- stampAnnotArgsList.Add(stampAnnotArgs);
- //if (selectedArgs != null) {
- //var annot = selectedArgs[0];
- //if (annot != null)
- //{
- // foreach (var item in selectedArgs)
- // {
- // selectedArgs[selectedArgs.IndexOf(item)] = stampAnnotArgs;
- // }
- // AddToPropertyPanel("ShapFillProperty", "", selectedArgs, annotAttribsList);
- // return stampAnnotArgs;
- //}
- // }
- AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
- return stampAnnotArgs;
- }
- public void SetStamp()
- {
- StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
- double lineWidthMultiple = LineWidthMultiple;
- if (Shape == "DotShape") { LineWidthMultiple = 5; }
- stampAnnotArgs.SetInkData(ShapePoints, LineWidth * LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
- LineWidthMultiple = lineWidthMultiple;
- //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- //PDFViewer.SetToolParam(stampArgs);
- //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
- //stampAnnotArgs.Opacity = 1;
- //stampAnnotArgs.StampText = "APPROVED";
- //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
- stampAnnotArgs.IsContinueMode = true;
- stampAnnotArgs.IsSignPoint = IsSignPoint;
- stampAnnotArgs.Opacity = FillOpacity;
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
- List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
- if (stampAnnotArgs != null)
- stampAnnotArgsList.Add(stampAnnotArgs);
- //AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
- bool isTemplateAnnot = false;
- bool isSnapshotEdit = false;
- AnnotHandlerEventArgs annotArgs = stampAnnotArgs;
- if (annotArgs != null)
- {
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- isRightMenuAddAnnot = false;
- }
- //当不是注释模板,且无创建注释时,属性面板显示为空内容
- if (isTemplateAnnot == false && annotArgs == null)
- {
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- else
- {
- if (isSnapshotEdit == true)
- {
- ShowPropertyPanel(false);
- isSnapshotEdit = false;
- }
- else
- {
- ShowPropertyPanel(true);
- }
- }
- }
- /// <summary>
- /// 手绘
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- List<AnnotHandlerEventArgs> newSelectedArgs = new List<AnnotHandlerEventArgs>();
- FreehandAnnotArgs freehandArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- freehandArgs = new FreehandAnnotArgs();
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null)
- {
- freehandArgs.InkColor = annotate.FreeHandColor;
- }
- else
- {
- freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
- }
- freehandArgs.RawPointList = new List<List<Point>> { new List<Point> { new Point(0.599976, 7.0286), new Point(5.57775, 11.8), new Point(13.4, 1.40002) } };
- freehandArgs.Transparency = 1;
- freehandArgs.LineWidth = 2;
- if (freehandArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(freehandArgs);
- }
- }
- else
- {
- freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
- foreach (var item in selectedArgs)
- {
- //if (ListPoint((item as FreehandAnnotArgs).RawPointList, ShapePoints)){
- foreach (var point in viewContentViewModel.FillAndSign)
- {
- if ((item as FreehandAnnotArgs).PageIndex == point.PageIndex && (item as FreehandAnnotArgs).AnnotIndex == point.AnnotIndex)
- {
- newSelectedArgs.Add(item);
- }
- }
- }
- freehandArgs.RawPointList = ShapePoints;
- freehandArgs.InkColor = (SelectColor as SolidColorBrush).Color;
- freehandArgs.Transparency = 1;
- freehandArgs.LineWidth = LineWidth;
- annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
- annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
- annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
- annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
- annotAttribsList[AnnotAttrib.Path] = freehandArgs.RawPointList;
- annotAttribsList[AnnotAttrib.Width] = freehandArgs.Width;
- annotAttribsList[AnnotAttrib.Height] = freehandArgs.Height;
- AddToPropertyPanel("ShapFillProperty", "Freehand", newSelectedArgs, annotAttribsList);
- //GetStamp();
- return freehandArgs;
- }
- //annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
- //annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
- //annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
- //annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
- //AddToPropertyPanel("ShapFillProperty", "Freehand", selectedArgs, annotAttribsList);
- return freehandArgs;
- }
- private bool ListPoint(List<List<Point>> leftpoints, List<List<Point>> rightpoints)
- {
- if (leftpoints.Count == rightpoints.Count)
- {
- if (leftpoints[0][0].X == rightpoints[0][0].X) { return true; }
- }
- return false;
- }
- /// <summary>
- /// 文本
- /// </summary>
- /// <param name="selectedfreetextArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- FreeTextAnnotArgs freetextArgs = null;
- TextAlignment textAlignment;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- freetextArgs = new FreeTextAnnotArgs();
- freetextArgs.Align = TextAlignment.Left;
- freetextArgs.BgColor = Colors.Transparent;
- freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
- freetextArgs.FontColor = Colors.Black;
- freetextArgs.FontSize = 14;
- freetextArgs.Transparency = 1;
- freetextArgs.LineColor = Colors.Black;
- freetextArgs.LineWidth = 0;
- freetextArgs.TextContent = string.Empty;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
- if (annotProperty != null)
- {
- freetextArgs.Align = annotProperty.TextAlign;
- freetextArgs.BgColor = annotProperty.BackgroundColor;
- freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
- freetextArgs.FontColor = annotProperty.ForgoundColor;
- freetextArgs.FontSize = annotProperty.FontSize;
- freetextArgs.Transparency = annotProperty.Opacity;
- freetextArgs.LineColor = annotProperty.BorderColor;
- freetextArgs.LineWidth = annotProperty.Thickness;
- freetextArgs.TextContent = annotProperty.NoteText;
- freetextArgs.FontWeight = annotProperty.FontWeight;
- freetextArgs.FontStyle = annotProperty.FontStyle;
- }
- int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
- if (align == 0)
- textAlignment = TextAlignment.Left;
- else if (align == 1)
- textAlignment = TextAlignment.Center;
- else
- textAlignment = TextAlignment.Right;
- if (freetextArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(freetextArgs);
- }
- }
- else
- {
- freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
- textAlignment = freetextArgs.Align;
- }
- annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
- annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
- annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
- annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
- annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
- annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
- annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
- annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
- annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
- annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
- annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
- annotAttribsList[AnnotAttrib.Text] = freetextArgs.TextContent;
- AddToPropertyPanel("FreetextAnnotProperty", DateOrText, selectedArgs, annotAttribsList);
- return freetextArgs;
- }
- /// <summary>
- /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
- /// </summary>
- /// <param name="viewContent">对应的注释面板</param>
- /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
- /// <param name="annot">注释</param>
- /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
- private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null, bool isUpData = false)
- {
- if (annots != null && annots.Count != 0)
- {
- propertyPanel.annotlists = annots;
- propertyPanel.annot = annots[0];
- }
- else
- {
- propertyPanel.annotlists = null;
- propertyPanel.annot = null;
- }
- if (annotAttribsList != null && annotAttribsList.Count != 0 && annots != null && annots.Count != 0)
- {
- if (annots.Count > 1)
- {
- if (propertyPanel.AnnotEvents == null)
- propertyPanel.AnnotEvents = new List<AnnotAttribEvent>();
- propertyPanel.AnnotEvents.Clear();
- foreach (var itemAnnot in annots)
- {
- var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, annotAttribsList);
- //PDFViewer.SelectAnnotation(itemAnnot.PageIndex, itemAnnot.AnnotIndex);
- propertyPanel.AnnotEvents.Add(eventitem);
- }
- }
- propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annots[0], annotAttribsList);
- if (annots[0] is LinkAnnotArgs && annotAttribEvent != null)
- {
- propertyPanel.AnnotEvent = annotAttribEvent;
- }
- }
- if (toolTag == "Freetext")
- {
- propertyPanel.SetIsTextFill(true);
- }
- else
- {
- propertyPanel.SetIsTextFill(false);
- }
- if (string.IsNullOrEmpty(viewContent) == false)
- {
- if (isUpData) { return; }
- if (viewContent == "ShapFillProperty")
- {
- NavigateToProperty(viewContent, propertyPanel); return;
- }
- viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
- }
- }
- private void NavigateToProperty(string btnName, AnnotTransfer annotPropertyPanel)
- {
- NavigationParameters values = new NavigationParameters();
- values.Add(ParameterNames.PDFViewer, PDFViewer);
- values.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
- values.Add("IsFillAndSign", IsFillAndSign);
- values.Add("Shape", Shape);
- values.Add("FillAndSignContentViewModel", this);
- regions.RequestNavigate(RegionNames.PropertyRegionName, btnName, values);
- viewContentViewModel.IsPropertyOpen = true;
- }
- /// <summary>
- /// 初始化按钮名称-属性面板字典
- /// </summary>
- private void InitDictionary()
- {
- btnToProperty["RbtnText"] = "TextFillProperty";
- btnToProperty["RbtnTick"] = "ShapFillProperty";
- btnToProperty["RbtnFork"] = "ShapFillProperty";
- btnToProperty["RbtnRectangle"] = "ShapFillProperty";
- btnToProperty["RbtnLine"] = "ShapFillProperty";
- btnToProperty["RbtnPoint"] = "ShapFillProperty";
- btnToProperty["RbtnDate"] = "DateFillProperty";
- btnToProperty["RbtnSign"] = "";
- }
- /// <summary>
- /// 手绘
- /// </summary>
- private void InitSelectFreeHandAnnotMenu()
- {
- var popMenu = new ContextMenu();
- PopMenu pop = new PopMenu(popMenu);
- var menuItem = new MenuItem();
- menuItem.Name = "FreeHandCopy";
- menuItem.Header = "复制";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
- menuItem = new MenuItem();
- menuItem.Name = "FreeHandCut";
- menuItem.Header = "剪切";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
- menuItem = new MenuItem();
- menuItem.Name = "FreeHandPaste";
- menuItem.Header = "粘贴";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
- menuItem = new MenuItem();
- menuItem.Name = "FreeHandDelete";
- menuItem.Header = "删除";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
- pop.AddItem(GetSeparator());
- menuItem = new MenuItem();
- menuItem.Name = "FreeHandDefault";
- menuItem.Header = "设置当前属性为默认值";
- pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
- FreeHandAnnotPopMenu = pop;
- }
- /// <summary>
- /// 文本
- /// </summary>
- private void InitSelectFreeTextAnnotMenu()
- {
- var popMenu = new ContextMenu();
- PopMenu pop = new PopMenu(popMenu);
- var menuItem = new MenuItem();
- menuItem.Name = "FreeTextCopy";
- menuItem.Header = "复制";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
- menuItem = new MenuItem();
- menuItem.Name = "FreeTextCut";
- menuItem.Header = "剪切";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
- menuItem = new MenuItem();
- menuItem.Name = "FreeTextPaste";
- menuItem.Header = "粘贴";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
- menuItem = new MenuItem();
- menuItem.Name = "FreeTextDelete";
- menuItem.Header = "删除";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
- pop.AddItem(GetSeparator());
- menuItem = new MenuItem();
- menuItem.Name = "FreeTextColor";
- menuItem.Header = "字体颜色";
- menuItem.Tag = "FontColor";
- pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
- menuItem = new MenuItem();
- menuItem.Name = "FreeTextColor";
- menuItem.Header = "填充颜色";
- menuItem.Tag = "FillColor";
- pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
- menuItem = new MenuItem();
- menuItem.Name = "FreeTextFontFamily";
- menuItem.Header = "字体";
- pop.AddItem(menuItem);
- var family = TextFont.GetFamily();
- foreach (var item in family)
- {
- RadioButton familyRdioBtn = new RadioButton();
- familyRdioBtn.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
- familyRdioBtn.Background = new SolidColorBrush(Colors.Transparent);
- familyRdioBtn.Name = item.ValueStr;
- familyRdioBtn.Tag = item.ValueStr;
- familyRdioBtn.GroupName = "FontFamily";
- familyRdioBtn.Content = item.Content;
- pop.BindingEvent(pop.AddChild("FreeTextFontFamily", familyRdioBtn), FreeTextFontFamily_MenuCommand);
- }
- menuItem = new MenuItem();
- menuItem.Name = "FreeTextAglin";
- menuItem.Header = "文本对齐";
- pop.AddItem(menuItem);
- var radioButton = new RadioButton();
- radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
- radioButton.Background = new SolidColorBrush(Colors.Transparent);
- radioButton.Name = "FreeTextAglinLeft";
- radioButton.Tag = "Left";
- radioButton.GroupName = "Aglin";
- radioButton.Content = "左对齐";
- pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
- radioButton = new RadioButton();
- radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
- radioButton.Background = new SolidColorBrush(Colors.Transparent);
- radioButton.Name = "FreeTextAglinCenter";
- radioButton.Tag = "Center";
- radioButton.GroupName = "Aglin";
- radioButton.Content = "居中对齐";
- pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
- radioButton = new RadioButton();
- radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
- radioButton.Background = new SolidColorBrush(Colors.Transparent);
- radioButton.Name = "FreeTextAglinRight";
- radioButton.Tag = "Right";
- radioButton.GroupName = "Aglin";
- radioButton.Content = "右对齐";
- pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
- radioButton = new RadioButton();
- radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
- radioButton.Background = new SolidColorBrush(Colors.Transparent);
- radioButton.Name = "FreeTextAglinJustify";
- radioButton.Tag = "Justify";
- radioButton.GroupName = "Aglin";
- radioButton.Content = "两端对齐";
- pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
- menuItem = new MenuItem();
- menuItem.Name = "FreeHandDefault";
- menuItem.Header = "设置当前属性为默认值";
- pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
- FreeTextAnnotPopMenu = pop;
- }
- /// <summary>
- /// 多选注释
- /// </summary>
- private void InitSelectMultiAnnotMenu()
- {
- var popMenu = new ContextMenu();
- PopMenu pop = new PopMenu(popMenu);
- var menuItem = new MenuItem();
- menuItem.Name = "MultiCopy";
- menuItem.Header = "复制";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
- menuItem = new MenuItem();
- menuItem.Name = "MultiCut";
- menuItem.Header = "剪切";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
- menuItem = new MenuItem();
- menuItem.Name = "MultiDelete";
- menuItem.Header = "删除";
- pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
- MultiAnnotPopMenu = pop;
- }
- private Separator GetSeparator()
- {
- Separator separator = new Separator();
- separator.Height = 1;
- separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
- separator.BorderThickness = new Thickness(1);
- return separator;
- }
- private void BindingPDFViewerHandler()
- {
- //来自PDFViewer的响应事件
- if (PDFViewer != null)
- {
- PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
- PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
- PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
- PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
- PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
- PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
- PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
- PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
- }
- }
- private void UnBindingPDFViewerHandler()
- {
- if (PDFViewer != null)
- {
- PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
- PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
- PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
- PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
- }
- }
- //在注释工具的状态下,右键菜单
- private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
- {
- if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
- return;
- switch (e.CommandType)
- {
- case CommandType.Context:
- if (e.AnnotEventArgsList.Count > 0)
- {
- if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
- {
- //绑定标记密文处右键菜单
- events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
- }
- else
- {
- if (e.AnnotEventArgsList.Count == 1)
- {
- var selectedAnnot = e.AnnotEventArgsList[0];
- switch (selectedAnnot.EventType)
- {
- case AnnotArgsType.AnnotFreehand:
- e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotFreeText:
- e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- }
- }
- else
- {
- bool isHigh = true;//是否为高亮
- foreach (var item in e.AnnotEventArgsList)
- {
- if (isHightAnnot(item) == false)
- {
- isHigh = false;
- break;
- }
- }
- MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
- MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
- e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
- }
- }
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- else
- {
- if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
- {
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- else
- {
- e.PopupMenu = ViewerContextMenu(sender);
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- }
- break;
- }
- }
- private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
- {
- if (e != null && e.DrawContext != null)
- {
- Rect hoverRect = new Rect(
- e.PaintRect.Left - 2,
- e.PaintRect.Top - 2,
- e.PaintRect.Width + 4,
- e.PaintRect.Height + 4);
- Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
- hoverPen.DashStyle = DashStyles.Dash;
- e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
- //Todo:目前ComPDFKit.Viewer没有e.Annot参数
- //便签,显示ToolTip内容
- //if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
- //{
- // if (PDFViewer.ToolTip == null)
- // {
- // var content = e.Annot.GetContent();
- // if (string.IsNullOrEmpty(content) == false)
- // {
- // ToolTip TipChild = new ToolTip();
- // TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
- // TipChild.MaxWidth = 246;
- // TipChild.Content = content;
- // TipChild.Visibility = Visibility.Visible;
- // TipChild.IsOpen = true;
- // TipChild.Placement = PlacementMode.Right;
- // var rec = e.Annot.GetRect();
- // TipChild.PlacementRectangle = new Rect(rec.left, rec.top, rec.right, rec.bottom);
- // TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
- // TipChild.Placement = PlacementMode.MousePoint;
- // PDFViewer.ToolTip = TipChild;
- // oldRect = hoverRect;
- // PDFViewer.MouseMove -= PDFViewer_MouseMove;
- // PDFViewer.MouseMove += PDFViewer_MouseMove;
- // return;
- // }
- // }
- //}
- }
- CloseAnnotToolTip();
- }
- private Rect oldRect = new Rect(0, 0, 0, 0);
- private void CloseAnnotToolTip()
- {
- if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
- {
- ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
- oldTips.IsOpen = false;
- oldTips.Visibility = Visibility.Collapsed;
- PDFViewer.ToolTip = null;
- PDFViewer.MouseMove -= PDFViewer_MouseMove;
- oldRect = new Rect(0, 0, 0, 0);
- }
- }
- private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
- {
- if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
- {
- var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
- var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
- var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
- if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
- {
- CloseAnnotToolTip();
- }
- }
- }
- private ContextMenu ViewerContextMenu(object sender)
- {
- ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
- ViewerContextMenu_Loaded(contextMenu, sender);
- return contextMenu;
- }
- private void ViewerContextMenu_Loaded(object sender, object e, Visibility visibility = Visibility.Collapsed)
- {
- ContextMenu contextMenu = sender as ContextMenu;
- contextMenu.DataContext = viewContentViewModel;
- if (contextMenu.Items.Count > 0)
- {
- int index = PDFViewer.CurrentIndex;
- //检测是否已存在相同数据
- CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
- foreach (var item in contextMenu.Items)
- {
- if (item is Separator separator)
- {
- separator.Visibility = visibility;
- }
- if (item is MenuItem menuItem1)
- {
- //if (menuItem1.Tag.ToString() == "DisplayAnnot" || menuItem1.Tag.ToString() == "HiddenAnnot")
- //{
- // SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
- //}
- switch (menuItem1.Tag.ToString())
- {
- case "Paste":
- //粘贴
- //if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
- //{
- // menuItem1.IsEnabled = false;
- // menuItem1.Opacity = 0.5;
- //}
- //else
- //{
- // menuItem1.IsEnabled = true;
- // menuItem1.Opacity = 1;
- //}
- menuItem1.CommandTarget = (UIElement)e;
- menuItem1.Command = ApplicationCommands.Paste;
- break;
- case "AddAnnotation":
- menuItem1.Visibility = visibility;
- break;
- case "HiddenAnnot":
- menuItem1.Visibility = visibility;
- break;
- case "DisplayAnnot":
- menuItem1.Visibility = visibility;
- break;
- case "AddBookMark":
- menuItem1.Visibility = visibility;
- break;
- case "DelBookMark":
- menuItem1.Visibility = visibility;
- break;
- case "ToolMode":
- menuItem1.Visibility = visibility;
- break;
- case "ReadModel":
- menuItem1.Visibility = visibility;
- break;
- case "UnReadModel":
- menuItem1.Visibility = visibility;
- break;
- case "ViewZoom":
- menuItem1.Visibility = visibility;
- break;
- case "PageDisplay":
- menuItem1.Visibility = visibility;
- break;
- case "Select":
- menuItem1.Click -= Select_Click;
- menuItem1.Click += Select_Click;
- break;
- case "Print":
- menuItem1.Command = viewContentViewModel.PrintCommand;
- break;
- }
- }
- }
- }
- }
- private void Select_Click(object sender, RoutedEventArgs e)
- {
- if (viewContentViewModel.OpenBOTA == false)
- {
- viewContentViewModel.OpenBOTA = true;
- }
- bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
- if (isBook == false)
- {
- bOTAContent.TabItemSearch.IsSelected = true;
- }
- }
- private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
- {
- bool isTabItem = false;
- bOTAContentViewModel = null;
- bOTAContent = null;
- if (regions.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
- {
- var views = regions.Regions[viewContentViewModel.BOTARegionName].Views;
- var model = views.FirstOrDefault(q => q is BOTAContent);
- if (model is BOTAContent bOTAContent1)
- {
- bOTAContent = bOTAContent1;
- bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
- if (bOTAContentViewModel.CurrentBar == tabItemText)
- {
- isTabItem = true;
- }
- }
- //foreach (var item in views)
- //{
- // if (item is BOTAContent bOTAContent1)
- // {
- // bOTAContent = bOTAContent1;
- // bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
- // if (bOTAContentViewModel.CurrentBar == tabItemText)
- // {
- // isTabItem = true;
- // break;
- // }
- // }
- //}
- }
- return isTabItem;
- }
- private bool isHightAnnot(AnnotHandlerEventArgs annot)
- {
- if (annot.EventType == AnnotArgsType.AnnotUnderline ||
- annot.EventType == AnnotArgsType.AnnotSquiggly ||
- annot.EventType == AnnotArgsType.AnnotHighlight ||
- annot.EventType == AnnotArgsType.AnnotStrikeout
- )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- //注释编辑事件
- private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
- {
- if (e != null && e.Count > 0)
- {
- for (int i = 0; i < e.Count; i++)
- {
- AnnotEditEvent editEvent = e[i];
- int pageindex = editEvent.PageIndex;
- int annotindex = editEvent.AnnotIndex;
- switch (editEvent.EditAction)
- {
- case ActionType.Add:
- if (Shape != "None") { viewContentViewModel.FillAndSign.Add(new FillAndSignIsShape(pageindex, annotindex, Shape)); }
- PDFViewer.SelectAnnotation(pageindex, annotindex);
- break;
- case ActionType.Del:
- if (Shape != "None")
- {
- for (int j = 0; j < viewContentViewModel.FillAndSign.Count; j++)
- {
- if (viewContentViewModel.FillAndSign[j].PageIndex == pageindex && viewContentViewModel.FillAndSign[j].AnnotIndex == annotindex)
- {
- viewContentViewModel.FillAndSign.Remove(viewContentViewModel.FillAndSign[j]);
- }
- }
- }
- break;
- }
- }
- }
- }
- //选中和非选中注释,右键菜单
- private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
- {
- if (e != null)
- {
- var annot = e.AnnotItemsList[0];
- if (annot != null)
- {
- if (e.AnnotItemsList.Count == 1)
- {
- //IsEdit = false;
- //IsAnnotCreateReset:是否为创建注释的状态
- if (e.IsAnnotCreateReset == false)
- {
- GetSelectedAnnots(e);
- //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
- //PDFViewer.SetToolParam(annot);
- }
- else
- {
- //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
- if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
- annot.EventType != AnnotArgsType.AnnotUnderline &&
- annot.EventType != AnnotArgsType.AnnotHighlight &&
- annot.EventType != AnnotArgsType.AnnotSquiggly &&
- annot.EventType != AnnotArgsType.AnnotLink &&
- annot.EventType != AnnotArgsType.AnnotFreehand &&
- annot.EventType != AnnotArgsType.AnnotSticky
- )
- {
- if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
- {
- foreach (var item in ToolExpandDict)
- {
- if (item.Value == e.AnnotItemsList[0].EventType)
- {
- annot = null;//新建注释时,回到默认值
- FindAnnotTypeKey(item.Key, ref annot);
- break;
- }
- }
- }
- }
- //else
- //PDFViewer.SetToolParam(annot);
- //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
- if (isRightMenuAddAnnot)
- {
- ShowPropertyPanel(false);
- }
- else
- {
- ShowPropertyPanel();
- }
- }
- }
- else
- {
- bool isDifferentAnnotTyle = false;
- var lastAnnot = annot;
- foreach (var item in e.AnnotItemsList)
- {
- if (lastAnnot.EventType != item.EventType)
- {
- if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
- {
- lastAnnot = item;
- continue;
- }
- lastAnnot = item;
- isDifferentAnnotTyle = true;
- break;
- }
- }
- if (isDifferentAnnotTyle)
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- else
- GetSelectedAnnots(e);
- }
- }
- }
- else
- {
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- }
- //private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
- //{
- // if (e != null && e.Count > 0)
- // {
- // for (int i = 0; i < e.Count; i++)
- // {
- // AnnotEditEvent editEvent = e[i];
- // switch (editEvent.EditAction)
- // {
- // case ActionType.Add:
- // // bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
- // if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
- // {
- // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
- // if (viewModel != null)
- // {
- // int pageindex = editEvent.PageIndex;
- // int annotindex = editEvent.AnnotIndex;
- // viewModel.UpdateAddedAnnot(pageindex, annotindex);
- // }
- // }
- // break;
- // case ActionType.Del:
- // //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
- // if (isTabItemAnnotation)
- // {
- // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
- // if (viewModel != null)
- // {
- // int pageindex = editEvent.PageIndex;
- // int annotindex = editEvent.AnnotIndex;
- // viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
- // }
- // }
- // break;
- // case ActionType.Modify:
- // isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
- // if (bOTAContent.TabItemAnnotation.IsSelected)
- // {
- // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
- // if (viewModel != null)
- // {
- // int pageindex = editEvent.PageIndex;
- // int annotindex = editEvent.AnnotIndex;
- // viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
- // }
- // }
- // break;
- // case ActionType.TextEdit:
- // break;
- // default:
- // break;
- // }
- // }
- // }
- //}
- private bool isShapAnnot(AnnotHandlerEventArgs annot)
- {
- if (annot.EventType == AnnotArgsType.AnnotCircle ||
- annot.EventType == AnnotArgsType.AnnotSquare ||
- annot.EventType == AnnotArgsType.AnnotLine
- )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- private void GetSelectedAnnots(AnnotAttribEvent e)
- {
- IsEdit = true;
- var annot = e.AnnotItemsList[0];
- switch (annot.EventType)
- {
- case AnnotArgsType.AnnotFreeText:
-
- GetFreetext(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotFreehand:
- if (viewContentViewModel.FillAndSign.Count < 1) { viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null); return; }
- bool isDifferen = false;
- foreach (var point in viewContentViewModel.FillAndSign)
- {
- if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
- {
- isDifferen=true;
- break;
- }
- else
- {
- isDifferen = false;
- }
- }
- if (!isDifferen) { viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null); return; }
- GetFreehand(e.AnnotItemsList);
- break;
- }
- }
- private void ShowPropertyPanel(bool show = true)
- {
- viewContentViewModel.IsPropertyOpen = show;
- }
- #region Navigation
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- UnBindingPDFViewerHandler();
- ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
- ViewerContextMenu_Loaded(contextMenu, null, Visibility.Visible);
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- ShowPropertyPanel(false);
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- IsFillAndSign = true;
- navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
- BindingPDFViewerHandler();
- HookShapeIsCheck = true;
- HookShapeIsCheck = false;
- InitFillAndSignProperty();
- ShowPropertyPanel(false);
- // InitCheckedEvent("RbtnTick");
- IsEdit = false;
- }
- #endregion
- }
- }
|