Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        protected void UpdatePen()
        {
            if (state.pen == null)
            {
                float sw = (float)(state.strokeWidth * state.scale);
                state.pen = new Pen((Color)state.strokeColor, sw);

                System.Drawing.Drawing2D.LineCap cap = System.Drawing.Drawing2D.LineCap.Flat;

                if (state.lineCap.Equals("round"))
                {
                    cap = System.Drawing.Drawing2D.LineCap.Round;
                }
                else if (state.lineCap.Equals("square"))
                {
                    cap = System.Drawing.Drawing2D.LineCap.Square;
                }

                state.pen.StartCap = cap;
                state.pen.EndCap   = cap;

                System.Drawing.Drawing2D.LineJoin join = System.Drawing.Drawing2D.LineJoin.Miter;

                if (state.lineJoin.Equals("round"))
                {
                    join = System.Drawing.Drawing2D.LineJoin.Round;
                }
                else if (state.lineJoin.Equals("bevel"))
                {
                    join = System.Drawing.Drawing2D.LineJoin.Bevel;
                }

                state.pen.LineJoin   = join;
                state.pen.MiterLimit = (float)state.miterLimit;

                if (state.dashed)
                {
                    float[] dash = new float[state.dashPattern.Length];

                    for (int i = 0; i < dash.Length; i++)
                    {
                        dash[i] = (float)(state.dashPattern[i] * state.strokeWidth);
                    }

                    state.pen.DashPattern = dash;
                }
            }
        }
Ejemplo n.º 2
0
        public static PenLineJoin ToEto(this sd2.LineJoin value)
        {
            switch (value)
            {
            case sd2.LineJoin.Bevel:
                return(PenLineJoin.Bevel);

            case sd2.LineJoin.Miter:
                return(PenLineJoin.Miter);

            case sd2.LineJoin.Round:
                return(PenLineJoin.Round);

            default:
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 3
0
        public static DrawingImage GetImage(System.Drawing.Drawing2D.LineJoin join)
        {
            const double height    = 1;
            const double width     = 2;
            const double lineWidth = 0.375 * height;

            PenLineJoin plj;

            switch (join)
            {
            case sdd.LineJoin.Bevel:
                plj = PenLineJoin.Bevel;
                break;

            case sdd.LineJoin.Miter:
            case sdd.LineJoin.MiterClipped:
                plj = PenLineJoin.Miter;
                break;

            case sdd.LineJoin.Round:
                plj = PenLineJoin.Round;
                break;

            default:
                plj = PenLineJoin.Bevel;
                break;
            }

            var             drawingGroup = new DrawingGroup();
            GeometryDrawing geometryDrawing;

            geometryDrawing = new GeometryDrawing
            {
                Geometry = new RectangleGeometry(new Rect(0, 0, width, height)),
                Pen      = new Pen(Brushes.Transparent, 0)
            };
            drawingGroup.Children.Add(geometryDrawing);

            geometryDrawing = new GeometryDrawing();
            var figure = new PathFigure
            {
                StartPoint = new Point(width, height * 0.875)
            };

            figure.Segments.Add(new PolyLineSegment(new Point[]
            {
                new Point(width / 2, height / 2),
                new Point(width, height * 0.175)
            }, true));
            geometryDrawing.Geometry = new PathGeometry(new PathFigure[] { figure });
            geometryDrawing.Pen      = new Pen(Brushes.Black, lineWidth)
            {
                LineJoin = plj
            };
            drawingGroup.Children.Add(geometryDrawing);

            drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0, 0, width, height));

            var geometryImage = new DrawingImage(drawingGroup);

            geometryImage.Freeze();
            return(geometryImage);
        }