|
@@ -1,10 +1,16 @@
|
|
|
-using ComPDFKit.Controls.Data;
|
|
|
+using ComPDFKit.Controls.Common;
|
|
|
+using ComPDFKit.Controls.Data;
|
|
|
using ComPDFKit.Controls.PDFControl;
|
|
|
using ComPDFKit.PDFAnnotation;
|
|
|
using ComPDFKit.PDFDocument;
|
|
|
using ComPDFKit.Tool;
|
|
|
+using ComPDFKit.Tool.Help;
|
|
|
using ComPDFKit.Tool.UndoManger;
|
|
|
+using ComPDFKitViewer.Annot;
|
|
|
+using ComPDFKitViewer.Helper;
|
|
|
using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Media;
|
|
|
|
|
@@ -24,7 +30,7 @@ namespace ComPDFKit.Controls.PDFControlUI
|
|
|
|
|
|
private AnnotHistory GetHistory()
|
|
|
{
|
|
|
- if(annotCore != null && annotCore.IsValid())
|
|
|
+ if (annotCore != null && annotCore.IsValid())
|
|
|
{
|
|
|
return new PolygonAnnotHistory();
|
|
|
}
|
|
@@ -38,32 +44,210 @@ namespace ComPDFKit.Controls.PDFControlUI
|
|
|
ctlBorderColorPicker.ColorChanged -= CtlBorderColorPicker_ColorChanged;
|
|
|
ctlFillColorPicker.ColorChanged -= CtlFillColorPicker_ColorChanged;
|
|
|
CPDFOpacityControl.OpacityChanged -= CPDFOpacityControl_OpacityChanged;
|
|
|
+ CPDFThicknessControl.ThicknessChanged -= CPDFThicknessControl_ThicknessChanged;
|
|
|
+ CPDFLineShapeControl.LineShapeChanged -= CPDFLineShapeControl_LineShapeChanged;
|
|
|
+ ctlLineStyle.LineStyleChanged -= CtlLineStyle_LineStyleChanged;
|
|
|
|
|
|
ctlBorderColorPicker.ColorChanged += CtlBorderColorPicker_ColorChanged;
|
|
|
ctlFillColorPicker.ColorChanged += CtlFillColorPicker_ColorChanged;
|
|
|
CPDFOpacityControl.OpacityChanged += CPDFOpacityControl_OpacityChanged;
|
|
|
+ CPDFThicknessControl.ThicknessChanged += CPDFThicknessControl_ThicknessChanged;
|
|
|
+ CPDFLineShapeControl.LineShapeChanged += CPDFLineShapeControl_LineShapeChanged;
|
|
|
+ ctlLineStyle.LineStyleChanged += CtlLineStyle_LineStyleChanged;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CtlLineStyle_LineStyleChanged(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ if (annotParam == null)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (annotCore != null && annotCore.IsValid())
|
|
|
+ {
|
|
|
+ float[] dashArray = null;
|
|
|
+ C_BORDER_STYLE borderStyle;
|
|
|
+ if (ctlLineStyle.DashStyle == DashStyles.Solid || ctlLineStyle.DashStyle == null)
|
|
|
+ {
|
|
|
+ dashArray = new float[0];
|
|
|
+ borderStyle = C_BORDER_STYLE.BS_SOLID;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ List<float> floatArray = new List<float>();
|
|
|
+ foreach (double num in ctlLineStyle.DashStyle.Dashes)
|
|
|
+ {
|
|
|
+ floatArray.Add((float)num);
|
|
|
+ }
|
|
|
+ dashArray = floatArray.ToArray();
|
|
|
+ borderStyle = C_BORDER_STYLE.BS_DASHDED;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (viewControl != null && viewControl.PDFViewTool != null)
|
|
|
+ {
|
|
|
+ AnnotHistory history = GetHistory();
|
|
|
+ history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
|
|
|
+ history.Action = HistoryAction.Update;
|
|
|
+ CPDFPolygonAnnotation polygonAnnotation = annotCore as CPDFPolygonAnnotation;
|
|
|
+ if (polygonAnnotation == null || polygonAnnotation.Dash.SequenceEqual(dashArray)) return;
|
|
|
+ history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
|
|
|
+ polygonAnnotation.SetBorderStyle(borderStyle, dashArray);
|
|
|
+ history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
|
|
|
+ annotCore.UpdateAp();
|
|
|
+ viewControl.UpdateAnnotFrame();
|
|
|
+ viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CPDFLineShapeControl_LineShapeChanged(object sender, CPDFBorderEffector e)
|
|
|
+ {
|
|
|
+ if (IsLoadedData)
|
|
|
+ {
|
|
|
+ if (annotCore != null && annotCore.IsValid())
|
|
|
+ {
|
|
|
+ (annotCore as CPDFPolygonAnnotation).SetAnnotBorderEffector(e);
|
|
|
+ annotCore.UpdateAp();
|
|
|
+ viewControl.UpdateAnnotFrame();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CPDFThicknessControl_ThicknessChanged(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ if (IsLoadedData)
|
|
|
+ {
|
|
|
+ if (annotCore != null && annotCore.IsValid())
|
|
|
+ {
|
|
|
+ double thickness = (sender as CPDFThicknessControl).Thickness;
|
|
|
+
|
|
|
+ if (Math.Abs(thickness - annotCore.GetTransparency()) > 1)
|
|
|
+ {
|
|
|
+ annotCore.SetBorderWidth((byte)thickness);
|
|
|
+ annotCore.UpdateAp();
|
|
|
+ viewControl.UpdateAnnotFrame();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ if (IsLoadedData)
|
|
|
+ {
|
|
|
+ if (annotCore != null && annotCore.IsValid())
|
|
|
+ {
|
|
|
+ double opacity = (sender as CPDFOpacityControl).OpacityValue / 100.0;
|
|
|
+ if (opacity > 0 && opacity <= 1)
|
|
|
+ {
|
|
|
+ opacity *= 255;
|
|
|
+ }
|
|
|
+ if (Math.Abs(opacity - annotCore.GetTransparency()) > 0.01)
|
|
|
+ {
|
|
|
+ annotCore.SetTransparency((byte)opacity);
|
|
|
+ annotCore.UpdateAp();
|
|
|
+ viewControl.UpdateAnnotFrame();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void CtlFillColorPicker_ColorChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ if (IsLoadedData)
|
|
|
+ {
|
|
|
+ if (annotCore != null && annotCore.IsValid())
|
|
|
+ {
|
|
|
+ if (annotCore is CPDFPolygonAnnotation polygonAnnotation)
|
|
|
+ {
|
|
|
+ PolygonAnnotHistory history = new PolygonAnnotHistory();
|
|
|
+ history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
|
|
|
+ history.Action = ComPDFKitViewer.Helper.HistoryAction.Update;
|
|
|
+ SolidColorBrush brush = (sender as ColorPickerControl)?.Brush as SolidColorBrush;
|
|
|
+
|
|
|
+ polygonAnnotation.SetBgColor(new byte[3]
|
|
|
+ {
|
|
|
+ brush.Color.R,
|
|
|
+ brush.Color.G,
|
|
|
+ brush.Color.B
|
|
|
+ });
|
|
|
+ history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
|
|
|
+
|
|
|
+ annotCore.UpdateAp();
|
|
|
+ viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
|
|
|
+ viewControl.UpdateAnnotFrame();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void CtlBorderColorPicker_ColorChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
- throw new NotImplementedException();
|
|
|
+ if (IsLoadedData)
|
|
|
+ {
|
|
|
+ if (annotCore != null && annotCore.IsValid())
|
|
|
+ {
|
|
|
+ if (annotCore is CPDFPolygonAnnotation polygonAnnotation)
|
|
|
+ {
|
|
|
+ PolygonAnnotHistory history = new PolygonAnnotHistory();
|
|
|
+ history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
|
|
|
+ history.Action = ComPDFKitViewer.Helper.HistoryAction.Update;
|
|
|
+ SolidColorBrush brush = (sender as ColorPickerControl)?.Brush as SolidColorBrush;
|
|
|
+ polygonAnnotation.SetLineColor(new byte[3]
|
|
|
+ {
|
|
|
+ brush.Color.R,
|
|
|
+ brush.Color.G,
|
|
|
+ brush.Color.B
|
|
|
+ });
|
|
|
+
|
|
|
+ history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
|
|
|
+
|
|
|
+ annotCore.UpdateAp();
|
|
|
+
|
|
|
+ viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
|
|
|
+ viewControl.UpdateAnnotFrame();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public void SetPresentAnnotAttrib(PolygonMeasureParam polygonParam, CPDFPolygonAnnotation annotation, CPDFDocument document, PDFViewControl view)
|
|
|
+ public void SetPresentAnnotAttrib(PolygonMeasureParam polygonParam, CPDFPolygonAnnotation annotation, PDFViewControl view, int PageCount)
|
|
|
{
|
|
|
annotParam = polygonParam;
|
|
|
annotCore = annotation;
|
|
|
- viewControl = view;
|
|
|
+ viewControl = view;
|
|
|
+ if (polygonParam == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Color lineColor = Color.FromRgb(polygonParam.LineColor[0], polygonParam.LineColor[1], polygonParam.LineColor[2]);
|
|
|
+
|
|
|
+ ctlBorderColorPicker.SetCheckedForColor(lineColor);
|
|
|
+
|
|
|
+ double opacity = polygonParam.Transparency / 255.0 * 100.0;
|
|
|
+ CPDFOpacityControl.OpacityValue = (int)Math.Ceiling(opacity);
|
|
|
+
|
|
|
+ float thickness = polygonParam.LineWidth;
|
|
|
+ CPDFThicknessControl.Thickness = (int)Math.Ceiling(thickness);
|
|
|
+
|
|
|
+ CPDFLineShapeControl.BorderEffector = annotation.GetAnnotBorderEffector();
|
|
|
+ if (polygonParam.BorderStyle == C_BORDER_STYLE.BS_SOLID)
|
|
|
+ {
|
|
|
+ ctlLineStyle.DashStyle = DashStyles.Solid;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ List<double> dashArray = new List<double>();
|
|
|
+ foreach (double num in polygonParam.LineDash)
|
|
|
+ {
|
|
|
+ dashArray.Add(num);
|
|
|
+ }
|
|
|
+ ctlLineStyle.DashStyle = new DashStyle(dashArray, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ NoteTextBox.Text = polygonParam.Content;
|
|
|
}
|
|
|
|
|
|
public CPDFAnnotationData GetPolygonData()
|
|
@@ -91,5 +275,18 @@ namespace ComPDFKit.Controls.PDFControlUI
|
|
|
{
|
|
|
IsLoadedData = false;
|
|
|
}
|
|
|
+
|
|
|
+ private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ {
|
|
|
+ if (IsLoadedData)
|
|
|
+ {
|
|
|
+ if (annotCore != null && annotCore.IsValid())
|
|
|
+ {
|
|
|
+ annotCore.SetContent(NoteTextBox.Text);
|
|
|
+ annotCore.UpdateAp();
|
|
|
+ viewControl?.UpdateAnnotFrame();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|