RotateTransform() публичный Метод

Applies the specified rotation operation to the transformation matrix of this object by prepending it to the object's transformation matrix.
public RotateTransform ( double angle ) : void
angle double
Результат void
    /// <summary>
    /// Demonstrates the use of XLinearGradientBrush.
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);

      XRect rect;
      XLinearGradientBrush brush;
      Graphics grfx = gfx.Internals.Graphics;

      XLinearGradientBrush brush2 = 
        new XLinearGradientBrush(
        new XPoint(100, 100), 
        new XPoint(300, 300), 
        XColors.DarkRed, XColors.Yellow);

      //gfx.FillRectangle(brush, 0, 0, 600, 600);
      //gfx.TranslateTransform(35, 200);
      //gfx.RotateTransform(17);

      rect = new XRect(20, 50, 100, 200);
      brush = new XLinearGradientBrush(rect, 
        XColors.DarkRed, XColors.Yellow, XLinearGradientMode.Horizontal);
      gfx.DrawRectangle(XPens.Red, brush, rect);

      rect = new XRect(140, 50, 100, 200);
      brush = new XLinearGradientBrush(rect, 
        XColors.DarkRed, XColors.Yellow, XLinearGradientMode.Vertical);
        gfx.DrawRectangle(XPens.Red, brush, rect);

      rect = new XRect(260, 50, 100, 200);
      brush = new XLinearGradientBrush(rect, 
        XColors.DarkRed, XColors.Yellow, XLinearGradientMode.ForwardDiagonal);
        gfx.DrawRectangle(XPens.Red, brush, rect);

      rect = new XRect(380, 50, 100, 200);
      brush = new XLinearGradientBrush(rect, 
        XColors.DarkRed, XColors.Yellow, XLinearGradientMode.BackwardDiagonal);
        gfx.DrawRectangle(XPens.Red, brush, rect);


      gfx.TranslateTransform(80, 250);
      gfx.ScaleTransform(1.1);
      gfx.RotateTransform(20);

      rect = new XRect(20, 50, 100, 200);
      brush = new XLinearGradientBrush(rect, 
        XColors.Orange, XColors.DarkBlue, XLinearGradientMode.Horizontal);
      gfx.DrawRectangle(XPens.Red, brush, rect);

      rect = new XRect(140, 50, 100, 200);
      brush = new XLinearGradientBrush(rect, 
        XColors.Orange, XColors.DarkBlue, XLinearGradientMode.Vertical);
      gfx.DrawRectangle(XPens.Red, brush, rect);

      rect = new XRect(260, 50, 100, 200);
      brush = new XLinearGradientBrush(rect, 
        XColors.Orange, XColors.DarkBlue, XLinearGradientMode.ForwardDiagonal);
      gfx.DrawRectangle(XPens.Red, brush, rect);

      rect = new XRect(380, 50, 100, 200);
      brush = new XLinearGradientBrush(rect, 
        XColors.Orange, XColors.DarkBlue, XLinearGradientMode.BackwardDiagonal);
      gfx.DrawRectangle(XPens.Red, brush, rect);
    }
Пример #2
0
    /// <summary>
    /// Demonstrates the use of XGraphics.Transform.
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      //gfx.Clear(this.properties.General.BackColor.Color);
      base.RenderPage(gfx);

      gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
      gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200)));

      Matrix matrix = new Matrix();
      //matrix.Scale(2f, 1.5f);
      //matrix.Translate(-200, -400);
      //matrix.Rotate(45);
      //matrix.Translate(200, 400);
      //gfx.Transform = matrix;
      //gfx.TranslateTransform(50, 30);

#if true
      gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend);
      gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend);
      gfx.RotateTransform(15, XMatrixOrder.Prepend);
#else
      gfx.TranslateTransform(30, 40, XMatrixOrder.Append);
      gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append);
      gfx.RotateTransform(15, XMatrixOrder.Append);
#endif
      bool id = matrix.IsIdentity;
      matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend);
      //matrix.Translate(30, -50);
      matrix.Rotate(15, MatrixOrder.Prepend);
      //Matrix mtx = gfx.Transform.ToGdiMatrix();
      //gfx.Transform = matrix;

      gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
      gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200)));
    }
Пример #3
0
    /// <summary>
    /// Demonstrates the use of XGraphics.Transform.
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);

      //XGraphicsState state = gfx.Save();

      gfx.Save();
      gfx.IntersectClip(new XRect(20, 20, 300, 500));
      gfx.DrawRectangle(XBrushes.Yellow, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);
      gfx.Restore();

      gfx.Save();
      gfx.IntersectClip(new XRect(100, 200, 300, 500));
      gfx.DrawRectangle(XBrushes.LightBlue, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);

      gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
      gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200)));


      Matrix matrix = new Matrix();
      //matrix.Scale(2f, 1.5f);
      //matrix.Translate(-200, -400);
      //matrix.Rotate(45);
      //matrix.Translate(200, 400);
      //gfx.Transform = matrix;
      //gfx.TranslateTransform(50, 30);

