Пример #1
0
        public void FillRectangle(Brush b, RectangleF rect, TClippingStyle clippingStyle)
        {
            FixRect(ref rect);
            if (PointOutside.Check(ref rect))
            {
                return;
            }
            if (b == null)
            {
                return;
            }

            if (clippingStyle == TClippingStyle.None)
            {
                Canvas.FillRectangle(b, rect);
            }
            else
            {
                using (GraphicsPath gp = new GraphicsPath())
                {
                    gp.AddRectangle(rect);
                    switch (clippingStyle)
                    {
                    case TClippingStyle.Exclude:
                        Canvas.SetClip(gp, CombineMode.Exclude);
                        break;

                    case TClippingStyle.Include:
                        Canvas.SetClip(gp, CombineMode.Intersect);
                        break;
                    }
                }
            }
        }
Пример #2
0
        public void DrawAndFillPolygon(Pen pen, Brush brush, TPointF[] points, TClippingStyle clippingStyle)
        {
            if (points == null || points.Length <= 1)
            {
                return;
            }
            if (!CheckPoints(points))
            {
                return;
            }

            StreamGeometry Line = new StreamGeometry();

            using (StreamGeometryContext sc = Line.Open())
            {
                sc.BeginFigure(new Point(points[0].X, points[0].Y), brush != null, true);
                for (int i = 1; i < points.Length; i++)
                {
                    sc.LineTo(new Point(points[i].X, points[i].Y), true, true);
                }
            }

            if (Line.CanFreeze)
            {
                Line.Freeze();
            }

            if (brush != null)
            {
                switch (clippingStyle)
                {
                case TClippingStyle.Exclude:
                    IntersectClip(Reverse(Line));
                    break;

                case TClippingStyle.Include:
                    IntersectClip(Line);
                    break;

                default:
                    //Will be handled below.
                    break;
                }
            }

            if (clippingStyle == TClippingStyle.None)
            {
                FCanvas.DrawGeometry(brush, pen, Line);
            }
        }
Пример #3
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);
            }
        }
Пример #4
0
        public void DrawAndFillPolygon(Pen pen, Brush brush, TPointF[] points, TClippingStyle clippingStyle)
        {
            switch (clippingStyle)
            {
            case TClippingStyle.None:
                Canvas.DrawAndFillPolygon(pen, brush, points);
                break;

            default:
                if (brush != null)
                {
                    Canvas.ClipPolygon(points, clippingStyle == TClippingStyle.Exclude);
                    SetClipped(true, RectangleF.Empty);
                }
                break;
            }
        }
Пример #5
0
        public void FillRectangle(Brush b, RectangleF rect, TClippingStyle clippingStyle)
        {
            if (b == null)
            {
                return;
            }
            switch (clippingStyle)
            {
            case TClippingStyle.None:
                Canvas.FillRectangle(b, rect.X, rect.Y, rect.Width, rect.Height);
                break;

            default:
                if (b != null)
                {
                    Canvas.ClipRectangle(rect.X, rect.Y, rect.Width, rect.Height, clippingStyle == TClippingStyle.Exclude);
                    SetClipped(true, RectangleF.Empty);
                }
                break;
            }
        }
Пример #6
0
        public void FillRectangle(Brush b, RectangleF rect, TClippingStyle clippingStyle)
        {
            FixRect(ref rect);
            if (PointOutside.Check(ref rect))
            {
                return;
            }
            if (b == null)
            {
                return;
            }

            if (clippingStyle == TClippingStyle.None)
            {
                FCanvas.DrawRectangle(b, null, new Rect(rect.Left, rect.Top, rect.Width, rect.Height));
            }
            else
            {
                RectangleGeometry r = new RectangleGeometry(new Rect(rect.Left, rect.Top, rect.Width, rect.Height));
                if (r.CanFreeze)
                {
                    r.Freeze();
                }

                switch (clippingStyle)
                {
                case TClippingStyle.Exclude:
                    IntersectClip(Reverse(r));
                    break;

                case TClippingStyle.Include:
                    IntersectClip(r);
                    break;

                default:
                    //Already handled.
                    break;
                }
            }
        }
