Exemple #1
0
        public TPointF Transform(TPointF p)
        {
            PointOutside.Check(ref p);
            Point p1 = FCanvas.TransformToVisual(MainCanvas).Transform(new Point(p.X, p.Y));

            return(new TPointF((real)p1.X, (real)p1.Y));
        }
Exemple #2
0
        public SizeF MeasureString(string Text, Font aFont, TPointF p)
        {
            PointOutside.Check(ref p);
            Typeface      TextTypeface = new Typeface(aFont.Family, aFont.Style, aFont.Weight, FontStretches.Normal);
            FormattedText fmtText      = new FormattedText(Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, TextTypeface, aFont.SizeInPix, null);

            //fmtText.SetTextDecorations(aFont.Decorations);
            return(new SizeF(fmtText.Width, fmtText.Height));
        }
Exemple #3
0
 public TPointF Transform(TPointF p)
 {
     PointOutside.Check(ref p);
     using (Matrix myMatrix = Canvas.Transform)
     {
         float[] DrawingMatrix = myMatrix.Elements;
         return(new TPointF(
                    (float)(DrawingMatrix[0] * p.X + DrawingMatrix[2] * p.Y + DrawingMatrix[4]),
                    (float)(DrawingMatrix[1] * p.X + DrawingMatrix[3] * p.Y + DrawingMatrix[5])));
     }
 }
Exemple #4
0
        public void DrawAndFillBeziers(Pen pen, Brush brush, TPointF[] points, TClippingStyle clippingStyle)
        {
            if (points.Length < 4 || (points.Length - 4) % 3 != 0)
            {
                int TotalPoints = 4;
                if (points.Length > TotalPoints)
                {
                    TotalPoints = 7 + ((points.Length - 5) / 3) * 3;
                }
                TPointF[] newpoints = new TPointF[TotalPoints];
                Array.Copy(points, newpoints, points.Length);
                for (int i = points.Length; i < TotalPoints; i++)
                {
                    newpoints[i] = points[points.Length - 1];
                }
                points = newpoints;
            }

            PointF[] fpoints = ToPointF(points);
            if (fpoints == null)
            {
                return;
            }
            if (brush != null)
            {
                using (GraphicsPath gp = new GraphicsPath())
                {
                    gp.AddBeziers(fpoints);
                    switch (clippingStyle)
                    {
                    case TClippingStyle.Exclude:
                        Canvas.SetClip(gp, CombineMode.Exclude);
                        break;

                    case TClippingStyle.Include:
                        Canvas.SetClip(gp, CombineMode.Intersect);
                        break;

                    default:
                        Canvas.FillPath(brush, gp);
                        break;
                    }
                }
            }
            if (pen != null && clippingStyle == TClippingStyle.None)
            {
                Canvas.DrawBeziers(pen, fpoints);
            }
        }
Exemple #5
0
        public static bool Check(ref TPointF p)
        {
            bool Result = false;

            if (p.X > MaxSize)
            {
                p.X = MaxSize; Result = true;
            }
            if (p.Y > MaxSize)
            {
                p.Y = MaxSize; Result = true;
            }
            if (p.X < MinSize)
            {
                p.X = MinSize; Result = true;
            }
            if (p.Y < MinSize)
            {
                p.Y = MinSize; Result = true;
            }

            return(Result);
        }
Exemple #6
0
 public SizeF MeasureString(string Text, Font aFont, TPointF p)
 {
     PointOutside.Check(ref p);
     return(Canvas.MeasureString(Text, aFont, new PointF(p.X, p.Y), FSFormat));
 }