#if true
      gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend);
      gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend);
      gfx.RotateTransform(15, XMatrixOrder.Prepend);
#else
      gfx.TranslateTransform(30, 40, XMatrixOrder.Append);
      gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append);
      gfx.RotateTransform(15, XMatrixOrder.Append);
#endif
      bool id = matrix.IsIdentity;
      matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend);
      //matrix.Translate(30, -50);
      matrix.Rotate(15, MatrixOrder.Prepend);
      //Matrix mtx = gfx.Transform.ToGdiMatrix();
      //gfx.Transform = matrix;

      gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
      gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200)));

      gfx.Restore();

      gfx.DrawLine(XPens.Red, 0, 0, 1000, 1000);

      gfx.DrawPolygon(XPens.SandyBrown, GetPentagram(75, new PointF(150, 200)));

    }
Пример #4
0
    /// <summary>
    /// Demonstrates the use of XGraphics.DrawImage.
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);

      XImage image = XImage.FromFile(@"..\..\images\Test (OS2).bmp");  

      double dx = gfx.PageSize.Width;
      double dy = gfx.PageSize.Height;

#if true
      gfx.TranslateTransform(dx / 2, dy / 2);
      gfx.RotateTransform(-60);
      gfx.TranslateTransform(-dx / 2, -dy / 2);
#endif

      gfx.DrawImage(image, (dx - image.PixelWidth) / 2, (dy - image.PixelHeight) / 2, image.PixelWidth, image.PixelHeight);
    }
Пример #5
0
    public override void RenderPage(XGraphics gfx)
    {
      //base.RenderPage(gfx);

      XPoint[] origins = new XPoint[] 
      { 
        new XPoint(100, 200), new XPoint(300, 200), 
        new XPoint(100, 400), new XPoint(300, 400),
        new XPoint(100, 600), new XPoint(350, 600),
      };
      XPoint origin;
      XGraphicsState state;
      float length = 100;

      // Not transformed
      origin = origins[0];
      DrawAxes(gfx, XPens.Black, origin, length);
      gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, origin);

      // Translation
      state = gfx.Save();
      origin = origins[1];
      DrawAxes(gfx, XPens.Black, origin, length);
      gfx.TranslateTransform(20, -30);
      DrawAxes(gfx, XPens.DarkGray, origin, length);
      gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, origin);
      gfx.Restore(state);

      // Translation
      state = gfx.Save();
      origin = origins[2];
      DrawAxes(gfx, XPens.Black, origin, length);
      gfx.TranslateTransform(20, -30);
      DrawAxes(gfx, XPens.DarkGray, origin, length);
      gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, origin);
      gfx.Restore(state);

      //// Scaling
      //state = gfx.Save();
      //origin = origins[2];
      //DrawAxes(gfx, XPens.Black, origin, length);
      //gfx.TranslateTransform(origin.X, origin.Y);
      //gfx.ScaleTransform(1.3, 1.5);
      //DrawAxes(gfx, XPens.DarkGray, new XPoint(), length);
      //gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0, 0);
      //gfx.Restore(state);

      // Rotation
      state = gfx.Save();
      origin = origins[3];  
      DrawAxes(gfx, XPens.Black, origin, length);
      gfx.TranslateTransform(origin.X, origin.Y);
      gfx.RotateTransform(-45);
      DrawAxes(gfx, XPens.DarkGray, new XPoint(), length);
      gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0 , 0);
      gfx.Restore(state);

      // Skewing (or shearing)
      state = gfx.Save();
      origin = origins[4];  
      DrawAxes(gfx, XPens.Black, origin, length);
      gfx.TranslateTransform(origin.X, origin.Y);
      gfx.MultiplyTransform(new Matrix(1, -0.3f, -0.4f, 1, 0, 0));
      DrawAxes(gfx, XPens.DarkGray, new XPoint(), length);
      gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0 , 0);
      gfx.Restore(state);

      // Reflection
      state = gfx.Save();
      origin = origins[5];  
      DrawAxes(gfx, XPens.Black, origin, length);
      gfx.TranslateTransform(origin.X, origin.Y);
      gfx.MultiplyTransform(new Matrix(-1, 0, 0, -1, 0, 0));
      DrawAxes(gfx, XPens.DarkGray, new XPoint(), length);
      gfx.DrawString(this.properties.Font1.Text, this.properties.Font1.Font, this.properties.Font1.Brush, 0 , 0);
      gfx.Restore(state);
    }
