Ejemplo n.º 1
0
        static public bool DrawGraphicsPath(
            System.Drawing.Graphics pGraphics,
            System.Drawing.Drawing2D.GraphicsPath pGraphicsPath,
            System.Drawing.Color clrPen,
            float fPenWidth)
        {
            if (pGraphics == null || pGraphicsPath == null)
            {
                return(false);
            }

            System.Drawing.Drawing2D.PathData pathData = pGraphicsPath.PathData;

            if (pathData.Points.Length <= 0)
            {
                return(false);
            }

            System.Drawing.Pen pen = new Pen(clrPen, fPenWidth);
            pen.LineJoin = LineJoin.Round;


            stBezier bezier    = new stBezier();
            stStart  start     = new stStart();
            PointF   prevPoint = new PointF();

            for (int i = 0; i < pathData.Types.Length; ++i)
            {
                byte maskedByte = pathData.Types[i];
                if (pathData.Types[i] == (byte)PathPointType.PathTypeMask)
                {
                    maskedByte = (byte)(pathData.Types[i] & 0x3);
                }

                switch (maskedByte)
                {
                case PathPointType.Start:
                case PathPointType.Start | PathPointType.PathMarker:
                    start.fPoint  = pathData.Points[i];
                    start.nCount  = 1;
                    start.bDrawn  = false;
                    bezier.nCount = 0;
                    break;

                case PathPointType.Line:
                case PathPointType.Line | PathPointType.PathMarker:
                    pGraphics.DrawLine(pen, prevPoint, pathData.Points[i]);
                    break;

                case PathPointType.Line | PathPointType.CloseSubpath:
                case PathPointType.Line | PathPointType.PathMarker | PathPointType.CloseSubpath:
                    pGraphics.DrawLine(pen, prevPoint, pathData.Points[i]);
                    pGraphics.DrawLine(pen, pathData.Points[i], start.fPoint);
                    start.nCount = 0;
                    break;

                case PathPointType.Bezier:
                case PathPointType.Bezier | PathPointType.PathMarker:
                    bezier.fPoints[bezier.nCount] = pathData.Points[i];
                    bezier.nCount++;
                    if (bezier.nCount == 1)
                    {
                        pGraphics.DrawLine(pen, prevPoint, pathData.Points[i]);
                    }
                    if (bezier.nCount >= 4)
                    {
                        pGraphics.DrawBezier(pen,
                                             bezier.fPoints[0], bezier.fPoints[1],
                                             bezier.fPoints[2], bezier.fPoints[3]);
                        bezier.nCount = 0;
                    }
                    break;

                case PathPointType.Bezier | PathPointType.CloseSubpath:
                case PathPointType.Bezier | PathPointType.PathMarker | PathPointType.CloseSubpath:
                    bezier.fPoints[bezier.nCount] = pathData.Points[i];
                    bezier.nCount++;
                    if (bezier.nCount == 1)
                    {
                        pGraphics.DrawLine(pen, prevPoint, pathData.Points[i]);
                    }
                    if (bezier.nCount >= 4)
                    {
                        pGraphics.DrawBezier(pen,
                                             bezier.fPoints[0], bezier.fPoints[1],
                                             bezier.fPoints[2], bezier.fPoints[3]);
                        bezier.nCount = 0;
                        if (start.nCount == 1)
                        {
                            pGraphics.DrawLine(pen, pathData.Points[i], start.fPoint);
                            start.nCount = 0;
                        }
                    }
                    else if (start.nCount == 1)
                    {
                        pGraphics.DrawLine(pen, pathData.Points[i], start.fPoint);
                        start.nCount = 0;
                        start.bDrawn = true;
                    }
                    break;

                default:
                {
                    //wchar_t buf[200];
                    //memset(buf,0, sizeof(buf));
                    //wsprintf(buf,_T("maskedByte: 0x%X\n"), maskedByte);
                    //OutputDebugStringW(buf);
                }
                break;
                }
                prevPoint = pathData.Points[i];
            }

            return(true);
        }
