public BarCodeRenderInfo(XGraphics gfx, XBrush brush, XFont font, XPoint position)
 {
   Gfx = gfx;
   Brush = brush;
   Font = font;
   Position = position;
 }
    /// <summary>
    /// Demonstrates the use of XGraphics.DrawBeziers.
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);

      int n = 2;
      int count = 1 + 3 * n;
      XPoint[] points = new XPoint[count];
      Random rnd = new Random(42);
      for (int idx = 0; idx < count; idx++)
      {
        points[idx].X = 20 + rnd.Next(600);
        points[idx].Y = 50 + rnd.Next(800);
      }

      // Draw the points
      XPen pen = new XPen(XColors.Red, 0.5);
      pen.DashStyle = XDashStyle.Dash;
      for (int idx = 0; idx + 3 < count; idx += 3)
      {
        gfx.DrawEllipse(XBrushes.Red, MakeRect(points[idx]));
        gfx.DrawEllipse(XBrushes.Red, MakeRect(points[idx + 1]));
        gfx.DrawEllipse(XBrushes.Red, MakeRect(points[idx + 2]));
        gfx.DrawEllipse(XBrushes.Red, MakeRect(points[idx + 3]));
        gfx.DrawLine(pen, points[idx], points[idx + 1]);
        gfx.DrawLine(pen, points[idx + 2], points[idx + 3]);
      }

      // Draw the curve
      gfx.DrawBeziers(properties.Pen2.Pen, points);
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="XLinearGradientBrush"/> class.
 /// </summary>
 public XLinearGradientBrush(XPoint point1, XPoint point2, XColor color1, XColor color2)
 {
   this.point1 = point1;
   this.point2 = point2;
   this.color1 = color1;
   this.color2 = color2;
 }
Example #4
0
        /// <summary>
        /// Calculates the space used for the axis title.
        /// </summary>
        internal override void Format()
        {
            XGraphics gfx = _rendererParms.Graphics;

            AxisTitleRendererInfo atri = ((AxisRendererInfo)_rendererParms.RendererInfo)._axisTitleRendererInfo;
            if (atri.AxisTitleText != "")
            {
                XSize size = gfx.MeasureString(atri.AxisTitleText, atri.AxisTitleFont);
                if (atri.AxisTitleOrientation != 0)
                {
                    XPoint[] points = new XPoint[2];
                    points[0].X = 0;
                    points[0].Y = 0;
                    points[1].X = size.Width;
                    points[1].Y = size.Height;

                    XMatrix matrix = new XMatrix();
                    matrix.RotatePrepend(-atri.AxisTitleOrientation);
                    matrix.TransformPoints(points);

                    size.Width = Math.Abs(points[1].X - points[0].X);
                    size.Height = Math.Abs(points[1].Y - points[0].Y);
                }

                atri.X = 0;
                atri.Y = 0;
                atri.Height = size.Height;
                atri.Width = size.Width;
            }
        }
    /// <summary>
    /// Demonstrates the use of XGraphics.DrawRoundedRectangle.
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);

      // Stroke ellipse
      gfx.DrawEllipse(properties.Pen1.Pen, 50, 100, 450, 150);

      // Fill ellipse
      gfx.DrawEllipse(properties.Brush2.Brush, new Rectangle(50, 300, 450, 150));

      // Stroke and fill ellipse
      gfx.DrawEllipse(properties.Pen2.Pen, properties.Brush2.Brush, new RectangleF(50, 500, 450, 150));

      // Stroke circle
      gfx.DrawEllipse(properties.Pen2.Pen, new XRect(100, 200, 400, 400));

#if DEBUG
      int count = 360;
      XPoint[] circle = new XPoint[count];
      for (int idx = 0; idx < count; idx++)
      {
        double rad = idx * 2 * Math.PI / count;
        circle[idx].X = Math.Cos(rad) * 200 + 300;
        circle[idx].Y = Math.Sin(rad) * 200 + 400;
      }
      gfx.DrawPolygon(properties.Pen3.Pen, circle);
