public void GetAbsolutePoints(ref PointF last, out PointF p)
 {
     if (this.IsRelative)
     {
         p = new PointF(this.X + last.X, this.Y + last.Y);
     }
     else
     {
         p = new PointF(this.X, this.Y);
     }
 }
 public static PointF CreateMirrorPoint(PointF mirrorPoint, PointF fixedPoint)
 {
     return new PointF(
         fixedPoint.X - (mirrorPoint.X - fixedPoint.X),
         fixedPoint.Y - (mirrorPoint.Y - fixedPoint.Y));
 }
 public static void Curve3GetControlPoints(PointF start, PointF controlPoint, PointF endPoint, out PointF control1, out PointF control2)
 {
     float x1 = start.X + (controlPoint.X - start.X) * 2 / 3;
     float y1 = start.Y + (controlPoint.Y - start.Y) * 2 / 3;
     float x2 = controlPoint.X + (endPoint.X - controlPoint.X) / 3;
     float y2 = controlPoint.Y + (endPoint.Y - controlPoint.Y) / 3;
     control1 = new PointF(x1, y1);
     control2 = new PointF(x2, y2);
 }
 public void GetAbsolutePoints(ref PointF last, out PointF c1, out PointF c2, out PointF p)
 {
     if (this.IsRelative)
     {
         p = new PointF(this.X + last.X, this.Y + last.Y);
         c1 = new PointF(this.X1 + last.X, this.Y1 + last.Y);
         c2 = new PointF(this.X2 + last.X, this.Y2 + last.Y);
     }
     else
     {
         p = new PointF(this.X, this.Y);
         c1 = new PointF(this.X1, this.Y1);
         c2 = new PointF(this.X2, this.Y2);
     }
 }
Beispiel #5
0
        internal void PaintRuns(PaintVisitor p)
        {
            //iterate from each words 
            CssBox latestOwner = null;
            var innerCanvas = p.InnerCanvas;
            var enterFont = innerCanvas.CurrentFont;
            var enterColor = innerCanvas.CurrentTextColor;
            var tmpRuns = this._runs;
            int j = tmpRuns.Count;
            for (int i = 0; i < j; ++i)
            {
                //-----------------
#if DEBUG
                dbugCounter.dbugRunPaintCount++;
#endif
                //-----------------

                CssRun w = tmpRuns[i];
                switch (w.Kind)
                {
                    case CssRunKind.SolidContent:
                        {
                            w.OwnerBox.Paint(p, new RectangleF(w.Left, w.Top, w.Width, w.Height));
                        }
                        break;
                    case CssRunKind.BlockRun:
                        {
                            //Console.WriteLine("blockrun"); 
                            CssBlockRun blockRun = (CssBlockRun)w;
                            int ox = p.CanvasOriginX;
                            int oy = p.CanvasOriginY;
                            p.SetCanvasOrigin(ox + (int)blockRun.Left, oy + (int)blockRun.Top);
                            blockRun.ContentBox.Paint(p);
                            p.SetCanvasOrigin(ox, oy);
                        }
                        break;
                    case CssRunKind.Text:
                        {
                            if (latestOwner != w.OwnerBox)
                            {
                                //change
                                latestOwner = w.OwnerBox;
                                //change font when change owner 

                                p.InnerCanvas.CurrentFont = latestOwner.ResolvedFont;
                                p.InnerCanvas.CurrentTextColor = latestOwner.ActualColor;
                            }

                            CssTextRun textRun = (CssTextRun)w;
                            var wordPoint = new PointF(w.Left, w.Top);
                            p.DrawText(CssBox.UnsafeGetTextBuffer(w.OwnerBox),
                               textRun.TextStartIndex,
                               textRun.TextLength, wordPoint,
                               new SizeF(w.Width, w.Height));
                        }
                        break;
                    default:
                        {
#if DEBUG
                            // w.OwnerBox.dbugPaintTextWordArea(g, offset, w);
#endif
                        }
                        break;
                }
            }

            //---
            //exit
            if (j > 0)
            {
                innerCanvas.CurrentFont = enterFont;
                innerCanvas.CurrentTextColor = enterColor;
            }
        }
