Example #1
0
        public static m.PathGeometry InvertHorizontally(m.PathGeometry toInvert, double maxHeight)
        {
            toInvert = toInvert.GetFlattenedPathGeometry(1, m.ToleranceType.Absolute);

            m.PathGeometry toReturn = new m.PathGeometry();

            foreach (m.PathFigure oldPf in toInvert.Figures)
            {
                m.PathFigure newPf = new m.PathFigure();

                Point newStartPoint = oldPf.StartPoint;

                newStartPoint.Y = maxHeight - newStartPoint.Y;
                newStartPoint.X = newStartPoint.X;

                newPf.StartPoint = newStartPoint;

                foreach (m.PathSegment oldPs in oldPf.Segments)
                {
                    m.PathSegment newPs = new m.PolyLineSegment();

                    foreach (Point point in ((m.PolyLineSegment)oldPs).Points)
                    {
                        Point tmp = point;
                        tmp.Y = maxHeight - tmp.Y;

                        ((m.PolyLineSegment)newPs).Points.Add(tmp);
                    }
                    newPf.Segments.Add(newPs);
                }
                toReturn.Figures.Add(newPf);
            }
            return(toReturn);
        }
Example #2
0
        public static m.PathGeometry ScalingPathGeometryOld(m.PathGeometry toDownsize, double scaling)
        {
            toDownsize = toDownsize.GetFlattenedPathGeometry(1, m.ToleranceType.Absolute);

            m.PathGeometry toReturn = new m.PathGeometry();

            foreach (m.PathFigure olfPf in toDownsize.Figures)
            {
                m.PathFigure newPf = new m.PathFigure();

                Point newStartPoint = olfPf.StartPoint;

                newStartPoint.X *= scaling;
                newStartPoint.Y *= scaling;

                newPf.StartPoint = newStartPoint;

                foreach (m.PathSegment oldPs in olfPf.Segments)
                {
                    m.PathSegment newPs = new m.PolyLineSegment();

                    foreach (Point point in ((m.PolyLineSegment)oldPs).Points)
                    {
                        Point tmp = point;
                        tmp.X *= scaling;
                        tmp.Y *= scaling;

                        ((m.PolyLineSegment)newPs).Points.Add(tmp);
                    }
                    newPf.Segments.Add(newPs);
                }
                toReturn.Figures.Add(newPf);
            }
            return(toReturn);
        }
Example #3
0
        public static m.PathGeometry CloseAllPathGeometries(m.PathGeometry toClose)
        {
            toClose = toClose.GetFlattenedPathGeometry(1, m.ToleranceType.Absolute);

            m.PathGeometry toReturn = new m.PathGeometry();

            foreach (m.PathFigure oldPf in toClose.Figures)
            {
                m.PathFigure newPf = new m.PathFigure {
                    StartPoint = oldPf.StartPoint
                };

                foreach (m.PathSegment oldPs in oldPf.Segments)
                {
                    m.PathSegment newPs = new m.PolyLineSegment();

                    foreach (Point point in ((m.PolyLineSegment)oldPs).Points)
                    {
                        ((m.PolyLineSegment)newPs).Points.Add(point);
                    }

                    ((m.PolyLineSegment)newPs).Points.Add(((m.PolyLineSegment)newPs).Points[0]);
                    newPf.Segments.Add(newPs);
                }
                toReturn.Figures.Add(newPf);
            }
            return(toReturn);
        }