Пример #6
0
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);

      PointF[] origins = new PointF[] 
      { 
        new PointF(100, 200), new PointF(300, 200), 
        new PointF(100, 400), new PointF(300, 400),
        new PointF(100, 600), new PointF(350, 600),
      };
      PointF origin;
      XGraphicsContainer container;
      float length = 100;

      // Not transformed
      origin = origins[0];
      DrawAxes(gfx, XPens.Black, origin, length);
      gfx.DrawString(this.properties.Font2.Text, this.properties.Font2.Font, this.properties.Font2.Brush, origin);

      // Translation
      container = gfx.BeginContainer(new RectangleF(10, 10, 1, 1), new RectangleF(0, 0, 1, 1), XGraphicsUnit.Point);
      origin = origins[1];
      DrawAxes(gfx, XPens.Black, origin, length);
      gfx.TranslateTransform(20, -30);
      DrawAxes(gfx, XPens.DarkGray, origin, length);
      gfx.DrawString(this.properties.Font2.Text, this.properties.Font2.Font, this.properties.Font2.Brush, origin);
      gfx.EndContainer(container);

      // Scaling
      container = gfx.BeginContainer(new RectangleF(0, 0, 1, 1), new RectangleF(0, 0, 1, 1), XGraphicsUnit.Point);
      origin = origins[2];
      DrawAxes(gfx, XPens.Black, origin, length);
      gfx.TranslateTransform(origin.X, origin.Y);
      gfx.ScaleTransform(1.3f, 1.5f);
      DrawAxes(gfx, XPens.DarkGray, new PointF(), length);
      gfx.DrawString(this.properties.Font2.Text, this.properties.Font2.Font, this.properties.Font2.Brush, 0, 0);
      gfx.EndContainer(container);

      // Rotation
      container = gfx.BeginContainer(new RectangleF(0, 0, 1, 1), new RectangleF(0, 0, 1, 1), XGraphicsUnit.Point);
      origin = origins[3];  
      DrawAxes(gfx, XPens.Black, origin, length);
      gfx.TranslateTransform(origin.X, origin.Y);
      gfx.RotateTransform(-45);
      DrawAxes(gfx, XPens.DarkGray, new PointF(), length);
      gfx.DrawString(this.properties.Font2.Text, this.properties.Font2.Font, this.properties.Font2.Brush, 0 , 0);
      gfx.EndContainer(container);

      // Skewing (or shearing)
      container = gfx.BeginContainer(new RectangleF(0, 0, 1, 1), new RectangleF(0, 0, 1, 1), XGraphicsUnit.Point);
      origin = origins[4];  
      DrawAxes(gfx, XPens.Black, origin, length);
      gfx.TranslateTransform(origin.X, origin.Y);
      gfx.MultiplyTransform(new Matrix(1, -0.3f, -0.4f, 1, 0, 0));
      DrawAxes(gfx, XPens.DarkGray, new PointF(), length);
      gfx.DrawString(this.properties.Font2.Text, this.properties.Font2.Font, this.properties.Font2.Brush, 0 , 0);
      gfx.EndContainer(container);

      // Reflection
      container = gfx.BeginContainer(new RectangleF(0, 0, 1, 1), new RectangleF(0, 0, 1, 1), XGraphicsUnit.Point);
      origin = origins[5];  
      DrawAxes(gfx, XPens.Black, origin, length);
      gfx.TranslateTransform(origin.X, origin.Y);
      gfx.MultiplyTransform(new Matrix(-1, 0, 0, -1, 0, 0));
      DrawAxes(gfx, XPens.DarkGray, new PointF(), length);
      gfx.DrawString(this.properties.Font2.Text, this.properties.Font2.Font, this.properties.Font2.Brush, 0 , 0);
      gfx.EndContainer(container);
    }
        private static void RenderToGraphics(Render.RenderContext ctx, int rot, float translateX, float translateY, XGraphics graphics)
        {
            graphics.TranslateTransform(translateX, translateY);
            graphics.RotateTransform(rot * 90);

            using (Maps.Rendering.RenderUtil.SaveState(graphics))
            {

                if (ctx.clipPath != null)
                {
                    XMatrix m = ctx.ImageSpaceToWorldSpace;
                    graphics.MultiplyTransform(m);
                    graphics.IntersectClip(ctx.clipPath);
                    m.Invert();
                    graphics.MultiplyTransform(m);
                }

                ctx.graphics = graphics;
                Maps.Rendering.Render.RenderTile(ctx);
            }


            if (ctx.border && ctx.clipPath != null)
            {
                using (Maps.Rendering.RenderUtil.SaveState(graphics))
                {
                    // Render border in world space
                    XMatrix m = ctx.ImageSpaceToWorldSpace;
                    graphics.MultiplyTransform(m);
                    XPen pen = new XPen(ctx.styles.imageBorderColor, 0.2f);

                    // PdfSharp can't ExcludeClip so we take advantage of the fact that we know 
                    // the path starts on the left edge and proceeds clockwise. We extend the 
                    // path with a counterclockwise border around it, then use that to exclude 
                    // the original path's region for rendering the border.
                    ctx.clipPath.Flatten();
                    RectangleF bounds = PathUtil.Bounds(ctx.clipPath);
                    bounds.Inflate(2 * (float)pen.Width, 2 * (float)pen.Width);
                    List<byte> types = new List<byte>(ctx.clipPath.Internals.GdiPath.PathTypes);
                    List<PointF> points = new List<PointF>(ctx.clipPath.Internals.GdiPath.PathPoints);

                    PointF key = points[0];
                    points.Add(new PointF(bounds.Left, key.Y)); types.Add(1);
                    points.Add(new PointF(bounds.Left, bounds.Bottom)); types.Add(1);
                    points.Add(new PointF(bounds.Right, bounds.Bottom)); types.Add(1);
                    points.Add(new PointF(bounds.Right, bounds.Top)); types.Add(1);
                    points.Add(new PointF(bounds.Left, bounds.Top)); types.Add(1);
                    points.Add(new PointF(bounds.Left, key.Y)); types.Add(1);
                    points.Add(new PointF(key.X, key.Y)); types.Add(1);

                    XGraphicsPath path = new XGraphicsPath(points.ToArray(), types.ToArray(), XFillMode.Winding);
                    graphics.IntersectClip(path);
                    graphics.DrawPath(pen, ctx.clipPath);
                }
            }
        }
