Пример #1
0
 public static void RoundedRectangle(this global::Cairo.Context cr, double x, double y, double w, double h, double r)
 {
     cr.MoveTo(x + r, y);
     cr.Arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2);
     cr.Arc(x + w - r, y + h - r, r, 0, Math.PI * 0.5);
     cr.Arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI);
     cr.Arc(x + r, y + r, r, Math.PI, Math.PI * 1.5);
 }
		public static void RoundedRectangle (this Context self, double x, double y, double width, double height, double radius)
		{
			// our radius can be no larger than half our height or width
			radius = Math.Min (radius, Math.Min (width / 2, height / 2));
			
			self.MoveTo (x + radius, y);
			self.Arc (x + width - radius, y + radius, radius, Math.PI * 1.5, Math.PI * 2);
			self.Arc (x + width - radius, y + height - radius, radius, 0, Math.PI * .5);
			self.Arc (x + radius, y + height - radius, radius, Math.PI * .5, Math.PI);
			self.Arc (x + radius, y + radius, radius, Math.PI, Math.PI * 1.5);
		}
Пример #3
0
		public static void RoundedRectangle(this Cairo.Context cr, double x, double y, double w, double h, double r)
		{
			if(r < 0.0001) {
				cr.Rectangle(x, y, w, h);
				return;
			}

			cr.MoveTo(x + r, y);
			cr.Arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2);
			cr.Arc(x + w - r, y + h - r, r, 0, Math.PI * 0.5);
			cr.Arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI);
			cr.Arc(x + r, y + r, r, Math.PI, Math.PI * 1.5);
		}
Пример #4
0
        public static Rectangle FillStrokedRoundedRectangle(this Context g, Rectangle r, double radius, Cairo.Color fill, Cairo.Color stroke, int lineWidth)
        {
            g.Save ();

            if ((radius > r.Height / 2) || (radius > r.Width / 2))
                radius = Math.Min (r.Height / 2, r.Width / 2);

            g.MoveTo (r.X, r.Y + radius);
            g.Arc (r.X + radius, r.Y + radius, radius, Math.PI, -Math.PI / 2);
            g.LineTo (r.X + r.Width - radius, r.Y);
            g.Arc (r.X + r.Width - radius, r.Y + radius, radius, -Math.PI / 2, 0);
            g.LineTo (r.X + r.Width, r.Y + r.Height - radius);
            g.Arc (r.X + r.Width - radius, r.Y + r.Height - radius, radius, 0, Math.PI / 2);
            g.LineTo (r.X + radius, r.Y + r.Height);
            g.Arc (r.X + radius, r.Y + r.Height - radius, radius, Math.PI / 2, Math.PI);
            g.ClosePath ();

            g.Color = fill;
            g.FillPreserve ();

            g.Color = stroke;
            g.LineWidth = lineWidth;

            Rectangle dirty = g.StrokeExtents ();

            g.Stroke ();
            g.Restore ();

            return dirty;
        }
Пример #5
0
        public static Path CreateRoundedRectanglePath(this Context g, Rectangle r, double radius)
        {
            g.Save ();

            if ((radius > r.Height / 2) || (radius > r.Width / 2))
                radius = Math.Min (r.Height / 2, r.Width / 2);

            g.MoveTo (r.X, r.Y + radius);
            g.Arc (r.X + radius, r.Y + radius, radius, Math.PI, -Math.PI / 2);
            g.LineTo (r.X + r.Width - radius, r.Y);
            g.Arc (r.X + r.Width - radius, r.Y + radius, radius, -Math.PI / 2, 0);
            g.LineTo (r.X + r.Width, r.Y + r.Height - radius);
            g.Arc (r.X + r.Width - radius, r.Y + r.Height - radius, radius, 0, Math.PI / 2);
            g.LineTo (r.X + radius, r.Y + r.Height);
            g.Arc (r.X + radius, r.Y + r.Height - radius, radius, Math.PI / 2, Math.PI);
            g.ClosePath ();

            Path p = g.CopyPath ();
            g.Restore ();

            return p;
        }
