|
@@ -1,5 +1,7 @@
|
|
|
-using ComPDFKitViewer;
|
|
|
+using ComPDFKit.PDFAnnotation;
|
|
|
+using ComPDFKitViewer;
|
|
|
using ComPDFKitViewer.AnnotEvent;
|
|
|
+using PDF_Office.Helper;
|
|
|
using PDF_Office.Model;
|
|
|
using PDF_Office.ViewModels.Tools;
|
|
|
using Prism.Commands;
|
|
@@ -7,15 +9,49 @@ using Prism.Mvvm;
|
|
|
using Prism.Regions;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Globalization;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using System.Windows;
|
|
|
+using System.Windows.Controls;
|
|
|
+using System.Windows.Data;
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
{
|
|
|
+
|
|
|
+ public class DashStyleConverter : IValueConverter
|
|
|
+ {
|
|
|
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
+ {
|
|
|
+ if (value is DashStyle)
|
|
|
+ {
|
|
|
+ var dash = value as DashStyle;
|
|
|
+ if (dash.Dashes.Count == 0 || dash.Dashes[0] == 0)
|
|
|
+ {
|
|
|
+ return DashStyles.Solid.Dashes;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DashStyle dashx = new DashStyle();
|
|
|
+ dashx.Dashes.Add(1);
|
|
|
+ dashx.Dashes.Add(1);
|
|
|
+ return dashx.Dashes;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
+ }
|
|
|
public class SharpsAnnotPropertyViewModel : BindableBase, INavigationAware
|
|
|
{
|
|
|
+ #region 属性
|
|
|
+
|
|
|
private AnnotArgsType annotType;
|
|
|
public AnnotArgsType AnnotType
|
|
|
{
|
|
@@ -53,14 +89,14 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
public Brush FillColor
|
|
|
{
|
|
|
get { return fillColor; }
|
|
|
- set {
|
|
|
+ set
|
|
|
+ {
|
|
|
SetProperty(ref fillColor, value);
|
|
|
AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, (fillColor as SolidColorBrush).Color);
|
|
|
AnnotEvent?.UpdateAnnot();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private double borderOpacity = 1;
|
|
|
public double BorderOpacity
|
|
|
{
|
|
@@ -88,11 +124,50 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
set
|
|
|
{
|
|
|
SetProperty(ref lineWidth, value);
|
|
|
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, lineWidth);
|
|
|
+
|
|
|
+ if (annotType == AnnotArgsType.AnnotLine)
|
|
|
+ AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, lineWidth);
|
|
|
+ else
|
|
|
+ AnnotEvent?.UpdateAttrib(AnnotAttrib.Thickness, lineWidth);
|
|
|
+
|
|
|
+ AnnotEvent?.UpdateAnnot();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Geometry dataPath = null;
|
|
|
+ public Geometry DataPath
|
|
|
+ {
|
|
|
+ get { return dataPath; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref dataPath, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private DashStyle dash = new DashStyle();
|
|
|
+ public DashStyle Dash
|
|
|
+ {
|
|
|
+ get { return dash; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref dash, value);
|
|
|
+ if(dash.Dashes[0] == 0)
|
|
|
+ {
|
|
|
+ AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, DashStyles.Solid);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dash);
|
|
|
+ }
|
|
|
+
|
|
|
AnnotEvent?.UpdateAnnot();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
public DelegateCommand<object> SelectedThickCommand { get; set; }
|
|
|
public DelegateCommand<object> SelectedColorCommand { get; set; }
|
|
|
|
|
@@ -100,6 +175,11 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
public DelegateCommand<object> SelectedFillColorCommand { get; set; }
|
|
|
|
|
|
public DelegateCommand<object> LineStyleCommand { get; set; }
|
|
|
+
|
|
|
+ public DelegateCommand<object> SharpsTypeCommand { get; set; }
|
|
|
+ public DelegateCommand<object> ThicknessChangedCommand { get; set; }
|
|
|
+
|
|
|
+ public event EventHandler<object> LoadPropertyHandler;
|
|
|
public SharpsAnnotPropertyViewModel()
|
|
|
{
|
|
|
SelectedThickCommand = new DelegateCommand<object>(SelectedThick_Command);
|
|
@@ -107,6 +187,85 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
SelectedFillOpacityCommand = new DelegateCommand<object>(SelectedFillOpacity_Command);
|
|
|
SelectedFillColorCommand = new DelegateCommand<object>(SelectedFillColor_Command);
|
|
|
LineStyleCommand = new DelegateCommand<object>(LineStyle_Command);
|
|
|
+ SharpsTypeCommand = new DelegateCommand<object>(SharpsType_Command);
|
|
|
+ ThicknessChangedCommand = new DelegateCommand<object>(ThicknessChanged_Command);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ThicknessChanged_Command(object obj)
|
|
|
+ {
|
|
|
+ if (obj != null)
|
|
|
+ {
|
|
|
+ var item = (ComboBoxItem)obj;
|
|
|
+ var content = (string)item.Content;
|
|
|
+ if (content != null)
|
|
|
+ {
|
|
|
+ var intData = int.Parse(content);
|
|
|
+ LineWidth = intData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SharpsType_Command(object obj)
|
|
|
+ {
|
|
|
+ if(obj != null)
|
|
|
+ {
|
|
|
+ var tag = (string)obj;
|
|
|
+ SharpsType(tag);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SharpsType(string tag,bool isFromToolsBtn = false)
|
|
|
+ {
|
|
|
+ Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
|
|
|
+ switch (tag)
|
|
|
+ {
|
|
|
+ case "Rect":
|
|
|
+ RectangleGeometry rectPath = new RectangleGeometry();
|
|
|
+ rectPath.Rect = new Rect(0, 5, 28, 22);
|
|
|
+ DataPath = rectPath;
|
|
|
+ changeData[AnnotArgsType.AnnotSquare] = tag;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "Circle":
|
|
|
+ EllipseGeometry circlePath = new EllipseGeometry();
|
|
|
+ circlePath.RadiusX = 14;
|
|
|
+ circlePath.RadiusY = 14;
|
|
|
+ circlePath.Center = new Point(14, 14);
|
|
|
+ DataPath = circlePath;
|
|
|
+ changeData[AnnotArgsType.AnnotCircle] = tag;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "Arrow":
|
|
|
+ {
|
|
|
+
|
|
|
+ ArrowHelper arrowLine = new ArrowHelper();
|
|
|
+ arrowLine.ArrowLength = 8;
|
|
|
+ arrowLine.LineStart = new Point(8, 24);
|
|
|
+ arrowLine.LineEnd = new Point(24, 8);
|
|
|
+ arrowLine.StartSharp = C_LINE_TYPE.LINETYPE_NONE;
|
|
|
+ arrowLine.EndSharp = C_LINE_TYPE.LINETYPE_ARROW;
|
|
|
+ DataPath = arrowLine.BuildArrowBody();
|
|
|
+ changeData[AnnotArgsType.AnnotLine] = tag;
|
|
|
+ // changeData[AnnotArgsType.AnnotLine] = tag;
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "Line":
|
|
|
+ {
|
|
|
+ ArrowHelper arrowLine = new ArrowHelper();
|
|
|
+ arrowLine.LineStart = new Point(0, 32);
|
|
|
+ arrowLine.LineEnd = new Point(32, 0);
|
|
|
+ DataPath = arrowLine.BuildArrowBody();
|
|
|
+ changeData[AnnotArgsType.AnnotLine] = tag;
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isFromToolsBtn == false)
|
|
|
+ PropertyPanel.AnnotTypeChangedInvoke(this, changeData);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -117,11 +276,18 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
var tag = obj as string;
|
|
|
if(tag == "Solid")
|
|
|
{
|
|
|
-
|
|
|
+ DashStyle dashAnnot = new DashStyle();
|
|
|
+ dashAnnot.Dashes.Add(0);
|
|
|
+ dashAnnot.Dashes.Add(0);
|
|
|
+ Dash = dashAnnot;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
+ DashStyle dashAnnot = new DashStyle();
|
|
|
+ dashAnnot.Dashes.Add(1);
|
|
|
+ dashAnnot.Dashes.Add(1);
|
|
|
+ Dash = dashAnnot;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -158,6 +324,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
changeData[AnnotArgsType.AnnotFreehand] = FillOpacity;
|
|
|
PropertyPanel.DataChangedInvoke(this, changeData);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void SelectedColor_Command(object obj)
|
|
@@ -175,12 +342,22 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
changeData[AnnotArgsType.AnnotFreehand] = obj;
|
|
|
PropertyPanel.DataChangedInvoke(this, changeData);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void SelectedThick_Command(object obj)
|
|
|
{
|
|
|
-
|
|
|
+ if (obj is double)
|
|
|
+ {
|
|
|
+ var tran = (double)obj;
|
|
|
+ BorderOpacity = tran;
|
|
|
+ SelectColor.Opacity = tran;
|
|
|
+
|
|
|
+ AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, tran);
|
|
|
+ AnnotEvent?.UpdateAnnot();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
|
@@ -203,14 +380,18 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
AnnotTypeTitle = "矩形";
|
|
|
break;
|
|
|
case AnnotArgsType.AnnotLine:
|
|
|
- AnnotTypeTitle = "线";
|
|
|
+
|
|
|
var annotLine = Annot as LineAnnotArgs;
|
|
|
if (annotLine != null)
|
|
|
{
|
|
|
-
|
|
|
+ if (annotLine.TailLineType == C_LINE_TYPE.LINETYPE_ARROW && annotLine.HeadLineType == C_LINE_TYPE.LINETYPE_NONE)
|
|
|
+ AnnotTypeTitle = "箭头";
|
|
|
+ else
|
|
|
+ AnnotTypeTitle = "线";
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public AnnotAttribEvent AnnotEvent { get; set; }
|
|
@@ -224,8 +405,68 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
AnnotEvent = PropertyPanel.AnnotEvent;
|
|
|
AnnotType = PropertyPanel.annot.EventType;
|
|
|
Annot = PropertyPanel.annot;
|
|
|
+ GetAnnotProperty();
|
|
|
+ LoadPropertyHandler?.Invoke(null, Annot);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ private void GetAnnotProperty()
|
|
|
+ {
|
|
|
+ if (Annot != null)
|
|
|
+ {
|
|
|
+ switch (Annot.EventType)
|
|
|
+ {
|
|
|
+ case AnnotArgsType.AnnotSquare:
|
|
|
+ if (Annot is SquareAnnotArgs)
|
|
|
+ {
|
|
|
+ var Square = Annot as SquareAnnotArgs;
|
|
|
+ SelectColor = new SolidColorBrush(Square.LineColor);
|
|
|
+ FillColor = new SolidColorBrush(Square.BgColor);
|
|
|
+ BorderOpacity = Square.Transparency;
|
|
|
+ FillOpacity = Square.Transparency;
|
|
|
+ LineWidth = Square.LineWidth;
|
|
|
+ SharpsType("Rect",true);
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case AnnotArgsType.AnnotCircle:
|
|
|
+ if (Annot is CircleAnnotArgs)
|
|
|
+ {
|
|
|
+ var Circle = Annot as CircleAnnotArgs;
|
|
|
+ SelectColor = new SolidColorBrush(Circle.LineColor);
|
|
|
+ FillColor = new SolidColorBrush(Circle.BgColor);
|
|
|
+ BorderOpacity = Circle.Transparency;
|
|
|
+ FillOpacity = Circle.Transparency;
|
|
|
+ LineWidth = Circle.LineWidth;
|
|
|
+ SharpsType("Circle", true);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case AnnotArgsType.AnnotLine:
|
|
|
+ if (Annot is LineAnnotArgs)
|
|
|
+ {
|
|
|
+ var line = Annot as LineAnnotArgs;
|
|
|
+ SelectColor = new SolidColorBrush(line.LineColor);
|
|
|
+ FillColor = new SolidColorBrush(line.LineColor);
|
|
|
+ BorderOpacity = line.Transparency;
|
|
|
+ FillOpacity = line.Transparency;
|
|
|
+ LineWidth = line.LineWidth;
|
|
|
+
|
|
|
+ if (line.TailLineType == C_LINE_TYPE.LINETYPE_ARROW && line.HeadLineType == C_LINE_TYPE.LINETYPE_NONE)
|
|
|
+ SharpsType("Arrow", true);
|
|
|
+ else
|
|
|
+ SharpsType("Line", true);
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|