|
@@ -12,8 +12,11 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
/// <summary>
|
|
|
/// Current control point drawing style.
|
|
|
/// </summary>
|
|
|
- protected DrawPointType currentDrawPointType { get;
|
|
|
- set; }
|
|
|
+ protected DrawPointType currentDrawPointType
|
|
|
+ {
|
|
|
+ get;
|
|
|
+ set;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
@@ -99,12 +102,14 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
/// <summary>
|
|
|
/// Current drawing rectangle (calculated during operation).
|
|
|
/// </summary>
|
|
|
- protected Thickness clipThickness = new Thickness(0, 0, 0, 0);
|
|
|
+ protected Thickness clipThickness = new Thickness(0, 0, 0, 0);
|
|
|
|
|
|
private Pen editPen { get; set; } = new Pen(new SolidColorBrush(Color.FromRgb(71, 126, 222)), 2) { DashStyle = DashStyles.Dash };
|
|
|
|
|
|
private Pen editHoverPen { get; set; } = new Pen(new SolidColorBrush(Color.FromRgb(71, 126, 222)), 2) { DashStyle = DashStyles.Dash };
|
|
|
|
|
|
+ protected bool isOutSideScaling = false;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Current actual display width and height of PDFVIewer.
|
|
|
/// </summary>
|
|
@@ -147,7 +152,8 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
}
|
|
|
|
|
|
protected List<Point> GetControlPoint(Rect currentRect)
|
|
|
- { List<Point> controlCurrentPoints = new List<Point>();
|
|
|
+ {
|
|
|
+ List<Point> controlCurrentPoints = new List<Point>();
|
|
|
controlCurrentPoints.Clear();
|
|
|
int centerX = (int)(currentRect.Left + currentRect.Right) / 2;
|
|
|
int centerY = (int)(currentRect.Top + currentRect.Bottom) / 2;
|
|
@@ -226,9 +232,22 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
- return NormalScaling(mousePoint);
|
|
|
+ if (!isOutSideScaling)
|
|
|
+ {
|
|
|
+ return NormalScaling(mousePoint);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return OutSideScaling(mousePoint);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ public void SetOutSideScaling(bool IsOutSideScaling)
|
|
|
+ {
|
|
|
+ isOutSideScaling = IsOutSideScaling;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private Size GetProportionalScalingSize(double width, double height)
|
|
|
{
|
|
|
double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
|
|
@@ -542,6 +561,316 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Provisional logic, to be further improved, not yet used: Draw the algorithm in the form of normal scaling (drag a point, only scale in one direction).
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="mousePoint">Current mouse position.</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ protected bool OutSideScaling(Point mousePoint)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ double left = 0, right = 0, top = 0, bottom = 0;
|
|
|
+ double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
|
|
|
+ double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
|
|
|
+
|
|
|
+ Point centerPoint = new Point((cacheRect.Right + cacheRect.Left) / 2, (cacheRect.Bottom + cacheRect.Top) / 2);
|
|
|
+ Point moveVector = (Point)(mousePoint - centerPoint);
|
|
|
+ moveVector = ProportionalScalingOffsetPos(moveVector);
|
|
|
+
|
|
|
+ switch (hitControlType)
|
|
|
+ {
|
|
|
+ case PointControlType.LeftTop:
|
|
|
+ {
|
|
|
+ left = centerPoint.X + moveVector.X;
|
|
|
+ right = cacheRect.Right;
|
|
|
+ top = centerPoint.Y + moveVector.Y;
|
|
|
+ bottom = cacheRect.Bottom;
|
|
|
+ if (isProportionalScaling)
|
|
|
+ {
|
|
|
+ Size size = GetProportionalScalingSize(right - left, bottom - top);
|
|
|
+ left = right - size.Width;
|
|
|
+ top = bottom - size.Height;
|
|
|
+ if (left < maxRect.Left)
|
|
|
+ {
|
|
|
+ double tmpWidth = right - left;
|
|
|
+ left = maxRect.Left;
|
|
|
+ double width = right - left;
|
|
|
+ double height = (bottom - top) * width / tmpWidth;
|
|
|
+ top = bottom - height;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (top < maxRect.Top)
|
|
|
+ {
|
|
|
+ double tmpHeight = bottom - top;
|
|
|
+ top = maxRect.Top;
|
|
|
+ double height = bottom - top;
|
|
|
+ double width = (right - left) * height / tmpHeight;
|
|
|
+ left = right - width;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (left + minWidth > right)
|
|
|
+ {
|
|
|
+ left = right - minWidth;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (top + minHeight > bottom)
|
|
|
+ {
|
|
|
+ top = bottom - minHeight;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case PointControlType.LeftMiddle:
|
|
|
+ {
|
|
|
+ left = centerPoint.X + moveVector.X;
|
|
|
+ right = cacheRect.Right;
|
|
|
+ top = cacheRect.Top;
|
|
|
+ bottom = cacheRect.Bottom;
|
|
|
+ if (left + minWidth > right)
|
|
|
+ {
|
|
|
+ left = right - minWidth;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case PointControlType.LeftBottom:
|
|
|
+ {
|
|
|
+ left = centerPoint.X + moveVector.X;
|
|
|
+ right = cacheRect.Right;
|
|
|
+ top = cacheRect.Top;
|
|
|
+ bottom = centerPoint.Y + moveVector.Y;
|
|
|
+ if (isProportionalScaling)
|
|
|
+ {
|
|
|
+ Size size = GetProportionalScalingSize(right - left, bottom - top);
|
|
|
+ left = right - size.Width;
|
|
|
+ bottom = top + size.Height;
|
|
|
+ if (left < maxRect.Left)
|
|
|
+ {
|
|
|
+ double tmpWidth = right - left;
|
|
|
+ left = maxRect.Left;
|
|
|
+ double width = right - left;
|
|
|
+ double height = (bottom - top) * width / tmpWidth;
|
|
|
+ bottom = top + height;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bottom > maxRect.Bottom)
|
|
|
+ {
|
|
|
+ double tmpHeight = bottom - top;
|
|
|
+ bottom = maxRect.Bottom;
|
|
|
+ double height = bottom - top;
|
|
|
+ double width = (right - left) * height / tmpHeight;
|
|
|
+ left = right - width;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (left + minWidth > right)
|
|
|
+ {
|
|
|
+ left = right - minWidth;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (top + minHeight > bottom)
|
|
|
+ {
|
|
|
+ bottom = top + minHeight;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case PointControlType.MiddlBottom:
|
|
|
+ {
|
|
|
+ left = cacheRect.Left;
|
|
|
+ right = cacheRect.Right;
|
|
|
+ top = cacheRect.Top;
|
|
|
+ bottom = centerPoint.Y + moveVector.Y;
|
|
|
+ if (top + minHeight > bottom)
|
|
|
+ {
|
|
|
+ bottom = top + minHeight;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case PointControlType.RightBottom:
|
|
|
+ {
|
|
|
+ left = cacheRect.Left;
|
|
|
+ right = centerPoint.X + moveVector.X;
|
|
|
+ top = cacheRect.Top;
|
|
|
+ bottom = centerPoint.Y + moveVector.Y;
|
|
|
+ if (isProportionalScaling)
|
|
|
+ {
|
|
|
+ Size size = GetProportionalScalingSize(right - left, bottom - top);
|
|
|
+ right = left + size.Width;
|
|
|
+ bottom = top + size.Height;
|
|
|
+ if (right > maxRect.Right)
|
|
|
+ {
|
|
|
+ double tmpWidth = right - left;
|
|
|
+ right = maxRect.Right;
|
|
|
+ double width = right - left;
|
|
|
+ double height = (bottom - top) * width / tmpWidth;
|
|
|
+ bottom = top + height;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bottom > maxRect.Bottom)
|
|
|
+ {
|
|
|
+ double tmpHeight = bottom - top;
|
|
|
+ bottom = maxRect.Bottom;
|
|
|
+ double height = bottom - top;
|
|
|
+ double width = (right - left) * height / tmpHeight;
|
|
|
+ right = left + width;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (left + minWidth > right)
|
|
|
+ {
|
|
|
+ right = left + minWidth;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (top + minHeight > bottom)
|
|
|
+ {
|
|
|
+ bottom = top + minHeight;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case PointControlType.RightMiddle:
|
|
|
+ {
|
|
|
+ left = cacheRect.Left;
|
|
|
+ right = centerPoint.X + moveVector.X;
|
|
|
+ top = cacheRect.Top;
|
|
|
+ bottom = cacheRect.Bottom;
|
|
|
+ if (left + minWidth > right)
|
|
|
+ {
|
|
|
+ right = left + minWidth;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case PointControlType.RightTop:
|
|
|
+ {
|
|
|
+ left = cacheRect.Left;
|
|
|
+ right = centerPoint.X + moveVector.X;
|
|
|
+ top = centerPoint.Y + moveVector.Y;
|
|
|
+ bottom = cacheRect.Bottom;
|
|
|
+ if (isProportionalScaling)
|
|
|
+ {
|
|
|
+ Size size = GetProportionalScalingSize(right - left, bottom - top);
|
|
|
+ right = left + size.Width;
|
|
|
+ top = bottom - size.Height;
|
|
|
+ if (right > maxRect.Right)
|
|
|
+ {
|
|
|
+ double tmpWidth = right - left;
|
|
|
+ right = maxRect.Right;
|
|
|
+ double width = right - left;
|
|
|
+ double height = (bottom - top) * width / tmpWidth;
|
|
|
+ top = bottom - height;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (top < maxRect.Top)
|
|
|
+ {
|
|
|
+ double tmpHeight = bottom - top;
|
|
|
+ top = maxRect.Top;
|
|
|
+ double height = bottom - top;
|
|
|
+ double width = (right - left) * height / tmpHeight;
|
|
|
+ right = left + width;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (left + minWidth > right)
|
|
|
+ {
|
|
|
+ right = left + minWidth;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (top + minHeight > bottom)
|
|
|
+ {
|
|
|
+ top = bottom - minHeight;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case PointControlType.MiddleTop:
|
|
|
+ {
|
|
|
+ left = cacheRect.Left;
|
|
|
+ right = cacheRect.Right;
|
|
|
+ top = centerPoint.Y + moveVector.Y;
|
|
|
+ bottom = cacheRect.Bottom;
|
|
|
+ if (top + minHeight > bottom)
|
|
|
+ {
|
|
|
+ top = bottom - minHeight;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case PointControlType.Body:
|
|
|
+ case PointControlType.Line:
|
|
|
+ {
|
|
|
+ double newleft = maxRect.Left - SetDrawRect.Width + 10;
|
|
|
+ double newright = maxRect.Right + SetDrawRect.Width - 10;
|
|
|
+ double newtop = maxRect.Top - SetDrawRect.Height + 10;
|
|
|
+ double newbottom = maxRect.Bottom + SetDrawRect.Height - 10;
|
|
|
+ if (newleft < 0)
|
|
|
+ {
|
|
|
+ newleft = 0;
|
|
|
+ }
|
|
|
+ Rect newMaxRect = new Rect(newleft, newtop, newright - newleft, newbottom - newtop);
|
|
|
+
|
|
|
+ Point OffsetPos = CalcMoveBound(cacheRect, ((Point)(mousePoint - mouseDownPoint)), newMaxRect);
|
|
|
+ left = cacheRect.Left + OffsetPos.X;
|
|
|
+ right = cacheRect.Right + OffsetPos.X;
|
|
|
+ top = cacheRect.Top + OffsetPos.Y;
|
|
|
+ bottom = cacheRect.Bottom + OffsetPos.Y;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ //if (left < maxRect.Left)
|
|
|
+ //{
|
|
|
+ // left = maxRect.Left;
|
|
|
+ //}
|
|
|
+
|
|
|
+ //if (top < maxRect.Top)
|
|
|
+ //{
|
|
|
+ // top = maxRect.Top;
|
|
|
+ //}
|
|
|
+
|
|
|
+ if (right > maxRect.Right + SetDrawRect.Width - 10)
|
|
|
+ {
|
|
|
+ if (left > maxRect.Right - 10)
|
|
|
+ {
|
|
|
+ left = maxRect.Right - 10;
|
|
|
+ }
|
|
|
+ right = maxRect.Right + SetDrawRect.Width - 10;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bottom > maxRect.Bottom + SetDrawRect.Height - 10)
|
|
|
+ {
|
|
|
+ if (top > maxRect.Bottom - 10)
|
|
|
+ {
|
|
|
+ top = maxRect.Bottom - 10;
|
|
|
+ }
|
|
|
+ bottom = maxRect.Bottom + SetDrawRect.Height - 10;
|
|
|
+ }
|
|
|
+
|
|
|
+ drawRect = new Rect(left, top, right - left, bottom - top);
|
|
|
+ moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Proportional scaling offset calibration
|
|
|
/// </summary>
|
|
@@ -687,10 +1016,10 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
//GeometryGroup controlGroup = new GeometryGroup();
|
|
|
//controlGroup.FillRule = FillRule.Nonzero;
|
|
|
clipThickness.Left = SetDrawRect.Left - drawRect.Left;
|
|
|
- clipThickness.Top= SetDrawRect.Top - drawRect.Top;
|
|
|
+ clipThickness.Top = SetDrawRect.Top - drawRect.Top;
|
|
|
clipThickness.Right = SetDrawRect.Right - drawRect.Right;
|
|
|
clipThickness.Bottom = SetDrawRect.Bottom - drawRect.Bottom;
|
|
|
- List<Point> controlCurrentPoints=GetControlPoint(drawRect);
|
|
|
+ List<Point> controlCurrentPoints = GetControlPoint(drawRect);
|
|
|
CombinedGeometry controlGroup = new CombinedGeometry();
|
|
|
RectangleGeometry paintGeometry = new RectangleGeometry();
|
|
|
paintGeometry.Rect = SetDrawRect;
|
|
@@ -776,7 +1105,7 @@ namespace ComPDFKit.Tool.DrawTool
|
|
|
/// <param name="moveRect">
|
|
|
/// Current rectangle to draw
|
|
|
/// </param>
|
|
|
- protected void DrawMoveBounds(DrawingContext drawDc, PointControlType controltype, Pen activePen, Brush moveBrush, Rect moveRect,Pen RectPen=null)
|
|
|
+ protected void DrawMoveBounds(DrawingContext drawDc, PointControlType controltype, Pen activePen, Brush moveBrush, Rect moveRect, Pen RectPen = null)
|
|
|
{
|
|
|
switch (controltype)
|
|
|
{
|