Example #4
0
        private void DrawFormattedText(DpiScaleInfo dpiInfo)
        {
            FormattedText formattedText = new FormattedText(
                "FABLE",
                new System.Globalization.CultureInfo("en-US"),
                FlowDirection.LeftToRight,
                new Typeface(
                    new System.Windows.Media.FontFamily("Segoe UI"),
                    FontStyles.Normal,
                    FontWeights.Bold,
                    FontStretches.Normal),
                120,
                System.Windows.Media.Brushes.Red,
                dpiInfo.PixelsPerDip);

            // Build a geometry out of the text.
            Geometry geometry = new PathGeometry();
            geometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));

            // Adjust the geometry to fit the aspect ration of the video by scaling it.
            ScaleTransform myScaleTransform = new ScaleTransform();
            myScaleTransform.ScaleX = .85;
            myScaleTransform.ScaleY = 2.0;
            geometry.Transform = myScaleTransform;

            // Flatten the geometry and create a PathGeometry out of it.
            PathGeometry pathGeometry = new PathGeometry();
            pathGeometry = geometry.GetFlattenedPathGeometry();

            // Use the PathGeometry for the empty placeholder Path element in XAML.
            path.Data = pathGeometry;

            // Use the PathGeometry for the animated ball that follows the path of the text outline.
            matrixAnimation.PathGeometry = pathGeometry;
        }
Example #5
0
        /// <summary>
        /// Extracts the the Coordinates out of a PathGeometry and puts them into a PolyLineSegment.
        /// </summary>
        /// <param name="allPointsContainer">The PathGeometry that Contains the all the Coordinates you want to convert</param>
        /// <returns></returns>
        public static List <m.PolyLineSegment> PathGeometryToPlsListOld(m.PathGeometry allPointsContainer)
        {
            allPointsContainer = allPointsContainer.GetFlattenedPathGeometry(1.0, m.ToleranceType.Absolute);

            return
                (allPointsContainer.Figures.Select(
                     figures =>
                     figures.Segments.SelectMany(segments => ((m.PolyLineSegment)segments).Points).ToList())
                 .Select(allPoints => new m.PolyLineSegment(allPoints, true))
                 .ToList());
        }
Example #6
0
        /// <summary>
        /// Returns the pure PathGeometry to easily display at the screen.
        /// </summary>
        /// <returns></returns>
        public static m.PathGeometry GeometryToPathGeometry(m.Geometry toConvert, double resolution = 20, bool wannaFlat = false)
        {
            m.PathGeometry myPathGeometry = toConvert.GetOutlinedPathGeometry(resolution,
                                                                              m.ToleranceType.Relative);

            if (wannaFlat)
            {
                myPathGeometry = myPathGeometry.GetFlattenedPathGeometry(resolution, m.ToleranceType.Relative);
            }

            return(myPathGeometry);
        }
Example #7
0
        public static m.PathGeometry ScalingPathGeometry(m.PathGeometry toScale, double scaling, bool scaleAtZero = false)
        {
            toScale = toScale.GetFlattenedPathGeometry(1, m.ToleranceType.Absolute);

            Point pointToScale = new Point();

            if (scaleAtZero)
            {
                pointToScale = new Point(0, 0);
            }
            else
            {
                Rect rect = GetMinimalMaxRect(toScale, 0);
                pointToScale = rect.BottomLeft;
            }


            m.PathGeometry toReturn = new m.PathGeometry();

            foreach (m.PathFigure olfPf in toScale.Figures)
            {
                m.PathFigure newPf = new m.PathFigure();

                Point newStartPoint = olfPf.StartPoint;

                newStartPoint.X = (newStartPoint.X - pointToScale.X) * scaling + pointToScale.X;
                newStartPoint.Y = (newStartPoint.Y - pointToScale.Y) * scaling + pointToScale.Y;

                newPf.StartPoint = newStartPoint;

                foreach (m.PathSegment oldPs in olfPf.Segments)
                {
                    m.PathSegment newPs = new m.PolyLineSegment();

                    foreach (Point point in ((m.PolyLineSegment)oldPs).Points)
                    {
                        Point tmp = point;
                        tmp.X = (tmp.X - pointToScale.X) * scaling + pointToScale.X;
                        tmp.Y = (tmp.Y - pointToScale.Y) * scaling + pointToScale.Y;

                        ((m.PolyLineSegment)newPs).Points.Add(tmp);
                    }
                    newPf.Segments.Add(newPs);
                }
                toReturn.Figures.Add(newPf);
            }
            return(toReturn);
        }