Exemple #7
0
        /// <summary>
        /// Returns the array of points needed to create an elliptical arc with bezier curves.
        /// </summary>
        /// <param name="cx">Center coordinate (x).</param>
        /// <param name="cy">Center coordinate (y).</param>
        /// <param name="a">Major radius.</param>
        /// <param name="b">Minor radius.</param>
        /// <param name="theta">Angle of the major axis respect to the x axis. (Radians)</param>
        /// <param name="lambda1">Starting angle of the arc. (Radians)</param>
        /// <param name="lambda2">Ending angle of the arc. (Radians)</param>
        /// <returns></returns>
        internal static TPointF[] GetPoints(double cx, double cy, double a, double b, double theta, double lambda1, double lambda2)
        {
            if (a <= 0 || b <= 0)
            {
                return(new TPointF[0]);
            }

            double eta1            = Math.Atan2(Math.Sin(lambda1) / b, Math.Cos(lambda1) / a);
            double eta2            = Math.Atan2(Math.Sin(lambda2) / b, Math.Cos(lambda2) / a);
            double cosTheta        = Math.Cos(theta);
            double sinTheta        = Math.Sin(theta);
            double defaultFlatness = 0.5;             // half a pixel
            double twoPi           = 2 * Math.PI;

            // make sure we have eta1 <= eta2 <= eta1 + 2 PI
            eta2 -= twoPi * Math.Floor((eta2 - eta1) / twoPi);

            // the preceding correction fails if we have exactly et2 - eta1 = 2 PI
            // it reduces the interval to zero length
            if ((lambda2 - lambda1 > Math.PI) && (eta2 - eta1 < Math.PI))
            {
                eta2 += 2 * Math.PI;
            }


            // find the number of Bezier curves needed
            bool found = false;
            int  n     = 1;

            while ((!found) && (n < 1024))
            {
                double dEta = (eta2 - eta1) / n;
                if (dEta <= 0.5 * Math.PI)
                {
                    double etaB = eta1;
                    found = true;
                    for (int i = 0; found && (i < n); ++i)
                    {
                        double etaA = etaB;
                        etaB += dEta;
                        found = (estimateError(a, b, etaA, etaB) <= defaultFlatness);
                    }
                }
                n = n << 1;
            }
            {
                TPointF[] Result = new TPointF[1 + 3 * n];
                double    dEta   = (eta2 - eta1) / n;
                double    etaB   = eta1;

                double cosEtaB  = Math.Cos(etaB);
                double sinEtaB  = Math.Sin(etaB);
                double aCosEtaB = a * cosEtaB;
                double bSinEtaB = b * sinEtaB;
                double aSinEtaB = a * sinEtaB;
                double bCosEtaB = b * cosEtaB;
                double xB       = cx + aCosEtaB * cosTheta - bSinEtaB * sinTheta;
                double yB       = cy + aCosEtaB * sinTheta + bSinEtaB * cosTheta;
                double xBDot    = -aSinEtaB * cosTheta - bCosEtaB * sinTheta;
                double yBDot    = -aSinEtaB * sinTheta + bCosEtaB * cosTheta;

                AddPoint(Result, 0, xB, yB);

                double t     = Math.Tan(0.5 * dEta);
                double alpha = Math.Sin(dEta) * (Math.Sqrt(4 + 3 * t * t) - 1) / 3;

                int rp = 1;
                for (int i = 0; i < n; i++)
                {
                    double xA    = xB;
                    double yA    = yB;
                    double xADot = xBDot;
                    double yADot = yBDot;

                    etaB    += dEta;
                    cosEtaB  = Math.Cos(etaB);
                    sinEtaB  = Math.Sin(etaB);
                    aCosEtaB = a * cosEtaB;
                    bSinEtaB = b * sinEtaB;
                    aSinEtaB = a * sinEtaB;
                    bCosEtaB = b * cosEtaB;
                    xB       = cx + aCosEtaB * cosTheta - bSinEtaB * sinTheta;
                    yB       = cy + aCosEtaB * sinTheta + bSinEtaB * cosTheta;
                    xBDot    = -aSinEtaB * cosTheta - bCosEtaB * sinTheta;
                    yBDot    = -aSinEtaB * sinTheta + bCosEtaB * cosTheta;

                    AddPoint(Result, rp, (xA + alpha * xADot), (yA + alpha * yADot)); rp++;
                    AddPoint(Result, rp, (xB - alpha * xBDot), (yB - alpha * yBDot)); rp++;
                    AddPoint(Result, rp, xB, yB); rp++;
                }
                return(Result);
            }
        }
Exemple #8
0
 public SizeF MeasureString(string Text, Font aFont, TPointF p)
 {
     return(Canvas.MeasureString(Text, aFont));
 }
Exemple #9
0
 public TPointF Transform(TPointF p)
 {
     return(Canvas.Transform(p));
 }