Пример #8
0
    void DrawMinuteHand(XGraphics gfx, XPen pen, XBrush brush)
    {
      XGraphicsState gs = gfx.Save();
      gfx.RotateTransform(360 * Time.Minute / 60 + 6 * Time.Second / 60);

      gfx.DrawPolygon(pen, brush,
        new XPoint[]{new XPoint(0,  200), new XPoint(50, 0),
                     new XPoint(0, -800), new XPoint(-50, 0)},
        XFillMode.Winding);
      gfx.Restore(gs);
    }
Пример #9
0
    void DrawSecondHand(XGraphics gfx, XPen pen)
    {
      XGraphicsState gs = gfx.Save();

      gfx.RotateTransform(360 * Time.Second / 60 + 6 * Time.Millisecond / 1000);

      gfx.DrawEllipse(new XSolidBrush(pen.Color), -15, -15, 30, 30);
      gfx.DrawLine(pen, 0, 40, 0, -800);
      gfx.Restore(gs);
    }
Пример #10
0
 static void DrawFace(XGraphics gfx, XPen pen, XBrush brush)
 {
   for (int i = 0; i < 60; i++)
   {
     int size = i % 5 == 0 ? 100 : 30;
     gfx.DrawEllipse(pen, brush, 0 - size / 2, -900 - size / 2, size, size);
     gfx.RotateTransform(6);
   }
 }
Пример #11
0
 void DrawHourHand(XGraphics gfx, XPen pen, XBrush brush)
 {
   XGraphicsState gs = gfx.Save();
   gfx.RotateTransform(360 * Time.Hour / 12 + 30 * Time.Minute / 60);
   gfx.DrawPolygon(pen, brush,
     new XPoint[]{new XPoint(0,  150), new XPoint(100, 0), 
                  new XPoint(0, -600), new XPoint(-100, 0)},
     XFillMode.Winding);
   gfx.Restore(gs);
 }
Пример #12
0
    /// <summary>
    /// Demonstrates the use of XGraphics.Transform.
    /// </summary>
    public override void RenderPage(XGraphics gfx)
    {
      XGraphicsState state1, state2;
      base.RenderPage(gfx);

      state1 = gfx.Save();  // Level 1
      gfx.TranslateTransform(20, 50);
      gfx.DrawLine(XPens.Blue, 0, 0, 10, 10);
      gfx.Restore(state1);

      state1 = gfx.Save();  // Level 2
      gfx.TranslateTransform(220, 50);
      gfx.DrawLine(XPens.Blue, 0, 0, 10, 10);
      XGraphicsPath clipPath = new XGraphicsPath();
      clipPath.AddPie(0, 10, 150, 100, -50, 100);
      gfx.IntersectClip(clipPath);
      gfx.DrawRectangle(XBrushes.LightYellow, 0, 0, 1000, 1000);

      state2 = gfx.Save();  // Level 3
      gfx.ScaleTransform(10);
      gfx.DrawLine(XPens.Red, 1, 1, 10, 10);

      //gfx.ResetClip();
      gfx.Restore(state2);  // Level 2

      gfx.DrawLine(XPens.Red, 1, 1, 10, 10);

      gfx.Restore(state1);

#if true_

      gfx.SetClip(new XRect(20, 20, 300, 500));
      gfx.DrawRectangle(XBrushes.Yellow, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);

      gfx.SetClip(new XRect(100, 200, 300, 500), XCombineMode.Intersect);
      gfx.DrawRectangle(XBrushes.LightBlue, 0, 0, gfx.PageSize.Width, gfx.PageSize.Height);

      gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
      gfx.DrawPolygon(properties.Pen1.Pen, GetPentagram(75, new PointF(150, 200)));


      Matrix matrix = new Matrix();
      //matrix.Scale(2f, 1.5f);
      //matrix.Translate(-200, -400);
      //matrix.Rotate(45);
      //matrix.Translate(200, 400);
      //gfx.Transform = matrix;
      //gfx.TranslateTransform(50, 30);

#if true
      gfx.TranslateTransform(30, 40, XMatrixOrder.Prepend);
      gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Prepend);
      gfx.RotateTransform(15, XMatrixOrder.Prepend);