Example #8
0
        public static double ComputeLength(PathGeometry path)
        {
            PathGeometry flattenedPath = path.GetFlattenedPathGeometry();
            double length = 0;
            Point prev = path.Figures[0].StartPoint;
            foreach (PolyLineSegment segment in flattenedPath.Figures[0].Segments)
            {
                foreach (Point p in segment.Points)
                {
                    double d = Point.Subtract(p, prev).Length;
                    prev = p;
                    length += d;
                }
            }

            return length;
        }
Example #9
0
        public static Rect GetMinimalMaxRect(m.PathGeometry pg, double rahmen)
        {
            pg = pg.GetFlattenedPathGeometry(1, m.ToleranceType.Absolute);
            m.PathSegment tmp        = pg.Figures[0].Segments[0];
            Point         firstPoint = ((m.PolyLineSegment)tmp).Points[0];

            Point max = firstPoint;
            Point min = firstPoint;

            foreach (m.PathFigure pathFigure in pg.Figures)
            {
                foreach (m.PathSegment segments in pathFigure.Segments)
                {
                    foreach (Point point in ((m.PolyLineSegment)segments).Points)
                    {
                        if (point.X > max.X)
                        {
                            max.X = point.X;
                        }
                        if (point.X < min.X)
                        {
                            min.X = point.X;
                        }
                        if (point.Y > max.Y)
                        {
                            max.Y = point.Y;
                        }
                        if (point.Y < min.Y)
                        {
                            min.Y = point.Y;
                        }
                    }
                }
            }

            min.X -= rahmen;
            min.Y -= rahmen;

            max.X += rahmen;
            max.Y += rahmen;

            return(new Rect(min, max));
        }
Example #10
0
        public static m.PathGeometry TranslatePathGeometry(m.PathGeometry toTranslate, double xOffset, double yOffset, bool textElement = false)
        {
            if (textElement)
            {
                yOffset *= -1;
            }

            toTranslate = toTranslate.GetFlattenedPathGeometry(1, m.ToleranceType.Absolute);

            m.PathGeometry toReturn = new m.PathGeometry();

            foreach (m.PathFigure oldPf in toTranslate.Figures)
            {
                m.PathFigure newPf = new m.PathFigure();

                Point newStartPoint = oldPf.StartPoint;

                newStartPoint.X = newStartPoint.X + xOffset;
                newStartPoint.Y = newStartPoint.Y + yOffset;

                newPf.StartPoint = newStartPoint;

                foreach (m.PathSegment oldPs in oldPf.Segments)
                {
                    m.PathSegment newPs = new m.PolyLineSegment();

                    foreach (Point point in ((m.PolyLineSegment)oldPs).Points)
                    {
                        Point tmp = point;
                        tmp.X = tmp.X + xOffset;
                        tmp.Y = tmp.Y + yOffset;

                        ((m.PolyLineSegment)newPs).Points.Add(tmp);
                    }
                    newPf.Segments.Add(newPs);
                }
                toReturn.Figures.Add(newPf);
            }
            return(toReturn);
        }
Example #11
0
 /// <summary>
 /// Converts a PolyQuadraticBezierSegment into a PolyLineSegment because I currently have no muse to calculate
 /// the correct Bézier curves.
 /// </summary>
 public static PdfSharp.Xps.XpsModel.PolyLineSegment FlattenSegment(PdfSharp.Xps.XpsModel.Point startPoint,
   PdfSharp.Xps.XpsModel.PolyQuadraticBezierSegment seg)
 {
   PathGeometry geo = new PathGeometry();
   PathFigure fig = new PathFigure();
   geo.Figures.Add(fig);
   fig.StartPoint = new Point(startPoint.X, startPoint.Y);
   int count = seg.Points.Count;
   Point[] points = new Point[count];
   for (int idx = 0; idx < count - 1; idx += 2)
   {
     QuadraticBezierSegment qbseg = new QuadraticBezierSegment(
       new Point(seg.Points[idx].X, seg.Points[idx].Y), new Point(seg.Points[idx + 1].X, seg.Points[idx + 1].Y), seg.IsStroked);
     fig.Segments.Add(qbseg);
   }
   geo = geo.GetFlattenedPathGeometry();
   fig = geo.Figures[0];
   PolyLineSegment lineSeg = (PolyLineSegment)fig.Segments[0];
   PdfSharp.Xps.XpsModel.PolyLineSegment resultSeg = new PdfSharp.Xps.XpsModel.PolyLineSegment();
   foreach (Point point in lineSeg.Points)
     resultSeg.Points.Add(new PdfSharp.Xps.XpsModel.Point(point.X, point.Y));
   return resultSeg;
 }
