123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293 |
- 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.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.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 ContextMenu = System.Windows.Controls.ContextMenu;
- 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()
- {
- InitAnnotHighlight();
- InitAnnotUnderline();
- InitAnnotSquiggly();
- InitAnnotStrikeout();
- }
- private void InitAnnotHighlight()
- {
- 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()
- {
- 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()
- {
- 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()
- {
- 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);
- }
- //注释工具按钮悬浮文案
- 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", "显示/隐藏注释");
- }
- //便签批注弹窗
- private void LoaedStickyNotePopup()
- {
- if (PDFViewer == null) return;
- if (customStickyPopup == null)
- {
- customStickyPopup = new StickyNotePopup();
- PDFViewer.SetStickyNotePop(customStickyPopup);
- }
- }
- #endregion 初始化数据
- #endregion 初始化
- #region 注释工具
- //注释工具
- private 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"://矩形
- annotArgs = GetRect();
- break;
- case "Circle"://圆
- annotArgs = GetCircle();
- break;
- case "Arrow"://箭头
- case "Line"://线
- annotArgs = GetArrowLine(tag);
- break;
- case "Stamp"://图章
- //付费锁
- if (!App.IsLogin)
- {
- dialogs.ShowDialog(DialogNames.IAPCompareDialog);
- return;
- }
- annotArgs = GetStamp();
- break;
- case "Image":
- annotArgs = GetImage();
- break;
- case "Signature"://签名
- //付费锁
- if (!App.IsLogin)
- {
- dialogs.ShowDialog(DialogNames.IAPCompareDialog);
- return;
- }
- annotArgs = GetSignature();
- PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
- break;
- case "Link"://链接
- //付费锁
- if (!App.IsLogin)
- {
- dialogs.ShowDialog(DialogNames.IAPCompareDialog);
- return;
- }
- propertyPanel.IsAddLink = true;
- viewContentViewModel.IsRightMenuCreateLink = isRightMenuAdd;
- annotArgs = GetLink();
- break;
- }
- if (annotArgs != null)
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- }
- //创建,选中,保留上次属性值的注释
- /// <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;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- highLightOpacity = highlightArgs.Transparency = defaultAnnot.Opacity;
- }
- else
- {
- }
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(highlightArgs);
- }
- else
- {
- highlightArgs = selectedArgs[0] as TextHighlightAnnotArgs;
- }
- AddToPropertyPanel("TextAnnotProperty", "HighLight", selectedArgs);
- return highlightArgs;
- }
- /// <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);
- CreateAnnotFromSelectPageText(linkArgs);
- }
- }
- AddToPropertyPanel("LinkAnnotProperty", "Link", selectedArgs, annotAttribEvent);
- return linkArgs;
- }
- /// <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;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- UnderLineOpacity = underlineArgs.Transparency = defaultAnnot.Opacity;
- }
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(underlineArgs);
- }
- else
- {
- underlineArgs = selectedArgs[0] as TextUnderlineAnnotArgs;
- }
- 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;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- strikeoutArgs.Transparency = defaultAnnot.Opacity;
- }
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(strikeoutArgs);
- }
- else
- {
- strikeoutArgs = selectedArgs[0] as TextStrikeoutAnnotArgs;
- }
- 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);
- }
- if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] == null)
- {
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freehandArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = freehandArgs.EventType;
- defaultAnnot.ForgoundColor = annotate.FreeHandColor;
- defaultAnnot.Opacity = 1;
- defaultAnnot.Thickness = 2;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- freehandArgs.Transparency = defaultAnnot.Opacity;
- freehandArgs.LineWidth = defaultAnnot.Thickness;
- 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
- {
- freehandArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] as FreehandAnnotArgs;
- }
- 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.Transparent;
- 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.FontFamily = new FontFamily(defaultAnnot.FontFamily);
- freetextArgs.FontSize = defaultAnnot.FontSize;
- freetextArgs.FontWeight = defaultAnnot.FontWeight;
- freetextArgs.FontStyle = defaultAnnot.FontStyle;
- freetextArgs.LineWidth = defaultAnnot.Thickness;
- 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
- {
- freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
- 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.FontFamily = defaultAnnot.FontFamily;
- freetextArgs.FontSize = defaultAnnot.FontSize;
- freetextArgs.FontWeight = defaultAnnot.FontWeight;
- freetextArgs.FontStyle = defaultAnnot.FontStyle;
- 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;
- }
- //根据选中的文本内容,来创建指定大小的注释。
- private void CreateAnnotFromSelectPageText(AnnotHandlerEventArgs annotArgs)
- {
- //点击注释工具,在阅读页根据选中的文本内容,创建注释矩形大小
- var drawRectTuple = DrawRectCreateAnnot();
- if (drawRectTuple != null)
- {
- annotArgs.ClientRect = drawRectTuple.Item2;
- PDFViewer.CreatePageAnnot(drawRectTuple.Item1, annotArgs);
- }
- }
- //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;
- }
- else
- {
- stickyAnnotArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] as StickyAnnotArgs;
- stickyAnnotArgs.Content = string.Empty;
- stickyAnnotArgs.StickyNote = string.Empty;
- }
- 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>
- private 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 = 1;
- 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
- {
- squareArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] as SquareAnnotArgs;
- }
- if (squareArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(squareArgs);
- CreateAnnotFromSelectPageText(squareArgs);
- }
- }
- else
- {
- squareArgs = selectedArgs[0] as SquareAnnotArgs;
- }
- AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
- return squareArgs;
- }
- /// <summary>
- /// 圆
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private 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 = 1;
- 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 = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] as CircleAnnotArgs;
- }
- if (circleAnnotArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(circleAnnotArgs);
- }
- }
- else
- {
- circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
- }
- AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
- return circleAnnotArgs;
- }
- /// <summary>
- /// 箭头 线
- /// </summary>
- /// <param name="TagStr"></param>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private 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.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
- isLastAnnot = (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null ? true : false);
- }
- else
- {
- 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 = 1;
- 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
- {
- if (lineArgs.TailLineType == C_LINE_TYPE.LINETYPE_ARROW)
- {
- lineArgs = propertyPanel.LastArrowAnnot as LineAnnotArgs;
- }
- else
- {
- lineArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] as LineAnnotArgs;
- }
- }
- if (lineArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(lineArgs);
- }
- }
- 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);
- 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
- return snapshotArgs;
- }
- #endregion 注释工具
- #region 菜单
- private bool InBookModeSetIsEnabled(MenuItem menuItem)
- {
- if (viewContentViewModel.mainViewModel.IsBookMode)
- {
- menuItem.IsEnabled = false;
- return true;
- }
- else
- {
- menuItem.IsEnabled = true;
- return false;
- }
- }
- 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 菜单
- }
- }
|