using ComPDFKit.PDFAnnotation;
using ComPDFKit.PDFDocument;
using ComPDFKitViewer;
using ComPDFKitViewer.AnnotEvent;
using ComPDFKitViewer.PdfViewer;
using Microsoft.Win32;
using PDF_Office.CustomControl;
using PDF_Office.Helper;
using PDF_Office.Properties;
using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
using PDF_Office.Views.PropertyPanel.AnnotPanel;
using PDFSettings;
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 System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using ContextMenu = System.Windows.Controls.ContextMenu;
using HorizontalAlignment = System.Windows.HorizontalAlignment;
using MenuItem = System.Windows.Controls.MenuItem;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
namespace PDF_Office.ViewModels.Tools
{
public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
{
#region 初始化
#region 初始化数据
//初始化注释的属性值,并存在本地缓存数据集里
private void InitDefaultValue()
{
InitAnnotHighlight();
InitAnnotUnderline();
InitAnnotSquiggly();
InitAnnotStrikeout();
}
private void InitAnnotHighlight()
{
DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotHighlight);
if (annotProperty == null)
{
annotProperty = new DefaultAnnotProperty();
annotProperty.AnnotToolType = AnnotArgsType.AnnotHighlight;
annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
annotProperty.Opacity = 0.5;
SettingHelper.SetAnnotDefaultProperty(annotProperty);
}
else
{
HighLightColor = new SolidColorBrush(annotProperty.BackgroundColor);
HighLightOpacity = annotProperty.Opacity;
}
}
private void InitAnnotUnderline()
{
DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotUnderline);
if (annotProperty == null)
{
annotProperty = new DefaultAnnotProperty();
annotProperty.AnnotToolType = AnnotArgsType.AnnotUnderline;
annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
annotProperty.Opacity = 0.5;
SettingHelper.SetAnnotDefaultProperty(annotProperty);
}
else
{
UnderLineColor = new SolidColorBrush(annotProperty.BackgroundColor);
UnderLineOpacity = annotProperty.Opacity;
}
}
private void InitAnnotSquiggly()
{
DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquiggly);
if (annotProperty == null)
{
annotProperty = new DefaultAnnotProperty();
annotProperty.AnnotToolType = AnnotArgsType.AnnotSquiggly;
annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
annotProperty.Opacity = 0.5;
SettingHelper.SetAnnotDefaultProperty(annotProperty);
}
else
{
SquigglyColor = new SolidColorBrush(annotProperty.BackgroundColor);
SquigglyOpacity = annotProperty.Opacity;
}
}
private void InitAnnotStrikeout()
{
DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStrikeout);
if (annotProperty == null)
{
annotProperty = new DefaultAnnotProperty();
annotProperty.AnnotToolType = AnnotArgsType.AnnotStrikeout;
annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
annotProperty.Opacity = 0.5;
SettingHelper.SetAnnotDefaultProperty(annotProperty);
}
else
{
StrikeoutColor = new SolidColorBrush(annotProperty.BackgroundColor);
StrikeoutOpacity = annotProperty.Opacity;
}
}
//用来记录选中和创建注释的标识
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);
}
#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"://图章
annotArgs = GetStamp();
break;
case "Image":
annotArgs = GetImage();
break;
case "Signature"://签名
annotArgs = GetSignature();
PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
break;
case "Link"://链接
viewContentViewModel.IsRightMenuCreateLink = isRightMenuAdd;
annotArgs = GetLink();
break;
}
}
///
/// 高亮注释
///
///
private AnnotHandlerEventArgs GetHighLight(TextHighlightAnnotArgs selectedhighlightArgs = null)
{
Dictionary annotAttribsList = new Dictionary();
TextHighlightAnnotArgs highlightArgs = null;
if (selectedhighlightArgs == null)
{
highlightArgs = new TextHighlightAnnotArgs();
highlightArgs.Color = Color.FromRgb(0xFF, 0xBB, 0x00);
highlightArgs.Transparency = 0.5;
DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotHighlight);
if (annotProperty != null)
{
highlightArgs.Color = annotProperty.ForgoundColor;
highlightArgs.Transparency = annotProperty.Opacity;
highlightArgs.Content = annotProperty.NoteText;
}
}
else
{
highlightArgs = selectedhighlightArgs;
}
annotAttribsList[AnnotAttrib.Color] = highlightArgs.Color;
annotAttribsList[AnnotAttrib.Transparency] = highlightArgs.Transparency;
annotAttribsList[AnnotAttrib.NoteText] = highlightArgs.Content;
AddToPropertyPanel("TextAnnotProperty", "HighLight", highlightArgs, annotAttribsList);
return highlightArgs;
}
///
/// 链接
///
///
///
///
public AnnotHandlerEventArgs GetLink(LinkAnnotArgs selectedLinkAnnotArgs = null, AnnotAttribEvent annotAttribEvent = null)
{
Dictionary annotAttribsList = new Dictionary();
LinkAnnotArgs linkArgs = new LinkAnnotArgs();
DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLink);
if (annotProperty != null)
{
}
if (selectedLinkAnnotArgs != null)
{
linkArgs = selectedLinkAnnotArgs;
}
else
{
linkArgs.URI = string.Empty;
linkArgs.LinkType = LINK_TYPE.GOTO;
linkArgs.DestIndex = -1;
}
annotAttribsList[AnnotAttrib.LinkType] = linkArgs.LinkType;
annotAttribsList[AnnotAttrib.LinkUri] = linkArgs.URI;
annotAttribsList[AnnotAttrib.LinkDestIndx] = linkArgs.DestIndex;
AddToPropertyPanel("LinkAnnotProperty", "Link", linkArgs, annotAttribsList, annotAttribEvent);
return linkArgs;
}
///
/// 下划线
///
///
///
private AnnotHandlerEventArgs GetUnderLine(TextUnderlineAnnotArgs selectedunderlineArgs = null)
{
Dictionary annotAttribsList = new Dictionary();
TextUnderlineAnnotArgs underlineArgs = null;
if (selectedunderlineArgs == null)
{
underlineArgs = new TextUnderlineAnnotArgs();
underlineArgs.Color = Color.FromRgb(0x12, 0xFD, 0xFF);
underlineArgs.Transparency = 1;
DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotUnderline);
if (annotProperty != null)
{
underlineArgs.Color = annotProperty.ForgoundColor;
underlineArgs.Transparency = annotProperty.Opacity;
underlineArgs.Content = annotProperty.NoteText;
}
}
else
{
underlineArgs = selectedunderlineArgs;
}
annotAttribsList[AnnotAttrib.Color] = underlineArgs.Color;
annotAttribsList[AnnotAttrib.Transparency] = underlineArgs.Transparency;
annotAttribsList[AnnotAttrib.NoteText] = underlineArgs.Content;
AddToPropertyPanel("TextAnnotProperty", "UnderLine", underlineArgs, annotAttribsList);
return underlineArgs;
}
///
/// 波浪线
///
///
///
private AnnotHandlerEventArgs GetSquiggly(TextSquigglyAnnotArgs selectedsquigglyArgs = null)
{
Dictionary annotAttribsList = new Dictionary();
TextSquigglyAnnotArgs squigglyArgs = null;
if (selectedsquigglyArgs == null)
{
squigglyArgs = new TextSquigglyAnnotArgs();
squigglyArgs.Color = Color.FromRgb(0xFF, 0x87, 0x16);
squigglyArgs.Transparency = 1;
DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquiggly);
if (annotProperty != null)
{
squigglyArgs.Color = annotProperty.ForgoundColor;
squigglyArgs.Transparency = annotProperty.Opacity;
squigglyArgs.Content = annotProperty.NoteText;
}
}
else
{
squigglyArgs = selectedsquigglyArgs;
}
annotAttribsList[AnnotAttrib.Color] = squigglyArgs.Color;
annotAttribsList[AnnotAttrib.Transparency] = squigglyArgs.Transparency;
annotAttribsList[AnnotAttrib.NoteText] = squigglyArgs.Content;
AddToPropertyPanel("TextAnnotProperty", "Squiggly", squigglyArgs, annotAttribsList);
return squigglyArgs;
}
///
/// 删除线
///
///
///
private AnnotHandlerEventArgs GetStrikeout(TextStrikeoutAnnotArgs selectedstrikeoutArgs = null)
{
Dictionary annotAttribsList = new Dictionary();
TextStrikeoutAnnotArgs strikeoutArgs = null;
if (selectedstrikeoutArgs == null)
{
strikeoutArgs = new TextStrikeoutAnnotArgs();
strikeoutArgs.Color = Color.FromRgb(0xFF, 0x3B, 0x30);
strikeoutArgs.Transparency = 1;
DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStrikeout);
if (annotProperty != null)
{
strikeoutArgs.Color = annotProperty.ForgoundColor;
strikeoutArgs.Transparency = annotProperty.Opacity;
strikeoutArgs.Content = annotProperty.NoteText;
}
}
else
{
strikeoutArgs = selectedstrikeoutArgs;
}
annotAttribsList[AnnotAttrib.Color] = strikeoutArgs.Color;
annotAttribsList[AnnotAttrib.Transparency] = strikeoutArgs.Transparency;
annotAttribsList[AnnotAttrib.NoteText] = strikeoutArgs.Content;
AddToPropertyPanel("TextAnnotProperty", "Strikeout", strikeoutArgs, annotAttribsList);
return strikeoutArgs;
}
///
/// 手绘
///
///
///
private AnnotHandlerEventArgs GetFreehand(FreehandAnnotArgs selectedfreehandArgs = null)
{
Dictionary annotAttribsList = new Dictionary();
FreehandAnnotArgs freehandArgs = null;
if (selectedfreehandArgs == null)
{
freehandArgs = new FreehandAnnotArgs();
freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
freehandArgs.Transparency = 1;
freehandArgs.LineWidth = 1;
DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreehand);
if (annotProperty != null)
{
freehandArgs.InkColor = annotProperty.ForgoundColor;
freehandArgs.Transparency = annotProperty.Opacity;
freehandArgs.LineWidth = annotProperty.Thickness;
freehandArgs.Content = annotProperty.NoteText;
}
}
else
{
freehandArgs = selectedfreehandArgs;
}
annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
AddToPropertyPanel("FreehandAnnotProperty", "Freehand", freehandArgs, annotAttribsList);
return freehandArgs;
}
///
/// 文本
///
///
///
private AnnotHandlerEventArgs GetFreetext(FreeTextAnnotArgs selectedfreetextArgs = null)
{
Dictionary annotAttribsList = new Dictionary();
FreeTextAnnotArgs freetextArgs = null;
TextAlignment textAlignment;
if (selectedfreetextArgs == null)
{
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;
}
else
{
freetextArgs = selectedfreetextArgs;
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;
AddToPropertyPanel("FreetextAnnotProperty", "Freetext", freetextArgs, annotAttribsList);
return freetextArgs;
}
///
/// 便签
///
///
///
private AnnotHandlerEventArgs GetStickyNote(StickyAnnotArgs selectedStickyArgs = null)
{
Dictionary annotAttribsList = new Dictionary();
StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
if (selectedStickyArgs == null)
{
stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
stickyAnnotArgs.StickyNote = string.Empty;
stickyAnnotArgs.Transparency = 1;
DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSticky);
if (annotProperty != null)
{
stickyAnnotArgs.Color = annotProperty.ForgoundColor;
stickyAnnotArgs.StickyNote = annotProperty.NoteText;
stickyAnnotArgs.Transparency = annotProperty.Opacity;
}
}
else
{
stickyAnnotArgs = selectedStickyArgs;
}
annotAttribsList[AnnotAttrib.Color] = stickyAnnotArgs.Color;
annotAttribsList[AnnotAttrib.Transparency] = stickyAnnotArgs.Transparency;
annotAttribsList[AnnotAttrib.NoteText] = stickyAnnotArgs.StickyNote;
annotAttribsList[AnnotAttrib.StickyIcon] = stickyAnnotArgs.IconName;
AddToPropertyPanel("StickyNoteProperty", "StickyNote", stickyAnnotArgs, annotAttribsList);
return stickyAnnotArgs;
}
///
/// 矩形
///
///
///
private AnnotHandlerEventArgs GetRect(SquareAnnotArgs selectedsquareArgs = null)
{
Dictionary annotAttribsList = new Dictionary();
SquareAnnotArgs squareArgs = null;
if (selectedsquareArgs == null)
{
squareArgs = new SquareAnnotArgs();
squareArgs.LineColor = Colors.Red;
squareArgs.BgColor = Colors.Transparent;
squareArgs.LineWidth = 1;
squareArgs.Transparency = 1;
squareArgs.LineDash = DashStyles.Solid;
squareArgs.Content = string.Empty;
DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquare);
if (annotProperty != null)
{
squareArgs.LineColor = annotProperty.BorderColor;
squareArgs.BgColor = annotProperty.BackgroundColor;
if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
{
squareArgs.LineDash = DashStyles.Solid;
}
else
{
DashStyle dash = new DashStyle();
foreach (var offset in annotProperty.DashArray)
{
dash.Dashes.Add(offset);
}
squareArgs.LineDash = dash;
}
squareArgs.LineWidth = annotProperty.Thickness;
squareArgs.Transparency = annotProperty.Opacity;
squareArgs.Content = annotProperty.NoteText;
}
}
else
{
squareArgs = selectedsquareArgs;
}
annotAttribsList[AnnotAttrib.Color] = squareArgs.LineColor;
annotAttribsList[AnnotAttrib.FillColor] = squareArgs.BgColor;
annotAttribsList[AnnotAttrib.LineStyle] = squareArgs.LineDash;
annotAttribsList[AnnotAttrib.Thickness] = squareArgs.LineWidth;
annotAttribsList[AnnotAttrib.Transparency] = squareArgs.Transparency;
annotAttribsList[AnnotAttrib.NoteText] = squareArgs.Content;
AddToPropertyPanel("SharpsAnnotProperty", "Rect", squareArgs, annotAttribsList);
return squareArgs;
}
///
/// 圆
///
///
///
private AnnotHandlerEventArgs GetCircle(CircleAnnotArgs selectedcircleAnnotArgs = null)
{
Dictionary annotAttribsList = new Dictionary();
CircleAnnotArgs circleAnnotArgs = null;
if (selectedcircleAnnotArgs == null)
{
circleAnnotArgs = new CircleAnnotArgs();
circleAnnotArgs.LineColor = Colors.Red;
circleAnnotArgs.BgColor = Colors.Transparent;
circleAnnotArgs.LineWidth = 1;
circleAnnotArgs.Transparency = 1;
circleAnnotArgs.LineDash = DashStyles.Solid;
circleAnnotArgs.Content = string.Empty;
DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotCircle);
if (annotProperty != null)
{
circleAnnotArgs.LineColor = annotProperty.BorderColor;
circleAnnotArgs.BgColor = annotProperty.BackgroundColor;
if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
{
circleAnnotArgs.LineDash = DashStyles.Solid;
}
else
{
DashStyle dash = new DashStyle();
foreach (var offset in annotProperty.DashArray)
{
dash.Dashes.Add(offset);
}
circleAnnotArgs.LineDash = dash;
}
circleAnnotArgs.LineWidth = annotProperty.Thickness;
circleAnnotArgs.Transparency = annotProperty.Opacity;
circleAnnotArgs.Content = annotProperty.NoteText;
}
}
else
{
circleAnnotArgs = selectedcircleAnnotArgs;
}
annotAttribsList[AnnotAttrib.Color] = circleAnnotArgs.LineColor;
annotAttribsList[AnnotAttrib.FillColor] = circleAnnotArgs.BgColor;
annotAttribsList[AnnotAttrib.LineStyle] = circleAnnotArgs.LineDash;
annotAttribsList[AnnotAttrib.Thickness] = circleAnnotArgs.LineWidth;
annotAttribsList[AnnotAttrib.Transparency] = circleAnnotArgs.Transparency;
annotAttribsList[AnnotAttrib.NoteText] = circleAnnotArgs.Content;
AddToPropertyPanel("SharpsAnnotProperty", "Circle", circleAnnotArgs, annotAttribsList);
return circleAnnotArgs;
}
///
/// 箭头 线
///
///
///
///
private AnnotHandlerEventArgs GetArrowLine(string TagStr, LineAnnotArgs selectedLineAnnotArgs = null)
{
Dictionary annotAttribsList = new Dictionary();
LineAnnotArgs lineArgs = new LineAnnotArgs();
if (selectedLineAnnotArgs == null)
{
lineArgs.LineColor = Colors.Red;
lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
if (TagStr == "Line")
{
lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
}
else
{
lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
}
lineArgs.LineDash = DashStyles.Solid;
lineArgs.LineWidth = 1;
lineArgs.Transparency = 1;
lineArgs.Content = string.Empty;
}
else
{
lineArgs = selectedLineAnnotArgs;
}
DefaultAnnotProperty annotProperty = null;
if (TagStr == "Line")
{
annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Line");
if (annotProperty != null)
{
annotProperty.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
annotProperty.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
}
}
else
{
annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Arrow");
}
if (annotProperty != null)
{
lineArgs.LineColor = annotProperty.BorderColor;
lineArgs.HeadLineType = annotProperty.HeadLineType;
lineArgs.TailLineType = annotProperty.TailLineType;
DashStyle dash = new DashStyle();
foreach (var offset in annotProperty.DashArray)
{
dash.Dashes.Add(offset);
}
lineArgs.LineDash = dash;
lineArgs.LineWidth = annotProperty.Thickness;
lineArgs.Transparency = annotProperty.Opacity;
lineArgs.Content = annotProperty.NoteText;
}
annotAttribsList[AnnotAttrib.Color] = lineArgs.LineColor;
annotAttribsList[AnnotAttrib.LineStart] = lineArgs.HeadLineType;
annotAttribsList[AnnotAttrib.LineEnd] = lineArgs.TailLineType;
annotAttribsList[AnnotAttrib.LineStyle] = lineArgs.LineDash;
annotAttribsList[AnnotAttrib.Thickness] = lineArgs.LineWidth;
annotAttribsList[AnnotAttrib.Transparency] = lineArgs.Transparency;
annotAttribsList[AnnotAttrib.NoteText] = lineArgs.Content;
AddToPropertyPanel("SharpsAnnotProperty", TagStr, lineArgs, annotAttribsList);
return lineArgs;
}
///
/// 图章
///
///
private AnnotHandlerEventArgs GetStamp()
{
StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
stampAnnotArgs.Opacity = 1;
stampAnnotArgs.StampText = "APPROVED";
stampAnnotArgs.Type = StampType.STANDARD_STAMP;
Dictionary annotAttribsList = new Dictionary();
annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgs, annotAttribsList);
return stampAnnotArgs;
}
///
/// 签名
///
///
private AnnotHandlerEventArgs GetSignature()
{
AddToPropertyPanel("SignatureAnnotProperty");
return null;
}
private AnnotHandlerEventArgs GetImage()
{
Dictionary annotAttribsList = new Dictionary();
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;
}
AddToPropertyPanel("ImageAnnotProperty", null, stampArgs, annotAttribsList);
return stampArgs;
}
///
/// 内容选择
///
///
///
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;
#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;
}
///
/// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
///
/// 对应的注释面板
/// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
/// 注释
/// 更改注释属性的键值对,更改值后会自动记录undoRedo容器里
private void AddToPropertyPanel(string viewContent, string toolTag = null, AnnotHandlerEventArgs annot = null, Dictionary annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null)
{
//if (string.IsNullOrEmpty(toolTag) == false)
//{
// if (!ToolExpandDict.ContainsKey(toolTag))
// {
// ToolExpandDict[toolTag] = true;
// }
//}
if (annot != null)
propertyPanel.annot = annot;
if (annotAttribsList != null)
{
propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annotAttribsList);
if (annot is LinkAnnotArgs && annotAttribEvent != null)
{
propertyPanel.AnnotEvent = annotAttribEvent;
}
}
if (string.IsNullOrEmpty(viewContent) == false)
{
viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
}
}
#endregion 注释工具
#region 属性面板
///
/// 展开显示属性面板
///
private void ShowPropertyPanel(bool show = true)
{
viewContentViewModel.IsPropertyOpen = show;
}
#endregion 属性面板
#region 菜单
private ContextMenu ViewerContextMenu()
{
ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
//contextMenu.Loaded += ContextMenu_Loaded;
ViewerContextMenu_Loaded(contextMenu, null);
return contextMenu;
}
private void ViewerContextMenu_Loaded(object sender, RoutedEventArgs e)
{
ContextMenu contextMenu = sender as ContextMenu;
if (contextMenu.Items.Count > 0)
{
int index = PDFViewer.CurrentIndex;
//检测是否已存在相同数据
CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
if (list != null)
{
isAddBookMark = false;
}
else
{
isAddBookMark = true;
}
foreach (var item in contextMenu.Items)
{
if (item is MenuItem menuItem1)
{
//if (menuItem1.Tag.ToString() == "DisplayAnnot" || menuItem1.Tag.ToString() == "HiddenAnnot")
//{
// SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
//}
switch (menuItem1.Tag.ToString())
{
case "Copy":
//粘贴
if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
{
menuItem1.IsEnabled = false;
menuItem1.Opacity = 0.5;
}
else
{
menuItem1.IsEnabled = true;
menuItem1.Opacity = 1;
}
menuItem1.CommandTarget = (UIElement)sender;
menuItem1.Command = ApplicationCommands.Copy;
break;
case "AddAnnotation":
if (menuItem1.Items.Count > 0)
{
SetAddAnnotation(menuItem1.Items);
}
break;
case "HiddenAnnot":
menuItem1.Click -= HiddenAnnot_Click;
menuItem1.Click += HiddenAnnot_Click;
SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
break;
case "DisplayAnnot":
menuItem1.Click -= DisplayAnnot_Click;
menuItem1.Click += DisplayAnnot_Click;
SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
break;
case "AddBookMark":
menuItem1.Click -= AddBookMark_Click;
menuItem1.Click += AddBookMark_Click;
SetMenuItemVisibility(menuItem1, "DelBookMark", "AddBookMark", isAddBookMark);
break;
case "DelBookMark":
menuItem1.Click -= DelBookMark_Click;
menuItem1.Click += DelBookMark_Click;
SetMenuItemVisibility(menuItem1, "DelBookMark", "AddBookMark", isAddBookMark);
break;
case "ToolMode":
if (menuItem1.Items.Count > 0)
{
SetToolMode(menuItem1.Items);
}
break;
case "ReadModel":
SetMenuItemVisibility(menuItem1, "ReadModel", "UnReadModel", App.IsBookMode);
menuItem1.Click -= ReadModel_Click;
menuItem1.Click += ReadModel_Click;
break;
case "UnReadModel":
SetMenuItemVisibility(menuItem1, "ReadModel", "UnReadModel", App.IsBookMode);
menuItem1.Click -= UnReadModel_Click;
menuItem1.Click += UnReadModel_Click;
break;
case "ViewZoom":
if (menuItem1.Items.Count > 0)
{
ViewZoom(menuItem1.Items);
}
break;
case "PageDisplay":
if (menuItem1.Items.Count > 0)
{
PageDisplay(menuItem1.Items);
}
break;
case "Select":
menuItem1.Click -= Select_Click;
menuItem1.Click += Select_Click;
break;
case "Print":
menuItem1.Command = viewContentViewModel.PrintCommand;
break;
}
}
}
}
}
private void SetMenuItemVisibility(MenuItem menuItem1, string right, string deny, bool flag)
{
if (menuItem1.Tag.ToString() == right && flag)
{
menuItem1.Visibility = Visibility.Collapsed;
}
if (menuItem1.Tag.ToString() == right && flag == false)
{
menuItem1.Visibility = Visibility.Visible;
}
if (menuItem1.Tag.ToString() == deny && flag == false)
{
menuItem1.Visibility = Visibility.Collapsed;
}
if (menuItem1.Tag.ToString() == deny && flag)
{
menuItem1.Visibility = Visibility.Visible;
}
}
private ContextMenu SelectAnnotContextMenu(object sender)
{
var popMenu = App.Current.FindResource("SelectAnnotContextMenu") as ContextMenu;
if (popMenu != null && popMenu.Items.Count == 4)
{
//剪切
MenuItem menuItem = popMenu.Items[0] as MenuItem;
menuItem.CommandTarget = (UIElement)sender;
menuItem.Command = ApplicationCommands.Cut;
//复制
menuItem = popMenu.Items[1] as MenuItem;
menuItem.CommandTarget = (UIElement)sender;
menuItem.Command = ApplicationCommands.Copy;
//删除
menuItem = popMenu.Items[2] as MenuItem;
menuItem.CommandTarget = (UIElement)sender;
menuItem.Command = ApplicationCommands.Delete;
//笔记
//menuItem = popMenu.Items[2] as MenuItem;
//menuItem.CommandTarget = (UIElement)sender;
//menuItem.Command = ApplicationCommands.no;
}
return popMenu;
}
private ContextMenu NoneSelectAnnotContextMenu(object sender, AnnotCommandArgs annotCommand)
{
ContextMenu popMenu = new ContextMenu();
popMenu.FontSize = 14;
//if (popMenu.Items.Count > 0)
//{
// popMenu.Items.Clear();
//}
MenuItem menuItem = new MenuItem();
menuItem = new MenuItem();
menuItem.CommandTarget = (UIElement)sender;
menuItem.Command = ApplicationCommands.Copy;
popMenu.Items.Add(menuItem);
menuItem = new MenuItem();
menuItem.CommandTarget = (UIElement)sender;
menuItem.Command = ApplicationCommands.Paste;
popMenu.Items.Add(menuItem);
//Separator separator = (Separator)App.Current.FindResource("Separator");
Separator separator = new Separator();
separator.Height = 1;
separator.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#33000000"));
separator.BorderThickness = new Thickness(1);
separator.Width = popMenu.Width;
separator.Style = (Style)App.Current.FindResource(System.Windows.Controls.ToolBar.SeparatorStyleKey);
popMenu.Items.Add(separator);
menuItem = new MenuItem();
SetSelectTextOrImageMenuItem("高亮", "HighLight", annotCommand, out menuItem);
popMenu.Items.Add(menuItem);
menuItem = new MenuItem();
SetSelectTextOrImageMenuItem("下划线", "UnderLine", annotCommand, out menuItem);
popMenu.Items.Add(menuItem);
menuItem = new MenuItem();
SetSelectTextOrImageMenuItem("删除线", "Strikeout", annotCommand, out menuItem);
popMenu.Items.Add(menuItem);
menuItem = new MenuItem();
SetSelectTextOrImageMenuItem("文本", "Freetext", annotCommand, out menuItem);
popMenu.Items.Add(menuItem);
menuItem = new MenuItem();
SetSelectTextOrImageMenuItem("便签", "StickyNote", annotCommand, out menuItem);
popMenu.Items.Add(menuItem);
menuItem = new MenuItem();
SetSelectTextOrImageMenuItem("矩形", "Rect", annotCommand, out menuItem);
popMenu.Items.Add(menuItem);
menuItem = new MenuItem();
SetSelectTextOrImageMenuItem("添加链接", "Link", annotCommand, out menuItem);
popMenu.Items.Add(menuItem);
//menuItem.CommandParameter = new object[] { this, annotCommand };
//menuItem.Command = viewContentViewModel.CreateLinkCommand;
//menuItem.Click -= AddLink_Click;
//menuItem.Click += AddLink_Click;
//popMenu.Items.Add(menuItem);
return popMenu;
}
private void AnnotToolMenu_Click(object sender, RoutedEventArgs e)
{
MenuItem clickMenu = sender as MenuItem;
if (clickMenu != null && clickMenu.CommandParameter is AnnotCommandArgs)
{
AnnotCommandArgs annotCommand = clickMenu.CommandParameter as AnnotCommandArgs;
//AnnotHandlerEventArgs annotHandlerEvent = null;
//FindAnnotTypeKey(clickMenu.Tag.ToString(), ref annotHandlerEvent, true);
switch (clickMenu.Tag.ToString())
{
case "SnapshotEdit"://内容选择
break;
case "HighLight"://字体高亮
TextHighlightAnnotArgs highlightArgs = (TextHighlightAnnotArgs)GetHighLight();
highlightArgs.ClientRect = annotCommand.TextRect;
highlightArgs.Content = annotCommand.Text;
bool flag = PDFViewer.CreatePageAnnot(annotCommand.PageIndex, highlightArgs);
break;
case "UnderLine"://下划线
break;
case "Squiggly"://波浪线
break;
case "Strikeout"://删除线
break;
case "Freehand"://手绘
break;
case "Freetext"://文本
FreeTextAnnotArgs textArgs = new FreeTextAnnotArgs();
textArgs.ClientRect = annotCommand.TextRect;
textArgs.Transparency = 1;
textArgs.BgColor = Colors.Transparent;
textArgs.LineColor = Colors.Red;
textArgs.LineWidth = 2;
//textArgs.TextContent = annotCommand.Text;
PDFViewer.CreatePageAnnot(annotCommand.PageIndex, textArgs);
break;
case "StickyNote"://便签
StickyAnnotArgs stickyAnnotArgs = (StickyAnnotArgs)GetStickyNote();
//stickyAnnotArgs.StickyNote = annotCommand.Text;
//stickyAnnotArgs.Color = annotProperty.ForgoundColor;
//stickyAnnotArgs.StickyNote = annotProperty.NoteText;
//stickyAnnotArgs.Transparency = annotProperty.Opacity;
stickyAnnotArgs.ClientRect = annotCommand.TextRect;
PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
break;
case "Rect"://矩形
SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
squareAnnotArgs.ClientRect = annotCommand.TextRect;
PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
break;
case "Circle"://圆
break;
case "Arrow"://箭头
case "Line"://线
break;
case "Stamp"://图章
break;
case "Image":
break;
case "Signature"://签名
break;
case "Link"://链接
LinkAnnotArgs linkArgs = new LinkAnnotArgs();
linkArgs.ClientRect = annotCommand.TextRect;
linkArgs.URI = string.Empty;
linkArgs.LinkType = LINK_TYPE.GOTO;
linkArgs.DestIndex = annotCommand.PageIndex;
PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
BtnLinkIsChecked = true;
AnnotHandlerEventArgs annotArgs = GetLink(linkArgs);
PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
PDFViewer.SetToolParam(annotArgs);
viewContentViewModel.IsPropertyOpen = true;
break;
}
}
}
private void SetSelectTextOrImageMenuItem(string header, string tag, AnnotCommandArgs annotCommand, out MenuItem menuItem)
{
menuItem = new MenuItem();
menuItem.Header = header;
menuItem.Tag = tag;
menuItem.Click -= AnnotToolMenu_Click;
menuItem.Click += AnnotToolMenu_Click;
menuItem.CommandParameter = annotCommand;
}
#endregion 菜单
}
}