Example #12
0
        /// <summary>
        /// Approximate this figure with a polygonal PathFigure
        /// </summary>
        /// <param name="tolerance">The approximation error tolerance</param>
        /// <param name="type">The way the error tolerance will be interpreted - relative or absolute</param>
        /// <returns>Returns the polygonal approximation as a PathFigure.</returns>
        public PathFigure GetFlattenedPathFigure(double tolerance, ToleranceType type)
        {
            PathGeometry geometry = new PathGeometry();

            geometry.Figures.Add(this);

            PathGeometry flattenedGeometry = geometry.GetFlattenedPathGeometry(tolerance, type);

            int count = flattenedGeometry.Figures.Count;

            if (count == 0)
            {
                return(new PathFigure());
            }
            else if (count == 1)
            {
                return(flattenedGeometry.Figures[0]);
            }
            else
            {
                throw new InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError));
            }
        }
Example #13
0
 /// <summary>
 /// Converts an ArcSegment into a PolyLineSegment because I currently have no muse to calculate
 /// the correct Bézier curves.
 /// </summary>
 public static PdfSharp.Xps.XpsModel.PolyLineSegment FlattenSegment(PdfSharp.Xps.XpsModel.Point startPoint,
   PdfSharp.Xps.XpsModel.ArcSegment seg)
 {
   PathGeometry geo = new PathGeometry();
   PathFigure fig = new PathFigure();
   geo.Figures.Add(fig);
   fig.StartPoint = new Point(startPoint.X, startPoint.Y);
   ArcSegment aseg = new ArcSegment(new Point(seg.Point.X, seg.Point.Y), new Size(seg.Size.Width, seg.Size.Height), seg.RotationAngle,
     seg.IsLargeArc, (SweepDirection)seg.SweepDirection, seg.IsStroked);
   fig.Segments.Add(aseg);
   geo = geo.GetFlattenedPathGeometry();
   fig = geo.Figures[0];
   //PolyLineSegment lineSeg = (PolyLineSegment)fig.Segments[0];
   PdfSharp.Xps.XpsModel.PolyLineSegment resultSeg = new PdfSharp.Xps.XpsModel.PolyLineSegment();
   int count = fig.Segments.Count;
   for (int idx = 0; idx < count; idx++)
   {
     PathSegment pathSeg = fig.Segments[idx];
     if (pathSeg is PolyLineSegment)
     {
       PolyLineSegment plseg = (PolyLineSegment)pathSeg;
       foreach (Point point in plseg.Points)
         resultSeg.Points.Add(new PdfSharp.Xps.XpsModel.Point(point.X, point.Y));
     }
     else if (pathSeg is LineSegment)
     {
       LineSegment lseg = (LineSegment)pathSeg;
       resultSeg.Points.Add(new PdfSharp.Xps.XpsModel.Point(lseg.Point.X, lseg.Point.Y));
     }
     else
     {
       Debugger.Break();
     }
   }
   return resultSeg;
 }