Пример #7
0
        public void DrawAndFillPolygon(Pen pen, Brush brush, TPointF[] points, TClippingStyle clippingStyle)
        {
            PointF[] fpoints = ToPointF(points);
            if (fpoints == null)
            {
                return;
            }
            if (brush != null)
            {
                if (clippingStyle == TClippingStyle.None)
                {
                    Canvas.FillPolygon(brush, fpoints);
                }
                else
                {
                    using (GraphicsPath gp = new GraphicsPath())
                    {
                        gp.AddLines(fpoints);
                        switch (clippingStyle)
                        {
                        case TClippingStyle.Exclude:
                            Canvas.SetClip(gp, CombineMode.Exclude);
                            break;

                        case TClippingStyle.Include:
                            Canvas.SetClip(gp, CombineMode.Intersect);
                            break;
                        }
                    }
                }
            }
            if (pen != null && clippingStyle == TClippingStyle.None)
            {
                Canvas.DrawPolygon(pen, fpoints);
            }
        }
Пример #8
0
        internal static void DrawPlainText(IFlxGraphics Canvas, ExcelFile Workbook, TShapeProperties ShProp, RectangleF Coords, TShadowInfo ShadowInfo, TClippingStyle Clipping, float Zoom100)
        {
            string Text = GetGeoText(ShProp);

            if (Text == null)
            {
                return;
            }
            Text = Text.Replace("\n", String.Empty);
            string[] Lines = Text.Split('\r');
            if (Lines == null || Lines.Length <= 0)
            {
                return;
            }
            int LinesLength = Lines[Lines.Length - 1].Length == 0? Lines.Length - 1: Lines.Length;               //Last line is an empty enter.

            if (LinesLength <= 0)
            {
                return;
            }

            using (Font TextFont = GetGeoFont(ShProp))
            {
                using (Pen pe = GetPen(ShProp, Workbook, ShadowInfo))
                {
                    Canvas.SaveTransform();
                    try
                    {
                        float   LineGap = Canvas.FontLinespacing(TextFont);
                        SizeF[] Sizes   = new SizeF[LinesLength];
                        Sizes[0]         = Canvas.MeasureStringEmptyHasHeight(Lines[0], TextFont);
                        Sizes[0].Height -= LineGap; //Linespacing is not included here.

                        SizeF sz = Sizes[0];
                        for (int i = 1; i < LinesLength; i++)
                        {
                            Sizes[i] = Canvas.MeasureStringEmptyHasHeight(Lines[i], TextFont);
                            if (Sizes[i].Width > sz.Width)
                            {
                                sz.Width = Sizes[i].Width;
                            }
                            sz.Height += Sizes[i].Height;
                        }

                        if (sz.Width <= 0 || sz.Height <= 0 || Coords.Width <= 0 || Coords.Height <= 0)
                        {
                            return;
                        }
                        float rx = Coords.Width / sz.Width;
                        float ry = Coords.Height / sz.Height;
                        Canvas.Scale(rx, ry);

                        using (Brush br = GetBrush(new RectangleF(Coords.Left / rx, Coords.Top / ry, sz.Width, sz.Height), ShProp, Workbook, ShadowInfo, Zoom100)) //Mast be selected AFTER scaling, so gradients work.
                        {
                            float y = LineGap;
                            for (int i = 0; i < LinesLength; i++)
                            {
                                y += Sizes[i].Height;
                                float x = (sz.Width - Sizes[i].Width) / 2f;
                                Canvas.DrawString(Lines[i], TextFont, pe, br, Coords.Left / rx + x, Coords.Top / ry + y);
                            }
                        }
                    }
                    finally
                    {
                        Canvas.ResetTransform();
                    }
                }
            }
        }