Ejemplo n.º 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;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void DrawString(string Text, Font aFont, Pen aPen, Brush aBrush, real x, real y)
        {
            if (PointOutside.Check(ref x, ref y))
            {
                return;
            }

            Text = Text.Replace('\u000a', '\u0000');            //Replace newlines with empty characters
            if (aBrush != null)
            {
                DrawString(Text, aFont, aBrush, x, y);
            }

            if (aPen != null)
            {
                Typeface TextTypeface = new Typeface(aFont.Family, aFont.Style, aFont.Weight, FontStretches.Normal);

                FormattedText fmtText = new FormattedText(Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, TextTypeface, aFont.SizeInPix, Brushes.Black); //Brush doesn't matter here.
                fmtText.SetTextDecorations(aFont.Decorations);
                Geometry TxtGeometry = fmtText.BuildHighlightGeometry(new Point(x, y));
                if (TxtGeometry.CanFreeze)
                {
                    TxtGeometry.Freeze();
                }
                FCanvas.DrawGeometry(null, aPen, TxtGeometry);
            }
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
 public void DrawString(string Text, Font aFont, Brush aBrush, float x, float y)
 {
     if (PointOutside.Check(ref x, ref y))
     {
         return;
     }
     Text = Text.Replace('\u000a', '\u0000');            //Replace newlines with empty characters
     Canvas.DrawString(Text, aFont, aBrush, x, y, FSFormat);
 }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
 public void DrawLine(Pen aPen, real x1, real y1, real x2, real y2)
 {
     PointOutside.Check(ref x1, ref y1);
     PointOutside.Check(ref x2, ref y2);
     if (aPen == null)
     {
         return;
     }
     FCanvas.DrawLine(aPen, new Point(x1, y1), new Point(x2, y2));
 }
Ejemplo n.º 7
0
 public void DrawLine(Pen aPen, float x1, float y1, float x2, float y2)
 {
     PointOutside.Check(ref x1, ref y1);
     PointOutside.Check(ref x2, ref y2);
     if (aPen == null)
     {
         return;
     }
     Canvas.DrawLine(aPen, x1, y1, x2, y2);
 }
Ejemplo n.º 8
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])));
     }
 }
Ejemplo n.º 9
0
 public void Rotate(float x, float y, float Alpha)
 {
     if (PointOutside.Check(ref x, ref y))
     {
         return;
     }
     using (Matrix myMatrix = Canvas.Transform)
     {
         myMatrix.RotateAt(-Alpha, new PointF(x, y), MatrixOrder.Prepend);
         Canvas.Transform = myMatrix;
     }
 }
Ejemplo n.º 10
0
 public void FillRectangle(Brush b, RectangleF rect)
 {
     FixRect(ref rect);
     if (PointOutside.Check(ref rect))
     {
         return;
     }
     if (b != null)
     {
         Canvas.FillRectangle(b, rect);
     }
 }
Ejemplo n.º 11
0
 public void FillRectangle(Brush b, float x1, float y1, float width, float height)
 {
     FixRect(ref x1, ref y1, ref width, ref height);
     if (PointOutside.Check(ref x1, ref y1, ref width, ref height))
     {
         return;
     }
     if (b == null)
     {
         return;
     }
     Canvas.FillRectangle(b, x1, y1, width, height);
 }
Ejemplo n.º 12
0
 public void DrawRectangle(Pen pen, float x, float y, float width, float height)
 {
     FixRect(ref x, ref y, ref width, ref height);
     if (PointOutside.Check(ref x, ref y, ref width, ref height))
     {
         return;
     }
     if (pen == null)
     {
         return;
     }
     Canvas.DrawRectangle(pen, x, y, width, height);
 }