Beispiel #6
0
        public override void ReEvaluateComputeValue(ref ReEvaluateArgs args)
        {
            var myspec = this.spec;
            this.fillColor = myspec.ActualColor;
            this.strokeColor = myspec.StrokeColor;
            this.ActualStrokeWidth = ConvertToPx(myspec.StrokeWidth, ref args);
            if (this.IsPathValid) { return; }
            ClearCachePath();
            if (segments == null)
            {
                this.myCachedPath = null;
            }
            else
            {
                List<SvgPathSeg> segs = this.segments;
                int segcount = segs.Count;
                GraphicsPath gpath = this.myCachedPath = new GraphicsPath();
                float lastMoveX = 0;
                float lastMoveY = 0;
                PointF lastPoint = new PointF();
                PointF p2 = new PointF();//curve control point
                PointF p3 = new PointF();//curve control point
                PointF intm_c3_c = new PointF();
                for (int i = 0; i < segcount; ++i)
                {
                    SvgPathSeg seg = segs[i];
                    switch (seg.Command)
                    {
                        case SvgPathCommand.ZClosePath:
                            {
                                gpath.CloseFigure();
                            }
                            break;
                        case SvgPathCommand.MoveTo:
                            {
                                var moveTo = (SvgPathSegMoveTo)seg;
                                PointF moveToPoint;
                                moveTo.GetAbsolutePoints(ref lastPoint, out moveToPoint);
                                lastPoint = moveToPoint;
                                gpath.StartFigure();
                                lastMoveX = lastPoint.X;
                                lastMoveY = lastPoint.Y;
                            }
                            break;
                        case SvgPathCommand.LineTo:
                            {
                                var lineTo = (SvgPathSegLineTo)seg;
                                PointF lineToPoint;
                                lineTo.GetAbsolutePoints(ref lastPoint, out lineToPoint);
                                gpath.AddLine(lastPoint, lineToPoint);
                                lastPoint = lineToPoint;
                            }
                            break;
                        case SvgPathCommand.HorizontalLineTo:
                            {
                                var hlintTo = (SvgPathSegLineToHorizontal)seg;
                                PointF lineToPoint;
                                hlintTo.GetAbsolutePoints(ref lastPoint, out lineToPoint);
                                gpath.AddLine(lastPoint, lineToPoint);
                                lastPoint = lineToPoint;
                            }
                            break;
                        case SvgPathCommand.VerticalLineTo:
                            {
                                var vlineTo = (SvgPathSegLineToVertical)seg;
                                PointF lineToPoint;
                                vlineTo.GetAbsolutePoints(ref lastPoint, out lineToPoint);
                                gpath.AddLine(lastPoint, lineToPoint);
                                lastPoint = lineToPoint;
                            }
                            break;
                        //---------------------------------------------------------------------------
                        //curve modes...... 
                        case SvgPathCommand.CurveTo:
                            {
                                //cubic curve to  (2 control points)
                                var cubicCurve = (SvgPathSegCurveToCubic)seg;
                                PointF p;
                                cubicCurve.GetAbsolutePoints(ref lastPoint, out p2, out p3, out p);
                                gpath.AddBezierCurve(lastPoint, p2, p3, p);
                                lastPoint = p;
                            }
                            break;
                        case SvgPathCommand.QuadraticBezierCurve:
                            {
                                //quadratic curve (1 control point)
                                //auto calculate for c1,c2 
                                var quadCurve = (SvgPathSegCurveToQuadratic)seg;
                                PointF p;
                                quadCurve.GetAbsolutePoints(ref lastPoint, out intm_c3_c, out p);
                                SvgCurveHelper.Curve3GetControlPoints(lastPoint, intm_c3_c, p, out p2, out p3);
                                gpath.AddBezierCurve(lastPoint, p2, p3, p);
                                lastPoint = p;
                            }
                            break;
                        //------------------------------------------------------------------------------------
                        case SvgPathCommand.SmoothCurveTo:
                            {
                                //smooth cubic curve to
                                var smthC4 = (SvgPathSegCurveToCubicSmooth)seg;
                                PointF c2, p;
                                smthC4.GetAbsolutePoints(ref lastPoint, out c2, out p);
                                //connect with prev segment
                                if (i > 0)
                                {
                                    //------------------
                                    //calculate p1 from  prev segment 
                                    //------------------
                                    var prevSeg = segments[i - 1];
                                    //check if prev is curve 
                                    switch (prevSeg.Command)
                                    {
                                        case SvgPathCommand.Arc:
                                        case SvgPathCommand.CurveTo:
                                        case SvgPathCommand.SmoothCurveTo:
                                        case SvgPathCommand.QuadraticBezierCurve:
                                        case SvgPathCommand.TSmoothQuadraticBezierCurveTo:

                                            //make mirror point

                                            p2 = SvgCurveHelper.CreateMirrorPoint(p3, lastPoint);
                                            p3 = c2;
                                            gpath.AddBezierCurve(lastPoint, p2, p3, p);
                                            break;
                                        default:

                                            continue;
                                    }
                                }

                                lastPoint = p;
                            }
                            break;
                        case SvgPathCommand.TSmoothQuadraticBezierCurveTo:
                            {
                                //curve 3
                                var smtC3 = (SvgPathSegCurveToQuadraticSmooth)seg;
                                PointF p;
                                smtC3.GetAbsolutePoints(ref lastPoint, out p);
                                if (i > 0)
                                {
                                    //------------------
                                    //calculate p1 from  prev segment 
                                    //------------------
                                    var prevSeg = segments[i - 1];
                                    //check if prev is curve 
                                    switch (prevSeg.Command)
                                    {
                                        case SvgPathCommand.Arc:
                                        case SvgPathCommand.CurveTo:
                                        case SvgPathCommand.SmoothCurveTo:
                                            {
                                                PointF c = SvgCurveHelper.CreateMirrorPoint(p3, lastPoint);
                                                SvgCurveHelper.Curve3GetControlPoints(lastPoint, c, p, out p2, out p3);
                                                gpath.AddBezierCurve(lastPoint, p2, p3, p);
                                                lastPoint = p;
                                            }
                                            break;
                                        case SvgPathCommand.TSmoothQuadraticBezierCurveTo:
                                            {
                                                //make mirror point
                                                PointF c = SvgCurveHelper.CreateMirrorPoint(intm_c3_c, lastPoint);
                                                SvgCurveHelper.Curve3GetControlPoints(lastPoint, c, p, out p2, out p3);
                                                gpath.AddBezierCurve(lastPoint, p2, p3, p);
                                                lastPoint = p;
                                                intm_c3_c = c;
                                            }
                                            break;
                                        case SvgPathCommand.QuadraticBezierCurve:
                                            {
                                                PointF c = SvgCurveHelper.CreateMirrorPoint(intm_c3_c, lastPoint);
                                                SvgCurveHelper.Curve3GetControlPoints(lastPoint, c, p, out p2, out p3);
                                                gpath.AddBezierCurve(lastPoint, p2, p3, p);
                                                lastPoint = p;
                                                intm_c3_c = c;
                                            }
                                            break;
                                        default:

                                            continue;
                                    }
                                }
                                lastPoint = p;
                            }
                            break;
                        case SvgPathCommand.Arc:
                            {
                                var arcTo = (SvgPathSegArc)seg;
                                PointF p;
                                arcTo.GetAbsolutePoints(ref lastPoint, out p);
                                if (lastPoint.IsEq(p))
                                {
                                    return;
                                }
                                if (arcTo.R1 == 0 && arcTo.R2 == 0)
                                {
                                    gpath.AddLine(lastPoint, p);
                                    lastPoint = p;
                                    return;
                                }
                                PointF[] bz4Points;
                                SvgCurveHelper.MakeBezierCurveFromArc(
                                    ref lastPoint,
                                    ref p,
                                    arcTo.R1,
                                    arcTo.R2,
                                    arcTo.Angle,
                                    arcTo.LargeArgFlag,
                                    arcTo.SweepFlag,
                                    out bz4Points);
                                int j = bz4Points.Length;
                                int nn = 0;
                                while (nn < j)
                                {
                                    gpath.AddBezierCurve(
                                        bz4Points[nn],
                                        bz4Points[nn + 1],
                                        bz4Points[nn + 2],
                                        bz4Points[nn + 3]);
                                    nn += 4;//step 4 points
                                }
                                //set control points
                                p3 = bz4Points[nn - 2];
                                p2 = bz4Points[nn - 3];
                                lastPoint = p;
                                //--------------------------------------------- 

                            }
                            break;
                        default:
                            throw new NotSupportedException();
                    }
                }
            }

            ValidatePath();
        }
