|
@@ -20,6 +20,7 @@ using ComPDFKit.Tool;
|
|
|
using ComPDFKit.PDFAnnotation;
|
|
|
using ComPDFKit.Import;
|
|
|
using ComPDFKitViewer.Helper;
|
|
|
+using ComPDFKitViewer.Annot;
|
|
|
|
|
|
namespace Compdfkit_Tools.PDFControl
|
|
|
{
|
|
@@ -58,23 +59,63 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
|
|
|
private CPDFViewerTool cPDFViewerTool;
|
|
|
CPDFAnnotation cPDFAnnotation;
|
|
|
+ bool openCreateAnnot = false;
|
|
|
+ bool selectedAnnot = false;
|
|
|
+ CPDFAnnotationData pdfAnnotationData = null;
|
|
|
+ C_ANNOTATION_TYPE CreateAnnotType = C_ANNOTATION_TYPE.C_ANNOTATION_UNKOWN;
|
|
|
public void LoadPDFViewToolHandler()
|
|
|
{
|
|
|
- cPDFViewerTool.SetViewerModel(ComPDFKit.Tool.ViewerModel.kCreateAnnot);
|
|
|
+ cPDFViewerTool.SetViewerModel(ComPDFKit.Tool.MouseModess.kViewer);
|
|
|
cPDFViewerTool.MouseLeftButtonDownHandler += CPDFViewerTool_MouseLeftButtonDownHandler;
|
|
|
cPDFViewerTool.MouseLeftButtonUpHandler += CPDFViewerTool_MouseLeftButtonUpHandler;
|
|
|
cPDFViewerTool.MouseMoveHandler += CPDFViewerTool_MouseMoveHandler;
|
|
|
+ cPDFViewerTool.SelectedDataChanging += CPDFViewerTool_SelectedDataChanging;
|
|
|
+ cPDFViewerTool.SelectedDataChanged += CPDFViewerTool_SelectedDataChanged;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CPDFViewerTool_SelectedDataChanged(object sender, ComPDFKit.Tool.DrawRect.SelectedRectData e)
|
|
|
+ {
|
|
|
+ if (e.annotData.AnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
|
|
|
+ {
|
|
|
+ CPDFLineAnnotation annotLine = (e.annotData.Annot as CPDFLineAnnotation);
|
|
|
+ //annotLine.SetLinePoints(startPoint, endPoint);
|
|
|
+ //annotLine.UpdateAp();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Rect rect1 = new Rect(
|
|
|
+ (e.Square.Left - e.annotData.PaintOffset.X) / e.annotData.CurrentZoom,
|
|
|
+ (e.Square.Top - e.annotData.PaintOffset.Y) / e.annotData.CurrentZoom,
|
|
|
+ e.Square.Width / e.annotData.CurrentZoom,
|
|
|
+ e.Square.Height / e.annotData.CurrentZoom
|
|
|
+ );
|
|
|
+ Rect rect = DpiHelper.StandardRectToPDFRect(rect1);
|
|
|
+ CRect cRect = new CRect((float)rect.Left, (float)rect.Bottom, (float)rect.Right, (float)rect.Top);
|
|
|
+ e.annotData.Annot.SetRect(cRect);
|
|
|
+ }
|
|
|
+ cPDFViewerTool.GetCPDFViewer().UpDataRenderFrame();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CPDFViewerTool_SelectedDataChanging(object sender, ComPDFKit.Tool.DrawRect.SelectedRectData e)
|
|
|
+ {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void CPDFViewerTool_MouseMoveHandler(object sender, MouseHitTeseType e)
|
|
|
{
|
|
|
if (e == ComPDFKit.Tool.MouseHitTeseType.kSelectRect)
|
|
|
{
|
|
|
-
|
|
|
+ if (selectedAnnot)
|
|
|
+ {
|
|
|
+ cPDFViewerTool.DrawMoveSelectedRect();
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- cPDFViewerTool.MoveDrawAnnot();
|
|
|
+ if (!openCreateAnnot)
|
|
|
+ {
|
|
|
+ cPDFViewerTool.MoveDrawAnnot();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -82,26 +123,29 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
{
|
|
|
if (e == ComPDFKit.Tool.MouseHitTeseType.kSelectRect)
|
|
|
{
|
|
|
-
|
|
|
+ if (selectedAnnot)
|
|
|
+ {
|
|
|
+ cPDFViewerTool.DrawEndSelectedRect();
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Rect rect = cPDFViewerTool.EndDrawAnnot();
|
|
|
- if (cPDFAnnotation != null)
|
|
|
+ if (!openCreateAnnot)
|
|
|
{
|
|
|
- Rect maxRect = cPDFViewerTool.GetDrawAnnotMaxRect();
|
|
|
- double zoom = cPDFViewerTool.GetCPDFViewer().GetZoom();
|
|
|
- Rect rect1 = new Rect(
|
|
|
- (rect.Left - maxRect.X) / zoom,
|
|
|
- (rect.Top - maxRect.Y) / zoom,
|
|
|
- rect.Width / zoom,
|
|
|
- rect.Height / zoom
|
|
|
- );
|
|
|
- Rect rect2 = DpiHelper.StandardRectToPDFRect(rect1);
|
|
|
- CRect cRect = new CRect((float)rect2.Left, (float)rect2.Bottom, (float)rect2.Right, (float)rect2.Top);
|
|
|
- cPDFAnnotation.SetRect(cRect);
|
|
|
- cPDFViewerTool.ClearDrawAnnot();
|
|
|
- cPDFViewerTool.GetCPDFViewer().UpDataRenderFrame();
|
|
|
+ Rect rect = cPDFViewerTool.EndDrawAnnot();
|
|
|
+ if (cPDFAnnotation != null)
|
|
|
+ {
|
|
|
+ if (rect.Width <= 0 && rect.Width <= 0)
|
|
|
+ {
|
|
|
+ cPDFAnnotation.RemoveAnnot();
|
|
|
+ cPDFAnnotation = null;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CRect cRect = new CRect((float)rect.Left, (float)rect.Bottom, (float)rect.Right, (float)rect.Top);
|
|
|
+ cPDFAnnotation.SetRect(cRect);
|
|
|
+ cPDFViewerTool.ClearDrawAnnot();
|
|
|
+ cPDFViewerTool.GetCPDFViewer().UpDataRenderFrame();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -110,14 +154,232 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
{
|
|
|
if (e == ComPDFKit.Tool.MouseHitTeseType.kUnknown)
|
|
|
{
|
|
|
- cPDFAnnotation = cPDFViewerTool.StartDrawAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE);
|
|
|
- if (cPDFAnnotation != null)
|
|
|
+ if (!openCreateAnnot)
|
|
|
+ {
|
|
|
+ if (CreateAnnotType!= C_ANNOTATION_TYPE.C_ANNOTATION_UNKOWN)
|
|
|
+ {
|
|
|
+ cPDFAnnotation = cPDFViewerTool.StartDrawAnnot(CreateAnnotType);
|
|
|
+ if (cPDFAnnotation != null)
|
|
|
+ {
|
|
|
+ cPDFViewerTool.CleanSelectedRect();
|
|
|
+ selectedAnnot = false;
|
|
|
+ SetAnnotAttributes(cPDFAnnotation, pdfAnnotationData);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
cPDFViewerTool.CleanSelectedRect();
|
|
|
- (cPDFAnnotation as CPDFSquareAnnotation).SetLineWidth(2);
|
|
|
- return;
|
|
|
+ selectedAnnot = false;
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ cPDFViewerTool.DrawStartSelectedSaRect();
|
|
|
+ selectedAnnot = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SetAnnotAttributes(CPDFAnnotation cPDFAnnotation, CPDFAnnotationData data)
|
|
|
+ {
|
|
|
+ if (pdfAnnotationData==null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ switch (cPDFAnnotation.Type)
|
|
|
+ {
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_UNKOWN:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
|
|
|
+ if (data.AnnotationType == CPDFAnnotationType.Square)
|
|
|
+ {
|
|
|
+
|
|
|
+ CPDFShapeData squareData = data as CPDFShapeData;
|
|
|
+ CPDFSquareAnnotation squareAnnot = cPDFAnnotation as CPDFSquareAnnotation;
|
|
|
+ squareAnnot.SetLineWidth(squareData.Thickness);
|
|
|
+ byte[] bgColor = { squareData.FillColor.R, squareData.FillColor.G, squareData.FillColor.B };
|
|
|
+ if (squareData.FillColor != Colors.Transparent)
|
|
|
+ {
|
|
|
+ squareAnnot.SetBgColor(bgColor);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ squareAnnot.ClearBgColor();
|
|
|
+ }
|
|
|
+ byte[] lineColor = { squareData.BorderColor.R, squareData.BorderColor.G, squareData.BorderColor.B };
|
|
|
+ squareAnnot.SetLineColor(lineColor);
|
|
|
+ byte transparency = (byte)Math.Round(squareData.Opacity * 255);
|
|
|
+ squareAnnot.SetTransparency(transparency);
|
|
|
+
|
|
|
+ if (squareData.DashStyle != null)
|
|
|
+ {
|
|
|
+ if (squareData.DashStyle.Dashes.Count == 0)
|
|
|
+ {
|
|
|
+ squareAnnot.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ List<float> floatArray = new List<float>();
|
|
|
+ foreach (var num in squareData.DashStyle.Dashes)
|
|
|
+ {
|
|
|
+ floatArray.Add((float)num);
|
|
|
+ }
|
|
|
+ squareAnnot.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, floatArray.ToArray());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ squareAnnot.SetAuthor(squareData.Author);
|
|
|
+ squareAnnot.SetContent(squareData.Note);
|
|
|
+ squareAnnot.UpdateAp();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
|
|
|
+ if (data.AnnotationType == CPDFAnnotationType.Circle)
|
|
|
+ {
|
|
|
+
|
|
|
+ CPDFShapeData circleData = data as CPDFShapeData;
|
|
|
+ CPDFCircleAnnotation circleAnnot = cPDFAnnotation as CPDFCircleAnnotation;
|
|
|
+ circleAnnot.SetLineWidth(circleData.Thickness);
|
|
|
+ byte[] bgColor = { circleData.FillColor.R, circleData.FillColor.G, circleData.FillColor.B };
|
|
|
+ if (circleData.FillColor!= Colors.Transparent)
|
|
|
+ {
|
|
|
+ circleAnnot.SetBgColor(bgColor);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ circleAnnot.ClearBgColor();
|
|
|
+ }
|
|
|
+ byte[] lineColor = { circleData.BorderColor.R, circleData.BorderColor.G, circleData.BorderColor.B };
|
|
|
+ circleAnnot.SetLineColor(lineColor);
|
|
|
+ byte transparency = (byte)Math.Round(circleData.Opacity * 255);
|
|
|
+ circleAnnot.SetTransparency(transparency);
|
|
|
+
|
|
|
+ if (circleData.DashStyle != null)
|
|
|
+ {
|
|
|
+ if (circleData.DashStyle.Dashes.Count == 0)
|
|
|
+ {
|
|
|
+ circleAnnot.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ List<float> floatArray = new List<float>();
|
|
|
+ foreach (var num in circleData.DashStyle.Dashes)
|
|
|
+ {
|
|
|
+ floatArray.Add((float)num);
|
|
|
+ }
|
|
|
+ circleAnnot.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, floatArray.ToArray());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ circleAnnot.SetAuthor(circleData.Author);
|
|
|
+ circleAnnot.SetContent(circleData.Note);
|
|
|
+ circleAnnot.UpdateAp();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_CARET:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_POPUP:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_FILEATTACHMENT:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_MOVIE:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_SCREEN:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_PRINTERMARK:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_TRAPNET:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_WATERMARK:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_3D:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
|
|
|
+ break;
|
|
|
+ case C_ANNOTATION_TYPE.C_ANNOTATION_INTERCHANGE:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SetCreateAnnot(CPDFAnnotationData data)
|
|
|
+ {
|
|
|
+ CPDFAnnotationType annotationType = data.AnnotationType;
|
|
|
+ pdfAnnotationData = data;
|
|
|
+ switch (annotationType)
|
|
|
+ {
|
|
|
+ case CPDFAnnotationType.Unknow:
|
|
|
+ cPDFViewerTool.SetViewerModel(ComPDFKit.Tool.MouseModess.kViewer);
|
|
|
+ return;
|
|
|
+ case CPDFAnnotationType.Highlight:
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Underline:
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Strikeout:
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Squiggly:
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.FreeText:
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Freehand:
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Note:
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Circle:
|
|
|
+ CreateAnnotType = C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE;
|
|
|
+ cPDFViewerTool.SetViewerModel(ComPDFKit.Tool.MouseModess.kCreateAnnot);
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Square:
|
|
|
+ CreateAnnotType = C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE;
|
|
|
+ cPDFViewerTool.SetViewerModel(ComPDFKit.Tool.MouseModess.kCreateAnnot);
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Arrow:
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Line:
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Stamp:
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Signature:
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Link:
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Audio:
|
|
|
+ break;
|
|
|
+ case CPDFAnnotationType.Image:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
@@ -127,10 +389,11 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
InitializeComponent();
|
|
|
}
|
|
|
|
|
|
- public void SetPDFViewer(CPDFViewer pdfViewer,CPDFViewerTool tool)
|
|
|
+
|
|
|
+ public void SetPDFViewer(CPDFViewer pdfViewer, CPDFViewerTool tool)
|
|
|
{
|
|
|
cPDFViewerTool = tool;
|
|
|
- if (cPDFViewerTool!=null)
|
|
|
+ if (cPDFViewerTool != null)
|
|
|
{
|
|
|
LoadPDFViewToolHandler();
|
|
|
}
|
|
@@ -282,6 +545,8 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ SetCreateAnnot(pdfAnnotationData);
|
|
|
+
|
|
|
CPDFAnnotationType annotationType = pdfAnnotationData.AnnotationType;
|
|
|
AnnotHandlerEventArgs annotHandlerEventArgs = null;
|
|
|
Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
|