|
@@ -1,10 +1,12 @@
|
|
using ComPDFKit.PDFAnnotation;
|
|
using ComPDFKit.PDFAnnotation;
|
|
|
|
+using ComPDFKit.Tool.Help;
|
|
using ComPDFKit.Tool.SettingParam;
|
|
using ComPDFKit.Tool.SettingParam;
|
|
using ComPDFKit.Viewer.Layer;
|
|
using ComPDFKit.Viewer.Layer;
|
|
using ComPDFKitViewer;
|
|
using ComPDFKitViewer;
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel;
|
|
|
|
+using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Reflection;
|
|
@@ -16,6 +18,7 @@ using System.Windows.Controls.Primitives;
|
|
using System.Windows.Input;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Media3D;
|
|
using System.Windows.Media.Media3D;
|
|
|
|
+using System.Windows.Shapes;
|
|
using System.Xml.Linq;
|
|
using System.Xml.Linq;
|
|
using static ComPDFKit.Tool.Help.ImportWin32;
|
|
using static ComPDFKit.Tool.Help.ImportWin32;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
@@ -28,14 +31,14 @@ namespace ComPDFKit.Tool.DrawTool
|
|
LeftTop,
|
|
LeftTop,
|
|
LeftMiddle,
|
|
LeftMiddle,
|
|
LeftBottom,
|
|
LeftBottom,
|
|
- MiddlBottom,
|
|
|
|
|
|
+ MiddleBottom,
|
|
RightBottom,
|
|
RightBottom,
|
|
RightMiddle,
|
|
RightMiddle,
|
|
RightTop,
|
|
RightTop,
|
|
- MiddleTop,
|
|
|
|
- Rotate,
|
|
|
|
|
|
+ MiddleTop,
|
|
Body,
|
|
Body,
|
|
- Line
|
|
|
|
|
|
+ Line,
|
|
|
|
+ Rotate
|
|
}
|
|
}
|
|
|
|
|
|
public enum SelectedType
|
|
public enum SelectedType
|
|
@@ -49,14 +52,15 @@ namespace ComPDFKit.Tool.DrawTool
|
|
public enum DrawPointType
|
|
public enum DrawPointType
|
|
{
|
|
{
|
|
Circle,
|
|
Circle,
|
|
- Square,
|
|
|
|
- Crop
|
|
|
|
|
|
+ Square,
|
|
|
|
+ Crop,
|
|
}
|
|
}
|
|
|
|
|
|
public enum DrawMoveType
|
|
public enum DrawMoveType
|
|
{
|
|
{
|
|
kDefault,
|
|
kDefault,
|
|
kReferenceLine,
|
|
kReferenceLine,
|
|
|
|
+ kRotatable
|
|
}
|
|
}
|
|
|
|
|
|
public class SelectedAnnotData
|
|
public class SelectedAnnotData
|
|
@@ -73,10 +77,11 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
|
|
|
public AnnotData annotData { get; set; }
|
|
public AnnotData annotData { get; set; }
|
|
|
|
|
|
|
|
+ public double rotationAngle { get; set; }
|
|
}
|
|
}
|
|
|
|
|
|
public partial class SelectedRect : DrawingVisual
|
|
public partial class SelectedRect : DrawingVisual
|
|
- {
|
|
|
|
|
|
+ {
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Re-layout child elements
|
|
/// Re-layout child elements
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -126,6 +131,8 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
|
|
|
protected bool isSelected = false;
|
|
protected bool isSelected = false;
|
|
|
|
|
|
|
|
+ protected bool canRotation = false;
|
|
|
|
+
|
|
protected SelectedType selectedType = SelectedType.None;
|
|
protected SelectedType selectedType = SelectedType.None;
|
|
|
|
|
|
public SelectedType GetSelectedType()
|
|
public SelectedType GetSelectedType()
|
|
@@ -177,13 +184,22 @@ namespace ComPDFKit.Tool.DrawTool
|
|
{
|
|
{
|
|
hitControlType = GetHitCropControlIndex(downPoint);
|
|
hitControlType = GetHitCropControlIndex(downPoint);
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
hitControlType = GetHitControlIndex(downPoint);
|
|
hitControlType = GetHitControlIndex(downPoint);
|
|
}
|
|
}
|
|
|
|
+
|
|
if (hitControlType != PointControlType.None)
|
|
if (hitControlType != PointControlType.None)
|
|
{
|
|
{
|
|
cacheRect = drawRect;
|
|
cacheRect = drawRect;
|
|
|
|
+ if(hitControlType != PointControlType.Rotate)
|
|
|
|
+ {
|
|
|
|
+ isInScaling = true;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ isInRotate = true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -193,6 +209,8 @@ namespace ComPDFKit.Tool.DrawTool
|
|
if (isMouseDown && hitControlType != PointControlType.None)
|
|
if (isMouseDown && hitControlType != PointControlType.None)
|
|
{
|
|
{
|
|
isMouseDown = false;
|
|
isMouseDown = false;
|
|
|
|
+ isInScaling = false;
|
|
|
|
+ isInRotate = false;
|
|
cacheRect = SetDrawRect = drawRect;
|
|
cacheRect = SetDrawRect = drawRect;
|
|
Draw();
|
|
Draw();
|
|
if ((int)upPoint.X != (int)mouseDownPoint.X || (int)upPoint.Y != (int)mouseDownPoint.Y)
|
|
if ((int)upPoint.X != (int)mouseDownPoint.X || (int)upPoint.Y != (int)mouseDownPoint.Y)
|
|
@@ -223,7 +241,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
}
|
|
}
|
|
|
|
|
|
public Cursor GetCursor(Point downPoint, Cursor cursor)
|
|
public Cursor GetCursor(Point downPoint, Cursor cursor)
|
|
- {
|
|
|
|
|
|
+ {
|
|
if (isMouseDown)
|
|
if (isMouseDown)
|
|
{
|
|
{
|
|
return cursor;
|
|
return cursor;
|
|
@@ -233,23 +251,22 @@ namespace ComPDFKit.Tool.DrawTool
|
|
{
|
|
{
|
|
case PointControlType.LeftTop:
|
|
case PointControlType.LeftTop:
|
|
case PointControlType.RightBottom:
|
|
case PointControlType.RightBottom:
|
|
- return Cursors.SizeNWSE;
|
|
|
|
-
|
|
|
|
|
|
+ return Cursors.SizeNWSE;
|
|
case PointControlType.LeftMiddle:
|
|
case PointControlType.LeftMiddle:
|
|
case PointControlType.RightMiddle:
|
|
case PointControlType.RightMiddle:
|
|
- return Cursors.SizeWE;
|
|
|
|
-
|
|
|
|
|
|
+ return Cursors.SizeWE;
|
|
case PointControlType.LeftBottom:
|
|
case PointControlType.LeftBottom:
|
|
case PointControlType.RightTop:
|
|
case PointControlType.RightTop:
|
|
return Cursors.SizeNESW;
|
|
return Cursors.SizeNESW;
|
|
-
|
|
|
|
- case PointControlType.MiddlBottom:
|
|
|
|
|
|
+ case PointControlType.MiddleBottom:
|
|
case PointControlType.MiddleTop:
|
|
case PointControlType.MiddleTop:
|
|
return Cursors.SizeNS;
|
|
return Cursors.SizeNS;
|
|
case PointControlType.Body:
|
|
case PointControlType.Body:
|
|
return Cursors.Arrow;
|
|
return Cursors.Arrow;
|
|
case PointControlType.Line:
|
|
case PointControlType.Line:
|
|
return Cursors.SizeAll;
|
|
return Cursors.SizeAll;
|
|
|
|
+ case PointControlType.Rotate:
|
|
|
|
+ return CommonHelper.RotationCursor;
|
|
default:
|
|
default:
|
|
return Cursors.Arrow;
|
|
return Cursors.Arrow;
|
|
}
|
|
}
|
|
@@ -299,8 +316,10 @@ namespace ComPDFKit.Tool.DrawTool
|
|
SolidColorBrush solidColorBrush = DrawParam.AnnotRectFillBrush;
|
|
SolidColorBrush solidColorBrush = DrawParam.AnnotRectFillBrush;
|
|
Pen pen = DrawParam.AnnotRectLinePen;
|
|
Pen pen = DrawParam.AnnotRectLinePen;
|
|
GetBrushAndPen(ref solidColorBrush, ref pen);
|
|
GetBrushAndPen(ref solidColorBrush, ref pen);
|
|
|
|
+ RotateTransform rotateTransform = new RotateTransform(rotateAngle, centerPoint.X, centerPoint.Y);
|
|
|
|
+ drawDC.PushTransform(rotateTransform);
|
|
drawDC?.DrawRectangle(solidColorBrush, pen, currentRect);
|
|
drawDC?.DrawRectangle(solidColorBrush, pen, currentRect);
|
|
-
|
|
|
|
|
|
+ drawDC.Pop();
|
|
SolidColorBrush PointBrush = DrawParam.AnnotPointBorderBrush;
|
|
SolidColorBrush PointBrush = DrawParam.AnnotPointBorderBrush;
|
|
Pen PointPen = DrawParam.AnnotPointPen;
|
|
Pen PointPen = DrawParam.AnnotPointPen;
|
|
GetPointBrushAndPen(ref PointBrush, ref PointPen);
|
|
GetPointBrushAndPen(ref PointBrush, ref PointPen);
|
|
@@ -310,16 +329,14 @@ namespace ComPDFKit.Tool.DrawTool
|
|
case DrawPointType.Circle:
|
|
case DrawPointType.Circle:
|
|
if (selectedType == SelectedType.PDFEdit)
|
|
if (selectedType == SelectedType.PDFEdit)
|
|
{
|
|
{
|
|
- DrawCirclePoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
|
|
|
|
-
|
|
|
|
- //DrawEditSelectionBox(drawDC, PointPen);
|
|
|
|
|
|
+ DrawCirclePoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
DrawCirclePoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
|
|
DrawCirclePoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
- case DrawPointType.Square:
|
|
|
|
|
|
+ case DrawPointType.Square:
|
|
DrawSquarePoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
|
|
DrawSquarePoint(drawDC, GetIgnorePoints(), pointSize, PointPen, PointBrush);
|
|
break;
|
|
break;
|
|
case DrawPointType.Crop:
|
|
case DrawPointType.Crop:
|
|
@@ -330,7 +347,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
drawDC = null;
|
|
drawDC = null;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private void GetMoveBrushAndPen(ref SolidColorBrush colorBrush, ref Pen pen)
|
|
private void GetMoveBrushAndPen(ref SolidColorBrush colorBrush, ref Pen pen)
|
|
{
|
|
{
|
|
switch (selectedType)
|
|
switch (selectedType)
|
|
@@ -340,7 +357,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
case SelectedType.Annot:
|
|
case SelectedType.Annot:
|
|
colorBrush = DrawParam.AnnotMoveBrush;
|
|
colorBrush = DrawParam.AnnotMoveBrush;
|
|
pen = DrawParam.AnnotMovePen;
|
|
pen = DrawParam.AnnotMovePen;
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
case SelectedType.PDFEdit:
|
|
case SelectedType.PDFEdit:
|
|
colorBrush = DrawParam.PDFEditMoveBrush;
|
|
colorBrush = DrawParam.PDFEditMoveBrush;
|
|
pen = DrawParam.PDFEditMovePen;
|
|
pen = DrawParam.PDFEditMovePen;
|
|
@@ -368,7 +385,8 @@ namespace ComPDFKit.Tool.DrawTool
|
|
}
|
|
}
|
|
else if (currentDrawPointType == DrawPointType.Crop)
|
|
else if (currentDrawPointType == DrawPointType.Crop)
|
|
{
|
|
{
|
|
- colorBrush = DrawParam.SPDFEditCropBorderBrush;//new SolidColorBrush((DrawParam.SPDFEditPointPen.Brush as SolidColorBrush).Color);
|
|
|
|
|
|
+ colorBrush = DrawParam.SPDFEditCropBorderBrush;
|
|
|
|
+ //new SolidColorBrush((DrawParam.SPDFEditPointPen.Brush as SolidColorBrush).Color);
|
|
pen = DrawParam.SPDFEditPointPen.Clone();
|
|
pen = DrawParam.SPDFEditPointPen.Clone();
|
|
pen.DashStyle = DashStyles.Solid;
|
|
pen.DashStyle = DashStyles.Solid;
|
|
}
|
|
}
|
|
@@ -578,6 +596,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
{
|
|
{
|
|
SetIgnorePoints(new List<PointControlType>());
|
|
SetIgnorePoints(new List<PointControlType>());
|
|
SetIsProportionalScaling(false);
|
|
SetIsProportionalScaling(false);
|
|
|
|
+ SetRoationHandle(false);
|
|
isProportionalScaling = false;
|
|
isProportionalScaling = false;
|
|
switch (annotData.AnnotType)
|
|
switch (annotData.AnnotType)
|
|
{
|
|
{
|
|
@@ -598,6 +617,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
|
|
|
case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
|
|
case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
|
|
SetIsProportionalScaling(true);
|
|
SetIsProportionalScaling(true);
|
|
|
|
+ SetRoationHandle(true);
|
|
break;
|
|
break;
|
|
|
|
|
|
case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
|
|
case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
|
|
@@ -608,11 +628,16 @@ namespace ComPDFKit.Tool.DrawTool
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
SetMaxRect(annotData.PaintOffset);
|
|
SetMaxRect(annotData.PaintOffset);
|
|
- SetRect(annotData.PaintRect, annotData.CurrentZoom);
|
|
|
|
|
|
+ SetRect(annotData.PaintRect, annotData.CurrentZoom);
|
|
selectedRectData = new SelectedAnnotData();
|
|
selectedRectData = new SelectedAnnotData();
|
|
selectedRectData.annotData = annotData;
|
|
selectedRectData.annotData = annotData;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void SetRoationHandle(bool canRotation)
|
|
|
|
+ {
|
|
|
|
+ this.canRotation = canRotation;
|
|
|
|
+ }
|
|
|
|
+
|
|
public void SetIsProportionalScaling(bool isProportionalScaling)
|
|
public void SetIsProportionalScaling(bool isProportionalScaling)
|
|
{
|
|
{
|
|
this.isProportionalScaling = isProportionalScaling;
|
|
this.isProportionalScaling = isProportionalScaling;
|
|
@@ -620,11 +645,11 @@ namespace ComPDFKit.Tool.DrawTool
|
|
if (isProportionalScaling)
|
|
if (isProportionalScaling)
|
|
{
|
|
{
|
|
ignorePoints.Add(PointControlType.LeftMiddle);
|
|
ignorePoints.Add(PointControlType.LeftMiddle);
|
|
- ignorePoints.Add(PointControlType.MiddlBottom);
|
|
|
|
|
|
+ ignorePoints.Add(PointControlType.MiddleBottom);
|
|
ignorePoints.Add(PointControlType.RightMiddle);
|
|
ignorePoints.Add(PointControlType.RightMiddle);
|
|
ignorePoints.Add(PointControlType.MiddleTop);
|
|
ignorePoints.Add(PointControlType.MiddleTop);
|
|
ignorePoints.Add(PointControlType.Rotate);
|
|
ignorePoints.Add(PointControlType.Rotate);
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public void SetDrawType(DrawPointType drawType)
|
|
public void SetDrawType(DrawPointType drawType)
|
|
@@ -688,7 +713,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
ignorePoints.Add(PointControlType.LeftTop);
|
|
ignorePoints.Add(PointControlType.LeftTop);
|
|
ignorePoints.Add(PointControlType.LeftMiddle);
|
|
ignorePoints.Add(PointControlType.LeftMiddle);
|
|
ignorePoints.Add(PointControlType.LeftBottom);
|
|
ignorePoints.Add(PointControlType.LeftBottom);
|
|
- ignorePoints.Add(PointControlType.MiddlBottom);
|
|
|
|
|
|
+ ignorePoints.Add(PointControlType.MiddleBottom);
|
|
ignorePoints.Add(PointControlType.RightBottom);
|
|
ignorePoints.Add(PointControlType.RightBottom);
|
|
ignorePoints.Add(PointControlType.RightMiddle);
|
|
ignorePoints.Add(PointControlType.RightMiddle);
|
|
ignorePoints.Add(PointControlType.RightTop);
|
|
ignorePoints.Add(PointControlType.RightTop);
|
|
@@ -704,7 +729,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
ignorePoints.Add(PointControlType.LeftTop);
|
|
ignorePoints.Add(PointControlType.LeftTop);
|
|
ignorePoints.Add(PointControlType.LeftMiddle);
|
|
ignorePoints.Add(PointControlType.LeftMiddle);
|
|
ignorePoints.Add(PointControlType.LeftBottom);
|
|
ignorePoints.Add(PointControlType.LeftBottom);
|
|
- ignorePoints.Add(PointControlType.MiddlBottom);
|
|
|
|
|
|
+ ignorePoints.Add(PointControlType.MiddleBottom);
|
|
ignorePoints.Add(PointControlType.RightBottom);
|
|
ignorePoints.Add(PointControlType.RightBottom);
|
|
ignorePoints.Add(PointControlType.RightMiddle);
|
|
ignorePoints.Add(PointControlType.RightMiddle);
|
|
ignorePoints.Add(PointControlType.RightTop);
|
|
ignorePoints.Add(PointControlType.RightTop);
|
|
@@ -799,6 +824,28 @@ namespace ComPDFKit.Tool.DrawTool
|
|
{
|
|
{
|
|
Point checkPoint = controlPoints[i];
|
|
Point checkPoint = controlPoints[i];
|
|
|
|
|
|
|
|
+ if (canRotation)
|
|
|
|
+ {
|
|
|
|
+ // Convert the rotation angle from degrees to radians
|
|
|
|
+ double angleRad = rotateAngle * Math.PI / 180.0;
|
|
|
|
+
|
|
|
|
+ // Calculate the sine and cosine of the angle
|
|
|
|
+ double cosAngle = Math.Cos(angleRad);
|
|
|
|
+ double sinAngle = Math.Sin(angleRad);
|
|
|
|
+
|
|
|
|
+ // Translate checkPoint to the origin (centerPoint becomes the origin)
|
|
|
|
+ double translatedX = checkPoint.X - centerPoint.X;
|
|
|
|
+ double translatedY = checkPoint.Y - centerPoint.Y;
|
|
|
|
+
|
|
|
|
+ // Apply the rotation matrix
|
|
|
|
+ double rotatedX = translatedX * cosAngle - translatedY * sinAngle;
|
|
|
|
+ double rotatedY = translatedX * sinAngle + translatedY * cosAngle;
|
|
|
|
+
|
|
|
|
+ // Translate the point back to its original position
|
|
|
|
+ checkPoint.X = rotatedX + centerPoint.X;
|
|
|
|
+ checkPoint.Y = rotatedY + centerPoint.Y;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (isIgnore && IgnorePointsList.Contains(checkPoint))
|
|
if (isIgnore && IgnorePointsList.Contains(checkPoint))
|
|
{
|
|
{
|
|
continue;
|
|
continue;
|
|
@@ -853,7 +900,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if ((PointControlType)i == PointControlType.MiddlBottom)
|
|
|
|
|
|
+ if ((PointControlType)i == PointControlType.MiddleBottom)
|
|
{
|
|
{
|
|
if (Math.Abs(point.Y - checkPoint.Y) < hlen && checkVector.Length < drawRect.Width/3)
|
|
if (Math.Abs(point.Y - checkPoint.Y) < hlen && checkVector.Length < drawRect.Width/3)
|
|
{
|
|
{
|
|
@@ -866,12 +913,21 @@ namespace ComPDFKit.Tool.DrawTool
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case DrawPointType.Square:
|
|
case DrawPointType.Square:
|
|
-
|
|
|
|
Rect checkRect = new Rect(Math.Max(checkPoint.X - pointSize, 0), Math.Max(checkPoint.Y - pointSize, 0), pointSize * 2, pointSize * 2);
|
|
Rect checkRect = new Rect(Math.Max(checkPoint.X - pointSize, 0), Math.Max(checkPoint.Y - pointSize, 0), pointSize * 2, pointSize * 2);
|
|
|
|
+
|
|
if (checkRect.Contains(point))
|
|
if (checkRect.Contains(point))
|
|
{
|
|
{
|
|
return (PointControlType)i;
|
|
return (PointControlType)i;
|
|
}
|
|
}
|
|
|
|
+ if (canRotation)
|
|
|
|
+ {
|
|
|
|
+ Vector checkVector1 = point - rotationPoint;
|
|
|
|
+
|
|
|
|
+ if (checkVector1.Length < pointSize)
|
|
|
|
+ {
|
|
|
|
+ return PointControlType.Rotate;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
|
|
|
|
case DrawPointType.Crop:
|
|
case DrawPointType.Crop:
|