Ejemplo n.º 2
0
        public static bool DrawGraphicsPath(
            System.Drawing.Graphics pGraphics,
            System.Drawing.Drawing2D.GraphicsPath pGraphicsPath,
            System.Drawing.Color clrPen,
            float fPenWidth)
        {
            if (pGraphics == null || pGraphicsPath == null)
            return false;

            System.Drawing.Drawing2D.PathData pathData = pGraphicsPath.PathData;

            if (pathData.Points.Length <= 0)
            return false;

            System.Drawing.Pen pen = new Pen(clrPen, fPenWidth);
            pen.LineJoin = LineJoin.Round;

            stBezier bezier = new stBezier();
            stStart start = new stStart();
            PointF prevPoint = new PointF();

            for (int i = 0; i < pathData.Types.Length; ++i)
            {
            byte maskedByte = pathData.Types[i];
            if (pathData.Types[i] == (byte)PathPointType.PathTypeMask)
            {
                maskedByte = (byte)(pathData.Types[i] & 0x3);
            }

            switch (maskedByte)
            {
                case PathPointType.Start:
                case PathPointType.Start | PathPointType.PathMarker:
                    start.fPoint = pathData.Points[i];
                    start.nCount = 1;
                    start.bDrawn = false;
                    bezier.nCount = 0;
                    break;

                case PathPointType.Line:
                case PathPointType.Line | PathPointType.PathMarker:
                    pGraphics.DrawLine(pen, prevPoint, pathData.Points[i]);
                    break;

                case PathPointType.Line | PathPointType.CloseSubpath:
                case PathPointType.Line | PathPointType.PathMarker | PathPointType.CloseSubpath:
                    pGraphics.DrawLine(pen, prevPoint, pathData.Points[i]);
                    pGraphics.DrawLine(pen, pathData.Points[i], start.fPoint);
                    start.nCount = 0;
                    break;

                case PathPointType.Bezier:
                case PathPointType.Bezier | PathPointType.PathMarker:
                    bezier.fPoints[bezier.nCount] = pathData.Points[i];
                    bezier.nCount++;
                    if (bezier.nCount == 1)
                        pGraphics.DrawLine(pen, prevPoint, pathData.Points[i]);
                    if (bezier.nCount >= 4)
                    {
                        pGraphics.DrawBezier(pen,
                            bezier.fPoints[0], bezier.fPoints[1],
                            bezier.fPoints[2], bezier.fPoints[3]);
                        bezier.nCount = 0;
                    }
                    break;

                case PathPointType.Bezier | PathPointType.CloseSubpath:
                case PathPointType.Bezier | PathPointType.PathMarker | PathPointType.CloseSubpath:
                    bezier.fPoints[bezier.nCount] = pathData.Points[i];
                    bezier.nCount++;
                    if (bezier.nCount == 1)
                        pGraphics.DrawLine(pen, prevPoint, pathData.Points[i]);
                    if (bezier.nCount >= 4)
                    {
                        pGraphics.DrawBezier(pen,
                            bezier.fPoints[0], bezier.fPoints[1],
                            bezier.fPoints[2], bezier.fPoints[3]);
                        bezier.nCount = 0;
                        if (start.nCount == 1)
                        {
                            pGraphics.DrawLine(pen, pathData.Points[i], start.fPoint);
                            start.nCount = 0;
                        }
                    }
                    else if (start.nCount == 1)
                    {
                        pGraphics.DrawLine(pen, pathData.Points[i], start.fPoint);
                        start.nCount = 0;
                        start.bDrawn = true;
                    }
                    break;
                default:
                    {
                        //wchar_t buf[200];
                        //memset(buf,0, sizeof(buf));
                        //wsprintf(buf,_T("maskedByte: 0x%X\n"), maskedByte);
                        //OutputDebugStringW(buf);
                    }
                    break;
            }
            prevPoint = pathData.Points[i];
            }

            return true;
        }