#endif
    }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the XRect class.
 /// </summary>
 public XRect(XPoint location, XSize size)
 {
   this.x = location.X;
   this.y = location.Y;
   this.width = size.Width;
   this.height = size.Height;
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the XRect class.
 /// </summary>
 public XRect(XPoint point1, XPoint point2)
 {
     _x = Math.Min(point1.X, point2.X);
     _y = Math.Min(point1.Y, point2.Y);
     _width = Math.Max(Math.Max(point1.X, point2.X) - _x, 0);
     _height = Math.Max(Math.Max(point1.Y, point2.Y) - _y, 0);
 }
Example #8
0
 /// <summary>
 /// Appends a Bézier segment from a curve.
 /// </summary>
 public static BezierSegment CreateCurveSegment(XPoint pt0, XPoint pt1, XPoint pt2, XPoint pt3, double tension3)
 {
   return new BezierSegment(
     new System.Windows.Point(pt1.X + tension3 * (pt2.X - pt0.X), pt1.Y + tension3 * (pt2.Y - pt0.Y)),
     new System.Windows.Point(pt2.X - tension3 * (pt3.X - pt1.X), pt2.Y - tension3 * (pt3.Y - pt1.Y)),
     new System.Windows.Point(pt2.X, pt2.Y), true);
 }
Example #9
0
 /// <summary>
 /// Convert from WinForms point to core point.
 /// </summary>
 public static XPoint[] Convert(RPoint[] points)
 {
     XPoint[] myPoints = new XPoint[points.Length];
     for (int i = 0; i < points.Length; i++)
         myPoints[i] = Convert(points[i]);
     return myPoints;
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the XRect class.
 /// </summary>
 public XRect(XPoint point1, XPoint point2)
 {
   this.x = Math.Min(point1.x, point2.x);
   this.y = Math.Min(point1.y, point2.y);
   this.width = Math.Max((double)(Math.Max(point1.x, point2.x) - this.x), 0);
   this.height = Math.Max((double)(Math.Max(point1.y, point2.y) - this.y), 0);
 }
    /// <summary>
    /// Draws the content of the area plot area.
    /// </summary>
    internal override void Draw()
    {
      ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;
      XRect plotAreaRect = cri.plotAreaRendererInfo.Rect;
      if (plotAreaRect.IsEmpty)
        return;

      XGraphics gfx = this.rendererParms.Graphics;
      XGraphicsState state = gfx.Save();
      //gfx.SetClip(plotAreaRect, XCombineMode.Intersect);
      gfx.IntersectClip(plotAreaRect);

      XMatrix matrix = cri.plotAreaRendererInfo.matrix;
      double xMajorTick = cri.xAxisRendererInfo.MajorTick;
      foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
      {
        int count = sri.series.Elements.Count;
        XPoint[] points = new XPoint[count + 2];
        points[0] = new XPoint(xMajorTick / 2, 0);
        for (int idx = 0; idx < count; idx++)
        {
          double pointValue = sri.series.Elements[idx].Value;
          if (double.IsNaN(pointValue))
            pointValue = 0;
          points[idx + 1] = new XPoint(idx + xMajorTick / 2, pointValue);
        }
        points[count + 1] = new XPoint(count - 1 + xMajorTick / 2, 0);
        matrix.TransformPoints(points);
        gfx.DrawPolygon(sri.LineFormat, sri.FillFormat, points, XFillMode.Winding);
      }

      //gfx.ResetClip();
      gfx.Restore(state);
    }
Example #12
0
 public Pagel(Pagel parent, XRect percetileRectangle)
 {
     parent.AddChild(this);
     this.minPoint = new XPoint(parent.Rectangle.X * percetileRectangle.X, parent.Rectangle.Y * percetileRectangle.Y);
     this.maxPoint = minPoint + new XPoint(parent.Rectangle.Width * percetileRectangle.Width,
         parent.Rectangle.Height * percetileRectangle.Height);
     this.Rectangle = new XRect(minPoint, maxPoint);
 }
 /// <summary>
 /// Gets a five-pointed star with the specified size and center.
 /// </summary>
 public static XPoint[] GetPentagram(double size, XPoint center)
 {
   XPoint[] points = Pentagram.Clone() as XPoint[];
   for (int idx = 0; idx < 5; idx++)
   {
     points[idx].X = points[idx].X * size + center.X;
     points[idx].Y = points[idx].Y * size + center.Y;
   }
   return points;
 }
Example #14
0
        public void DrawBarCharts(XGraphics gfx)
        {
            XPoint backgroundPoint = new XPoint(20, page_.Height * 0.55);
            XRect backgroundRect = new XRect(backgroundPoint.X, backgroundPoint.Y, page_.Width - 40, page_.Height * 0.425);
            double quarterRectWidth = backgroundRect.Width * 0.25;
            double offset = quarterRectWidth * 0.25;
            DrawingUtil.DrawOutlineRect(backgroundRect, gfx, new XSize(40,40));
            gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromKnownColor(XKnownColor.Gray)),
                backgroundRect,
                new XSize(40, 40));

            DoubleBar ShoulderFlexionBar = new DoubleBar(userParameters_[dataReadStart + 4], userParameters_[dataReadStart + 9], gfx);
            ShoulderFlexionBar.Draw(new XPoint(quarterRectWidth - offset, backgroundPoint.Y + 20),
                backgroundRect,
                XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\DOS.png"));

            DoubleBar hipFlexionBar = new DoubleBar(userParameters_[dataReadStart + 5], userParameters_[dataReadStart + 10], gfx);
            hipFlexionBar.Draw(new XPoint(quarterRectWidth * 2 - offset, backgroundPoint.Y + 20),
                backgroundRect,
                 XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\DOS.png"));

            DoubleBar kneeFlexionBar = new DoubleBar(userParameters_[dataReadStart + 6], userParameters_[dataReadStart + 11], gfx);
            kneeFlexionBar.Draw(new XPoint(quarterRectWidth * 3 - offset, backgroundPoint.Y + 20),
                backgroundRect,
                XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\DOS.png"));

            DoubleBar ankleFlexionBar = new DoubleBar(userParameters_[dataReadStart + 7], userParameters_[dataReadStart + 12], gfx);
            ankleFlexionBar.Draw(new XPoint(quarterRectWidth * 4 - offset, backgroundPoint.Y + 20),
                backgroundRect,
                XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\DOS.png"));

            gfx.DrawString("Degrees :",
                new XFont("Arial", 10),
                XBrushes.Black,
                (backgroundPoint + new XPoint(0, 20)) + new XPoint(backgroundRect.Width * 0.05, backgroundRect.Height * 0.05),
                XStringFormats.Center);

            gfx.DrawString("LSI % :",
                new XFont("Arial", 10),
                XBrushes.Black,
                (backgroundPoint + new XPoint(0, 20)) + new XPoint(backgroundRect.Width * 0.05, backgroundRect.Height * 0.125),
                XStringFormats.Center);

            XPoint top = new XPoint(backgroundPoint.X, backgroundPoint.Y + backgroundRect.Height * 0.2);
            XPoint bottom = new XPoint(backgroundPoint.X, backgroundPoint.Y + backgroundRect.Height * 0.8);
            for (int i = 11; i > 0; i--)
            {
                float increment = -i * 0.1f;

                XPoint percentagePoint = DrawingUtil.Instance.Interpolate(top, bottom, increment);
                percentagePoint = new XPoint(percentagePoint.X, Math.Floor(percentagePoint.Y));
                gfx.DrawString(((11 - i) * 10).ToString() + "%", new XFont("Arial", 8), XBrushes.Black, percentagePoint + new XPoint(5, -2));
                gfx.DrawLine(XPens.LightGray, percentagePoint, percentagePoint + new XPoint(backgroundRect.Width, 0));
            }
        }
    /// <summary>
    /// Appends a Bézier segment from a curve.
    /// </summary>
    public static BezierSegment CreateCurveSegment(XPoint pt0, XPoint pt1, XPoint pt2, XPoint pt3, double tension3)
    {
#if !SILVERLIGHT
      return new BezierSegment(
        new System.Windows.Point(pt1.X + tension3 * (pt2.X - pt0.X), pt1.Y + tension3 * (pt2.Y - pt0.Y)),
        new System.Windows.Point(pt2.X - tension3 * (pt3.X - pt1.X), pt2.Y - tension3 * (pt3.Y - pt1.Y)),
        new System.Windows.Point(pt2.X, pt2.Y), true);
#else
      return new BezierSegment(); // AGHACK
#endif
    }
Example #16
0
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);

      XPoint[] points = new XPoint[]
      {
        new XPoint(50, 100),
        new XPoint(450, 120),
        new XPoint(550, 300),
        new XPoint(150, 380),
      };
      gfx.DrawCurve(properties.Pen2.Pen, points, properties.General.Tension);
    }
Example #17
0
        public void Draw(XPoint basePoint, XRect baseRect, XImage img)
        {
            XFont headerFont = new XFont("Arial", 16);
            XFont subfont = new XFont("Arial", 10);
            char degree = Convert.ToChar('\u00b0');
            gfx.DrawString(parameterLeft.Name.Substring(5, parameterLeft.Name.Length - 5), headerFont, XBrushes.Black, basePoint, XStringFormats.Center);
            gfx.DrawString(parameterLeft.Value.ToString() + degree, subfont, XBrushes.Black, basePoint + new XPoint(-15, baseRect.Height * 0.05),XStringFormats.Center);
            gfx.DrawString(parameterRight.Value.ToString() + degree, subfont, XBrushes.Black, basePoint + new XPoint(20, baseRect.Height * 0.05), XStringFormats.Center);

            XBrush brush = XBrushes.Black;

            brush = DrawingUtil.Instance.ChooseBrushColor(parameterLeft.LSI, 49, 74);

            XRect r = new XRect(basePoint + new XPoint(-baseRect.Width * 0.05, baseRect.Height * 0.075),
                new XSize(baseRect.Width * 0.1, baseRect.Height * 0.075));

            DrawingUtil.DrawOutlineRect(r, gfx, new XSize(10, 10));

            gfx.DrawRoundedRectangle(brush, r, new XSize(10,10));
            gfx.DrawString(parameterLeft.LSI.ToString("0") + "%",
                subfont,
                XBrushes.Black,
                basePoint + new XPoint(baseRect.Width * -0.025, baseRect.Height * 0.125));

            XSolidBrush blue = new XSolidBrush(XColor.FromArgb(127, 0, 0, 255));
            XSolidBrush yellow = new XSolidBrush(XColor.FromArgb(127, 255, 255, 0));

            XPoint top = new XPoint(basePoint.X - 20,Math.Ceiling( basePoint.Y + baseRect.Height * 0.2));
            XPoint bottom = new XPoint(basePoint.X - 20, Math.Ceiling(basePoint.Y + baseRect.Height * 0.8));

            XPoint leftRectPoint = Interpolate(bottom, top, -parameterLeft.Percentage);
            XRect leftBar = new XRect(leftRectPoint, new XSize(20, bottom.Y - leftRectPoint.Y  ));
            gfx.DrawRectangle(blue, leftBar);

            XPoint rigthRectPoint = Interpolate(bottom, top, -parameterRight.Percentage);
            XRect rightBar = new XRect(rigthRectPoint + new XPoint(30,0), new XSize(20, bottom.Y - rigthRectPoint.Y));
            gfx.DrawRectangle(yellow, rightBar);

            XPoint offset = new XPoint(25, 0);
            gfx.DrawLine(XPens.Green, top + offset, bottom + offset);
            gfx.DrawLine(XPens.Yellow, Interpolate(bottom, top, - parameterLeft.AmberVal) + offset, bottom + offset);
            gfx.DrawLine(XPens.Red, Interpolate(bottom, top, -parameterLeft.RedVal) + offset, bottom + offset);

            gfx.DrawString("L", subfont, XBrushes.Black, bottom + new XPoint(5, -2));
            gfx.DrawString("R", subfont, XBrushes.Black, bottom + new XPoint(35, -2));

            double wRatio = (double)img.PixelWidth / (double)img.PixelHeight;

            gfx.DrawImage(img, new XRect(new XPoint(bottom.X, bottom.Y), new XSize(wRatio * 50, 50)));
            img.Dispose();
        }
Example #18
0
        public void DrawStats(XGraphics gfx)
        {
            XFont large = new XFont("Arial", 20);
            XFont small = new XFont("Arial", 12);

            double yOff = page_.Height * 0.11;

            XRect rect = new XRect(20, yOff, page_.Width - 40, page_.Height - (yOff + 20));
            DrawingUtil.DrawOutlineRect(rect, gfx, cornerRadius);
            gfx.DrawRoundedRectangle(backgroundBrush, rect, cornerRadius);
            XPoint center = new XPoint(page_.Width * 0.5, page_.Height * 0.45);

            XImage sideLunge = XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\SideLunge.png");
            XImage frontLunge = XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\FrontLunge.png");

            gfx.DrawString("Left Lunge", large, XBrushes.Black, new XPoint(center.X - page_.Width * 0.25, page_.Height * 0.25), XStringFormats.Center);
            gfx.DrawString("Right Lunge", large, XBrushes.Black, new XPoint(center.X + page_.Width * 0.25, page_.Height * 0.25), XStringFormats.Center);

            for (int i = 0; i < 4; i++)
            {
                Parameter param1 = userParameters_.ElementAt(dataReadStart + i);
                Parameter param2 = userParameters_.ElementAt(dataReadStart + i + 4);
                char degree = Convert.ToChar('\u00b0');
                XBrush leftParamCol = XBrushes.Green;
                XBrush rightParamCol = XBrushes.Green;

                double y = (i * page_.Height * 0.15f) + page_.Height * 0.35;
                gfx.DrawString(param1.Name, small, XBrushes.Black, new XPoint(center.X - page_.Width * 0.25, y), XStringFormats.Center);

                leftParamCol = DrawingUtil.Instance.ChooseBrushColor(param1.Color);
                XRect infoRect = new XRect(center.X - page_.Width * 0.25 - 25, y + 20, 50, 35);
                DrawingUtil.DrawOutlineRect(infoRect, gfx, new XSize(10, 10));
                gfx.DrawRoundedRectangle(leftParamCol, infoRect, new XSize(10, 10));
                gfx.DrawString(param1.Value.ToString() + degree, small, XBrushes.Black, new XPoint(infoRect.X + 25, infoRect.Y + 17.5), XStringFormats.Center);

                gfx.DrawString(param2.Name, small, XBrushes.Black, new XPoint(center.X + page_.Width * 0.25, y), XStringFormats.Center);
                rightParamCol = DrawingUtil.Instance.ChooseBrushColor(param2.Color);
                infoRect = new XRect(center.X + page_.Width * 0.25 - 25, y + 20, 50, 35);
                DrawingUtil.DrawOutlineRect(infoRect, gfx, new XSize(10, 10));
                gfx.DrawRoundedRectangle(rightParamCol, infoRect, new XSize(10, 10));
                gfx.DrawString(param2.Value.ToString() + degree, small, XBrushes.Black, new XPoint(infoRect.X + 25, infoRect.Y + 17.5), XStringFormats.Center);

                XImage img = i > 1 ? frontLunge : sideLunge;

                double wRatio = (double)img.PixelWidth / (double)sideLunge.PixelHeight;
                XRect imgRect = new XRect(center.X - wRatio * 40, y, wRatio * 80, 80);
                gfx.DrawImage(img, imgRect);
            }
        }
    /// <summary>
    /// Demonstrates the use of XGraphics.DrawLines.
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      //base.RenderPage(gfx);

      XPoint[] points = new XPoint[]
      {
        new XPoint(50, 100),
        new XPoint(450, 120),
        new XPoint(550, 300),
        new XPoint(150, 380),
        new XPoint(120, 190),
      };

      gfx.DrawLines(properties.Pen2.Pen, points);
    }
Example #20
0
        /// <summary>
        /// Appends a Bézier segment from a curve.
        /// </summary>
        public static BezierSegment CreateCurveSegment(XPoint pt0, XPoint pt1, XPoint pt2, XPoint pt3, double tension3)
        {
#if !SILVERLIGHT && !NETFX_CORE
            return new BezierSegment(
                new SysPoint(pt1.X + tension3 * (pt2.X - pt0.X), pt1.Y + tension3 * (pt2.Y - pt0.Y)),
                new SysPoint(pt2.X - tension3 * (pt3.X - pt1.X), pt2.Y - tension3 * (pt3.Y - pt1.Y)),
                new SysPoint(pt2.X, pt2.Y), true);
#else
            BezierSegment bezierSegment = new BezierSegment();
            bezierSegment.Point1 = new SysPoint(pt1.X + tension3 * (pt2.X - pt0.X), pt1.Y + tension3 * (pt2.Y - pt0.Y));
            bezierSegment.Point2 = new SysPoint(pt2.X - tension3 * (pt3.X - pt1.X), pt2.Y - tension3 * (pt3.Y - pt1.Y));
            bezierSegment.Point3 = new SysPoint(pt2.X, pt2.Y);
            return bezierSegment;
#endif
        }
Example #21
0
    void DrawCodePage(XGraphics gfx, XPoint origin)
    {
      const double dx = 25;
      const double dy = 25;
      XFont labelFont = new XFont("Verdana", 10, XFontStyle.Bold);
      //XFont font = new XFont("Bauhaus", 16);
      XFont font = this.properties.Font1.Font;
      //XFont labelFont = font;
      //font = new XFont("Symbol", 16);
      Encoding encoding = Encoding.GetEncoding(1252);
      double asdf = XColors.LightGray.GS;
      //XBrush lighter = new XSolidBrush(XColor.FromGrayScale(XColor.LightGray.GS * 1.1));
      XBrush lighter = new XSolidBrush(XColor.FromGrayScale(0.9));

      XFontStyle style = font.Style;
      double lineSpace = font.GetHeight(gfx);
      int cellSpace   = font.FontFamily.GetLineSpacing(style);
      int cellAscent  = font.FontFamily.GetCellAscent(style);
      int cellDescent = font.FontFamily.GetCellDescent(style);
      int cellLeading = cellSpace - cellAscent - cellDescent;

      double ascent  = lineSpace * cellAscent / cellSpace;
      double descent = lineSpace * cellDescent / cellSpace;
      double leading = lineSpace * cellLeading / cellSpace;

      double x = origin.X + dx;
      double y = origin.Y;
      //for (int idx = 0; idx < 16; idx++)
      //  gfx.DrawString("x" + idx.ToString("X"), labelFont, XBrushes.DarkGray, x + idx * dx, y);
      for (int row = 0; row < 16; row++)
      {
        x = origin.X;
        y += dy;
        //gfx.DrawString(row.ToString("X") + "x", labelFont, XBrushes.DarkGray, x, y);
        for (int clm = 0; clm < 16; clm++)
        {
          x += dx;
          string glyph = encoding.GetString(new byte[1]{Convert.ToByte(row * 16 + clm)});
          glyph += "!";
          XSize size = gfx.MeasureString(glyph, font);
          gfx.DrawRectangle(XBrushes.LightGray, x, y - size.Height + descent, size.Width, size.Height);
          gfx.DrawRectangle(lighter, x, y - size.Height + descent, size.Width, leading);
          gfx.DrawRectangle(lighter, x, y, size.Width, descent);
          gfx.DrawString(glyph, font, XBrushes.Black, x, y);
        }
      }
    }
Example #22
0
    /// <summary>
    /// Renders the OMR code.
    /// </summary>
    protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
    {
      XGraphicsState state = gfx.Save();

      switch (this.direction)
      {
        case CodeDirection.RightToLeft:
          gfx.RotateAtTransform(180, position);
          break;

        case CodeDirection.TopToBottom:
          gfx.RotateAtTransform(90, position);
          break;

        case CodeDirection.BottomToTop:
          gfx.RotateAtTransform(-90, position);
          break;
      }

      //XPoint pt = center - this.size / 2;
      XPoint pt = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size);
      uint value;
      uint.TryParse(this.text, out value);
#if true
      // HACK: Project Wallenwein: set LK
      value |= 1;
      this.synchronizeCode = true;
#endif
      if (this.synchronizeCode)
      {
        XRect rect = new XRect(pt.x, pt.y, this.makerThickness, this.size.height);
        gfx.DrawRectangle(brush, rect);
        pt.x += 2 * this.makerDistance;
      }
      for (int idx = 0; idx < 32; idx++)
      {
        if ((value & 1) == 1)
        {
          XRect rect = new XRect(pt.x + idx * this.makerDistance, pt.y, this.makerThickness, this.size.height);
          gfx.DrawRectangle(brush, rect);
        }
        value = value >> 1;
      }
      gfx.Restore(state);
    }
