本文整理汇总了C#中PdfSharp.Drawing.XGraphics.Restore方法的典型用法代码示例。如果您正苦于以下问题:C# XGraphics.Restore方法的具体用法?C# XGraphics.Restore怎么用?C# XGraphics.Restore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PdfSharp.Drawing.XGraphics
的用法示例。
在下文中一共展示了XGraphics.Restore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderPage
/// <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)));
}
示例2: Box
void Box(XGraphics gfx, XRect rect, double startAngle, double sweepAngle)
{
double xc = rect.X + rect.Width / 2;
double yc = rect.Y + rect.Height / 2;
double a = startAngle * 0.017453292519943295;
double b = (startAngle + sweepAngle) * 0.017453292519943295;
XGraphicsState state = gfx.Save();
gfx.IntersectClip(rect);
#if true
#if true_
for (double deg = 0; deg < 360; deg += 10)
gfx.DrawLine(XPens.Yellow, xc, yc,
(xc + rect.Width / 2 * Math.Cos(deg * 0.017453292519943295)),
(yc + rect.Height / 2 * Math.Sin(deg * 0.017453292519943295)));
#endif
double f = Math.Max(rect.Width / 2, rect.Height / 2);
for (double deg = 0; deg < 360; deg += 10)
gfx.DrawLine(XPens.Goldenrod, xc, yc,
(xc + f * Math.Cos(deg * 0.017453292519943295)),
(yc + f * Math.Sin(deg * 0.017453292519943295)));
gfx.DrawLine(XPens.PaleGreen, xc, rect.Y, xc, rect.Y + rect.Height);
gfx.DrawLine(XPens.PaleGreen, rect.X, yc, rect.X + rect.Width, yc);
//gfx.DrawLine(XPens.DarkGray, xc, yc, (xc + rect.Width / 2 * Math.Cos(a)), (yc + rect.Height / 2 * Math.Sin(a)));
//gfx.DrawLine(XPens.DarkGray, xc, yc, (xc + rect.Width / 2 * Math.Cos(b)), (yc + rect.Height / 2 * Math.Sin(b)));
#endif
gfx.Restore(state);
gfx.DrawRectangle(properties.Pen1.Pen, rect);
}
示例3: DrawTo
public void DrawTo(XGraphics context)
{
var state = context.Save();
layout.Transform(context, form.Size);
form.PageIndex = sourcePageIndex;
context.DrawImage(form, 0, 0);
context.Restore(state);
}
示例4: RenderPage
/// <summary>
/// Demonstrates the use of XGraphics.SetClip.
/// </summary>
public override void RenderPage(XGraphics gfx)
{
base.RenderPage(gfx);
gfx.Save();
gfx.TranslateTransform(50, 50);
gfx.IntersectClip(new Rectangle(0, 0, 400, 250));
gfx.TranslateTransform(50, 50);
//gfx.Clear(XColor.GhostWhite);
gfx.DrawEllipse(XPens.Green, XBrushes.Yellow, 40, 40, 500, 500);
gfx.Restore();
gfx.Save();
//gfx.Transform = new XMatrix(); //XMatrix.Identity;
gfx.TranslateTransform(200, 200);
gfx.IntersectClip(new Rectangle(0, 0, 400, 250));
gfx.DrawEllipse(XPens.Green, XBrushes.Yellow, 40, 40, 500, 500);
gfx.Restore();
}
示例5: Render
/// <summary>
/// Renders the content of the page.
/// </summary>
public void Render(XGraphics xGraphics)
{
const double textPossitionX = 50;
double textPossitionY = 100;
const string fontFamilyName = "Times";
const int fontSizeHeader = 18;
const int fontSizeText = 12;
XFont fontHeader = new XFont(fontFamilyName, fontSizeHeader, XFontStyle.Bold);
XFont fontText = new XFont(fontFamilyName, fontSizeText);
XFont fontItalic = new XFont(fontFamilyName, fontSizeText, XFontStyle.BoldItalic);
double lineSpacing = fontText.GetHeight(xGraphics);
xGraphics.DrawString("This is Header", fontHeader, XBrushes.Black, textPossitionX, textPossitionX);
textPossitionY += lineSpacing;
xGraphics.DrawString("This is normal.", fontText, XBrushes.Black, textPossitionX, textPossitionY);
textPossitionY += lineSpacing;
xGraphics.DrawString("This is Italic.", fontItalic, XBrushes.Black, textPossitionX, textPossitionY);
textPossitionY += lineSpacing*3;
//Bitmap bitmap = (Bitmap)Image.FromFile(@"E:\temp\klicaj.jpeg");
XImage xImage = null;
if (item != null)
{
if (item.Image != null)
{
MemoryStream memoryStream = new MemoryStream(item.Image);
Bitmap bitmap = (Bitmap) Image.FromStream(memoryStream, true, true);
xImage = XImage.FromGdiPlusImage(bitmap);
}
}
if (xImage != null)
{
XRect rcImage = new XRect(100, textPossitionY, 100, 100*Math.Sqrt(2));
xGraphics.DrawImage(xImage, rcImage);
}
XGraphicsState state = xGraphics.Save();
xGraphics.Restore(state);
}
示例6: DrawRectangle
/// <summary>
/// Draw the texture image in the given graphics at the given location.
/// </summary>
public void DrawRectangle(XGraphics g, double x, double y, double width, double height)
{
var prevState = g.Save();
g.IntersectClip(new XRect(x, y, width, height));
double rx = _translateTransformLocation.X;
double w = _image.PixelWidth, h = _image.PixelHeight;
while (rx < x + width)
{
double ry = _translateTransformLocation.Y;
while (ry < y + height)
{
g.DrawImage(_image, rx, ry, w, h);
ry += h;
}
rx += w;
}
g.Restore(prevState);
}
示例7: Render
/// <summary>
/// Renders the matrix code.
/// </summary>
protected internal override void Render(XGraphics gfx, XBrush brush, 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 pos = position + CodeBase.CalcDistance(this.anchor, AnchorType.TopLeft, this.size);
if (this.matrixImage == null)
this.matrixImage = DataMatrixImage.GenerateMatrixImage(Text, Encoding, Rows, Columns);
if (QuietZone > 0)
{
XSize sizeWithZone = new XSize(this.size.width, this.size.height);
sizeWithZone.width = sizeWithZone.width / (Columns + 2 * QuietZone) * Columns;
sizeWithZone.height = sizeWithZone.height / (Rows + 2 * QuietZone) * Rows;
XPoint posWithZone = new XPoint(pos.X, pos.Y);
posWithZone.X += size.width / (Columns + 2 * QuietZone) * QuietZone;
posWithZone.Y += size.height / (Rows + 2 * QuietZone) * QuietZone;
gfx.DrawRectangle(XBrushes.White, pos.x, pos.y, size.width, size.height);
gfx.DrawImage(matrixImage, posWithZone.x, posWithZone.y, sizeWithZone.width, sizeWithZone.height);
}
else
gfx.DrawImage(matrixImage, pos.x, pos.y, this.size.width, this.size.height);
gfx.Restore(state);
}
示例8: RenderPage
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);
}
示例9: EndBox
public void EndBox(XGraphics gfx)
{
gfx.Restore(this.state);
gfx.TranslateTransform(-62, -63);
gfx.RotateAtTransform(-90.0, new XPoint(height / 4, width / 4));
}
示例10: DrawIcon
void DrawIcon(XGraphics gfx, string iconName, XPoint position, double width, double height)
{
var iconPath = Server.MapPath("~/Content/icons/" + iconName + ".png");
if (System.IO.File.Exists(iconPath))
{
using (XImage image = XImage.FromFile(iconPath))
{
var state = gfx.Save();
gfx.DrawImage(image, position.X, position.Y, width, height);
gfx.Restore(state);
}
}
}
示例11: Render
/// <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);
}
示例12: DrawLineArrowInternal
private static XPoint DrawLineArrowInternal(XGraphics gfx, XPen pen, XSolidBrush brush, double x, double y, double angle, Core2D.Style.ArrowStyle style)
{
XPoint pt;
var rt = new XMatrix();
var c = new XPoint(x, y);
rt.RotateAtPrepend(angle, c);
double rx = style.RadiusX;
double ry = style.RadiusY;
double sx = 2.0 * rx;
double sy = 2.0 * ry;
switch (style.ArrowType)
{
default:
case Core2D.Style.ArrowType.None:
{
pt = new XPoint(x, y);
}
break;
case Core2D.Style.ArrowType.Rectangle:
{
pt = rt.Transform(new XPoint(x - sx, y));
var rect = new XRect(x - sx, y - ry, sx, sy);
gfx.Save();
gfx.RotateAtTransform(angle, c);
DrawRectangleInternal(gfx, brush, pen, style.IsStroked, style.IsFilled, ref rect);
gfx.Restore();
}
break;
case Core2D.Style.ArrowType.Ellipse:
{
pt = rt.Transform(new XPoint(x - sx, y));
gfx.Save();
gfx.RotateAtTransform(angle, c);
var rect = new XRect(x - sx, y - ry, sx, sy);
DrawEllipseInternal(gfx, brush, pen, style.IsStroked, style.IsFilled, ref rect);
gfx.Restore();
}
break;
case Core2D.Style.ArrowType.Arrow:
{
pt = rt.Transform(new XPoint(x, y));
var p11 = rt.Transform(new XPoint(x - sx, y + sy));
var p21 = rt.Transform(new XPoint(x, y));
var p12 = rt.Transform(new XPoint(x - sx, y - sy));
var p22 = rt.Transform(new XPoint(x, y));
DrawLineInternal(gfx, pen, style.IsStroked, ref p11, ref p21);
DrawLineInternal(gfx, pen, style.IsStroked, ref p12, ref p22);
}
break;
}
return pt;
}
示例13: RenderPage
/// <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
}
示例14: EndBox
public void EndBox(XGraphics gfx)
{
gfx.Restore(this.state);
}
示例15: DrawSecondHand
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);
}