1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.PDFDocument;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer.PdfViewer;
- using Dropbox.Api.TeamLog;
- using Microsoft.Office.Core;
- 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.AnnotPanel;
- using PDF_Master.ViewModels.Tools.AnnotManager;
- using PDF_Master.Views.BOTA;
- using PDF_Master.Views.PropertyPanel.AnnotPanel;
- using PDFSettings;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Documents;
- using System.Windows.Forms;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using static Dropbox.Api.Sharing.ListFileMembersIndividualResult;
- using Color = System.Windows.Media.Color;
- using ContextMenu = System.Windows.Controls.ContextMenu;
- using FontFamily = System.Windows.Media.FontFamily;
- using HorizontalAlignment = System.Windows.HorizontalAlignment;
- using MenuItem = System.Windows.Controls.MenuItem;
- using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
- namespace PDF_Master.ViewModels.Tools
- {
- //文件说明:初始化注释工具的数据,注释工具,菜单响应事件
- public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
- {
- #region 初始化
- #region 初始化数据
- //初始化注释的属性值,并存在本地缓存数据集里
- private void InitDefaultValue()
- {
- InitToolBtnUI();
- }
- //注释工具按钮初始化时的属性值
- private void InitToolBtnUI()
- {
- var annotate = Settings.Default.AppProperties.Annotate;
- InitAnnotHighlight(annotate);
- InitAnnotUnderline(annotate);
- InitAnnotSquiggly(annotate);
- InitAnnotStrikeout(annotate);
- InitAnnotFreeHand(annotate);
- InitAnnotLine(annotate);
- }
- private void InitAnnotLine(AnnotatePropertyClass annotate)
- {
- if (annotate != null && annotate.LineColor != Colors.Transparent)
- {
- LineColor = new SolidColorBrush(annotate.LineColor);
- }
- else
- {
- LineColor = new SolidColorBrush(Colors.Red);
- }
- if (annotate != null && annotate.ArrowColor != Colors.Transparent)
- {
- ArrowColor = new SolidColorBrush(annotate.ArrowColor);
- }
- else
- {
- ArrowColor = new SolidColorBrush(Colors.Red);
- }
- }
- private void InitAnnotFreeHand(AnnotatePropertyClass annotate)
- {
- if (annotate != null && annotate.FreeHandColor != Colors.Transparent)
- {
- FreeHandColor = new SolidColorBrush(annotate.FreeHandColor);
- }
- else
- {
- Color color = Color.FromRgb(0x38, 0xE0, 0x2E);
- FreeHandColor = new SolidColorBrush(color);
- }
- }
- private void InitAnnotHighlight(AnnotatePropertyClass annotate)
- {
- //var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null && annotate.HighLightColor != Colors.Transparent)
- {
- HighLightColor = new SolidColorBrush(annotate.HighLightColor);
- HighLightOpacity = 1;
- }
- else
- {
- HighLightColor = new SolidColorBrush(Colors.Red);
- HighLightOpacity = 1;
- }
- }
- private void InitAnnotUnderline(AnnotatePropertyClass annotate)
- {
- //var annotate = Settings.Default.AppProperties.Annotate;
- //避免默认值为透明度
- if (annotate != null && annotate.UnderLineColor != Colors.Transparent)
- {
- UnderLineColor = new SolidColorBrush(annotate.UnderLineColor);
- HighLightOpacity = 1;
- }
- else
- {
- UnderLineColor = new SolidColorBrush(Colors.Red);
- UnderLineOpacity = 1;
- }
- }
- private void InitAnnotSquiggly(AnnotatePropertyClass annotate)
- {
- //var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null && annotate.StrikethroughColor != Colors.Transparent)
- {
- SquigglyColor = new SolidColorBrush(annotate.StrikethroughColor);
- SquigglyOpacity = 1;
- }
- else
- {
- SquigglyColor = new SolidColorBrush(Colors.Red);
- SquigglyOpacity = 1;
- }
- }
- private void InitAnnotStrikeout(AnnotatePropertyClass annotate)
- {
- //var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null && annotate.StrikethroughColor != Colors.Transparent)
- {
- StrikeoutColor = new SolidColorBrush(annotate.StrikethroughColor);
- StrikeoutOpacity = 1;
- }
- else
- {
- StrikeoutColor = new SolidColorBrush(Colors.Red);
- StrikeoutOpacity = 1;
- }
- }
- //在xaml里引用
- public Dictionary<string, string> GetToolTipDict
- { get { return ToolTipDict; } }
- //用来记录选中、创建注释的标识
- private void InitToolDict()
- {
- ToolExpandDict.Add("SnapshotEdit", AnnotArgsType.SnapshotWithEditTool);
- ToolExpandDict.Add("HighLight", AnnotArgsType.AnnotHighlight);
- ToolExpandDict.Add("UnderLine", AnnotArgsType.AnnotUnderline);
- ToolExpandDict.Add("Squiggly", AnnotArgsType.AnnotSquiggly);
- ToolExpandDict.Add("Strikeout", AnnotArgsType.AnnotStrikeout);
- ToolExpandDict.Add("Freehand", AnnotArgsType.AnnotFreehand);
- ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
- ToolExpandDict.Add("StickyNote", AnnotArgsType.AnnotSticky);
- ToolExpandDict.Add("Rect", AnnotArgsType.AnnotSquare);
- ToolExpandDict.Add("Circle", AnnotArgsType.AnnotCircle);
- ToolExpandDict.Add("Arrow", AnnotArgsType.AnnotLine);
- ToolExpandDict.Add("Line", AnnotArgsType.AnnotLine);
- ToolExpandDict.Add("Link", AnnotArgsType.AnnotLink);
- ToolExpandDict.Add("Stamp", AnnotArgsType.AnnotStamp);
- }
- //注释工具按钮悬浮文案
- private void InitToolTipDict()
- {
- //原来文案
- //ToolTipDict.Add("Hand", "滚动工具");
- //ToolTipDict.Add("BtnSelecttool", "内容选择工具");
- //ToolTipDict.Add("SnapshotEdit", "内容选择工具");
- //ToolTipDict.Add("HighLight", "高亮" + " | Ctrl+Alt+H");
- //ToolTipDict.Add("UnderLine", "下划线" + " | Ctrl+Alt+U");
- //ToolTipDict.Add("Squiggly", "波浪线" + " | Ctrl+Alt+Q");
- //ToolTipDict.Add("Strikeout", "删除线" + " | Ctrl+Alt+S");
- //ToolTipDict.Add("Freehand", "手绘");
- //ToolTipDict.Add("Freetext", "文字");
- //ToolTipDict.Add("StickyNote", "便签");
- //ToolTipDict.Add("Rect", "矩形");
- //ToolTipDict.Add("Circle", "圆");
- //ToolTipDict.Add("Arrow", "箭头");
- //ToolTipDict.Add("Line", "线条");
- //ToolTipDict.Add("Link", "超链接");
- //ToolTipDict.Add("Stamp", "图章");
- //ToolTipDict.Add("Image", "图片");
- //ToolTipDict.Add("Signature", "签名");
- //ToolTipDict.Add("ShowAnnot", "显示/隐藏注释");
- ToolTipDict.Add("Hand", App.MainPageLoader.GetString("ToolTipsAonnot_ScrollTool"));
- ToolTipDict.Add("BtnSelecttool", App.MainPageLoader.GetString("ToolTipsAonnot_ContentSelection"));
- ToolTipDict.Add("SnapshotEdit", App.MainPageLoader.GetString("ToolTipsAonnot_ContentSelection"));
- ToolTipDict.Add("HighLight", App.MainPageLoader.GetString("ToolTipsAonnot_HighLight"));
- ToolTipDict.Add("UnderLine", App.MainPageLoader.GetString("ToolTipsAonnot_UnderLine"));
- ToolTipDict.Add("Squiggly", App.MainPageLoader.GetString("ToolTipsAonnot_Squiggly"));
- ToolTipDict.Add("Strikeout", App.MainPageLoader.GetString("ToolTipsAonnot_Strikeout"));
- ToolTipDict.Add("Freehand", App.MainPageLoader.GetString("ToolTipsAonnot_Freehand"));
- ToolTipDict.Add("Freetext", App.MainPageLoader.GetString("ToolTipsAonnot_Text"));
- ToolTipDict.Add("StickyNote", App.MainPageLoader.GetString("ToolTipsAonnot_StickyNote"));
- ToolTipDict.Add("Rect", App.MainPageLoader.GetString("ToolTipsAonnot_Sharps"));
- ToolTipDict.Add("Circle", App.MainPageLoader.GetString("ToolTipsAonnot_Sharps"));
- ToolTipDict.Add("Arrow", App.MainPageLoader.GetString("ToolTipsAonnot_Sharps"));
- ToolTipDict.Add("Line", App.MainPageLoader.GetString("ToolTipsAonnot_Sharps"));
- ToolTipDict.Add("Link", App.MainPageLoader.GetString("ToolTipsAonnot_Link"));
- ToolTipDict.Add("Stamp", App.MainPageLoader.GetString("ToolTipsAonnot_Stamp"));
- ToolTipDict.Add("Image", App.MainPageLoader.GetString("ToolTipsAonnot_Stamp"));
- ToolTipDict.Add("Signature", App.MainPageLoader.GetString("ToolTipsAonnot_Signature"));
- ToolTipDict.Add("ShowAnnot", App.MainPageLoader.GetString("ToolTipsAonnot_ShowAnnot"));
- }
- //便签批注弹窗
- private void LoaedStickyNotePopup()
- {
- if (PDFViewer == null) return;
- if (customStickyPopup == null)
- {
- customStickyPopup = new StickyNotePopup(events);
- PDFViewer.SetStickyNotePop(customStickyPopup);
- }
- }
- #endregion 初始化数据
- #endregion 初始化
- #region 注释工具
- //注释工具
- public void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
- {
- switch (tag)
- {
- case "SnapshotEdit"://内容选择
- annotArgs = GetSnapshotEdit();
- break;
- case "HighLight"://字体高亮
- annotArgs = GetHighLight();
- break;
- case "UnderLine"://下划线
- annotArgs = GetUnderLine();
- break;
- case "Squiggly"://波浪线
- annotArgs = GetSquiggly();
- break;
- case "Strikeout"://删除线
- annotArgs = GetStrikeout();
- break;
- case "Freehand"://手绘
- annotArgs = GetFreehand();
- break;
- case "Freetext"://文本
- annotArgs = GetFreetext();
- break;
- case "StickyNote"://便签
- annotArgs = GetStickyNote();
- break;
- case "Rect"://矩形
- switch (PropertyPanel.SharpsAnnot)
- {
- case "Rect":
- annotArgs = GetRect();
- break;
- case "Circle":
- annotArgs = GetCircle();
- break;
- case "Arrow":
- annotArgs = GetArrowLine("Arrow");
- break;
- case "Line":
- annotArgs = GetArrowLine("Line");
- break;
- }
- break;
- case "RectKey":
- //选中时需设置以及点击图形按钮选中("Rect"->即代表按钮标识有代表矩形图案(将快捷键矩形改名为RectKey))
- StrAnnotToolChecked = "Rect";
- PropertyPanel.IsSharpAnnotSelected = true;
- annotArgs = GetRect();
- break;
- case "Circle"://圆
- StrAnnotToolChecked = "Rect";
- PropertyPanel.IsSharpAnnotSelected = true;
- annotArgs = GetCircle();
- break;
- case "Arrow"://箭头
- case "Line"://线
- StrAnnotToolChecked = "Rect";
- PropertyPanel.IsSharpAnnotSelected = true;
- annotArgs = GetArrowLine(tag);
- break;
- case "Stamp"://图章
- //付费锁
- //判断本地有没有token,没有显示登录,有再判断登录状态
- if (!ViewContentViewModel.IAPBeforeFunction())
- {
- StrAnnotToolChecked = "";
- return;
- }
- annotArgs = GetStamp();
- break;
- case "Image":
- annotArgs = GetImage();
- break;
- case "Signature"://签名
- //判断本地有没有token,没有显示登录,有再判断登录状态
- if (!ViewContentViewModel.IAPBeforeFunction())
- {
- StrAnnotToolChecked = "";
- return;
- }
- annotArgs = GetSignature();
- PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
- break;
- case "Link"://链接
- //付费锁
- //判断本地有没有token,没有显示登录,有再判断登录状态
- //if (!viewContentViewModel.IAPBeforeFunction())
- //{
- // StrAnnotToolChecked = "";
- // return;
- //}
- PropertyPanel.IsAddLink = true;
- ViewContentViewModel.IsRightMenuCreateLink = isRightMenuAdd;
- annotArgs = GetLink();
- break;
- }
- if (annotArgs != null)
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- }
- /// <summary>
- /// 链接
- /// </summary>
- /// <param name="selectedArgs">所选中的注释</param>
- /// <param name="annotAttribEvent">注释属性列表</param>
- public AnnotHandlerEventArgs GetLink(List<AnnotHandlerEventArgs> selectedArgs = null, AnnotAttribEvent annotAttribEvent = null)
- {
- LinkAnnotArgs linkArgs = new LinkAnnotArgs();
- if (selectedArgs != null && selectedArgs.Count > 0)
- {
- linkArgs = selectedArgs[0] as LinkAnnotArgs;
- }
- else
- {
- linkArgs.URI = string.Empty;
- linkArgs.LinkType = LINK_TYPE.GOTO;
- linkArgs.DestIndex = -1;
- if (linkArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(linkArgs);
- if (ViewContentViewModel.IsRightMenuCreateLink == false)
- {
- AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(linkArgs);
- if (annotHandler is LinkAnnotArgs annotArgs)
- {
- selectedArgs.Clear();
- selectedArgs.Add(annotArgs);
- PropertyPanel.IsSelectedTextAddLink = true;
- //PDFViewer.SelectAnnotation(annotArgs.PageIndex, annotArgs.AnnotIndex);
- //viewContentViewModel.IsPropertyOpen = true;
- //return linkArgs;
- }
- }
- }
- }
- AddToPropertyPanel("LinkAnnotProperty", "Link", selectedArgs, annotAttribEvent);
- return linkArgs;
- }
- //创建,选中,保留上次属性值的注释
- /// <summary>
- /// 高亮注释
- /// </summary>
- private AnnotHandlerEventArgs GetHighLight(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- TextHighlightAnnotArgs highlightArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- highlightArgs = new TextHighlightAnnotArgs();
- highlightArgs.Transparency = HighLightOpacity;
- highlightArgs.Color = (HighLightColor as SolidColorBrush).Color;
- if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotHighlight] == null)
- {
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(highlightArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = highlightArgs.EventType;
- defaultAnnot.ForgoundColor = (HighLightColor as SolidColorBrush).Color;
- defaultAnnot.Opacity = 1;
- HighLightOpacity = defaultAnnot.Opacity;
- HighLightColor = new SolidColorBrush(defaultAnnot.ForgoundColor);
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- //else
- //{
- // (HighLightColor as SolidColorBrush).Color = defaultAnnot.ForgoundColor;
- // highlightArgs.Color = defaultAnnot.ForgoundColor;
- //}
- //HighLightOpacity = highlightArgs.Transparency = defaultAnnot.Opacity;
- highlightArgs.Color = defaultAnnot.ForgoundColor;
- highlightArgs.Transparency = defaultAnnot.Opacity;
- }
- //else
- //{
- // TextHighlightAnnotArgs annotArgs = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotHighlight] as TextHighlightAnnotArgs;
- // highlightArgs = new TextHighlightAnnotArgs();
- // highlightArgs.Color = annotArgs.Color;
- // highlightArgs.Transparency = annotArgs.Transparency;
- // HighLightColor = new SolidColorBrush(highlightArgs.Color);
- // HighLightOpacity = highlightArgs.Transparency;
- //}
- selectedArgs = new List<AnnotHandlerEventArgs>();
- highlightArgs.Color = (HighLightColor as SolidColorBrush).Color;
- highlightArgs.Transparency = HighLightOpacity;
- selectedArgs.Add(highlightArgs);
- }
- else
- {
- highlightArgs = selectedArgs[0] as TextHighlightAnnotArgs;
- HighLightColor = new SolidColorBrush(highlightArgs.Color);
- HighLightOpacity = highlightArgs.Transparency;
- }
- //selectedArgs = new List<AnnotHandlerEventArgs>();
- //selectedArgs.Add(highlightArgs);
- AddToPropertyPanel("TextAnnotProperty", "HighLight", selectedArgs);
- return highlightArgs;
- }
- /// <summary>
- /// 下划线
- /// </summary>
- /// <param name="selectedArgs"></param>
- private AnnotHandlerEventArgs GetUnderLine(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- TextUnderlineAnnotArgs underlineArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- underlineArgs = new TextUnderlineAnnotArgs();
- underlineArgs.Transparency = UnderLineOpacity;
- underlineArgs.Color = (UnderLineColor as SolidColorBrush).Color;
- if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotUnderline] == null)
- {
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(underlineArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = underlineArgs.EventType;
- defaultAnnot.ForgoundColor = (UnderLineColor as SolidColorBrush).Color;
- defaultAnnot.Opacity = 1;
- UnderLineOpacity = defaultAnnot.Opacity;
- UnderLineColor = new SolidColorBrush(defaultAnnot.ForgoundColor);
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- underlineArgs.Color = defaultAnnot.ForgoundColor;
- underlineArgs.Transparency = defaultAnnot.Opacity;
- }
- selectedArgs = new List<AnnotHandlerEventArgs>();
- underlineArgs.Color = (UnderLineColor as SolidColorBrush).Color;
- underlineArgs.Transparency = UnderLineOpacity;
- selectedArgs.Add(underlineArgs);
- }
- else
- {
- underlineArgs = selectedArgs[0] as TextUnderlineAnnotArgs;
- UnderLineColor = new SolidColorBrush(underlineArgs.Color);
- UnderLineOpacity = underlineArgs.Transparency;
- }
- //selectedArgs = new List<AnnotHandlerEventArgs>();
- //selectedArgs.Add(underlineArgs);
- AddToPropertyPanel("TextAnnotProperty", "UnderLine", selectedArgs);
- return underlineArgs;
- }
- /// <summary>
- /// 波浪线
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetSquiggly(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- TextSquigglyAnnotArgs squigglyArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- squigglyArgs = new TextSquigglyAnnotArgs();
- squigglyArgs.Transparency = SquigglyOpacity;
- squigglyArgs.Color = (squigglyColor as SolidColorBrush).Color;
- if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquiggly] == null)
- {
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squigglyArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = squigglyArgs.EventType;
- defaultAnnot.ForgoundColor = (squigglyColor as SolidColorBrush).Color;
- defaultAnnot.Opacity = 1;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- SquigglyOpacity = squigglyArgs.Transparency = defaultAnnot.Opacity;
- }
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(squigglyArgs);
- }
- else
- {
- squigglyArgs = selectedArgs[0] as TextSquigglyAnnotArgs;
- }
- AddToPropertyPanel("TextAnnotProperty", "Squiggly", selectedArgs);
- return squigglyArgs;
- }
- /// <summary>
- /// 删除线
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetStrikeout(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- TextStrikeoutAnnotArgs strikeoutArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- strikeoutArgs = new TextStrikeoutAnnotArgs();
- strikeoutArgs.Transparency = StrikeoutOpacity;
- strikeoutArgs.Color = (StrikeoutColor as SolidColorBrush).Color;
- if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotStrikeout] == null)
- {
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(strikeoutArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = strikeoutArgs.EventType;
- defaultAnnot.ForgoundColor = (StrikeoutColor as SolidColorBrush).Color;
- defaultAnnot.Opacity = 1;
- StrikeoutOpacity = defaultAnnot.Opacity;
- StrikeoutColor = new SolidColorBrush(defaultAnnot.ForgoundColor);
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- strikeoutArgs.Color = defaultAnnot.ForgoundColor;
- strikeoutArgs.Transparency = defaultAnnot.Opacity;
- }
- selectedArgs = new List<AnnotHandlerEventArgs>();
- strikeoutArgs.Color = (StrikeoutColor as SolidColorBrush).Color;
- strikeoutArgs.Transparency = StrikeoutOpacity;
- selectedArgs.Add(strikeoutArgs);
- }
- else
- {
- strikeoutArgs = selectedArgs[0] as TextStrikeoutAnnotArgs;
- StrikeoutColor = new SolidColorBrush(strikeoutArgs.Color);
- StrikeoutOpacity = strikeoutArgs.Transparency;
- }
- AddToPropertyPanel("TextAnnotProperty", "Strikeout", selectedArgs);
- return strikeoutArgs;
- }
- /// <summary>
- /// 手绘
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- 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.InkColor = (FreeHandColor as SolidColorBrush).Color;
- if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] == null)
- {
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freehandArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = freehandArgs.EventType;
- defaultAnnot.ForgoundColor = (FreeHandColor as SolidColorBrush).Color;
- defaultAnnot.Opacity = 1;
- defaultAnnot.Thickness = 2;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- freehandArgs.Transparency = defaultAnnot.Opacity;
- freehandArgs.LineWidth = defaultAnnot.Thickness;
- freehandArgs.InkColor = defaultAnnot.ForgoundColor;
- if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
- {
- freehandArgs.LineDash = DashStyles.Solid;
- }
- else
- {
- var collect = new DoubleCollection();
- foreach (var item in defaultAnnot.DashArray)
- {
- collect.Add(item);
- }
- if (freehandArgs.LineDash == null)
- freehandArgs.LineDash = new DashStyle();
- freehandArgs.LineDash.Dashes = collect;
- }
- }
- else
- {
- FreehandAnnotArgs freehandAnnotArgs = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] as FreehandAnnotArgs;
- freehandArgs = new FreehandAnnotArgs();
- freehandArgs.InkColor = freehandAnnotArgs.InkColor;
- freehandArgs.Transparency = freehandAnnotArgs.Transparency;
- freehandArgs.LineWidth = freehandAnnotArgs.LineWidth;
- freehandArgs.LineDash = freehandAnnotArgs.LineDash;
- }
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(freehandArgs);
- }
- else
- {
- freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
- if (NavigatedToFillAndSignVM(selectedArgs, "Freehand"))
- {
- return freehandArgs;
- }
- }
- AddToPropertyPanel("FreehandAnnotProperty", "Freehand", selectedArgs);
- return freehandArgs;
- }
- /// <summary>
- /// 文本
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- FreeTextAnnotArgs freetextArgs = null;
- TextAlignment textAlignment;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- freetextArgs = new FreeTextAnnotArgs();
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null)
- {
- freetextArgs.FontColor = annotate.TextAnnoteColor;
- }
- else
- {
- freetextArgs.FontColor = Colors.Black;
- }
- if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreeText] == null)
- {
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freetextArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = freetextArgs.EventType;
- defaultAnnot.ForgoundColor = freetextArgs.FontColor;
- defaultAnnot.BorderColor = Colors.Transparent;
- defaultAnnot.BackgroundColor = Colors.White;
- defaultAnnot.Opacity = 1;
- defaultAnnot.FontFamily = Settings.Default.AppProperties.Annotate.TextFontFamaily;
- defaultAnnot.FontSize = 14;
- defaultAnnot.TextAlign = TextAlignment.Left;
- defaultAnnot.Thickness = 0;
- defaultAnnot.NoteText = string.Empty;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- freetextArgs.FontColor = defaultAnnot.ForgoundColor;
- freetextArgs.LineColor = defaultAnnot.BorderColor;
- freetextArgs.BgColor = defaultAnnot.BackgroundColor;
- freetextArgs.Transparency = defaultAnnot.Opacity;
- freetextArgs.FontName = defaultAnnot.FontFamily;
- freetextArgs.FontSize = defaultAnnot.FontSize;
- freetextArgs.IsBold = defaultAnnot.FontWeight == FontWeights.Bold;
- freetextArgs.IsItalic = defaultAnnot.FontStyle == FontStyles.Italic;
- freetextArgs.LineWidth = defaultAnnot.Thickness;
- freetextArgs.BgColor = defaultAnnot.BackgroundColor;
- 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;
- freetextArgs.Align = textAlignment;
- }
- else
- {
- FreeTextAnnotArgs freeText = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreeText] as FreeTextAnnotArgs;
- freetextArgs = SetFreetextArgs(freeText);
- //freetextArgs = SetFreetextArgs(freeText);
- //freetextArgs.Content = string.Empty;
- //freetextArgs.TextContent = string.Empty;
- }
- if (freetextArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(freetextArgs);
- SelectTextCreateAnnot(freetextArgs);
- }
- }
- else
- {
- FreeTextAnnotArgs freeText = selectedArgs[0] as FreeTextAnnotArgs;
- freetextArgs = SetFreetextArgs(freeText);
- textAlignment = freetextArgs.Align;
- if (NavigatedToFillAndSignVM(selectedArgs, "Freetext"))
- {
- return freetextArgs;
- }
- }
- AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs);
- return freetextArgs;
- }
- private FreeTextAnnotArgs SetFreetextArgs(FreeTextAnnotArgs defaultAnnot)
- {
- FreeTextAnnotArgs freetextArgs = new FreeTextAnnotArgs();
- freetextArgs.FontColor = defaultAnnot.FontColor;
- freetextArgs.LineColor = defaultAnnot.LineColor;
- freetextArgs.BgColor = defaultAnnot.BgColor;
- freetextArgs.Transparency = defaultAnnot.Transparency;
- freetextArgs.FontName = defaultAnnot.FontName;
- freetextArgs.FontSize = defaultAnnot.FontSize;
- freetextArgs.IsBold = defaultAnnot.IsBold;
- freetextArgs.IsItalic = defaultAnnot.IsItalic;
- freetextArgs.LineWidth = defaultAnnot.LineWidth;
- freetextArgs.Align = defaultAnnot.Align;
- return freetextArgs;
- }
- private void SelectTextCreateAnnot(FreeTextAnnotArgs freeText)
- {
- List<TextSelectNode> selectList = PDFViewer.GetSelectTextInfo();
- if (selectList != null && selectList.Count > 0)
- {
- foreach (TextSelectNode selectNode in selectList)
- {
- FreeTextAnnotArgs textArgs = new FreeTextAnnotArgs();
- Rect clientRect = Rect.Empty;
- foreach (Rect rawRect in selectNode.RawRect)
- {
- clientRect.Union(rawRect);
- }
- if (clientRect.IsEmpty == false)
- {
- clientRect = new Rect(
- clientRect.Left / 72D * 96D,
- clientRect.Top / 72D * 96D,
- clientRect.Width / 72D * 96D,
- clientRect.Height / 72D * 96D);
- textArgs.ClientRect = DpiHelpers.GetDpiRelatedRect(clientRect);
- //textArgs.Transparency = 1;
- //textArgs.BgColor = Colors.Transparent;
- //textArgs.LineColor = Colors.Red;
- //textArgs.LineWidth = 2;
- textArgs.Transparency = freeText.Transparency;
- textArgs.BgColor = freeText.BgColor;
- textArgs.LineColor = freeText.LineColor;
- textArgs.LineWidth = freeText.LineWidth;
- textArgs.TextContent = selectNode.SelectText;
- PDFViewer.CreatePageAnnot(selectNode.PageIndex, textArgs);
- }
- break;
- }
- }
- }
- //获取选中文字内容的区域大小,以及内容内容所在的页码
- private Tuple<int, Rect> DrawRectCreateAnnot()
- {
- List<TextSelectNode> selectList = PDFViewer.GetSelectTextInfo();
- Rect clientRect = Rect.Empty;
- int pageIndex = -1;
- if (selectList != null && selectList.Count > 0)
- {
- pageIndex = selectList[0].PageIndex;
- }
- if (selectList != null && selectList.Count > 0)
- {
- foreach (TextSelectNode selectNode in selectList)
- {
- foreach (Rect rawRect in selectNode.RawRect)
- {
- clientRect.Union(rawRect);
- }
- int dpi = DpiHelpers.Dpi;
- if (clientRect.IsEmpty == false)
- {
- clientRect = new Rect(
- clientRect.Left / 72D * dpi,
- clientRect.Top / 72D * dpi,
- clientRect.Width / 72D * dpi,
- clientRect.Height / 72D * dpi);
- }
- break;
- }
- }
- if (clientRect != Rect.Empty && pageIndex > -1)
- {
- return new Tuple<int, Rect>(pageIndex, clientRect);
- }
- return null;
- }
- /// <summary>
- /// 根据选中的文本内容,来创建指定大小的注释。
- /// </summary>
- /// <param name="annotArgs"></param>
- private AnnotHandlerEventArgs CreateAnnotFromSelectPageText(AnnotHandlerEventArgs annotArgs)
- {
- AnnotHandlerEventArgs annotHandler = null;
- //点击注释工具,在阅读页根据选中的文本内容,创建注释矩形大小
- var drawRectTuple = DrawRectCreateAnnot();
- if (drawRectTuple != null)
- {
- if (annotArgs is LinkAnnotArgs linkAnnot)
- {
- linkAnnot.ClientRect = drawRectTuple.Item2;
- linkAnnot.URI = string.Empty;
- linkAnnot.LinkType = LINK_TYPE.GOTO;
- //linkAnnot.DestIndex = drawRectTuple.Item1;
- //PDFViewer.CreatePageAnnot(drawRectTuple.Item1, linkAnnot);
- List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
- lists.Add(linkAnnot);
- PropertyPanel.IsAddLink = true;
- ViewContentViewModel.IsSelectedTextAddLink = true;
- AnnotHandlerEventArgs annotArgs1 = GetLink(lists);
- //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- //PDFViewer.SetToolParam(annotArgs1);
- ViewContentViewModel.IsPropertyOpen = true;
- annotHandler = linkAnnot;
- }
- if (annotArgs is SquareAnnotArgs squareAnnot)
- {
- PropertyPanel.IsSelectedTextAddShape = true;
- squareAnnot.ClientRect = drawRectTuple.Item2;
- PDFViewer.CreatePageAnnot(drawRectTuple.Item1, squareAnnot);
- annotHandler = squareAnnot;
- }
- if (annotArgs is CircleAnnotArgs circleAnnot)
- {
- PropertyPanel.IsSelectedTextAddShape = true;
- circleAnnot.ClientRect = drawRectTuple.Item2;
- PDFViewer.CreatePageAnnot(drawRectTuple.Item1, circleAnnot);
- annotHandler = circleAnnot;
- }
- if (annotArgs is LineAnnotArgs lineAnnot)
- {
- PropertyPanel.IsSelectedTextAddShape = true;
- lineAnnot.ClientRect = drawRectTuple.Item2;
- lineAnnot.LinePoints.Add(new System.Windows.Point(drawRectTuple.Item2.Left, drawRectTuple.Item2.Top));
- lineAnnot.LinePoints.Add(new System.Windows.Point(drawRectTuple.Item2.Right, drawRectTuple.Item2.Bottom));
- PDFViewer.CreatePageAnnot(drawRectTuple.Item1, lineAnnot);
- annotHandler = lineAnnot;
- }
- }
- return annotHandler;
- }
- //Event导航到填写与签名的属性面板
- private bool NavigatedToFillAndSignVM(List<AnnotHandlerEventArgs> annots, string tag)
- {
- if (ViewContentViewModel.FillAndSign != null && ViewContentViewModel.FillAndSign.Count > 0 && annots != null && annots.Count > 0)
- {
- var annotFillAndSign = ViewContentViewModel.FillAndSign.FirstOrDefault(temp => temp.PageIndex == annots[0].PageIndex && temp.AnnotIndex == annots[0].AnnotIndex);
- if (annotFillAndSign != null)
- {
- this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = tag, AppUnicode = App.mainWindowViewModel.SelectedItem.Unicode, Annots = annots });
- return true;
- }
- }
- return false;
- }
- private void FromFillAndSign(FillAndSigntEventArgs obj)
- {
- if (obj != null)
- {
- if (string.IsNullOrEmpty(obj.Action) == false)
- {
- if (obj.Action == "Clear")
- {
- ViewContentViewModel.AnnotSignatures.Clear();
- }
- }
- }
- }
- /// <summary>
- /// 便签
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null)
- {
- stickyAnnotArgs.Color = annotate.NoteAnnoteColor;
- }
- else
- {
- stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
- }
- if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] == null)
- {
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(stickyAnnotArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = stickyAnnotArgs.EventType;
- defaultAnnot.NoteText = string.Empty;
- defaultAnnot.Opacity = 1;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- stickyAnnotArgs.Transparency = defaultAnnot.Opacity;
- //希望defaultAnnot里面可以缓存这个名字 2023/4/4
- stickyAnnotArgs.IconName = "Comment";
- }
- else
- {
- //新创建对象进行赋值,避免传引用导致对象混淆2023/5/23
- //stickyAnnotArgs = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] as StickyAnnotArgs;
- //stickyAnnotArgs.Content = string.Empty;
- //stickyAnnotArgs.StickyNote = string.Empty;
- StickyAnnotArgs sticky = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] as StickyAnnotArgs;
- stickyAnnotArgs.Transparency = sticky.Transparency;
- stickyAnnotArgs.IconName = sticky.IconName;
- stickyAnnotArgs.Color = sticky.Color;
- //希望defaultAnnot里面可以缓存这个名字 2023/4/4
- //stickyAnnotArgs.IconName = "Comment";
- }
- if (stickyAnnotArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(stickyAnnotArgs);
- }
- }
- else
- {
- stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
- }
- List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
- if (stickyAnnotArgs != null)
- stickyAnnotArgsList.Add(stickyAnnotArgs);
- AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs);
- return stickyAnnotArgs;
- }
- /// <summary>
- /// 矩形
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- public AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- SquareAnnotArgs squareArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- squareArgs = new SquareAnnotArgs();
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null)
- {
- squareArgs.BgColor = annotate.RectangleFillColor;
- squareArgs.LineColor = annotate.RectangleBorderColor;
- }
- else
- {
- squareArgs.LineColor = Colors.Red;
- squareArgs.BgColor = Colors.Red;
- }
- if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] == null)
- {
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squareArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = squareArgs.EventType;
- defaultAnnot.Thickness = 2;
- defaultAnnot.Opacity = 1;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- squareArgs.LineWidth = defaultAnnot.Thickness;
- squareArgs.Transparency = defaultAnnot.Opacity;
- if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
- {
- squareArgs.LineDash = DashStyles.Solid;
- }
- else
- {
- var collect = new DoubleCollection();
- foreach (var item in defaultAnnot.DashArray)
- {
- collect.Add(item);
- }
- if (squareArgs.LineDash == null)
- squareArgs.LineDash = new DashStyle();
- squareArgs.LineDash.Dashes = collect;
- }
- }
- else
- {
- SquareAnnotArgs squareAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] as SquareAnnotArgs;
- squareArgs.BgColor = squareAnnot.BgColor;
- squareArgs.LineColor = squareAnnot.LineColor;
- squareArgs.LineWidth = squareAnnot.LineWidth;
- squareArgs.Transparency = squareAnnot.Transparency;
- squareArgs.LineDash = squareAnnot.LineDash;
- squareArgs.ClientRect = Rect.Empty;
- }
- if (squareArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(squareArgs);
- if (StrAnnotToolChecked == "Rect")
- {
- AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(squareArgs);
- if (annotHandler is SquareAnnotArgs annotArgs)
- {
- selectedArgs.Clear();
- selectedArgs.Add(annotArgs);
- }
- }
- }
- }
- else
- {
- squareArgs = selectedArgs[0] as SquareAnnotArgs;
- }
- AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
- return squareArgs;
- }
- /// <summary>
- /// 圆
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- public AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- CircleAnnotArgs circleAnnotArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- circleAnnotArgs = new CircleAnnotArgs();
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null)
- {
- circleAnnotArgs.LineColor = annotate.CircleBorderColor;
- circleAnnotArgs.BgColor = annotate.CircleFillColor;
- }
- else
- {
- circleAnnotArgs.LineColor = Colors.Red;
- circleAnnotArgs.BgColor = Colors.Red;
- }
- if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] == null)
- {
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(circleAnnotArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = circleAnnotArgs.EventType;
- defaultAnnot.Thickness = 2;
- defaultAnnot.Opacity = 1;
- defaultAnnot.NoteText = string.Empty;
- defaultAnnot.DashArray = null;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- circleAnnotArgs.LineWidth = defaultAnnot.Thickness;
- circleAnnotArgs.Transparency = defaultAnnot.Opacity;
- if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
- {
- circleAnnotArgs.LineDash = DashStyles.Solid;
- }
- else
- {
- var collect = new DoubleCollection();
- foreach (var item in defaultAnnot.DashArray)
- {
- collect.Add(item);
- }
- if (circleAnnotArgs.LineDash == null)
- circleAnnotArgs.LineDash = new DashStyle();
- circleAnnotArgs.LineDash.Dashes = collect;
- }
- }
- else
- {
- CircleAnnotArgs circleAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] as CircleAnnotArgs;
- circleAnnotArgs.LineColor = circleAnnot.LineColor;
- circleAnnotArgs.BgColor = circleAnnot.BgColor;
- circleAnnotArgs.LineWidth = circleAnnot.LineWidth;
- circleAnnotArgs.Transparency = circleAnnot.Transparency;
- circleAnnotArgs.LineDash = circleAnnot.LineDash;
- circleAnnotArgs.ClientRect = Rect.Empty;
- }
- if (circleAnnotArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(circleAnnotArgs);
- if (StrAnnotToolChecked == "Rect")
- {
- AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(circleAnnotArgs);
- if (annotHandler is CircleAnnotArgs annotArgs)
- {
- selectedArgs.Clear();
- selectedArgs.Add(annotArgs);
- }
- }
- }
- }
- else
- {
- circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
- }
- AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
- return circleAnnotArgs;
- }
- /// <summary>
- /// 箭头 线
- /// </summary>
- /// <param name="TagStr"></param>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- public AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- LineAnnotArgs lineArgs = new LineAnnotArgs();
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- //var annotate = Settings.Default.AppProperties.Annotate;
- //if (annotate != null)
- //{
- // lineArgs.LineColor = annotate.LineColor;
- //}
- //else
- //{
- // lineArgs.LineColor = Colors.Red;
- //}
- //lineArgs.LineColor = Colors.Red;
- lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
- bool isLastAnnot = false;
- if (TagStr == "Line")
- {
- lineArgs.LineColor = (LineColor as SolidColorBrush).Color;
- lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
- isLastAnnot = (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null ? true : false);
- }
- else
- {
- lineArgs.LineColor = (ArrowColor as SolidColorBrush).Color;
- lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
- isLastAnnot = (PropertyPanel.LastArrowAnnot != null ? true : false);
- }
- if (isLastAnnot == false)
- {
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(lineArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = lineArgs.EventType;
- defaultAnnot.Thickness = 2;
- defaultAnnot.Opacity = 1;
- defaultAnnot.NoteText = string.Empty;
- defaultAnnot.DashArray = null;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- lineArgs.LineDash = DashStyles.Solid;
- lineArgs.LineWidth = defaultAnnot.Thickness;
- lineArgs.Transparency = defaultAnnot.Opacity;
- if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
- {
- lineArgs.LineDash = DashStyles.Solid;
- }
- else
- {
- var collect = new DoubleCollection();
- foreach (var item in defaultAnnot.DashArray)
- {
- collect.Add(item);
- }
- if (lineArgs.LineDash == null)
- lineArgs.LineDash = new DashStyle();
- lineArgs.LineDash.Dashes = collect;
- }
- }
- else
- {
- LineAnnotArgs lineAnnot = null;
- if (lineArgs.TailLineType == C_LINE_TYPE.LINETYPE_ARROW)
- {
- lineAnnot = PropertyPanel.LastArrowAnnot as LineAnnotArgs;
- }
- else
- {
- lineAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] as LineAnnotArgs;
- }
- lineArgs.LineColor = lineAnnot.LineColor;
- lineArgs.HeadLineType = lineAnnot.HeadLineType;
- lineArgs.TailLineType = lineAnnot.TailLineType;
- lineArgs.LineWidth = lineAnnot.LineWidth;
- lineArgs.Transparency = lineAnnot.Transparency;
- lineArgs.LineDash = lineAnnot.LineDash;
- }
- if (lineArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(lineArgs);
- if (StrAnnotToolChecked == "Rect")
- {
- AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(lineArgs);
- if (annotHandler is LineAnnotArgs annotArgs)
- {
- selectedArgs.Clear();
- selectedArgs.Add(annotArgs);
- }
- }
- }
- }
- else
- {
- lineArgs = selectedArgs[0] as LineAnnotArgs;
- }
- AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs);
- return lineArgs;
- }
- /// <summary>
- /// 图章
- /// </summary>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetStamp()
- {
- StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
- stampAnnotArgs.Opacity = 1;
- stampAnnotArgs.StampText = "APPROVED";
- stampAnnotArgs.Type = StampType.STANDARD_STAMP;
- List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
- if (stampAnnotArgs != null)
- stampAnnotArgsList.Add(stampAnnotArgs);
- if (string.IsNullOrEmpty(StrAnnotToolChecked))
- {
- if (IsNoSelectMenu)
- {
- AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
- return stampAnnotArgs;
- }
- ViewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- return stampAnnotArgs;
- }
- //已选中注释工具的前提下,选中页面已经添加的图章注释时,右侧属性面板显示空状态(不自动收起)
- if (StrAnnotToolChecked != "Stamp" && string.IsNullOrEmpty(StrAnnotToolChecked) == false)
- {
- ViewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- ShowPropertyPanel(true);
- return stampAnnotArgs;
- }
- AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
- return stampAnnotArgs;
- }
- /// <summary>
- /// 签名
- /// </summary>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetSignature()
- {
- AddToPropertyPanel("SignatureAnnotProperty");
- return null;
- }
- private AnnotHandlerEventArgs GetImage()
- {
- StampAnnotArgs stampArgs = new StampAnnotArgs();
- stampArgs.Opacity = 1;
- stampArgs.Type = StampType.IMAGE_STAMP;
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
- if (openFileDialog.ShowDialog() == true)
- {
- stampArgs.ImagePath = openFileDialog.FileName;
- }
- List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
- if (stampArgs != null)
- stampArgsList.Add(stampArgs);
- AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList);
- return stampArgs;
- }
- /// <summary>
- /// 内容选择
- /// </summary>
- /// <param name="annotBtn"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetSnapshotEdit()
- {
- SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
- //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
- snapshotArgs.ControlPointColor = Colors.White;
- snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
- snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
- SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
- SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
- SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
- SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
- #region to do
- //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
- //snapshotArgs.ToolPanel = snapMenu;
- //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
- //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
- //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
- //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
- //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
- //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
- #endregion to do
- StrAnnotToolChecked = "";
- return snapshotArgs;
- }
- #endregion 注释工具
- #region 菜单
- private bool InBookModeSetIsHidden(object obj)
- {
- bool flag = false;
- if (obj is MenuItem menuItem)
- {
- if (ViewContentViewModel.mainViewModel.IsBookMode)
- {
- menuItem.Visibility = Visibility.Collapsed;
- return true;
- }
- else
- {
- menuItem.Visibility = Visibility.Visible;
- return false;
- }
- }
- if (obj is Separator separator)
- {
- if (ViewContentViewModel.mainViewModel.IsBookMode)
- {
- separator.Visibility = Visibility.Collapsed;
- return true;
- }
- else
- {
- separator.Visibility = Visibility.Visible;
- return false;
- }
- }
- return flag;
- }
- private void ExportPicture_MenuItemClick()
- {
- //图片提取
- try
- {
- List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
- Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
- foreach (int pageIndex in imageDict.Keys)
- {
- imageList = imageDict[pageIndex];
- }
- string path = PDFViewer.Document.FileName;
- System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
- if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- int i = 1;
- int pagenum = 1;
- string choosePath = folderDialog.SelectedPath;
- string sPath = choosePath + "\\" + path + "_Extract Image";
- sPath = GetExportPathName(sPath);
- if (!Directory.Exists(sPath))
- {
- Directory.CreateDirectory(sPath);
- }
- if (Directory.Exists(sPath))
- {
- foreach (System.Drawing.Bitmap image in imageList)
- {
- foreach (var item in imageDict.Keys)
- {
- pagenum = item;
- }
- string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
- string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
- image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
- i++;
- }
- System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
- }
- }
- }
- catch (Exception ex) { }
- }
- public string GetExportPathName(string path)
- {
- int i = 1;
- string outpath = path;
- while (Directory.Exists(outpath))
- {
- outpath = path + $"({i.ToString()})";
- i++;
- }
- return outpath;
- }
- private string GetNum(int num)
- {
- if (num % 10 < 1)
- {
- return "00" + num.ToString();
- }
- if (num % 10 >= 1 && num % 10 < 10)
- {
- return "0" + num.ToString();
- }
- else
- {
- return num.ToString();
- }
- }
- #endregion 菜单
- }
- }
|