Beispiel #7
0
        //---------
        public void DrawText(char[] str, int startAt, int len, PointF point, SizeF size)
        {
#if DEBUG
            dbugCounter.dbugDrawStringCount++;
#endif
            var g = this.canvas;
            g.DrawText(str, startAt, len, new Rectangle(
                  (int)point.X, (int)point.Y,
                  (int)size.Width, (int)size.Height), 0
                  );
        }
Beispiel #8
0
 public void AddLine(PointF p1, PointF p2)
 {
     cmds.Add(PathCommand.Line);
     points.Add(p1.X); points.Add(p1.Y);
     points.Add(p2.X); points.Add(p2.Y);
 }
        /// <summary>
        /// Draw specific border (top/bottom/left/right) with the box data (style/width/rounded).<br/>
        /// </summary>
        /// <param name="borderSide">desired border to draw</param>
        /// <param name="box">the box to draw its borders, contain the borders data</param>
        /// <param name="g">the device to draw into</param>
        /// <param name="rect">the rectangle the border is enclosing</param>
        /// <param name="isLineStart">Specifies if the border is for a starting line (no bevel on left)</param>
        /// <param name="isLineEnd">Specifies if the border is for an ending line (no bevel on right)</param>
        static void DrawBorder(CssSide borderSide, CssBox box,
            PaintVisitor p, RectangleF rect, bool isLineStart, bool isLineEnd)
        {
            float actualBorderWidth;
            Color borderColor;
            CssBorderStyle style;
            GetBorderBorderDrawingInfo(box, borderSide, out style, out borderColor, out actualBorderWidth);
            Canvas g = p.InnerCanvas;
            if (box.HasSomeRoundCorner)
            {
                GraphicsPath borderPath = GetRoundedBorderPath(p, borderSide, box, rect);
                if (borderPath != null)
                {
                    // rounded border need special path 
                    var smooth = g.SmoothingMode;
                    if (!p.AvoidGeometryAntialias && box.HasSomeRoundCorner)
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                    }


                    p.DrawPath(borderPath, borderColor, actualBorderWidth);
                    //using (var pen = GetPen(p.Platform, style, borderColor, actualBorderWidth))
                    //using (borderPath)
                    //{
                    //    g.DrawPath(pen, borderPath);
                    //}
                    g.SmoothingMode = smooth;
                }
            }
            else
            {
                // non rounded border 
                switch (style)
                {
                    case CssBorderStyle.Inset:
                    case CssBorderStyle.Outset:
                        {
                            // inset/outset border needs special rectangle
                            PointF[] borderPnts = new PointF[4];
                            SetInOutsetRectanglePoints(borderSide, box, rect, isLineStart, isLineEnd, borderPnts);
                            g.FillPolygon(borderColor, borderPnts);
                        }
                        break;
                    default:
                        {
                            // solid/dotted/dashed border draw as simple line


                            //using (var pen = GetPen(p.Platform, style, borderColor, actualBorderWidth))
                            //{
                            var prevColor = g.StrokeColor;
                            g.StrokeColor = borderColor;
                            float prevStrokeW = g.StrokeWidth;
                            g.StrokeWidth = actualBorderWidth;
                            switch (borderSide)
                            {
                                case CssSide.Top:
                                    g.DrawLine((float)Math.Ceiling(rect.Left), rect.Top + box.ActualBorderTopWidth / 2, rect.Right - 1, rect.Top + box.ActualBorderTopWidth / 2);
                                    break;
                                case CssSide.Left:
                                    g.DrawLine(rect.Left + box.ActualBorderLeftWidth / 2, (float)Math.Ceiling(rect.Top), rect.Left + box.ActualBorderLeftWidth / 2, (float)Math.Floor(rect.Bottom));
                                    break;
                                case CssSide.Bottom:
                                    g.DrawLine((float)Math.Ceiling(rect.Left), rect.Bottom - box.ActualBorderBottomWidth / 2, rect.Right - 1, rect.Bottom - box.ActualBorderBottomWidth / 2);
                                    break;
                                case CssSide.Right:
                                    g.DrawLine(rect.Right - box.ActualBorderRightWidth / 2, (float)Math.Ceiling(rect.Top), rect.Right - box.ActualBorderRightWidth / 2, (float)Math.Floor(rect.Bottom));
                                    break;
                            }

                            g.StrokeWidth = prevStrokeW;
                            g.StrokeColor = prevColor;
                        }
                        break;
                }
            }
        }