Example #23
0
        public void Draw(XPoint basePoint, XRect baseRect, XImage image)
        {
            XFont headerFont = new XFont("Arial", 16);
            XFont subfont = new XFont("Arial", 10);
            char degree = Convert.ToChar('\u00b0');
            gfx.DrawString(parameterLeft.Name.Substring(5, parameterLeft.Name.Length - 5), headerFont, XBrushes.Black, basePoint, XStringFormats.Center);
            gfx.DrawString(parameterLeft.Value.ToString() + degree, subfont, XBrushes.Black, basePoint + new XPoint(-25, baseRect.Height * 0.05),XStringFormats.Center);
            gfx.DrawString(parameterRight.Value.ToString() + degree, subfont, XBrushes.Black, basePoint + new XPoint(25, baseRect.Height * 0.05), XStringFormats.Center);

            XBrush brush = XBrushes.Black;

            if (parameterLeft.LSI >= 75)
                brush = XBrushes.Green;
            else
                brush = XBrushes.Gold;

            gfx.DrawRoundedRectangle(brush,
                new XRect(basePoint + new XPoint(-baseRect.Width * 0.05, baseRect.Height * 0.075),
                new XSize(baseRect.Width * 0.1, baseRect.Height * 0.075)),
                new XSize(10,10));
            gfx.DrawString(parameterLeft.LSI.ToString("0") + "%",
                subfont,
                XBrushes.Black,
                basePoint + new XPoint(baseRect.Width * -0.025, baseRect.Height * 0.125));

            XSolidBrush blue = new XSolidBrush(XColor.FromArgb(127, 0, 0, 255));
            XSolidBrush yellow = new XSolidBrush(XColor.FromArgb(127, 255, 255, 0));

            XPoint top = new XPoint(basePoint.X - 20, basePoint.Y + baseRect.Height * 0.2);
            XPoint bottom = new XPoint(basePoint.X - 20, basePoint.Y + baseRect.Height * 0.8);

            XPoint leftRectPoint = Interpolate(bottom, top, -parameterLeft.Percentage);
            XRect leftBar = new XRect(leftRectPoint, new XSize(20, bottom.Y - leftRectPoint.Y  ));
            gfx.DrawRectangle(blue, leftBar);

            XPoint rigthRectPoint = Interpolate(bottom, top, -parameterRight.Percentage);
            XRect rightBar = new XRect(rigthRectPoint + new XPoint(30,0), new XSize(20, bottom.Y - rigthRectPoint.Y));
            gfx.DrawRectangle(yellow, rightBar);

            gfx.DrawString("L", subfont, XBrushes.Black, bottom + new XPoint(5, -2));
            gfx.DrawString("R", subfont, XBrushes.Black, bottom + new XPoint(35, -2));

            gfx.DrawImage(image, new XRect(bottom.X, bottom.Y, 50, 50));
            image.Dispose();
        }