Ejemplo n.º 13
0
 public void DrawRectangle(Pen pen, real x, real y, real width, real height)
 {
     FixRect(ref x, ref y, ref width, ref height);
     if (PointOutside.Check(ref x, ref y, ref width, ref height))
     {
         return;
     }
     if (pen == null)
     {
         return;
     }
     FCanvas.DrawRectangle(null, pen, new Rect(x, y, width, height));
 }
Ejemplo n.º 14
0
 public void FillRectangle(Brush b, real x1, real y1, real width, real height)
 {
     FixRect(ref x1, ref y1, ref width, ref height);
     if (PointOutside.Check(ref x1, ref y1, ref width, ref height))
     {
         return;
     }
     if (b == null)
     {
         return;
     }
     FCanvas.DrawRectangle(b, null, new Rect(x1, y1, width, height));
 }
Ejemplo n.º 15
0
 public void FillRectangle(Brush b, RectangleF rect)
 {
     FixRect(ref rect);
     if (PointOutside.Check(ref rect))
     {
         return;
     }
     if (b == null)
     {
         return;
     }
     FCanvas.DrawRectangle(b, null, new Rect(rect.Left, rect.Top, rect.Width, rect.Height));
 }
Ejemplo n.º 16
0
        public void DrawString(string Text, Font aFont, Brush aBrush, real x, real y)
        {
            if (PointOutside.Check(ref x, ref y))
            {
                return;
            }
            Text = Text.Replace('\u000a', '\u0000');            //Replace newlines with empty characters

            Typeface TextTypeface = new Typeface(aFont.Family, aFont.Style, aFont.Weight, FontStretches.Normal);

            FormattedText fmtText = new FormattedText(Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, TextTypeface, aFont.SizeInPix, aBrush);

            fmtText.SetTextDecorations(aFont.Decorations);
            FCanvas.DrawText(fmtText, new Point(x, y));
        }
Ejemplo n.º 17
0
 public void DrawAndFillRectangle(Pen pen, Brush b, float x, float y, float width, float height)
 {
     FixRect(ref x, ref y, ref width, ref height);
     if (PointOutside.Check(ref x, ref y, ref width, ref height))
     {
         return;
     }
     if (b != null)
     {
         Canvas.FillRectangle(b, x, y, width, height);
     }
     if (pen != null)
     {
         Canvas.DrawRectangle(pen, x, y, width, height);
     }
 }
Ejemplo n.º 18
0
 public void DrawString(string Text, Font aFont, Pen aPen, Brush aBrush, float x, float y)
 {
     if (PointOutside.Check(ref x, ref y))
     {
         return;
     }
     Text = Text.Replace('\u000a', '\u0000');            //Replace newlines with empty characters
     if (aBrush != null)
     {
         Canvas.DrawString(Text, aFont, aBrush, x, y, FSFormat);
     }
     if (aPen != null)
     {
         GraphicsPath TextPath = new GraphicsPath();
         TextPath.AddString(Text, aFont.FontFamily, (int)aFont.Style, aFont.Size, new PointF(x, y), FSFormat);
         Canvas.DrawPath(aPen, TextPath);
     }
 }
Ejemplo n.º 19
0
        private static bool CheckPoints(TPointF[] points)
        {
            bool AllPointsOutside = true;

            for (int i = 0; i < points.Length; i++)
            {
                if (!PointOutside.Check(ref points[i]))
                {
                    AllPointsOutside = false;
                }
            }

            if (AllPointsOutside)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 20
0
        public void Rotate(real x, real y, real Alpha)
        {
            if (PointOutside.Check(ref x, ref y))
            {
                return;
            }

            RotateTransform rt = new RotateTransform();

            rt.Angle   = -Alpha;
            rt.CenterX = x;
            rt.CenterY = y;
            if (rt.CanFreeze)
            {
                rt.Freeze();
            }

            FCanvas.PushTransform(rt);
            GraphicsSave[GraphicsSave.Count - 1]++;
        }
Ejemplo n.º 21
0
        private static PointF[] ToPointF(TPointF[] points)
        {
            bool AllPointsOutside = true;

            PointF[] Result = new PointF[points.Length];
            for (int i = 0; i < points.Length; i++)
            {
                if (!PointOutside.Check(ref points[i]))
                {
                    AllPointsOutside = false;
                }
                Result[i] = new PointF(points[i].X, points[i].Y);
            }

            if (AllPointsOutside)
            {
                return(null);
            }
            return(Result);
        }
Ejemplo n.º 22
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;
                }
            }
        }