#else
      gfx.TranslateTransform(30, 40, XMatrixOrder.Append);
      gfx.ScaleTransform(2.0f, 2.0f, XMatrixOrder.Append);
      gfx.RotateTransform(15, XMatrixOrder.Append);
#endif
      bool id = matrix.IsIdentity;
      matrix.Scale(2.0f, 2.0f, MatrixOrder.Prepend);
      //matrix.Translate(30, -50);
      matrix.Rotate(15, MatrixOrder.Prepend);
      Matrix mtx = gfx.Transform.ToMatrix();
      //gfx.Transform = matrix;

      gfx.DrawLine(XPens.MediumSlateBlue, 0, 0, 150, 200);
      gfx.DrawPolygon(properties.Pen2.Pen, GetPentagram(75, new PointF(150, 200)));

      gfx.ResetClip();

      gfx.DrawLine(XPens.Red, 0, 0, 1000, 1000);

      gfx.DrawPolygon(XPens.SandyBrown, GetPentagram(75, new PointF(150, 200)));
#endif
    }
    public override void RenderPage(XGraphics gfx)
    {
#if true_
      // Create a new PDF document
      //PdfDocument document = new PdfDocument();

      // Create a font
      XFont font = new XFont("Verdana", 16);

      // Create a new page
      //PdfPage page = document.AddPage();
      //XGraphics gfx = XGraphics.FromPdfPage(page);
      //gfx.DrawString("XPdfForm Sample", font, XBrushes.DarkGray, 15, 25, XStringFormat.Default);

      // Step 1: Create an XForm and draw some graphics on it

      // Create an empty XForm object with the specified width and height
      // A form is bound to its target document when it is created. The reason is that the form can 
      // share fonts and other objects with its target document.
      XForm form = new XForm(gfx, XUnit.FromMillimeter(70), XUnit.FromMillimeter(55));

      // Create an XGraphics object for drawing the contents of the form.
      XGraphics formGfx = XGraphics.FromForm(form);

      // Draw a large transparent rectangle to visualize the area the form occupies
      XColor back = XColors.Orange;
      back.A = 0.2;
      XSolidBrush brush = new XSolidBrush(back);
      formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000);


      // On a form you can draw...

      //// ... text
      //formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormat.TopLeft);
      //XPen pen = XPens.LightBlue.Clone();
      //pen.Width = 2.5;

      // ... graphics like Bézier curves
      //formGfx.DrawBeziers(pen, XPoint.ParsePoints("30,120 80,20, 100,140 175,33.3"));

      //// ... raster images like GIF files
      //XGraphicsState state = formGfx.Save();
      //formGfx.RotateAtTransform(17, new XPoint(30, 30));
      //formGfx.DrawImage(XImage.FromFile("../../../../XGraphicsLab/images/Test.gif"), 20, 20);
      //formGfx.Restore(state);

      //// ... and forms like XPdfForm objects
      //state = formGfx.Save();
      //formGfx.RotateAtTransform(-8, new XPoint(165, 115));
      //formGfx.DrawImage(XPdfForm.FromFile("../../../../PDFs/SomeLayout.pdf"), new XRect(140, 80, 50, 50 * Math.Sqrt(2)));
      //formGfx.Restore(state);

      // When you finished drawing on the form, dispose the XGraphic object.
      formGfx.Dispose();


      // Step 2: Draw the XPdfForm on your PDF page like an image

      // Draw the form on the page of the document in its original size
      gfx.DrawImage(form, 20, 50);

#if true_
      // Draw it stretched
      gfx.DrawImage(form, 300, 100, 250, 40);

      // Draw and rotate it
      int d = 25;
      for (int idx = 0; idx < 360; idx += d)
      {
        gfx.DrawImage(form, 300, 480, 200, 200);
        gfx.RotateAtTransform(d, new XPoint(300, 480));
      }
#endif

      //// Save the document...
      //string filename = "XForms.pdf";
      //document.Save(filename);
      //// ...and start a viewer.
      //Process.Start(filename);
#else
      //base.RenderPage(gfx);

      int cx = 300;
      int cy = 240;
      XForm form;
      //if (gfx.PdfPage == null)
        form = new XForm(gfx, cx, cy);
      //else
      //  form = new XForm(gfx.PdfPage.Owner, cx, cy);

      double dx = gfx.PageSize.Width;
      double dy = gfx.PageSize.Height;

      XGraphics formgfx = XGraphics.FromForm(form);
      XSolidBrush brush = new XSolidBrush(XColor.FromArgb(128, 0, 255, 255));
      formgfx.DrawRectangle(brush, -1000, -1000, 2000, 2000);
      formgfx.DrawLine(XPens.Red, 0, 0, cx, cy);
      formgfx.DrawLine(XPens.Red, cx, 0, 0, cy);

      XFont font = new XFont("Times", 16, XFontStyle.BoldItalic);
      formgfx.DrawString("Text", font, XBrushes.DarkOrange, 0, 0, XStringFormats.TopLeft);
      formgfx.DrawString("Text", font, XBrushes.DarkOrange, new XRect(0, 0, cx, cy), XStringFormats.Center);

      // Required to finish drawing the form. Both cases are correct.