Example #24
0
 private static void DrawLineCurveInternal(XGraphics gfx, XPen pen, bool isStroked, ref XPoint pt1, ref XPoint pt2, double curvature, Core2D.Style.CurveOrientation orientation, Core2D.Shape.PointAlignment pt1a, Core2D.Shape.PointAlignment pt2a)
 {
     if (isStroked)
     {
         var path = new XGraphicsPath();
         double p1x = pt1.X;
         double p1y = pt1.Y;
         double p2x = pt2.X;
         double p2y = pt2.Y;
         Core2D.Shapes.XLineExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt1a, pt2a, ref p1x, ref p1y, ref p2x, ref p2y);
         path.AddBezier(
             pt1.X, pt1.Y,
             p1x, p1y,
             p2x, p2y,
             pt2.X, pt2.Y);
         gfx.DrawPath(pen, path);
     }
 }
Example #25
0
        public XPoint[] GeneratePoints(XPoint center, float size, int sides, XGraphics gfx, int angleOffset = 270)
        {
            XPoint[] points = new XPoint[sides + 1];
            float degreeSegments = 360.0f / sides;

            //calculte all of the point in the polygon
            for (int i = 0; i < sides; i++)
            {
                float angle = i * degreeSegments + angleOffset;
                angle *= ((float)Math.PI / 180);
                XPoint location = new XPoint(size * Math.Cos(angle) + center.X,
                    size * Math.Sin(angle) + center.Y);

                points[i] = location;
            }
            points[sides] = points[0];
            return points;
        }
    /// <summary>
    /// Source and more infos: http://www.math.dartmouth.edu/~dlittle/java/SpiroGraph/
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);

      //int R =  60, r =  60, p =   60, N = 270; // Cardioid
      //int R =  60, r = -45, p = -101, N = 270; // Rounded Square
      //int R =  75, r = -25, p =   85, N = 270; // Gold fish
      //int R =  75, r = -30, p =   60, N = 270; // Star fish
      //int R = 100, r =  49, p =   66, N =   7; // String of Pearls
      //int R =  90, r =   1, p =  105, N = 105; // Rotating Triangle

      //int R =  90, r =   1, p =  105, N = 105;
      int R =  60, r =   2, p =  122, N = 490;

      int revs = Math.Abs(r) / Gcd(R, Math.Abs(r));
      XPoint[] points = new XPoint[revs * N + 1];
      for (int i = 0; i <= revs * N; i++)
      {
        double t = 4 * i * Math.PI / N;
        points[i].X = ((R+r)*Math.Cos(t) - p * Math.Cos((R+r)* t / r));
        points[i].Y = ((R+r)*Math.Sin(t) - p * Math.Sin((R+r)* t / r));
      }

#if true
      // Draw as lines
      gfx.TranslateTransform(300, 250);
      gfx.DrawLines(properties.Pen2.Pen, points);

      //gfx.DrawPolygon(properties.Pen2.Pen, properties.Brush2.Brush, points, properties.General.FillMode);

      // Draw as closed curve
      gfx.TranslateTransform(0, 400);
      gfx.DrawClosedCurve(properties.Pen2.Pen, properties.Brush2.Brush, points, properties.General.FillMode,
        properties.General.Tension);
#else
      gfx.TranslateTransform(300, 400);
      XSolidBrush dotBrush = new XSolidBrush(properties.Pen2.Pen.Color);
      float width = properties.Pen2.Width;
      for (int i = 0; i < revs * N; i++)
        gfx.DrawEllipse(dotBrush,points[i].X, points[i].Y, width, width);
#endif
    }
    /// <summary>
    /// Draws the content of the line plot area.
    /// </summary>
    internal override void Draw()
    {
      ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

      XRect plotAreaRect = cri.plotAreaRendererInfo.Rect;
      if (plotAreaRect.IsEmpty)
        return;

      XGraphics gfx = this.rendererParms.Graphics;
      XGraphicsState state = gfx.Save();
      //gfx.SetClip(plotAreaRect, XCombineMode.Intersect);
      gfx.IntersectClip(plotAreaRect);

      //TODO null-Values müssen berücksichtigt werden.
      //     Verbindungspunkte können fehlen, je nachdem wie null-Values behandelt werden sollen.
      //     (NotPlotted, Interpolate etc.)

      // Draw lines and markers for each data series.
      XMatrix matrix = cri.plotAreaRendererInfo.matrix;

      double xMajorTick = cri.xAxisRendererInfo.MajorTick;
      foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
      {
        int count = sri.series.Elements.Count;
        XPoint[] points = new XPoint[count];
        for (int idx = 0; idx < count; idx++)
        {
          double v = sri.series.Elements[idx].Value;
          if (double.IsNaN(v))
            v = 0;
          points[idx] = new XPoint(idx + xMajorTick / 2, v);
        }
        matrix.TransformPoints(points);
        gfx.DrawLines(sri.LineFormat, points);
        DrawMarker(gfx, points, sri);
      }

      //gfx.ResetClip();
      gfx.Restore(state);
    }