Ejemplo n.º 23
0
 public void SetClipReplace(RectangleF rect)
 {
     PointOutside.Check(ref rect);
     Canvas.SetClip(rect, System.Drawing.Drawing2D.CombineMode.Replace);
 }
Ejemplo n.º 24
0
 public void SetClipIntersect(RectangleF rect)
 {
     PointOutside.Check(ref rect);
     Canvas.SetClip(rect, System.Drawing.Drawing2D.CombineMode.Intersect);
 }
Ejemplo n.º 25
0
        public void DrawImage(Image image, RectangleF destRect, RectangleF srcRect, long transparentColor, int brightness, int contrast, int gamma, Color shadowColor, Stream imgData)
        {
            if (PointOutside.Check(ref srcRect))
            {
                return;
            }
            if (PointOutside.Check(ref destRect))
            {
                return;
            }
            if (image.Height <= 0 || image.Width <= 0)
            {
                return;
            }
            bool ChangedParams = brightness != FlxConsts.DefaultBrightness ||
                                 contrast != FlxConsts.DefaultContrast ||
                                 gamma != FlxConsts.DefaultGamma ||
                                 shadowColor != ColorUtil.Empty;

            ImageAttributes imgAtt = null;

            try
            {
                if (transparentColor != FlxConsts.NoTransparentColor)
                {
                    long  cl  = transparentColor;
                    Color tcl = ColorUtil.FromArgb((int)(cl & 0xFF), (int)((cl & 0xFF00) >> 8), (int)((cl & 0xFF0000) >> 16));
                    imgAtt = new ImageAttributes();
                    imgAtt.SetColorKey(tcl, tcl);
                }

                if (gamma != FlxConsts.DefaultGamma)
                {
                    if (imgAtt == null)
                    {
                        imgAtt = new ImageAttributes();
                    }
                    imgAtt.SetGamma((float)((UInt32)gamma) / 65536f);
                }

                if (!ChangedParams && srcRect.Top == 0 && srcRect.Left == 0 && srcRect.Width == image.Width && srcRect.Height == image.Height && imgAtt == null)
                {
                    bool Retry = false;
                    try
                    {
                        Canvas.DrawImage(image, destRect);                          //Optimizes the most common case, but there is also an error when cropping metafiles. At least we make sure here this won't have any error on 99% of the cases.
                    }
                    catch (System.Runtime.InteropServices.ExternalException ex)
                    {
                        if (FlexCelTrace.HasListeners)
                        {
                            FlexCelTrace.Write(new TRenderMetafileError(ex.Message));
                        }

                        Retry = true;                         //metafiles can raise nasty errors here.
                    }
                    if (Retry)
                    {
                        using (Image bmp = FlgConsts.RasterizeWMF(image))
                        {
                            Canvas.DrawImage(bmp, destRect);
                        }
                    }
                }
                else
                {
                    Image FinalImage = image;
                    try
                    {
                        if (image.RawFormat.Equals(ImageFormat.Wmf) || image.RawFormat.Equals(ImageFormat.Emf))
                        {
                            FinalImage = FlgConsts.RasterizeWMF(image);                             //metafiles do not like cropping or changing attributes.
                        }

                        if (ChangedParams)
                        {
                            if (shadowColor != ColorUtil.Empty)
                            {
                                FlgConsts.MakeImageGray(ref imgAtt, shadowColor);
                            }
                            else
                            {
                                FlgConsts.AdjustImage(ref imgAtt, brightness, contrast);
                            }
                        }

                        PointF[] ImageRect = new PointF[] { new PointF(destRect.Left, destRect.Top), new PointF(destRect.Right, destRect.Top), new PointF(destRect.Left, destRect.Bottom) };
                        Canvas.DrawImage(FinalImage,
                                         ImageRect,
                                         srcRect, GraphicsUnit.Pixel, imgAtt);
                    }
                    finally
                    {
                        if (FinalImage != image)
                        {
                            FinalImage.Dispose();
                        }
                    }
                }
            }
            finally
            {
                if (imgAtt != null)
                {
                    imgAtt.Dispose();
                }
            }
        }