#if true
      formgfx.Dispose();
#else
      form.DrawingFinished();
#endif
      gfx.DrawImage(form, 50, 50);

#if true_
      gfx.TranslateTransform(dx / 2, dy / 2);
      gfx.RotateTransform(-25);
      gfx.TranslateTransform(-dx / 2, -dy / 2);

      gfx.DrawImage(form, (dx - form.Width) / 2, (dy - form.Height) / 2, form.Width, form.Height);
#endif
#endif
    }
Пример #14
0
        static void watermarkprint(XGraphics gfx, PdfPage page, XFont font)
        {
            string watermark = "TestME";

            // Get the size (in point) of the text
            XSize size = gfx.MeasureString(watermark, font);

            // Define a rotation transformation at the center of the page
            gfx.TranslateTransform(page.Width / 2, page.Height / 2);
            gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
            gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

            // Create a string format
            XStringFormat format = new XStringFormat();
            format.Alignment = XStringAlignment.Near;
            format.LineAlignment = XLineAlignment.Near;

            // Create a dimmed red brush
            XBrush brush = new XSolidBrush(XColor.FromArgb(60, 128, 125, 123));

            // Draw the string
            gfx.DrawString(watermark, font, brush,
              new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
              format);
        }
        public static void Test(PdfSharp.Drawing.XGraphics gfx)
        {
            XRect  rect;
            XPen   pen;
            double x = 50, y = 100;
            XFont  fontH1     = new XFont("Times", 18, XFontStyle.Bold);
            XFont  font       = new XFont("Times", 12);
            XFont  fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic);
            double ls         = font.GetHeight(gfx);

            // Draw some text
            gfx.DrawString("Create PDF on the fly with PDFsharp",
                           fontH1, XBrushes.Black, x, x);
            gfx.DrawString("With PDFsharp you can use the same code to draw graphic, " +
                           "text and images on different targets.", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("The object used for drawing is the XGraphics object.",
                           font, XBrushes.Black, x, y);
            y += 2 * ls;

            // Draw an arc
            pen           = new XPen(XColors.Red, 4);
            pen.DashStyle = XDashStyle.Dash;
            gfx.DrawArc(pen, x + 20, y, 100, 60, 150, 120);

            // Draw a star
            XGraphicsState gs = gfx.Save();

            gfx.TranslateTransform(x + 140, y + 30);
            for (int idx = 0; idx < 360; idx += 10)
            {
                gfx.RotateTransform(10);
                gfx.DrawLine(XPens.DarkGreen, 0, 0, 30, 0);
            }
            gfx.Restore(gs);

            // Draw a rounded rectangle
            rect = new XRect(x + 230, y, 100, 60);
            pen  = new XPen(XColors.DarkBlue, 2.5);
            XColor color1 = XColor.FromKnownColor(System.Drawing.KnownColor.DarkBlue);
            XColor color2 = XColors.Red;
            XLinearGradientBrush lbrush = new XLinearGradientBrush(rect, color1, color2,
                                                                   XLinearGradientMode.Vertical);

            gfx.DrawRoundedRectangle(pen, lbrush, rect, new XSize(10, 10));

            // Draw a pie
            pen           = new XPen(XColors.DarkOrange, 1.5);
            pen.DashStyle = XDashStyle.Dot;
            gfx.DrawPie(pen, XBrushes.Blue, x + 360, y, 100, 60, -130, 135);

            // Draw some more text
            y += 60 + 2 * ls;
            gfx.DrawString("With XGraphics you can draw on a PDF page as well as " +
                           "on any System.Drawing.Graphics object.", font, XBrushes.Black, x, y);
            y += ls * 1.1;
            gfx.DrawString("Use the same code to", font, XBrushes.Black, x, y);
            x += 10;
            y += ls * 1.1;
            gfx.DrawString("• draw on a newly created PDF page", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw above or beneath of the content of an existing PDF page",
                           font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw in a window", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw on a printer", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw in a bitmap image", font, XBrushes.Black, x, y);
            x -= 10;
            y += ls * 1.1;
            gfx.DrawString("You can also import an existing PDF page and use it like " +
                           "an image, e.g. draw it on another PDF page.", font, XBrushes.Black, x, y);
            y += ls * 1.1 * 2;
            gfx.DrawString("Imported PDF pages are neither drawn nor printed; create a " +
                           "PDF file to see or print them!", fontItalic, XBrushes.Firebrick, x, y);
            y += ls * 1.1;
            gfx.DrawString("Below this text is a PDF form that will be visible when " +
                           "viewed or printed with a PDF viewer.", fontItalic, XBrushes.Firebrick, x, y);
            y += ls * 1.1;
            XGraphicsState state   = gfx.Save();
            XRect          rcImage = new XRect(100, y, 100, 100 * System.Math.Sqrt(2));

            gfx.DrawRectangle(XBrushes.Snow, rcImage);
            gfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), rcImage);
            gfx.Restore(state);
        }
