Exemplo n.º 1
0
        protected override Geometry OnCreateOutlineFillGeometry(RectDouble bounds, IDictionary <string, object> settingValues)
        {
            Geometry ellipseGeometry = this.GetEllipseGeometry(bounds);
            float    num             = (float)settingValues[ToolSettings.Null.Pen.Width.Path];

            System.Drawing.Drawing2D.DashStyle gdipDashStyle = (System.Drawing.Drawing2D.DashStyle)settingValues[ToolSettings.Null.Pen.DashStyle.Path];
            PaintDotNet.UI.Media.DashStyle     style2        = DashStyleUtil.ToMedia(gdipDashStyle);
            StrokeStyle style3 = new StrokeStyle {
                DashStyle = style2
            }.EnsureFrozen <StrokeStyle>();
            WidenedGeometry freezable = new WidenedGeometry {
                Geometry            = ellipseGeometry,
                Thickness           = num,
                StrokeStyle         = style3,
                FlatteningTolerance = 0.0001
            };

            return(freezable.EnsureFrozen <WidenedGeometry>());
        }
Exemplo n.º 2
0
        private void Initialize()
        {
            if ((this.allShapePropertyValuesMap == null) && (this.allShapePropertyValuesArray != null))
            {
                this.allShapePropertyValuesMap = ShapePropertyValuesUtil.ToReadOnlyMap(this.allShapePropertyValuesArray);
            }
            PaintDotNet.UI.Media.DashStyle style = DashStyleUtil.ToMedia(this.PenDashStyle);
            this.outlinePen = new Pen {
                Brush     = SolidColorBrushCache.Get((ColorRgba128Float)Colors.White),
                Thickness = this.PenWidth,
                LineJoin  = PenLineJoin.Miter,
                DashStyle = style
            }.EnsureFrozen <Pen>();
            RectDouble   baseBounds = this.BaseBounds;
            VectorDouble txScale    = this.Transform.GetScale();
            VectorDouble num3       = (VectorDouble)(this.EndPoint - this.StartPoint);
            PointDouble  endPoint   = new PointDouble(this.StartPoint.X + (num3.X * txScale.X), this.StartPoint.Y + (num3.Y * txScale.Y));
            Dictionary <string, object> settingValues = (from gsp in this.Shape.RenderSettingPaths select KeyValuePairUtil.Create <string, object>(gsp, base.GetDrawingSettingValue(gsp))).ToDictionary <string, object>();

            PaintDotNet.Shapes.ShapeRenderParameters renderParams = new PaintDotNet.Shapes.ShapeRenderParameters(this.StartPoint, endPoint, txScale, settingValues, null);
            this.shapePropertySchema = this.Shape.CreatePropertyCollection(renderParams);
            foreach (Property property in this.shapePropertySchema)
            {
                property.ValueChanged += delegate(object s, ValueEventArgs <object> e) {
                    throw new ReadOnlyException();
                };
                property.ReadOnlyChanged += delegate(object s, ValueEventArgs <bool> e) {
                    throw new ReadOnlyException();
                };
            }
            this.shapeRenderParams = new PaintDotNet.Shapes.ShapeRenderParameters(this.StartPoint, endPoint, txScale, settingValues, this.ShapePropertyValues);
            this.shapeRenderData   = LazyResult.New <PaintDotNet.Shapes.ShapeRenderData>(delegate {
                PaintDotNet.Shapes.ShapeRenderData renderData = this.Shape.CreateRenderData(this.shapeRenderParams);
                Matrix3x2Double matrix = Matrix3x2Double.ScalingAt(1.0 / Math.Abs(txScale.X), 1.0 / Math.Abs(txScale.Y), this.StartPoint.X, this.StartPoint.Y);
                return(PaintDotNet.Shapes.ShapeRenderData.Transform(PaintDotNet.Shapes.ShapeRenderData.Transform(renderData, matrix), this.transform));
            }, LazyThreadSafetyMode.ExecutionAndPublication, new SingleUseCriticalSection());
        }
Exemplo n.º 3
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);
        }