Пример #6
0
		public static void RoundedRectangle(this Cairo.Context cr, double x, double y, double w, double h,
            double r, CairoCorners corners, bool topBottomFallsThrough)
        {
            if(topBottomFallsThrough && corners == CairoCorners.None) {
                cr.MoveTo(x, y - r);
                cr.LineTo(x, y + h + r);
                cr.MoveTo(x + w, y - r);
                cr.LineTo(x + w, y + h + r);
                return;
            } else if(r < 0.0001 || corners == CairoCorners.None) {
                cr.Rectangle(x, y, w, h);
                return;
            }

            if((corners & (CairoCorners.TopLeft | CairoCorners.TopRight)) == 0 && topBottomFallsThrough) {
                y -= r;
                h += r;
                cr.MoveTo(x + w, y);
            } else {
                if((corners & CairoCorners.TopLeft) != 0) {
                    cr.MoveTo(x + r, y);
                } else {
                    cr.MoveTo(x, y);
                }

                if((corners & CairoCorners.TopRight) != 0) {
                    cr.Arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2);
                } else {
                    cr.LineTo(x + w, y);
                }
            }

            if((corners & (CairoCorners.BottomLeft | CairoCorners.BottomRight)) == 0 && topBottomFallsThrough) {
                h += r;
                cr.LineTo(x + w, y + h);
                cr.MoveTo(x, y + h);
                cr.LineTo(x, y + r);
                cr.Arc(x + r, y + r, r, Math.PI, Math.PI * 1.5);
            } else {
                if((corners & CairoCorners.BottomRight) != 0) {
                    cr.Arc(x + w - r, y + h - r, r, 0, Math.PI * 0.5);
                } else {
                    cr.LineTo(x + w, y + h);
                }

                if((corners & CairoCorners.BottomLeft) != 0) {
                    cr.Arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI);
                } else {
                    cr.LineTo(x, y + h);
                }

                if((corners & CairoCorners.TopLeft) != 0) {
                    cr.Arc(x + r, y + r, r, Math.PI, Math.PI * 1.5);
                } else {
                    cr.LineTo(x, y);
                }
            }
        }
    public static void DrawPieChart(this PdfContentByte canvas,
        PieChart chart,
        float x0,
        float y0,
        float r = 50f,
        Font font = null,
        bool showCaption = true)
    {
        if (chart.Values.Length != chart.Captions.Length) {
            return;
        }

        if (font == null) {
            font = FontFactory.GetFont(FontFactory.TIMES, 8);
        }

        canvas.SetLineWidth(0f);

        double _x1, _y1, _x2, _y2;
        float x1, y1, x2, y2;

        canvas.SetLineWidth(1f);
        float cRadius = (float)(r + 0.5);
        canvas.Circle(x0, y0, cRadius);
        canvas.SetColorStroke(BaseColor.GRAY);
        canvas.Stroke();

        canvas.SetLineWidth(0f);
        float rectX1 = x0 - r;
        float rectY1 = y0 - r;

        float xPoint = x0 + r;
        float yPoint = y0 + r;

        //canvas.Rectangle(rectX1, rectY1, 2 * r, 2 * r);
        //canvas.Stroke();

        double _startAngle = 0;
        double _endAngle = 0;

        float startAngle = 0;
        float endAngle = 0;

        float captionY = y0 + (chart.Values.Length - 1) * 6;
        double _percentage;
        string percentage;

        for (int counter = 0; counter < chart.Values.Length; counter++) {
            if (chart.TotalValues > 0)
                _percentage = chart.Angles[counter] * 100 / 360;
            else
                _percentage = 0;

            if (showCaption) {
                //captions from here
                canvas.SetColorStroke(chart.ChartColors[counter]);
                canvas.SetColorFill(chart.ChartColors[counter]);
                canvas.Rectangle(x0 + r + 10, captionY, 7, 7);
                canvas.ClosePathFillStroke();

                percentage = string.Format("{0:N}", _percentage);
                ColumnText text2 = new ColumnText(canvas);
                Phrase phrase = new Phrase(string.Format("{0} ({1}%)", chart.Captions[counter], percentage), font);
                text2.SetSimpleColumn(phrase, x0 + r + 20, captionY, x0 + r + 200, captionY, 0f, 0);
                text2.Go();

                captionY -= 12;
                if (_percentage == 0) {
                    continue;
                }
                //end of caption
            }

            if (chart.TotalValues <= 0)
                continue;

            if (_percentage <= 50) {
                //get coordinate on circle
                _x1 = x0 + r * Math.Cos(_startAngle * Math.PI / 180);
                _y1 = y0 + r * Math.Sin(_startAngle * Math.PI / 180);
                x1 = (float)_x1;
                y1 = (float)_y1;

                _endAngle += chart.Angles[counter];
                _x2 = x0 + r * Math.Cos(_endAngle * Math.PI / 180);
                _y2 = y0 + r * Math.Sin(_endAngle * Math.PI / 180);
                x2 = (float)_x2;
                y2 = (float)_y2;

                startAngle = (float)_startAngle;
                endAngle = (float)_endAngle;

                //set the colors to be used
                canvas.SetColorStroke(chart.ChartColors[counter]);
                canvas.SetColorFill(chart.ChartColors[counter]);

                //draw the triangle within the circle
                canvas.MoveTo(x0, y0);
                canvas.LineTo(x1, y1);
                canvas.LineTo(x2, y2);
                canvas.LineTo(x0, y0);
                canvas.ClosePathFillStroke();
                //draw the arc
                canvas.Arc(rectX1, rectY1, xPoint, yPoint, startAngle, (float)chart.Angles[counter]);
                canvas.ClosePathFillStroke();
                _startAngle += chart.Angles[counter];
            }
            else {
                //DO THE FIRST PART
                //get coordinate on circle
                _x1 = x0 + r * Math.Cos(_startAngle * Math.PI / 180);
                _y1 = y0 + r * Math.Sin(_startAngle * Math.PI / 180);
                x1 = (float)_x1;
                y1 = (float)_y1;

                _endAngle += 180;
                _x2 = x0 + r * Math.Cos(_endAngle * Math.PI / 180);
                _y2 = y0 + r * Math.Sin(_endAngle * Math.PI / 180);
                x2 = (float)_x2;
                y2 = (float)_y2;

                startAngle = (float)_startAngle;
                endAngle = (float)_endAngle;

                //set the colors to be used
                canvas.SetColorStroke(chart.ChartColors[counter]);
                canvas.SetColorFill(chart.ChartColors[counter]);

                //draw the triangle within the circle
                canvas.MoveTo(x0, y0);
                canvas.LineTo(x1, y1);
                canvas.LineTo(x2, y2);
                canvas.LineTo(x0, y0);
                canvas.ClosePathFillStroke();
                //draw the arc
                canvas.Arc(rectX1, rectY1, xPoint, yPoint, startAngle, 180);
                canvas.ClosePathFillStroke();

                //DO THE SECOND PART
                //get coordinate on circle
                _x1 = x0 + r * Math.Cos((_startAngle + 180) * Math.PI / 180);
                _y1 = y0 + r * Math.Sin((_startAngle + 180) * Math.PI / 180);
                x1 = (float)_x1;
                y1 = (float)_y1;

                _endAngle += chart.Angles[counter] - 180;
                _x2 = x0 + r * Math.Cos(_endAngle * Math.PI / 180);
                _y2 = y0 + r * Math.Sin(_endAngle * Math.PI / 180);
                x2 = (float)_x2;
                y2 = (float)_y2;

                startAngle = (float)_startAngle;
                endAngle = (float)_endAngle;

                //set the colors to be used
                canvas.SetColorStroke(chart.ChartColors[counter]);
                canvas.SetColorFill(chart.ChartColors[counter]);

                //draw the triangle within the circle
                canvas.MoveTo(x0, y0);
                canvas.LineTo(x1, y1);
                canvas.LineTo(x2, y2);
                canvas.LineTo(x0, y0);
                canvas.ClosePathFillStroke();
                //draw the arc
                canvas.Arc(rectX1, rectY1, xPoint, yPoint, startAngle + 180, (float)(chart.Angles[counter] - 180));
                canvas.ClosePathFillStroke();

                _startAngle += chart.Angles[counter];
            }

        }
    }