Пример #16
0
        public static void DrawLabel(XGraphics g, string text, PointF labelPos, XFont font, XBrush brush, LabelStyle labelStyle)
        {
            using (RenderUtil.SaveState(g))
            {
                if (labelStyle.Uppercase)
                    text = text.ToUpper();
                if (labelStyle.Wrap)
                    text = text.Replace(' ', '\n');

                g.TranslateTransform(labelPos.X, labelPos.Y);
                g.ScaleTransform(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY);
                g.TranslateTransform(labelStyle.Translation.X, labelStyle.Translation.Y);
                g.RotateTransform(labelStyle.Rotation);
                g.ScaleTransform(labelStyle.Scale.Width, labelStyle.Scale.Height);

                if (labelStyle.Rotation != 0)
                    g.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;

                XSize size = g.MeasureString(text, font);
                size.Width *= 2; // prevent cut-off e.g. when rotated
                XRect bounds = new XRect(-size.Width / 2, -size.Height / 2, size.Width, size.Height);

                XTextFormatter tf = new XTextFormatter(g);
                tf.Alignment = XParagraphAlignment.Center;
                tf.DrawString(text, font, brush, bounds);
            }
        }
Пример #17
0
    /// <summary>
    /// Renders the content of the page.
    /// </summary>
    public void Render(XGraphics gfx)
    {
      XRect rect;
      XPen pen;
      double x = 50, y = 100;
      XFont fontH1 = new XFont("Times", 18, XFontStyle.Bold);
      XFont font = new XFont("Times", 12);
      XFont fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic);
      double ls = font.GetHeight(gfx);

      // Draw some text
      gfx.DrawString("Create PDF on the fly with PDFsharp",
          fontH1, XBrushes.Black, x, x);
      gfx.DrawString("With PDFsharp you can use the same code to draw graphic, " +
          "text and images on different targets.", font, XBrushes.Black, x, y);
      y += ls;
      gfx.DrawString("The object used for drawing is the XGraphics object.", 
          font, XBrushes.Black, x, y);
      y += 2 * ls;

      // Draw an arc
      pen = new XPen(XColors.Red, 4);
      pen.DashStyle = XDashStyle.Dash;
      gfx.DrawArc(pen, x + 20, y, 100, 60, 150, 120);

      // Draw a star
      XGraphicsState gs = gfx.Save();
      gfx.TranslateTransform(x + 140, y + 30);
      for (int idx = 0; idx < 360; idx += 10)
      {
        gfx.RotateTransform(10);
        gfx.DrawLine(XPens.DarkGreen, 0, 0, 30, 0);
      }
      gfx.Restore(gs);

      // Draw a rounded rectangle
      rect = new XRect(x + 230, y, 100, 60);
      pen = new XPen(XColors.DarkBlue, 2.5);
      XColor color1 = XColor.FromKnownColor(KnownColor.DarkBlue);
      XColor color2 = XColors.Red;
      XLinearGradientBrush lbrush = new XLinearGradientBrush(rect, color1, color2, 
        XLinearGradientMode.Vertical);
      gfx.DrawRoundedRectangle(pen, lbrush, rect, new XSize(10, 10));
      
      // Draw a pie
      pen = new XPen(XColors.DarkOrange, 1.5);
      pen.DashStyle = XDashStyle.Dot;
      gfx.DrawPie(pen, XBrushes.Blue, x + 360, y, 100, 60, -130, 135);
      
      // Draw some more text
      y += 60 + 2 * ls;
      gfx.DrawString("With XGraphics you can draw on a PDF page as well as " +
          "on any System.Drawing.Graphics object.", font, XBrushes.Black, x, y);
      y += ls * 1.1;
      gfx.DrawString("Use the same code to", font, XBrushes.Black, x, y);
      x += 10;
      y += ls * 1.1;
      gfx.DrawString("• draw on a newly created PDF page", font, XBrushes.Black, x, y);
      y += ls;
      gfx.DrawString("• draw above or beneath of the content of an existing PDF page", 
          font, XBrushes.Black, x, y);
      y += ls;
      gfx.DrawString("• draw in a window", font, XBrushes.Black, x, y);
      y += ls;
      gfx.DrawString("• draw on a printer", font, XBrushes.Black, x, y);
      y += ls;
      gfx.DrawString("• draw in a bitmap image", font, XBrushes.Black, x, y);
      x -= 10;
      y += ls * 1.1;
      gfx.DrawString("You can also import an existing PDF page and use it like " +
          "an image, e.g. draw it on another PDF page.", font, XBrushes.Black, x, y);
      y += ls * 1.1 * 2;
      gfx.DrawString("Imported PDF pages are neither drawn nor printed; create a " + 
          "PDF file to see or print them!", fontItalic, XBrushes.Firebrick, x, y);
      y += ls * 1.1;
      gfx.DrawString("Below this text is a PDF form that will be visible when " + 
          "viewed or printed with a PDF viewer.", fontItalic, XBrushes.Firebrick, x, y);
      y += ls * 1.1;
      XGraphicsState state = gfx.Save();
      XRect rcImage = new XRect(100, y, 100, 100 * Math.Sqrt(2));
      gfx.DrawRectangle(XBrushes.Snow, rcImage);
      gfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), rcImage);
      gfx.Restore(state);
    }