Ejemplo n.º 26
0
        public void DrawImage(Image image, RectangleF destRect, RectangleF srcRect, long transparentColor, int brightness, int contrast, int gamma, Color shadowColor, Stream imgData)
        {
            if (PointOutside.Check(ref srcRect))
            {
                return;
            }
            if (PointOutside.Check(ref destRect))
            {
                return;
            }
            if (image.Height <= 0 || image.Width <= 0)
            {
                return;
            }
            bool ChangedParams = brightness != FlxConsts.DefaultBrightness ||
                                 contrast != FlxConsts.DefaultContrast ||
                                 gamma != FlxConsts.DefaultGamma ||
                                 shadowColor != Colors.Transparent;

            ImageAttributes imgAtt = null;

            try
            {
                if (transparentColor != FlxConsts.NoTransparentColor)
                {
                    long  cl  = transparentColor;
                    Color tcl = ColorUtil.FromArgb(0xFF, (byte)(cl & 0xFF), (byte)((cl & 0xFF00) >> 8), (byte)((cl & 0xFF0000) >> 16));
                    imgAtt = new ImageAttributes();
                    imgAtt.SetColorKey(tcl, tcl);
                }

                if (gamma != FlxConsts.DefaultGamma)
                {
                    if (imgAtt == null)
                    {
                        imgAtt = new ImageAttributes();
                    }
                    imgAtt.SetGamma((real)((UInt32)gamma) / 65536f);
                }

                if (!ChangedParams && srcRect.Top == 0 && srcRect.Left == 0 && srcRect.Width == image.Width && srcRect.Height == image.Height && imgAtt == null)
                {
                    FCanvas.DrawImage(image, destRect);
                }
                else
                {
                    Image FinalImage = image;
                    try
                    {
                        if (image.RawFormat.Equals(ImageFormat.Wmf) || image.RawFormat.Equals(ImageFormat.Emf))
                        {
                            FinalImage = FlgConsts.RasterizeWMF(image);                             //metafiles do not like cropping or changing attributes.
                        }

                        if (ChangedParams)
                        {
                            if (shadowColor != ColorUtil.Empty)
                            {
                                FlgConsts.MakeImageGray(ref imgAtt, shadowColor);
                            }
                            else
                            {
                                FlgConsts.AdjustImage(ref imgAtt, brightness, contrast);
                            }
                        }

                        PointF[] ImageRect = new PointF[] { new PointF(destRect.Left, destRect.Top), new PointF(destRect.Right, destRect.Top), new PointF(destRect.Left, destRect.Bottom) };
                        FCanvas.DrawImage(FinalImage,
                                          ImageRect,
                                          srcRect, GraphicsUnit.Pixel, imgAtt);
                    }
                    finally
                    {
                        if (FinalImage != image)
                        {
                            FinalImage.Dispose();
                        }
                    }
                }
            }
            finally
            {
                if (imgAtt != null)
                {
                    imgAtt.Dispose();
                }
            }
        }
Ejemplo n.º 27
0
 public void SetClipIntersect(RectangleF rect)
 {
     PointOutside.Check(ref rect);
     IntersectClip(new RectangleGeometry(rect));
 }
Ejemplo n.º 28
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));
 }