Example #28
0
        public void DrawBarCharts(XGraphics gfx)
        {
            XPoint backgroundPoint = new XPoint(20, page.Height * 0.585);
            XRect backgroundRect = new XRect(backgroundPoint.X, backgroundPoint.Y, page.Width - 40, page.Height * 0.41);
            gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromKnownColor(XKnownColor.Gray)),
                backgroundRect,
                new XSize(40, 40));

            DoubleBar ShoulderFlexionBar = new DoubleBar(userParameters["LEFT Shoulder Flexion"], userParameters["RIGHT Shoulder Flexion"], gfx);
            ShoulderFlexionBar.Draw(new XPoint(quaterWidth * 0.5  - 10,backgroundPoint.Y + 20),
                backgroundRect,
                XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Shoulder Flexion.png"));

            DoubleBar hipFlexionBar = new DoubleBar(userParameters["LEFT Hip Flexion"], userParameters["RIGHT Hip Flexion"], gfx);
            hipFlexionBar.Draw(new XPoint(quaterWidth * 2 - (quaterWidth * 0.5) - 10, backgroundPoint.Y + 20),
                backgroundRect,
                 XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Hip Flexion.png"));

            DoubleBar kneeFlexionBar = new DoubleBar(userParameters["LEFT Knee Flexion"], userParameters["RIGHT Knee Flexion"], gfx);
            kneeFlexionBar.Draw(new XPoint(quaterWidth * 3 - (quaterWidth * 0.5) - 10, backgroundPoint.Y + 20),
                backgroundRect,
                XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Knee Flexion.png"));

            DoubleBar ankleFlexionBar = new DoubleBar(userParameters["LEFT Ankle Flexion"], userParameters["RIGHT Ankle Flexion"], gfx);
            ankleFlexionBar.Draw(new XPoint(quaterWidth * 4 - (quaterWidth * 0.5) - 10, backgroundPoint.Y + 20),
                backgroundRect,
                XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Ankle Flexion.png"));

            XPoint top = new XPoint(backgroundPoint.X, backgroundPoint.Y + backgroundRect.Height * 0.2);
            XPoint bottom = new XPoint(backgroundPoint.X, backgroundPoint.Y + backgroundRect.Height * 0.8);
            for (int i = 11; i > 0; i--)
            {
                float increment = -i * 0.1f;

                XPoint percentagePoint = Interpolate(top, bottom, increment);
                gfx.DrawString(((11 - i) * 10).ToString() + "%", new XFont("Arial", 8), XBrushes.Black, percentagePoint + new XPoint(5, 0));
                gfx.DrawLine(XPens.Black, percentagePoint, percentagePoint + new XPoint(backgroundRect.Width, 0));

            }
        }
Example #29
0
        /// <summary>
        /// Draws the content of the line plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)_rendererParms.RendererInfo;

            XRect plotAreaRect = cri.plotAreaRendererInfo.Rect;
            if (plotAreaRect.IsEmpty)
                return;

            XGraphics gfx = _rendererParms.Graphics;
            XGraphicsState state = gfx.Save();
            //gfx.SetClip(plotAreaRect, XCombineMode.Intersect);
            gfx.IntersectClip(plotAreaRect);

            //TODO Treat null values correctly.
            //     Points can be missing. Treat null values accordingly (NotPlotted, Interpolate etc.)

            // Draw lines and markers for each data series.
            XMatrix matrix = cri.plotAreaRendererInfo._matrix;

            double xMajorTick = cri.xAxisRendererInfo.MajorTick;
            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                int count = sri._series.Elements.Count;
                XPoint[] points = new XPoint[count];
                for (int idx = 0; idx < count; idx++)
                {
                    double v = sri._series.Elements[idx].Value;
                    if (double.IsNaN(v))
                        v = 0;
                    points[idx] = new XPoint(idx + xMajorTick / 2, v);
                }
                matrix.TransformPoints(points);
                gfx.DrawLines(sri.LineFormat, points);
                DrawMarker(gfx, points, sri);
            }

            //gfx.ResetClip();
            gfx.Restore(state);
        }
Example #30
0
 /// <summary>
 /// Indicates whether the rectangle contains the specified point.
 /// </summary>
 public bool Contains(XPoint point)
 {
     return(Contains(point.X, point.Y));
 }
Example #31
0
 /// <summary>
 /// Adds a point and a vector.
 /// </summary>
 public static XPoint Add(XPoint point, XVector vector)
 {
     return(new XPoint(point._x + vector.X, point._y + vector.Y));
 }
Example #32
0
 /// <summary>
 /// Adds a point and a vector.
 /// </summary>
 public static XPoint Add(XPoint point, XVector vector)
 {
     return(new XPoint(point.x + vector.x, point.y + vector.y));
 }
Example #33
0
        public static PDF.XGraphicsPath ToXGraphicsPath(this IPathGeometry pg, Func <double, double> scale)
        {
            var gp = new PDF.XGraphicsPath()
            {
                FillMode = pg.FillRule == FillRule.EvenOdd ? PDF.XFillMode.Alternate : PDF.XFillMode.Winding
            };

            foreach (var pf in pg.Figures)
            {
                var startPoint = pf.StartPoint;

                foreach (var segment in pf.Segments)
                {
                    if (segment is IArcSegment arcSegment)
                    {
#if WPF
                        var point1 = new PDF.XPoint(
                            scale(startPoint.X),
                            scale(startPoint.Y));
                        var point2 = new PDF.XPoint(
                            scale(arcSegment.Point.X),
                            scale(arcSegment.Point.Y));
                        var size = new PDF.XSize(
                            scale(arcSegment.Size.Width),
                            scale(arcSegment.Size.Height));
                        gp.AddArc(
                            point1,
                            point2,
                            size, arcSegment.RotationAngle, arcSegment.IsLargeArc,
                            arcSegment.SweepDirection == SweepDirection.Clockwise ? PDF.XSweepDirection.Clockwise : PDF.XSweepDirection.Counterclockwise);
                        startPoint = arcSegment.Point;
#else
                        // TODO: Convert WPF/SVG elliptical arc segment format to GDI+ bezier curves.
                        startPoint = arcSegment.Point;
#endif
                    }
                    else if (segment is ICubicBezierSegment cubicBezierSegment)
                    {
                        gp.AddBezier(
                            scale(startPoint.X),
                            scale(startPoint.Y),
                            scale(cubicBezierSegment.Point1.X),
                            scale(cubicBezierSegment.Point1.Y),
                            scale(cubicBezierSegment.Point2.X),
                            scale(cubicBezierSegment.Point2.Y),
                            scale(cubicBezierSegment.Point3.X),
                            scale(cubicBezierSegment.Point3.Y));
                        startPoint = cubicBezierSegment.Point3;
                    }
                    else if (segment is ILineSegment)
                    {
                        var lineSegment = segment as ILineSegment;
                        gp.AddLine(
                            scale(startPoint.X),
                            scale(startPoint.Y),
                            scale(lineSegment.Point.X),
                            scale(lineSegment.Point.Y));
                        startPoint = lineSegment.Point;
                    }
                    else if (segment is IQuadraticBezierSegment quadraticBezierSegment)
                    {
                        var    p1 = startPoint;
                        var    p2 = quadraticBezierSegment.Point1;
                        var    p3 = quadraticBezierSegment.Point2;
                        double x1 = p1.X;
                        double y1 = p1.Y;
                        double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0;
                        double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0;
                        double x3 = x2 + (p3.X - p1.X) / 3.0;
                        double y3 = y2 + (p3.Y - p1.Y) / 3.0;
                        double x4 = p3.X;
                        double y4 = p3.Y;
                        gp.AddBezier(
                            scale(x1),
                            scale(y1),
                            scale(x2),
                            scale(y2),
                            scale(x3),
                            scale(y3),
                            scale(x4),
                            scale(y4));
                        startPoint = quadraticBezierSegment.Point2;
                    }
                    else
                    {
                        throw new NotSupportedException("Not supported segment type: " + segment.GetType());
                    }
                }

                if (pf.IsClosed)
                {
                    gp.CloseFigure();
                }
                else
                {
                    gp.StartFigure();
                }
            }

            return(gp);
        }
Example #34
0
        /// <summary>
        /// Creates between 1 and 5 Béziers curves from parameters specified like in WPF.
        /// </summary>
        public static List <XPoint> BezierCurveFromArc(XPoint point1, XPoint point2, XSize size,
                                                       double rotationAngle, bool isLargeArc, bool clockwise, PathStart pathStart)
        {
            // See also http://www.charlespetzold.com/blog/blog.xml from January 2, 2008:
            // http://www.charlespetzold.com/blog/2008/01/Mathematics-of-ArcSegment.html
            double δx = size.Width;
            double δy = size.Height;

            Debug.Assert(δx * δy > 0);
            double factor             = δy / δx;
            bool   isCounterclockwise = !clockwise;

            // Adjust for different radii and rotation angle.
            XMatrix matrix = new XMatrix();

            matrix.RotateAppend(-rotationAngle);
            matrix.ScaleAppend(δy / δx, 1);
            XPoint pt1 = matrix.Transform(point1);
            XPoint pt2 = matrix.Transform(point2);

            // Get info about chord that connects both points.
            XPoint  midPoint  = new XPoint((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2);
            XVector vect      = pt2 - pt1;
            double  halfChord = vect.Length / 2;

            // Get vector from chord to center.
            XVector vectRotated;

            // (comparing two Booleans here!)
            if (isLargeArc == isCounterclockwise)
            {
                vectRotated = new XVector(-vect.Y, vect.X);
            }
            else
            {
                vectRotated = new XVector(vect.Y, -vect.X);
            }

            vectRotated.Normalize();

            // Distance from chord to center.
            double centerDistance = Math.Sqrt(δy * δy - halfChord * halfChord);

            if (double.IsNaN(centerDistance))
            {
                centerDistance = 0;
            }

            // Calculate center point.
            XPoint center = midPoint + centerDistance * vectRotated;

            // Get angles from center to the two points.
            double α = Math.Atan2(pt1.Y - center.Y, pt1.X - center.X);
            double β = Math.Atan2(pt2.Y - center.Y, pt2.X - center.X);

            // (another comparison of two Booleans!)
            if (isLargeArc == (Math.Abs(β - α) < Math.PI))
            {
                if (α < β)
                {
                    α += 2 * Math.PI;
                }
                else
                {
                    β += 2 * Math.PI;
                }
            }

            // Invert matrix for final point calculation.
            matrix.Invert();
            double sweepAngle = β - α;

            // Let the algorithm of GDI+ DrawArc to Bézier curves do the rest of the job
            return(BezierCurveFromArc(center.X - δx * factor, center.Y - δy, 2 * δx * factor, 2 * δy,
                                      α / Calc.Deg2Rad, sweepAngle / Calc.Deg2Rad, pathStart, ref matrix));
        }
Example #35
0
 /// <summary>
 /// Multiplies a point with a matrix.
 /// </summary>
 public static XPoint Multiply(XPoint point, XMatrix matrix)
 {
     return(matrix.Transform(point));
 }
Example #36
0
 /// <summary>
 /// Indicates whether this instance and a specified point are equal.
 /// </summary>
 public bool Equals(XPoint value)
 {
     return(Equals(this, value));
 }
Example #37
0
 public static XPoint Add(XVector vector, XPoint point)
 {
     return(new XPoint(point.X + vector._x, point.Y + vector._y));
 }
Example #38
0
        /// <summary>
        /// Appends a Bézier segment from a curve.
        /// </summary>
        public static BezierSegment CreateCurveSegment(XPoint pt0, XPoint pt1, XPoint pt2, XPoint pt3, double tension3)
        {
#if !SILVERLIGHT && !NETFX_CORE
            return(new BezierSegment(
                       new SysPoint(pt1.X + tension3 * (pt2.X - pt0.X), pt1.Y + tension3 * (pt2.Y - pt0.Y)),
                       new SysPoint(pt2.X - tension3 * (pt3.X - pt1.X), pt2.Y - tension3 * (pt3.Y - pt1.Y)),
                       new SysPoint(pt2.X, pt2.Y), true));
#else
            BezierSegment bezierSegment = new BezierSegment();
            bezierSegment.Point1 = new SysPoint(pt1.X + tension3 * (pt2.X - pt0.X), pt1.Y + tension3 * (pt2.Y - pt0.Y));
            bezierSegment.Point2 = new SysPoint(pt2.X - tension3 * (pt3.X - pt1.X), pt2.Y - tension3 * (pt3.Y - pt1.Y));
            bezierSegment.Point3 = new SysPoint(pt2.X, pt2.Y);
            return(bezierSegment);
#endif
        }
Example #39
0
 /// <summary>
 /// Sets current rectangle to the union of the current rectangle and the specified point.
 /// </summary>
 public void Union(XPoint point)
 {
     Union(new XRect(point, point));
 }
Example #40
0
        GetArcAngle(
            XPoint startPoint,   // Start point
            XPoint endPoint,     // End point
            bool isLargeArc,     // Choose the larger of the 2 possible arcs if TRUE
            //SweepDirection sweepDirection,      // Direction n which to sweep the arc.
            bool isClockwise,
            out double cosArcAngle, // Cosine of a the sweep angle of one arc piece
            out double sinArcAngle, // Sine of a the sweep angle of one arc piece
            out int pieces)         // Out: The number of pieces
        {
            double angle;

            // The points are on the unit circle, so:
            cosArcAngle = startPoint.X * endPoint.X + startPoint.Y * endPoint.Y;
            sinArcAngle = startPoint.X * endPoint.Y - startPoint.Y * endPoint.X;

            if (cosArcAngle >= 0)
            {
                if (isLargeArc)
                {
                    // The angle is between 270 and 360 degrees, so
                    pieces = 4;
                }
                else
                {
                    // The angle is between 0 and 90 degrees, so
                    pieces = 1;
                    return; // We already have the cosine and sine of the angle
                }
            }
            else
            {
                if (isLargeArc)
                {
                    // The angle is between 180 and 270 degrees, so
                    pieces = 3;
                }
                else
                {
                    // The angle is between 90 and 180 degrees, so
                    pieces = 2;
                }
            }

            // We have to chop the arc into the computed number of pieces.  For cPieces=2 and 4 we could
            // have uses the half-angle trig formulas, but for pieces=3 it requires solving a cubic
            // equation; the performance difference is not worth the extra code, so we'll get the angle,
            // divide it, and get its sine and cosine.

            Debug.Assert(pieces > 0);
            angle = Math.Atan2(sinArcAngle, cosArcAngle);

            if (isClockwise)
            {
                if (angle < 0)
                {
                    angle += Math.PI * 2;
                }
            }
            else
            {
                if (angle > 0)
                {
                    angle -= Math.PI * 2;
                }
            }

            angle      /= pieces;
            cosArcAngle = Math.Cos(angle);
            sinArcAngle = Math.Sin(angle);
        }
Example #41
0
 /// <summary>
 /// Returns the intersection of a rectangle and a point.
 /// </summary>
 public static XRect Union(XRect rect, XPoint point)
 {
     rect.Union(new XRect(point, point));
     return(rect);
 }
Example #42
0
 /// <summary>
 /// Initializes a new instance of the XRect class.
 /// </summary>
 public XRect(XPoint point, XVector vector)
     : this(point, point + vector)
 {
 }
Example #43
0
        //+-------------------------------------------------------------------------------------------------
        //
        //  Function: ArcToBezier
        //
        //  Synopsis: Compute the Bezier approximation of an arc
        //
        //  Notes:    This utilitycomputes the Bezier approximation for an elliptical arc as it is defined
        //            in the SVG arc spec. The ellipse from which the arc is carved is axis-aligned in its
        //            own coordinates, and defined there by its x and y radii. The rotation angle defines
        //            how the ellipse's axes are rotated relative to our x axis. The start and end points
        //            define one of 4 possible arcs; the sweep and large-arc flags determine which one of
        //            these arcs will be chosen. See SVG spec for details.
        //
        //            Returning pieces = 0 indicates a line instead of an arc
        //                      pieces = -1 indicates that the arc degenerates to a point
        //
        //--------------------------------------------------------------------------------------------------
        public static PointCollection ArcToBezier(double xStart, double yStart, double xRadius, double yRadius, double rotationAngle,
                                                  bool isLargeArc, bool isClockwise, double xEnd, double yEnd, out int pieces)
        {
            double  cosArcAngle, sinArcAngle, xCenter, yCenter, r, bezDist;
            XVector vecToBez1, vecToBez2;
            XMatrix matToEllipse;

            double fuzz2        = FUZZ * FUZZ;
            bool   isZeroCenter = false;

            pieces = -1;

            // In the following, the line segment between between the arc's start and
            // end points is referred to as "the chord".

            // Transform 1: Shift the origin to the chord's midpoint
            double x = (xEnd - xStart) / 2;
            double y = (yEnd - yStart) / 2;

            double halfChord2 = x * x + y * y; // (half chord length)^2

            // Degenerate case: single point
            if (halfChord2 < fuzz2)
            {
                // The chord degeneartes to a point, the arc will be ignored
                return(null);
            }

            // Degenerate case: straight line
            if (!AcceptRadius(halfChord2, fuzz2, ref xRadius) || !AcceptRadius(halfChord2, fuzz2, ref yRadius))
            {
                // We have a zero radius, add a straight line segment instead of an arc
                pieces = 0;
                return(null);
            }

            if (xRadius == 0 || yRadius == 0)
            {
                // We have a zero radius, add a straight line segment instead of an arc
                pieces = 0;
                return(null);
            }

            // Transform 2: Rotate to the ellipse's coordinate system
            rotationAngle = -rotationAngle * Calc.Deg2Rad;

            double cos = Math.Cos(rotationAngle);
            double sin = Math.Sin(rotationAngle);

            r = x * cos - y * sin;
            y = x * sin + y * cos;
            x = r;

            // Transform 3: Scale so that the ellipse will become a unit circle
            x /= xRadius;
            y /= yRadius;

            // We get to the center of that circle along a verctor perpendicular to the chord
            // from the origin, which is the chord's midpoint. By Pythagoras, the length of that
            // vector is sqrt(1 - (half chord)^2).

            halfChord2 = x * x + y * y; // now in the circle coordinates

            if (halfChord2 > 1)
            {
                // The chord is longer than the circle's diameter; we scale the radii uniformly so
                // that the chord will be a diameter. The center will then be the chord's midpoint,
                // which is now the origin.
                r            = Math.Sqrt(halfChord2);
                xRadius     *= r;
                yRadius     *= r;
                xCenter      = yCenter = 0;
                isZeroCenter = true;

                // Adjust the unit-circle coordinates x and y
                x /= r;
                y /= r;
            }
            else
            {
                // The length of (-y,x) or (x,-y) is sqrt(rHalfChord2), and we want a vector
                // of length sqrt(1 - rHalfChord2), so we'll multiply it by:
                r = Math.Sqrt((1 - halfChord2) / halfChord2);
                //if (isLargeArc != (eSweepDirection == SweepDirection.Clockwise))
                if (isLargeArc != isClockwise)
                // Going to the center from the origin=chord-midpoint
                {
                    // in the direction of (-y, x)
                    xCenter = -r * y;
                    yCenter = r * x;
                }
                else
                {
                    // in the direction of (y, -x)
                    xCenter = r * y;
                    yCenter = -r * x;
                }
            }

            // Transformation 4: shift the origin to the center of the circle, which then becomes
            // the unit circle. Since the chord's midpoint is the origin, the start point is (-x, -y)
            // and the endpoint is (x, y).
            XPoint ptStart = new XPoint(-x - xCenter, -y - yCenter);
            XPoint ptEnd   = new XPoint(x - xCenter, y - yCenter);

            // Set up the matrix that will take us back to our coordinate system.  This matrix is
            // the inverse of the combination of transformation 1 thru 4.
            matToEllipse = new XMatrix(cos * xRadius, -sin * xRadius,
                                       sin * yRadius, cos * yRadius,
                                       (xEnd + xStart) / 2, (yEnd + yStart) / 2);

            if (!isZeroCenter)
            {
                // Prepend the translation that will take the origin to the circle's center
                matToEllipse.OffsetX += (matToEllipse.M11 * xCenter + matToEllipse.M21 * yCenter);
                matToEllipse.OffsetY += (matToEllipse.M12 * xCenter + matToEllipse.M22 * yCenter);
            }

            // Get the sine & cosine of the angle that will generate the arc pieces
            GetArcAngle(ptStart, ptEnd, isLargeArc, isClockwise, out cosArcAngle, out sinArcAngle, out pieces);

            // Get the vector to the first Bezier control point
            bezDist = GetBezierDistance(cosArcAngle, 1);

            //if (eSweepDirection == SweepDirection.Counterclockwise)
            if (!isClockwise)
            {
                bezDist = -bezDist;
            }

            vecToBez1 = new XVector(-bezDist * ptStart.Y, bezDist * ptStart.X);

            PointCollection result = new PointCollection();

            // Add the arc pieces, except for the last
            for (int idx = 1; idx < pieces; idx++)
            {
                // Get the arc piece's endpoint
                XPoint ptPieceEnd = new XPoint(ptStart.X * cosArcAngle - ptStart.Y * sinArcAngle, ptStart.X * sinArcAngle + ptStart.Y * cosArcAngle);
                vecToBez2 = new XVector(-bezDist * ptPieceEnd.Y, bezDist * ptPieceEnd.X);

                result.Add(matToEllipse.Transform(ptStart + vecToBez1));
                result.Add(matToEllipse.Transform(ptPieceEnd - vecToBez2));
                result.Add(matToEllipse.Transform(ptPieceEnd));

                // Move on to the next arc
                ptStart   = ptPieceEnd;
                vecToBez1 = vecToBez2;
            }

            // Last arc - we know the endpoint
            vecToBez2 = new XVector(-bezDist * ptEnd.Y, bezDist * ptEnd.X);

            result.Add(matToEllipse.Transform(ptStart + vecToBez1));
            result.Add(matToEllipse.Transform(ptEnd - vecToBez2));
            result.Add(new XPoint(xEnd, yEnd));

            return(result);
        }
Example #44
0
 public XSize(XPoint pt) // DELETE: 08-12-31
 {
     width  = pt.X;
     height = pt.Y;
 }
Example #45
0
        /// <summary>
        /// Appends a Bézier segment from a curve.
        /// </summary>
        public static BezierSegment CreateCurveSegment(XPoint pt0, XPoint pt1, XPoint pt2, XPoint pt3, double tension3)
        {
#if !SILVERLIGHT
            return(new BezierSegment(
                       new Point(pt1.X + tension3 * (pt2.X - pt0.X), pt1.Y + tension3 * (pt2.Y - pt0.Y)),
                       new Point(pt2.X - tension3 * (pt3.X - pt1.X), pt2.Y - tension3 * (pt3.Y - pt1.Y)),
                       new Point(pt2.X, pt2.Y), true));
#else
            return(new BezierSegment()); // AGHACK
#endif
        }
Example #46
0
 /// <summary>
 /// Subtracts a vector from a point.
 /// </summary>
 public static XPoint Subtract(XPoint point, XVector vector)
 {
     return(new XPoint(point._x - vector.X, point._y - vector.Y));
 }
Example #47
0
 /// <summary>
 /// Subtracts a vector from a point.
 /// </summary>
 public static XPoint Subtract(XPoint point, XVector vector)
 {
     return(new XPoint(point.x - vector.x, point.y - vector.y));
 }
Example #48
0
 /// <summary>
 /// Subtracts a point from a point.
 /// </summary>
 public static XVector Subtract(XPoint point1, XPoint point2)
 {
     return(new XVector(point1._x - point2._x, point1._y - point2._y));
 }
Example #49
0
 /// <summary>
 /// Indicates whether the specified points are equal.
 /// </summary>
 public static bool Equals(XPoint point1, XPoint point2)
 {
     return(point1.X.Equals(point2.X) && point1.Y.Equals(point2.Y));
 }
Example #50
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pg"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        public static PDF.XGraphicsPath ToXGraphicsPath(this IPathGeometry pg, double dx, double dy, Func <double, double> scale)
        {
            var gp = new PDF.XGraphicsPath()
            {
                FillMode = pg.FillRule == FillRule.EvenOdd ? PDF.XFillMode.Alternate : PDF.XFillMode.Winding
            };

            foreach (var pf in pg.Figures)
            {
                var startPoint = pf.StartPoint;

                foreach (var segment in pf.Segments)
                {
                    if (segment is IArcSegment arcSegment)
                    {
#if WPF
                        var point1 = new PDF.XPoint(
                            scale(startPoint.X + dx),
                            scale(startPoint.Y + dy));
                        var point2 = new PDF.XPoint(
                            scale(arcSegment.Point.X + dx),
                            scale(arcSegment.Point.Y + dy));
                        var size = new PDF.XSize(
                            scale(arcSegment.Size.Width),
                            scale(arcSegment.Size.Height));
                        gp.AddArc(
                            point1,
                            point2,
                            size, arcSegment.RotationAngle, arcSegment.IsLargeArc,
                            arcSegment.SweepDirection == SweepDirection.Clockwise ? PDF.XSweepDirection.Clockwise : PDF.XSweepDirection.Counterclockwise);
                        startPoint = arcSegment.Point;
#else
                        throw new NotSupportedException("Not supported segment type: " + segment.GetType());
                        // TODO: Convert WPF/SVG elliptical arc segment format to GDI+ bezier curves.
                        //startPoint = arcSegment.Point;
#endif
                    }
                    else if (segment is ICubicBezierSegment cubicBezierSegment)
                    {
                        gp.AddBezier(
                            scale(startPoint.X + dx),
                            scale(startPoint.Y + dy),
                            scale(cubicBezierSegment.Point1.X + dx),
                            scale(cubicBezierSegment.Point1.Y + dy),
                            scale(cubicBezierSegment.Point2.X + dx),
                            scale(cubicBezierSegment.Point2.Y + dy),
                            scale(cubicBezierSegment.Point3.X + dx),
                            scale(cubicBezierSegment.Point3.Y + dy));
                        startPoint = cubicBezierSegment.Point3;
                    }
                    else if (segment is ILineSegment)
                    {
                        var lineSegment = segment as ILineSegment;
                        gp.AddLine(
                            scale(startPoint.X + dx),
                            scale(startPoint.Y + dy),
                            scale(lineSegment.Point.X + dx),
                            scale(lineSegment.Point.Y + dy));
                        startPoint = lineSegment.Point;
                    }
                    else if (segment is IPolyCubicBezierSegment polyCubicBezierSegment)
                    {
                        if (polyCubicBezierSegment.Points.Length >= 3)
                        {
                            gp.AddBezier(
                                scale(startPoint.X + dx),
                                scale(startPoint.Y + dy),
                                scale(polyCubicBezierSegment.Points[0].X + dx),
                                scale(polyCubicBezierSegment.Points[0].Y + dy),
                                scale(polyCubicBezierSegment.Points[1].X + dx),
                                scale(polyCubicBezierSegment.Points[1].Y + dy),
                                scale(polyCubicBezierSegment.Points[2].X + dx),
                                scale(polyCubicBezierSegment.Points[2].Y + dy));
                        }

                        if (polyCubicBezierSegment.Points.Length > 3 &&
                            polyCubicBezierSegment.Points.Length % 3 == 0)
                        {
                            for (int i = 3; i < polyCubicBezierSegment.Points.Length; i += 3)
                            {
                                gp.AddBezier(
                                    scale(polyCubicBezierSegment.Points[i - 1].X + dx),
                                    scale(polyCubicBezierSegment.Points[i - 1].Y + dy),
                                    scale(polyCubicBezierSegment.Points[i].X + dx),
                                    scale(polyCubicBezierSegment.Points[i].Y + dy),
                                    scale(polyCubicBezierSegment.Points[i + 1].X + dx),
                                    scale(polyCubicBezierSegment.Points[i + 1].Y + dy),
                                    scale(polyCubicBezierSegment.Points[i + 2].X + dx),
                                    scale(polyCubicBezierSegment.Points[i + 2].Y + dy));
                            }
                        }

                        startPoint = polyCubicBezierSegment.Points.Last();
                    }
                    else if (segment is IPolyLineSegment polyLineSegment)
                    {
                        if (polyLineSegment.Points.Length >= 1)
                        {
                            gp.AddLine(
                                scale(startPoint.X + dx),
                                scale(startPoint.Y + dy),
                                scale(polyLineSegment.Points[0].X + dx),
                                scale(polyLineSegment.Points[0].Y + dy));
                        }

                        if (polyLineSegment.Points.Length > 1)
                        {
                            for (int i = 1; i < polyLineSegment.Points.Length; i++)
                            {
                                gp.AddLine(
                                    scale(polyLineSegment.Points[i - 1].X + dx),
                                    scale(polyLineSegment.Points[i - 1].Y + dy),
                                    scale(polyLineSegment.Points[i].X + dx),
                                    scale(polyLineSegment.Points[i].Y + dy));
                            }
                        }

                        startPoint = polyLineSegment.Points.Last();
                    }
                    else if (segment is IPolyQuadraticBezierSegment polyQuadraticSegment)
                    {
                        if (polyQuadraticSegment.Points.Length >= 2)
                        {
                            var    p1 = startPoint;
                            var    p2 = polyQuadraticSegment.Points[0];
                            var    p3 = polyQuadraticSegment.Points[1];
                            double x1 = p1.X;
                            double y1 = p1.Y;
                            double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0;
                            double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0;
                            double x3 = x2 + (p3.X - p1.X) / 3.0;
                            double y3 = y2 + (p3.Y - p1.Y) / 3.0;
                            double x4 = p3.X;
                            double y4 = p3.Y;
                            gp.AddBezier(
                                scale(x1 + dx),
                                scale(y1 + dy),
                                scale(x2 + dx),
                                scale(y2 + dy),
                                scale(x3 + dx),
                                scale(y3 + dy),
                                scale(x4 + dx),
                                scale(y4 + dy));
                        }

                        if (polyQuadraticSegment.Points.Length > 2 &&
                            polyQuadraticSegment.Points.Length % 2 == 0)
                        {
                            for (int i = 3; i < polyQuadraticSegment.Points.Length; i += 3)
                            {
                                var    p1 = polyQuadraticSegment.Points[i - 1];
                                var    p2 = polyQuadraticSegment.Points[i];
                                var    p3 = polyQuadraticSegment.Points[i + 1];
                                double x1 = p1.X;
                                double y1 = p1.Y;
                                double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0;
                                double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0;
                                double x3 = x2 + (p3.X - p1.X) / 3.0;
                                double y3 = y2 + (p3.Y - p1.Y) / 3.0;
                                double x4 = p3.X;
                                double y4 = p3.Y;
                                gp.AddBezier(
                                    scale(x1 + dx),
                                    scale(y1 + dy),
                                    scale(x2 + dx),
                                    scale(y2 + dy),
                                    scale(x3 + dx),
                                    scale(y3 + dy),
                                    scale(x4 + dx),
                                    scale(y4 + dy));
                            }
                        }

                        startPoint = polyQuadraticSegment.Points.Last();
                    }
                    else if (segment is IQuadraticBezierSegment quadraticBezierSegment)
                    {
                        var    p1 = startPoint;
                        var    p2 = quadraticBezierSegment.Point1;
                        var    p3 = quadraticBezierSegment.Point2;
                        double x1 = p1.X;
                        double y1 = p1.Y;
                        double x2 = p1.X + (2.0 * (p2.X - p1.X)) / 3.0;
                        double y2 = p1.Y + (2.0 * (p2.Y - p1.Y)) / 3.0;
                        double x3 = x2 + (p3.X - p1.X) / 3.0;
                        double y3 = y2 + (p3.Y - p1.Y) / 3.0;
                        double x4 = p3.X;
                        double y4 = p3.Y;
                        gp.AddBezier(
                            scale(x1 + dx),
                            scale(y1 + dy),
                            scale(x2 + dx),
                            scale(y2 + dy),
                            scale(x3 + dx),
                            scale(y3 + dy),
                            scale(x4 + dx),
                            scale(y4 + dy));
                        startPoint = quadraticBezierSegment.Point2;
                    }
                    else
                    {
                        throw new NotSupportedException("Not supported segment type: " + segment.GetType());
                    }
                }

                if (pf.IsClosed)
                {
                    gp.CloseFigure();
                }
                else
                {
                    gp.StartFigure();
                }
            }

            return(gp);
        }
Example #51
0
 public XSize(XPoint pt) // DELETE: 08-12-31
 {
     this.width  = pt.X;
     this.height = pt.Y;
 }
Example #52
-1
 private static void DrawLineInternal(XGraphics gfx, XPen pen, bool isStroked, ref XPoint p0, ref XPoint p1)
 {
     if (isStroked)
     {
         gfx.DrawLine(pen, p0, p1);
     }
 }