Пример #18
0
    /// <summary>
    /// Draws an image transformed.
    /// </summary>
    void DrawImageRotated(XGraphics gfx, int number)
    {
      BeginBox(gfx, number, "DrawImage (rotated)");

      XImage image = XImage.FromFile(jpegSamplePath);

      const double dx = 250, dy = 140;

      gfx.TranslateTransform(dx / 2, dy / 2);
      gfx.ScaleTransform(0.7);
      gfx.RotateTransform(-25);
      gfx.TranslateTransform(-dx / 2, -dy / 2);

      //XMatrix matrix = new XMatrix();  //XMatrix.Identity;

      double width = image.PixelWidth * 72 / image.HorizontalResolution;
      double height = image.PixelHeight * 72 / image.HorizontalResolution;

      gfx.DrawImage(image, (dx - width) / 2, 0, width, height);

      EndBox(gfx);
    }
Пример #19
0
 public static void DrawChevron(XGraphics graphics, PointF pos, float angle, float size, Brush fillBrush)
 {
     if (m_chevronPath == null)
       {
     var apex = new PointF(0.5f, 0);
     var leftCorner = new PointF(-0.5f, 0.5f);
     var rightCorner = new PointF(-0.5f, -0.5f);
     m_chevronPath = new XGraphicsPath();
     m_chevronPath.AddLine(apex, rightCorner);
     m_chevronPath.AddLine(rightCorner, leftCorner);
     m_chevronPath.AddLine(leftCorner, apex);
       }
       var state = graphics.Save();
       graphics.TranslateTransform(pos.X, pos.Y);
       graphics.RotateTransform(angle);
       graphics.ScaleTransform(size, size);
       graphics.DrawPath(fillBrush, m_chevronPath);
       graphics.Restore(state);
 }
        /// <summary>
        /// Draws a PNG image with transparency.
        /// </summary>
        public void DrawPngRotated(XGraphics gfx, int number, XImage pngImage)
        {
            //BeginBox(gfx, number, "DrawImage (PNG)");

            XImage image = pngImage;

            //const double dx = 250, dy = 140;

            //double width = image.PixelWidth * 72 / image.HorizontalResolution;
            //double height = image.PixelHeight * 72 / image.HorizontalResolution;

            //gfx.DrawImage(image, (dx - width) / 2, (dy - height) / 2, width, height);

            const double dx = 250, dy = 140;

            gfx.TranslateTransform(dx / 2, dy / 2);
            gfx.ScaleTransform(0.7);
            gfx.RotateTransform(-25);
            gfx.TranslateTransform(-dx / 2, -dy / 2);

            double width = image.PixelWidth * 72 / image.HorizontalResolution;
            double height = image.PixelHeight * 72 / image.HorizontalResolution;

            gfx.DrawImage(image, 0, 0, width, height);
            //gfx.DrawImage(image, 0, 0, width, height);

            //EndBox(gfx);
        }
Пример #21
0
 /// <summary>
 /// Draws the Watermark
 /// </summary>
 /// <param name="gfx">XGraphics object</param>
 private void AddWatermark(XGraphics gfx)
 {
     gfx.RotateTransform(-40);
     XFont font = new XFont("Arial Rounded MT Bold", 60, XFontStyle.Regular);
     XBrush brush = new XSolidBrush(XColor.FromArgb(70, 255, 0, 0));
     gfx.DrawString("VALGKORT", font, brush, -120, 250);
     gfx.RotateTransform(40);
 }
Пример #22
-1
    public override void RenderPage(XGraphics gfx)
    {
      base.RenderPage(gfx);

      XImage image = XImage.FromFile(@"..\..\..\..\samples\PDFs\SomeLayout.pdf");

      double dx = gfx.PageSize.Width;
      double dy = gfx.PageSize.Height;

#if true
      gfx.TranslateTransform(dx / 2, dy / 2);
      gfx.RotateTransform(-25);
      gfx.TranslateTransform(-dx / 2, -dy / 2);
#endif

      gfx.DrawImage(image, (dx - image.PixelWidth) / 2, (dy - image.PixelHeight) / 2, image.PixelWidth, image.PixelHeight);
    }