Beispiel #10
0
        /// <summary>
        ///	Offset Method
        /// </summary>
        ///
        /// <remarks>
        ///	Moves the RectangleF a specified distance.
        /// </remarks>

        public void Offset(PointF pos)
        {
            Offset(pos.X, pos.Y);
        }
Beispiel #11
0
        /// <summary>
        ///	Contains Method
        /// </summary>
        ///
        /// <remarks>
        ///	Checks if a Point lies within this RectangleF.
        /// </remarks>

        public bool Contains(PointF pt)
        {
            return Contains(pt.X, pt.Y);
        }
Beispiel #12
0
        // -----------------------
        // Public Constructors
        // -----------------------

        /// <summary>
        ///	RectangleF Constructor
        /// </summary>
        ///
        /// <remarks>
        ///	Creates a RectangleF from PointF and SizeF values.
        /// </remarks>

        public RectangleF(PointF location, SizeF size)
        {
            x = location.X;
            y = location.Y;
            width = size.Width;
            height = size.Height;
        }
 static GraphicsPath CreateRoundRectGraphicPath(float x, float y, float w, float h, float c_rx, float c_ry)
 {
     var _path = new GraphicsPath();
     var arcBounds = new RectangleF();
     var lineStart = new PointF();
     var lineEnd = new PointF();
     var width = w;
     var height = h;
     var rx = c_rx * 2;
     var ry = c_ry * 2;
     // Start
     _path.StartFigure();
     // Add first arc
     arcBounds.Location = new PointF(x, y);
     arcBounds.Width = rx;
     arcBounds.Height = ry;
     _path.AddArc(arcBounds, 180, 90);
     // Add first line
     lineStart.X = Math.Min(x + rx, x + width * 0.5f);
     lineStart.Y = y;
     lineEnd.X = Math.Max(x + width - rx, x + width * 0.5f);
     lineEnd.Y = lineStart.Y;
     _path.AddLine(lineStart, lineEnd);
     // Add second arc
     arcBounds.Location = new PointF(x + width - rx, y);
     _path.AddArc(arcBounds, 270, 90);
     // Add second line
     lineStart.X = x + width;
     lineStart.Y = Math.Min(y + ry, y + height * 0.5f);
     lineEnd.X = lineStart.X;
     lineEnd.Y = Math.Max(y + height - ry, y + height * 0.5f);
     _path.AddLine(lineStart, lineEnd);
     // Add third arc
     arcBounds.Location = new PointF(x + width - rx, y + height - ry);
     _path.AddArc(arcBounds, 0, 90);
     // Add third line
     lineStart.X = Math.Max(x + width - rx, x + width * 0.5f);
     lineStart.Y = y + height;
     lineEnd.X = Math.Min(x + rx, x + width * 0.5f);
     lineEnd.Y = lineStart.Y;
     _path.AddLine(lineStart, lineEnd);
     // Add third arc
     arcBounds.Location = new PointF(x, y + height - ry);
     _path.AddArc(arcBounds, 90, 90);
     // Add fourth line
     lineStart.X = x;
     lineStart.Y = Math.Max(y + height - ry, y + height * 0.5f);
     lineEnd.X = lineStart.X;
     lineEnd.Y = Math.Min(y + ry, y + height * 0.5f);
     _path.AddLine(lineStart, lineEnd);
     // Close
     _path.CloseFigure();
     return _path;
 }