Example #14
0
    /// <summary>
    /// Appends the content of a PathGeometry object.
    /// </summary>
    internal void AppendPath(PathGeometry geometry)
    {
#if true_
      // sissy version
      geometry = geometry.GetFlattenedPathGeometry();
#endif
      foreach (PathFigure figure in geometry.Figures)
      {
        System.Windows.Point currentPoint = new System.Windows.Point();

        // Move to start point
        currentPoint = figure.StartPoint;
        AppendFormat("{0:0.####} {1:0.####} m\n", currentPoint.X, currentPoint.Y);

        foreach (PathSegment segment in figure.Segments)
        {
          Type type = segment.GetType();
          if (type == typeof(LineSegment))
          {
            // Draw a single line
            System.Windows.Point point = ((LineSegment)segment).Point;
            currentPoint = point;
            AppendFormat("{0:0.####} {1:0.####} l\n", point.X, point.Y);
          }
          else if (type == typeof(PolyLineSegment))
          {
            // Draw connected lines
            PointCollection points = ((PolyLineSegment)segment).Points;
            foreach (System.Windows.Point point in points)
            {
              currentPoint = point; // I forced myself not to optimize this assignment
              AppendFormat("{0:0.####} {1:0.####} l\n", point.X, point.Y);
            }
          }
          else if (type == typeof(BezierSegment))
          {
            // Draw Bézier curve
            BezierSegment seg = (BezierSegment)segment;
            System.Windows.Point point1 = seg.Point1;
            System.Windows.Point point2 = seg.Point2;
            System.Windows.Point point3 = seg.Point3;
            AppendFormat("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n",
              point1.X, point1.Y, point2.X, point2.Y, point3.X, point3.Y);
            currentPoint = point3;
          }
          else if (type == typeof(PolyBezierSegment))
          {
            // Draw connected Bézier curves
            PointCollection points = ((PolyBezierSegment)segment).Points;
            int count = points.Count;
            if (count > 0)
            {
              Debug.Assert(count % 3 == 0, "Number of Points in PolyBezierSegment are not a multiple of 3.");
              for (int idx = 0; idx < count - 2; idx += 3)
              {
                System.Windows.Point point1 = points[idx];
                System.Windows.Point point2 = points[idx + 1];
                System.Windows.Point point3 = points[idx + 2];
                AppendFormat("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n",
                  point1.X, point1.Y, point2.X, point2.Y, point3.X, point3.Y);
              }
              currentPoint = points[count - 1];
            }
          }
          else if (type == typeof(ArcSegment))
          {
            // Draw arc
            ArcSegment seg = (ArcSegment)segment;
            AppendPartialArc(currentPoint, seg.Point, seg.RotationAngle, seg.Size, seg.IsLargeArc, seg.SweepDirection, PathStart.Ignore1st);
            currentPoint = seg.Point;
          }
          else if (type == typeof(QuadraticBezierSegment))
          {
            QuadraticBezierSegment seg = (QuadraticBezierSegment)segment;
            currentPoint = seg.Point2;
            // TODOWPF: Undone because XGraphics has no such curve type
            throw new NotImplementedException("AppendPath with QuadraticBezierSegment.");
          }
          else if (type == typeof(PolyQuadraticBezierSegment))
          {
            PolyQuadraticBezierSegment seg = (PolyQuadraticBezierSegment)segment;
            currentPoint = seg.Points[seg.Points.Count - 1];
            // TODOWPF: Undone because XGraphics has no such curve type
            throw new NotImplementedException("AppendPath with PolyQuadraticBezierSegment.");
          }
        }
        if (figure.IsClosed)
          Append("h\n");
      }
    }
Example #15
0
        /// <summary>
        /// Approximate this figure with a polygonal PathFigure
        /// </summary>
        /// <param name="tolerance">The approximation error tolerance</param>
        /// <param name="type">The way the error tolerance will be interpreted - relative or absolute</param>
        /// <returns>Returns the polygonal approximation as a PathFigure.</returns>
        public PathFigure GetFlattenedPathFigure(double tolerance, ToleranceType type)
        {
            PathGeometry geometry = new PathGeometry();
            geometry.Figures.Add(this);

            PathGeometry flattenedGeometry = geometry.GetFlattenedPathGeometry(tolerance, type);

            int count = flattenedGeometry.Figures.Count;

            if (count == 0)
            {
                return new PathFigure();
            }
            else if (count == 1)
            {
                return flattenedGeometry.Figures[0];
            }
            else
            {
                throw new InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError));
            }
        }