Exemple #1
0
        private Geometry Reverse(Geometry RegionToReverse)
        {
            CombinedGeometry Reversed = new CombinedGeometry(GeometryCombineMode.Exclude, FPageRect, RegionToReverse);
            Geometry         Result   = Reversed.GetFlattenedPathGeometry();

            if (Result.CanFreeze)
            {
                Result.Freeze();
            }
            return(Result);
        }
        private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            EllipseGeometry  el       = new EllipseGeometry(new Point(150, 150), 100, 50);
            EllipseGeometry  el1      = new EllipseGeometry(new Point(200, 150), 100, 100);
            Geometry         gl       = el;
            Geometry         gl1      = el1;
            CombinedGeometry CombineG = new CombinedGeometry(GeometryCombineMode.Xor, gl, gl1);
            var path = new Path();

            path.Fill   = Brushes.Red;
            path.Stroke = Brushes.Green;
            path.Data   = CombineG.GetFlattenedPathGeometry();
            this.gr.Children.Add(path);
        }
Exemple #3
0
        public static Point[] GetIntersectionPoints(System.Windows.Media.Geometry g1, System.Windows.Media.Geometry g2)
        {
            System.Windows.Media.Geometry og1 = g1.GetWidenedPathGeometry(new Pen(Brushes.Black, 1.0));
            System.Windows.Media.Geometry og2 = g2.GetWidenedPathGeometry(new Pen(Brushes.Black, 1.0));
            CombinedGeometry cg = new CombinedGeometry(GeometryCombineMode.Intersect, og1, og2);
            PathGeometry     pg = cg.GetFlattenedPathGeometry();

            Point[] result = new Point[pg.Figures.Count];
            for (int i = 0; i < pg.Figures.Count; i++)
            {
                Rect fig = new PathGeometry(new PathFigure[] { pg.Figures[i] }).Bounds;
                result[i] = new Point(fig.Left + fig.Width / 2.0, fig.Top + fig.Height / 2.0);
            }
            return(result);
        }
Exemple #4
0
        public static IEnumerable <Point> GetIntersectionPoints(Geometry g1, Geometry g2)
        {
            Geometry og1 = g1.GetWidenedPathGeometry(new Pen(Brushes.Black, 1.0));
            Geometry og2 = g2.GetWidenedPathGeometry(new Pen(Brushes.Black, 1.0));

            CombinedGeometry cg = new CombinedGeometry(GeometryCombineMode.Intersect, og1, og2);

            PathGeometry pg = cg.GetFlattenedPathGeometry();

            foreach (PathFigure figure in pg.Figures)
            {
                Rect fig = new PathGeometry(new[] { figure }).Bounds;
                yield return(new Point(fig.Left + fig.Width / 2.0, fig.Top + fig.Height / 2.0));
            }
        }
        public string Text2Path(String strText, string strCulture, bool LtoR, string strTypeFace, int nSize, Thickness masks)
        {
            // Set up the Culture
            if (strCulture == "")
            {
                strCulture = "en-us";
            }
            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(strCulture);


            // Set up the flow direction
            System.Windows.FlowDirection fd;
            if (LtoR)
            {
                fd = FlowDirection.LeftToRight;
            }
            else
            {
                fd = FlowDirection.RightToLeft;
            }

            // Set up the font family from the parameter
            FontFamily ff = new FontFamily(strTypeFace);

            // Create the new typeface
            System.Windows.Media.Typeface tf = new System.Windows.Media.Typeface(ff,

                                                                                 FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);


            // Create a formatted text object from the text,

            // culture, flowdirection, typeface, size and black


            FormattedText t = new FormattedText(strText, ci, fd, tf, nSize,

                                                System.Windows.Media.Brushes.Black);

            // Build a Geometry out of this
            Geometry g = t.BuildGeometry(new Point(0, 0));

            // Get the Path info from the geometry
            PathGeometry p     = g.GetFlattenedPathGeometry();
            var          x     = nSize - masks.Left - masks.Right;
            var          y     = nSize - masks.Top - masks.Bottom;
            var          size  = new Size(x < 0 ? 0 : x, y < 0 ? 0 : y);
            var          rectv = new Rect(new Point(masks.Left, masks.Top), size);

            RectangleGeometry rg = new RectangleGeometry(rectv);
            var cg = new CombinedGeometry(p, rg);

            cg.GeometryCombineMode = GeometryCombineMode.Intersect;



            p = cg.GetFlattenedPathGeometry();

            // Return the path info
            return(p.ToString());
        }