Beispiel #14
0
 public LinearGradientBrush(PointF stop1, Color c1, PointF stop2, Color c2)
 {
     this.stopColors.Add(c1);
     this.stopColors.Add(c2);
     this.stopPoints.Add(stop1);
     this.stopPoints.Add(stop2);
 }
Beispiel #15
0
        public static LinearGradientBrush CreateLinearGradientBrush(RectangleF rect,
            Color startColor, Color stopColor, float degreeAngle)
        {
            //find radius
            int w = Math.Abs((int)(rect.Right - rect.Left));
            int h = Math.Abs((int)(rect.Bottom - rect.Top));
            int max = Math.Max(w, h);
            float radius = (float)Math.Pow(2 * (max * max), 0.5f);
            //find point1 and point2
            //not implement! 
            bool fromNegativeAngle = false;
            if (degreeAngle < 0)
            {
                fromNegativeAngle = true;
                degreeAngle = -degreeAngle;
            }

            PointF startPoint = new PointF(rect.Left, rect.Top);
            PointF stopPoint = new PointF(rect.Right, rect.Top);
            if (degreeAngle > 360)
            {
            }
            //-------------------------
            if (degreeAngle == 0)
            {
                startPoint = new PointF(rect.Left, rect.Bottom);
                stopPoint = new PointF(rect.Right, rect.Bottom);
            }
            else if (degreeAngle < 90)
            {
                startPoint = new PointF(rect.Left, rect.Bottom);
                var angleRad = DegreesToRadians(degreeAngle);
                stopPoint = new PointF(
                   rect.Left + (float)(Math.Cos(angleRad) * radius),
                   rect.Bottom - (float)(Math.Sin(angleRad) * radius));
            }
            else if (degreeAngle == 90)
            {
                startPoint = new PointF(rect.Left, rect.Bottom);
                stopPoint = new PointF(rect.Left, rect.Top);
            }
            else if (degreeAngle < 180)
            {
                startPoint = new PointF(rect.Right, rect.Bottom);
                var angleRad = DegreesToRadians(degreeAngle);
                var pos = (float)(Math.Cos(angleRad) * radius);
                stopPoint = new PointF(
                   rect.Right + (float)(Math.Cos(angleRad) * radius),
                   rect.Bottom - (float)(Math.Sin(angleRad) * radius));
            }
            else if (degreeAngle == 180)
            {
                startPoint = new PointF(rect.Right, rect.Bottom);
                stopPoint = new PointF(rect.Left, rect.Bottom);
            }
            else if (degreeAngle < 270)
            {
                startPoint = new PointF(rect.Right, rect.Top);
                var angleRad = DegreesToRadians(degreeAngle);
                stopPoint = new PointF(
                   rect.Right - (float)(Math.Cos(angleRad) * radius),
                   rect.Top + (float)(Math.Sin(angleRad) * radius));
            }
            else if (degreeAngle == 270)
            {
                startPoint = new PointF(rect.Left, rect.Top);
                stopPoint = new PointF(rect.Left, rect.Bottom);
            }
            else if (degreeAngle < 360)
            {
                startPoint = new PointF(rect.Left, rect.Top);
                var angleRad = DegreesToRadians(degreeAngle);
                stopPoint = new PointF(
                   rect.Left + (float)(Math.Cos(angleRad) * radius),
                   rect.Top + (float)(Math.Sin(angleRad) * radius));
            }
            else if (degreeAngle == 360)
            {
                startPoint = new PointF(rect.Left, rect.Bottom);
                stopPoint = new PointF(rect.Right, rect.Bottom);
            }

            return new LinearGradientBrush(startPoint, startColor, stopPoint, stopColor);
        }
        internal static void MakeBezierCurveFromArc(ref PointF start,
            ref PointF end,
            float rx,
            float ry,
            float angle,
            SvgArcSize arcSize,
            SvgArcSweep arcSweep,
            out PointF[] bezier4Points)
        {
            double sinPhi = Math.Sin(angle * SvgPathSegArc.RAD_PER_DEG);
            double cosPhi = Math.Cos(angle * SvgPathSegArc.RAD_PER_DEG);
            double x1dash = cosPhi * (start.X - end.X) / 2.0 + sinPhi * (start.Y - end.Y) / 2.0;
            double y1dash = -sinPhi * (start.X - end.X) / 2.0 + cosPhi * (start.Y - end.Y) / 2.0;
            double root;
            double numerator = (rx * rx * ry * ry) - (rx * rx * y1dash * y1dash) - (ry * ry * x1dash * x1dash);
            if (numerator < 0.0)
            {
                float s = (float)Math.Sqrt(1.0 - numerator / (rx * rx * ry * ry));
                rx *= s;
                ry *= s;
                root = 0.0;
            }
            else
            {
                root = ((arcSize == SvgArcSize.Large && arcSweep == SvgArcSweep.Positive)
                    || (arcSize == SvgArcSize.Small && arcSweep == SvgArcSweep.Negative) ? -1.0 : 1.0) * Math.Sqrt(numerator / (rx * rx * y1dash * y1dash + ry * ry * x1dash * x1dash));
            }


            double cxdash = root * rx * y1dash / ry;
            double cydash = -root * ry * x1dash / rx;
            double cx = cosPhi * cxdash - sinPhi * cydash + (start.X + end.X) / 2.0;
            double cy = sinPhi * cxdash + cosPhi * cydash + (start.Y + end.Y) / 2.0;
            double theta1 = SvgPathSegArc.CalculateVectorAngle(1.0, 0.0, (x1dash - cxdash) / rx, (y1dash - cydash) / ry);
            double dtheta = SvgPathSegArc.CalculateVectorAngle((x1dash - cxdash) / rx, (y1dash - cydash) / ry, (-x1dash - cxdash) / rx, (-y1dash - cydash) / ry);
            if (arcSweep == SvgArcSweep.Negative && dtheta > 0)
            {
                dtheta -= 2.0 * Math.PI;
            }
            else if (arcSweep == SvgArcSweep.Positive && dtheta < 0)
            {
                dtheta += 2.0 * Math.PI;
            }

            int nsegments = (int)Math.Ceiling((double)Math.Abs(dtheta / (Math.PI / 2.0)));
            double delta = dtheta / nsegments;
            double t = 8.0 / 3.0 * Math.Sin(delta / 4.0) * Math.Sin(delta / 4.0) / Math.Sin(delta / 2.0);
            double startX = start.X;
            double startY = start.Y;
            bezier4Points = new PointF[nsegments * 4];
            int nn = 0;
            for (int n = 0; n < nsegments; ++n)
            {
                double cosTheta1 = Math.Cos(theta1);
                double sinTheta1 = Math.Sin(theta1);
                double theta2 = theta1 + delta;
                double cosTheta2 = Math.Cos(theta2);
                double sinTheta2 = Math.Sin(theta2);
                double endpointX = cosPhi * rx * cosTheta2 - sinPhi * ry * sinTheta2 + cx;
                double endpointY = sinPhi * rx * cosTheta2 + cosPhi * ry * sinTheta2 + cy;
                double dx1 = t * (-cosPhi * rx * sinTheta1 - sinPhi * ry * cosTheta1);
                double dy1 = t * (-sinPhi * rx * sinTheta1 + cosPhi * ry * cosTheta1);
                double dxe = t * (cosPhi * rx * sinTheta2 + sinPhi * ry * cosTheta2);
                double dye = t * (sinPhi * rx * sinTheta2 - cosPhi * ry * cosTheta2);
                bezier4Points[nn] = new PointF((float)startX, (float)startY);
                bezier4Points[nn + 1] = new PointF((float)(startX + dx1), (float)(startY + dy1));
                bezier4Points[nn + 2] = new PointF((float)(endpointX + dxe), (float)(endpointY + dye));
                bezier4Points[nn + 3] = new PointF((float)endpointX, (float)endpointY);
                nn += 4;
                theta1 = theta2;
                startX = (float)endpointX;
                startY = (float)endpointY;
            }
        }
 /// <summary>
 /// Set rectangle for inset/outset border as it need diagonal connection to other borders.
 /// </summary>
 /// <param name="border">Desired border</param>
 /// <param name="b">Box which the border corresponds</param>
 /// <param name="r">the rectangle the border is enclosing</param>
 /// <param name="isLineStart">Specifies if the border is for a starting line (no bevel on left)</param>
 /// <param name="isLineEnd">Specifies if the border is for an ending line (no bevel on right)</param>
 /// <returns>Beveled border path, null if there is no rounded corners</returns>
 static void SetInOutsetRectanglePoints(CssSide border, CssBox b, RectangleF r, bool isLineStart, bool isLineEnd,
     PointF[] _borderPts)
 {
     switch (border)
     {
         case CssSide.Top:
             _borderPts[0] = new PointF(r.Left, r.Top);
             _borderPts[1] = new PointF(r.Right, r.Top);
             _borderPts[2] = new PointF(r.Right, r.Top + b.ActualBorderTopWidth);
             _borderPts[3] = new PointF(r.Left, r.Top + b.ActualBorderTopWidth);
             if (isLineEnd)
                 _borderPts[2].X -= b.ActualBorderRightWidth;
             if (isLineStart)
                 _borderPts[3].X += b.ActualBorderLeftWidth;
             break;
         case CssSide.Right:
             _borderPts[0] = new PointF(r.Right - b.ActualBorderRightWidth, r.Top + b.ActualBorderTopWidth);
             _borderPts[1] = new PointF(r.Right, r.Top);
             _borderPts[2] = new PointF(r.Right, r.Bottom);
             _borderPts[3] = new PointF(r.Right - b.ActualBorderRightWidth, r.Bottom - b.ActualBorderBottomWidth);
             break;
         case CssSide.Bottom:
             _borderPts[0] = new PointF(r.Left, r.Bottom - b.ActualBorderBottomWidth);
             _borderPts[1] = new PointF(r.Right, r.Bottom - b.ActualBorderBottomWidth);
             _borderPts[2] = new PointF(r.Right, r.Bottom);
             _borderPts[3] = new PointF(r.Left, r.Bottom);
             if (isLineStart)
                 _borderPts[0].X += b.ActualBorderLeftWidth;
             if (isLineEnd)
                 _borderPts[1].X -= b.ActualBorderRightWidth;
             break;
         case CssSide.Left:
             _borderPts[0] = new PointF(r.Left, r.Top);
             _borderPts[1] = new PointF(r.Left + b.ActualBorderLeftWidth, r.Top + b.ActualBorderTopWidth);
             _borderPts[2] = new PointF(r.Left + b.ActualBorderLeftWidth, r.Bottom - b.ActualBorderBottomWidth);
             _borderPts[3] = new PointF(r.Left, r.Bottom);
             break;
     }
 }
 public static void DrawBorder(CssSide border, PointF[] borderPts, Canvas g, CssBox box, Color solidColor, RectangleF rectangle)
 {
     SetInOutsetRectanglePoints(border, box, rectangle, true, true, borderPts);
     g.FillPolygon(solidColor, borderPts);
 }
Beispiel #19
0
        public void AddBezierCurve(PointF p1, PointF p2, PointF p3, PointF p4)
        {
            cmds.Add(PathCommand.Bezier);
            points.Add(p1.X); points.Add(p1.Y);
            points.Add(p2.X); points.Add(p2.Y);
            points.Add(p3.X); points.Add(p3.Y);
            points.Add(p4.X); points.Add(p4.Y);

        }
Beispiel #20
0
 internal void PaintBorder(CssBox box, CssSide border, Color solidColor, RectangleF rect)
 {
     PointF[] borderPoints = new PointF[4];
     BorderPaintHelper.DrawBorder(solidColor, border, borderPoints, this.canvas, box, rect);
 }