예제 #1
0
        private static PathGeometry ExtendPathGeometry(PathGeometry geometry, double exLength)
        {
            if (geometry.Figures.Count != 1)
            {
                throw new ArgumentException();
            }
            PathGeometry          geometry2     = (PathGeometry)geometry.Clone();
            PointAndTangentDouble pointAtLength = geometry.GetPointAtLength(0.0, flatteningTolerance);
            VectorDouble          num2          = pointAtLength.Tangent.NormalizeOrZeroCopy();
            PointDouble           num3          = pointAtLength.Point - ((PointDouble)(num2 * exLength));

            geometry2.Figures[0].Segments.Insert(0, new LineSegment(pointAtLength.Point));
            geometry2.Figures[0].StartPoint = num3;
            PointAndTangentDouble num4  = geometry.GetPointAtLength(double.PositiveInfinity, flatteningTolerance);
            VectorDouble          num5  = num4.Tangent.NormalizeOrZeroCopy();
            PointDouble           point = num4.Point + ((PointDouble)(num5 * exLength));

            geometry2.Figures[0].Segments.Add(new LineSegment(point));
            return(geometry2);
        }
예제 #2
0
        private static Geometry CreateStrokedLineGeometry(Geometry lineGeometry, double strokeWidth, LineCap2 startCap, LineCap2 endCap, PaintDotNet.UI.Media.DashStyle dashStyle)
        {
            Geometry    geometry;
            Geometry    geometry2;
            Geometry    geometry3;
            Geometry    geometry4;
            Geometry    geometry5;
            double      length      = lineGeometry.GetLength(flatteningTolerance);
            StrokeStyle strokeStyle = new StrokeStyle {
                DashStyle = dashStyle,
                LineJoin  = PenLineJoin.Round
            };
            double num2 = 0.0;

            switch (startCap)
            {
            case LineCap2.Flat:
                geometry = null;
                break;

            case LineCap2.Arrow:
                geometry = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, false, false).EnsureFrozen <Geometry>();
                num2     = 0.5;
                break;

            case LineCap2.ArrowFilled:
                geometry = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, true, true).EnsureFrozen <Geometry>();
                num2     = 1.5;
                break;

            case LineCap2.Rounded:
                strokeStyle.StartLineCap = PenLineCap.Round;
                geometry = null;
                break;

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <LineCap2>(startCap, "startCap");
            }
            double num3 = 0.0;

            switch (endCap)
            {
            case LineCap2.Flat:
                geometry2 = null;
                break;

            case LineCap2.Arrow:
                geometry2 = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, false, false).EnsureFrozen <Geometry>();
                num3      = 0.5;
                break;

            case LineCap2.ArrowFilled:
                geometry2 = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, true, true).EnsureFrozen <Geometry>();
                num3      = 1.5;
                break;

            case LineCap2.Rounded:
                strokeStyle.EndLineCap = PenLineCap.Round;
                geometry2 = null;
                break;

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <LineCap2>(endCap, "endCap");
            }
            strokeStyle.Freeze();
            if (geometry == null)
            {
                geometry3 = null;
            }
            else
            {
                PointAndTangentDouble pointAtLength = lineGeometry.GetPointAtLength(0.0, flatteningTolerance);
                double          radians             = Math.Atan2(pointAtLength.Tangent.Y, pointAtLength.Tangent.X) + 3.1415926535897931;
                Matrix3x2Double num9   = Matrix3x2Double.RotationByRadians(radians);
                Matrix3x2Double num10  = Matrix3x2Double.Translation(pointAtLength.Point.X, pointAtLength.Point.Y);
                Matrix3x2Double matrix = num9 * num10;
                geometry3 = geometry.GetTransformedGeometry(matrix).EnsureFrozen <Geometry>();
            }
            if (geometry2 == null)
            {
                geometry4 = null;
            }
            else
            {
                double num14 = lineGeometry.GetLength(flatteningTolerance);
                PointAndTangentDouble num15 = lineGeometry.GetPointAtLength(num14, flatteningTolerance);
                Matrix3x2Double       num18 = Matrix3x2Double.RotationByRadians(Math.Atan2(num15.Tangent.Y, num15.Tangent.X));
                Matrix3x2Double       num19 = Matrix3x2Double.Translation(num15.Point.X, num15.Point.Y);
                Matrix3x2Double       num20 = num18 * num19;
                geometry4 = geometry2.GetTransformedGeometry(num20).EnsureFrozen <Geometry>();
            }
            double startLength = 0.0;
            double endLength   = length;

            if (num2 != 0.0)
            {
                startLength = strokeWidth * num2;
            }
            if (num3 != 0.0)
            {
                endLength = length - (strokeWidth * num3);
            }
            if ((startLength != 0.0) || (endLength != length))
            {
                geometry5 = GetTrimmedGeometry(lineGeometry, startLength, endLength).EnsureFrozen <Geometry>();
            }
            else
            {
                geometry5 = lineGeometry;
            }
            Geometry item = new WidenedGeometry(geometry5, strokeWidth, strokeStyle)
            {
                FlatteningTolerance = flatteningTolerance
            }.EnsureFrozen <WidenedGeometry>();
            GeometryGroup group = new GeometryGroup {
                FillRule = FillRule.Nonzero
            };

            group.Children.Add(item);
            if (geometry3 != null)
            {
                group.Children.Add(geometry3);
            }
            if (geometry4 != null)
            {
                group.Children.Add(geometry4);
            }
            group.Freeze();
            return(group);
        }