Пример #8
0
 public static void Arc(this IGeometryFigures _, double x, double y, double width, double height, double start, double stop)
 {
     _.Arc(new Rectangle(x, y, width, height), start, stop);
 }
Пример #9
0
		public static Rectangle FillRoundedRectangle (this Context g, Rectangle r, double radius, Color fill)
		{
			g.Save ();

			if ((radius > r.Height / 2) || (radius > r.Width / 2))
				radius = Math.Min (r.Height / 2, r.Width / 2);

			g.MoveTo (r.X, r.Y + radius);
			g.Arc (r.X + radius, r.Y + radius, radius, Math.PI, -Math.PI / 2);
			g.LineTo (r.X + r.Width - radius, r.Y);
			g.Arc (r.X + r.Width - radius, r.Y + radius, radius, -Math.PI / 2, 0);
			g.LineTo (r.X + r.Width, r.Y + r.Height - radius);
			g.Arc (r.X + r.Width - radius, r.Y + r.Height - radius, radius, 0, Math.PI / 2);
			g.LineTo (r.X + radius, r.Y + r.Height);
			g.Arc (r.X + radius, r.Y + r.Height - radius, radius, Math.PI / 2, Math.PI);
			g.ClosePath ();

			g.SetSourceColor (fill);

			Rectangle dirty = g.FixedStrokeExtents ();

			g.Fill ();
			g.Restore ();

			return dirty;
		}