예제 #3
0
        protected override void OnGetStatus(out ImageResource image, out string text)
        {
            string            str;
            PointDouble       startPoint;
            PointDouble       endPoint;
            double            length;
            double            num4;
            string            str2;
            string            str3;
            ShapesToolChanges changes = base.Changes;

            switch (this.State)
            {
            case TransactedToolState.Drawing:
                if (changes == null)
                {
                    break;
                }
                goto Label_003A;

            case TransactedToolState.Dirty:
            case TransactedToolState.Editing:
                goto Label_003A;
            }
            base.OnGetStatus(out image, out text);
            return;

Label_003A:
            if (this.State == TransactedToolState.Dirty)
            {
                str = PdnResources.GetString("LineTool.StatusText.NotAdjusting.Format");
            }
            else
            {
                str = PdnResources.GetString("LineTool.StatusText.Format");
            }
            if (changes.ShapeRenderData.OutlineDraw.IsEmpty)
            {
                startPoint = changes.StartPoint;
                endPoint   = changes.EndPoint;
                length     = 0.0;
                num4       = 0.0;
            }
            else
            {
                PointAndTangentDouble pointAtLength = changes.ShapeRenderData.OutlineDraw.GetPointAtLength(0.0);
                PointAndTangentDouble num12         = changes.ShapeRenderData.OutlineDraw.GetPointAtLength(double.PositiveInfinity);
                startPoint = pointAtLength.Point;
                endPoint   = num12.Point;
                length     = changes.ShapeRenderData.OutlineDraw.GetLength();
                num4       = (-180.0 * Math.Atan2(endPoint.Y - startPoint.Y, endPoint.X - startPoint.X)) / 3.1415926535897931;
            }
            MeasurementUnit units = base.AppWorkspace.Units;
            PointDouble     num5  = new PointDouble(base.Document.PixelToPhysicalX(startPoint.X, units), base.Document.PixelToPhysicalY(startPoint.Y, units));
            PointDouble     num6  = new PointDouble(base.Document.PixelToPhysicalX(endPoint.X, units), base.Document.PixelToPhysicalY(endPoint.Y, units));
            VectorDouble    num7  = (VectorDouble)(num6 - num5);
            double          num8  = base.Document.PixelToPhysicalX(length, units);
            double          num9  = base.Document.PixelToPhysicalY(length, units);
            double          num10 = (num8 + num9) / 2.0;

            if (units != MeasurementUnit.Pixel)
            {
                str3 = PdnResources.GetString("MeasurementUnit." + units.ToString() + ".Abbreviation");
                str2 = "F2";
            }
            else
            {
                str3 = string.Empty;
                str2 = "F0";
            }
            string str4 = PdnResources.GetString("MeasurementUnit." + units.ToString() + ".Plural");
            string str5 = string.Format(str, new object[] { num7.X.ToString(str2), str3, num7.Y.ToString(str2), str3, num10.ToString("F2"), str4, num4.ToString("F2") });

            image = base.Image;
            text  = str5;
        }