/// <summary> /// Renders the bar code. /// </summary> protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position) { XGraphicsState state = gfx.Save(); BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position); InitRendering(info); info.CurrPosInString = 0; //info.CurrPos = Center - Size / 2; info.CurrPos = position - CalcDistance(AnchorType.TopLeft, Anchor, Size); if (TurboBit) { RenderTurboBit(info, true); } RenderStart(info); while (info.CurrPosInString < Text.Length) { RenderNextChar(info); RenderGap(info, false); } RenderStop(info); if (TurboBit) { RenderTurboBit(info, false); } if (TextLocation != TextLocation.None) { RenderText(info); } gfx.Restore(state); }
void ResetTransform(XGraphicsState state) { if (state != null) { this.gfx.Restore(state); } }
XGraphicsState Transform() { Area frameContentArea = this.renderInfo.LayoutInfo.ContentArea; XGraphicsState state = this.gfx.Save(); XUnit xPosition; XUnit yPosition; switch (this.textframe.Orientation) { case TextOrientation.Downward: case TextOrientation.Vertical: case TextOrientation.VerticalFarEast: xPosition = frameContentArea.X + frameContentArea.Width; yPosition = frameContentArea.Y; this.gfx.TranslateTransform(xPosition, yPosition); this.gfx.RotateTransform(90); break; case TextOrientation.Upward: state = this.gfx.Save(); xPosition = frameContentArea.X; yPosition = frameContentArea.Y + frameContentArea.Height; this.gfx.TranslateTransform(xPosition, yPosition); this.gfx.RotateTransform(-90); break; default: xPosition = frameContentArea.X; yPosition = frameContentArea.Y; this.gfx.TranslateTransform(xPosition, yPosition); break; } return(state); }
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); }
/// <summary> /// Resets the clipping. /// </summary> private void RestoreInitialClip() { //Get back to the initial state _graphics.Restore(_initialState); _initialState = _graphics.Save(); //Restore transform _graphics.MultiplyTransform(_transform); _clippingRegion = new Region(); }
protected 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); }
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); }
/// <summary> /// Resets the clipping. /// </summary> private void RestoreInitialClip() { //Get back to the initial state graphics.Restore(initialState); initialState = graphics.Save(); //Restore transform graphics.MultiplyTransform(transform); clippingRegion = new Region(); }
/// <summary> /// Restores the state to the initial state. /// </summary> private void RestoreInitialTransform() { //Go to the initial state _graphics.Restore(_initialState); _initialState = _graphics.Save(); //We've just restored the initial state so the there are no transformations active. _transform = new Matrix(); //Restore the last clipping ApplyClip(_clippingRegion); }
private void BeginAddress(XGraphics gfx, int number, string address) { XRect rect = new XRect(40, 60 + 6 * 60, 104 * 3.5, 16); XFont font = new XFont("Verdana", 12, XFontStyle.Regular); rect.X += (104 * 3.5 + 20) * (number % 2); rect.Y += 17 * (number / 2); gfx.DrawString(address, font, XBrushes.Navy, rect, XStringFormats.TopCenter); state = gfx.Save(); }
public void PdfDraw(XGraphics g) { XStringFormat formatDec = new XStringFormat(); formatDec.Alignment = XStringAlignment.Near; formatDec.LineAlignment = XLineAlignment.Center; XSolidBrush b = new XSolidBrush(Color.Black); for (int i = 0; i < ParentTest.Paper.Blocks.X - 1; i += 7) { g.DrawEllipse(b, new Rectangle(DesignZone.Left + ((Settings.blockWidth - Settings.blockHeight) / 2) + (i * Settings.blockWidth), DesignZone.Bottom - 1 - Settings.blockHeight, Settings.blockHeight, Settings.blockHeight)); } for (int i = 0; i < ParentTest.Paper.Blocks.Y - 1; i += 7) { g.DrawEllipse(b, new Rectangle(DesignZone.Right - 1 - Settings.blockHeight, DesignZone.Top + (i * Settings.blockHeight), Settings.blockHeight, Settings.blockHeight)); } g.DrawEllipse(b, new Rectangle(DesignZone.Right - 1 - Settings.blockHeight, DesignZone.Bottom - 1 - Settings.blockHeight, Settings.blockHeight, Settings.blockHeight)); XGraphicsState gs = g.Save(); g.RotateAtTransform(90, new XPoint(DesignZone.Right - 1 - (int)(Settings.blockHeight / 2), DesignZone.Top + (2 * Settings.blockHeight))); XStringFormat pageNumFormat = new XStringFormat(); pageNumFormat.LineAlignment = XLineAlignment.Far; g.Restore(gs); var barcode = BarCode.CreateArray(Hash()); Point start = new Point(DesignZone.Left + (4 * Settings.blockWidth) - 57, DesignZone.Bottom - 25); XBrush bGray = new XSolidBrush(XColor.FromArgb(Program.Test.BarCodeGray, Program.Test.BarCodeGray, Program.Test.BarCodeGray)); for (int i = 0; i < 19; i++) { for (int j = 0; j < 4; j++) { if (barcode[i, j] == 0) { g.DrawRectangle(bGray, start.X + (i * 6), start.Y + (j * 6), 6, 6); } } } foreach (TestElement testElement in TestElements) { testElement.PdfDraw(g); } }
private void DrawBody(XGraphics gfx) { for (int x = 0; x < 15; x++) { XGraphicsState state1 = gfx.Save(); gfx.RotateAtTransform(-70, new XPoint(200 + (x * 20), 250)); gfx.DrawString("Long Text Here : Always expect more " + (x + 1), FontUtility.HeaderContentNormal, XBrushes.Black, new XPoint(200 + (x * 20), 250)); gfx.Restore(state1); } for (int x = 0; x < 15; x++) { XPen pen = new XPen(XColors.Gray, 1); gfx.DrawRectangle(pen, XBrushes.White, new XRect(195 + (x * 20), 260, 8, 25)); if (x % 2 == 0) { gfx.DrawRectangle(XBrushes.LightGray, new XRect(195 + (x * 20), 270, 8, 15)); } } int lineHeight = 20; int topHeight = 0; for (int x = 0; x < 20; x++) { topHeight = 300 + lineHeight * x; gfx.DrawLine(XPens.LightGray, 50, topHeight, 490, topHeight); if (x % 2 == 0) { gfx.DrawString("&", FontUtility.BodyContentTick, XBrushes.Green, new XRect(50, topHeight + 8, 10, 0)); } else { gfx.DrawString("#", FontUtility.BodyContentTick, XBrushes.Green, new XRect(50, topHeight + 8, 10, 0)); } gfx.DrawString("Associate Consultant " + (x + 1), FontUtility.BodyContentNormal, XBrushes.Black, new XRect(60, topHeight + 8, 100, 0)); gfx.DrawString("8/2011 - present", FontUtility.BodyContentNormal, XBrushes.Black, new XRect(50, topHeight + 16, 100, 0)); for (int y = 0; y < 16; y++) { XPen pen = new XPen(XColors.Gray, 1); gfx.DrawLine(pen, new XPoint(190 + (y * 20), topHeight), new XPoint(190 + (y * 20), (topHeight + 20))); if (y % 2 == 0) { gfx.DrawImage(XImage.FromFile("../Images/Green-Tick.png"), new XRect(190 + (y * 20) + 5, topHeight + 6, 10, 10)); } } } gfx.DrawLine(XPens.LightGray, 50, topHeight + lineHeight, 490, topHeight + lineHeight); }
void RenderContent() { FormattedTextFrame formattedTextFrame = ((TextFrameFormatInfo)_renderInfo.FormatInfo).FormattedTextFrame; RenderInfo[] renderInfos = formattedTextFrame.GetRenderInfos(); if (renderInfos == null) { return; } XGraphicsState state = Transform(); RenderByInfos(renderInfos); ResetTransform(state); }
void RenderContent(CancellationToken ct) { FormattedTextFrame formattedTextFrame = ((TextFrameFormatInfo)this.renderInfo.FormatInfo).formattedTextFrame; RenderInfo[] renderInfos = formattedTextFrame.GetRenderInfos(); if (renderInfos == null) { return; } XGraphicsState state = Transform(); RenderByInfos(renderInfos, ct); ResetTransform(state); }
/// <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); }
public static void DrawBeziers() { string fn = @"input.pdf"; using (PdfSharp.Pdf.PdfDocument document = PdfSharp.Pdf.IO.PdfReader.Open(fn)) { // 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. using (XForm form = new XForm(document, XUnit.FromMillimeter(70), XUnit.FromMillimeter(55))) { // Create an XGraphics object for drawing the contents of the form. using (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, XStringFormats.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("../../../../../../dev/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 * System.Math.Sqrt(2))); formGfx.Restore(state); // When you finished drawing on the form, dispose the XGraphic object. } // End Using formGfx } // End Using form } // End Using document }
public static void PDFExport(string Paydate) { string InvoiceNumber = "" + SelectedInvoiceNumber + ""; PdfDocument document = new PdfDocument(); document.Info.Title = "Invoice"; document.Info.Author = "Jack Huckins"; document.Info.Subject = "Service Invoice"; PdfPage page = new PdfPage(); page = document.AddPage(); page.Width = XUnit.FromInch(8.5); page.Height = XUnit.FromInch(11); XGraphics gfx = default(XGraphics); gfx = XGraphics.FromPdfPage(page); XForm form = new XForm(document, XUnit.FromMillimeter(300), XUnit.FromMillimeter(300)); XGraphics formGfx = default(XGraphics); formGfx = XGraphics.FromForm(form); XGraphicsState state = default(XGraphicsState); state = formGfx.Save(); //..... Invoice Results GetInvResults(Paydate); PrepareInvoiceTop(formGfx, state, InvoiceNumber); PrepareInvoiceData(6, 217, formGfx); PrepareFooter(formGfx); state = formGfx.Save(); formGfx.Dispose(); gfx.DrawImage(form, 0, 0); //document.Save("c:\\Invoices\\Inv " + InvoiceNumber + ".pdf") SetReportPath(); document.Save(ReportPath); TimeConnector.Data.ActionLog.Insert("PDF Export", "" + InvoiceNumber + ""); //UpdatePDFLabel("30 second Check", Form1.lblPDFStatus); //var _with1 = ViewPDF; //_with1.PdfName = Export.ReportPath; //_with1.Show(); }
/// <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); }
public InternalGraphicsState(XGraphics gfx, XGraphicsState state) { this.gfx = gfx; this.state = state; state.InternalState = this; //#if GDI // //GdiGraphicsState = state.GdiState; // this.gfx = gfx; // this.state = state; // state.InternalState = this; //#endif //#if WPF // this.gfx = gfx; // this.state = state; // state.InternalState = this; //#endif }
/// <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); }
/// <summary> /// Renders the matrix code. /// </summary> protected internal override void Render(XGraphics gfx, XBrush brush, XPoint position) { XGraphicsState state = gfx.Save(); switch (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 + CalcDistance(Anchor, AnchorType.TopLeft, Size); if (MatrixImage == null) { MatrixImage = DataMatrixImage.GenerateMatrixImage(Text, Encoding, Rows, Columns); } if (QuietZone > 0) { XSize sizeWithZone = new XSize(Size.Width, 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, Size.Width, Size.Height); } gfx.Restore(state); }
public void DrawBox(XGraphics gfx, XRect rect, XBrush brush) { gfx.DrawRectangle(brush, rect); //gfx.DrawRoundedRectangle(this.borderPen, new XSolidBrush(this.backColor), rect, new XSize(dEllipse, dEllipse)); //rect.Inflate(-5, -5); //XFont font = new XFont("Verdana", 12, XFontStyle.Regular); //gfx.DrawString(title, font, XBrushes.Black, rect, XStringFormat.CenterTop); //rect.Inflate(-10, -5); //rect.Y += 20; //rect.Height -= 20; //gfx.DrawRectangle(XPens.Red, rect); this._state = gfx.Save(); gfx.TranslateTransform(rect.X, rect.Y); SetBoxX(0); SetBoxY(0); }
/// <summary> /// Draws first chart only. /// </summary> public void DrawChart(XGraphics gfx) { XGraphicsState state = gfx.Save(); gfx.TranslateTransform(this.location.X, this.location.Y); if (this.chartList.Count > 0) { XRect chartRect = new XRect(0, 0, this.size.Width, this.size.Height); Chart chart = (Chart)this.chartList[0]; RendererParameters parms = new RendererParameters(gfx, chartRect); parms.DrawingItem = chart; ChartRenderer renderer = GetChartRenderer(chart, parms); renderer.Init(); renderer.Format(); renderer.Draw(); } gfx.Restore(state); }
/// <summary> /// Draws the content of the area 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); 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); }
/// <summary> /// Draws the content of the pie plot area. /// </summary> internal override void Draw() { ChartRendererInfo cri = (ChartRendererInfo)_rendererParms.RendererInfo; XRect plotAreaRect = cri.plotAreaRendererInfo.Rect; if (plotAreaRect.IsEmpty) { return; } if (cri.seriesRendererInfos.Length == 0) { return; } XGraphics gfx = _rendererParms.Graphics; XGraphicsState state = gfx.Save(); // Draw sectors. SeriesRendererInfo sri = cri.seriesRendererInfos[0]; foreach (SectorRendererInfo sector in sri._pointRendererInfos) { if (!double.IsNaN(sector.StartAngle) && !double.IsNaN(sector.SweepAngle)) { gfx.DrawPie(sector.FillFormat, sector.Rect, sector.StartAngle, sector.SweepAngle); } } // Draw border of the sectors. foreach (SectorRendererInfo sector in sri._pointRendererInfos) { if (!double.IsNaN(sector.StartAngle) && !double.IsNaN(sector.SweepAngle)) { gfx.DrawPie(sector.LineFormat, sector.Rect, sector.StartAngle, sector.SweepAngle); } } gfx.Restore(state); }
/// <summary> /// Renders the bar code. /// </summary> protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position) { XGraphicsState state = gfx.Save(); BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position); InitRendering(info); info.CurrPosInString = 0; info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size); // EAN13 Barcode should be a total of 113 modules wide. int numberOfBars = 12; // The length - country code numberOfBars *= 7; // Each character has 7 bars numberOfBars += 2 * (Quite.Length + Leading.Length); numberOfBars += Separator.Length; info.ThinBarWidth = ((double)this.Size.Width / (double)numberOfBars); RenderStart(info); m_leftBlock.x = info.CurrPos.x + info.ThinBarWidth / 2; RenderLeft(info); m_leftBlock.Width = info.CurrPos.x - m_leftBlock.x; RenderSeparator(info); m_rightBlock.x = info.CurrPos.x; RenderRight(info); m_rightBlock.Width = info.CurrPos.x - m_rightBlock.x - info.ThinBarWidth / 2; RenderStop(info); if (this.TextLocation == TextLocation.BelowEmbedded) { RenderText(info); } gfx.Restore(state); }
public void BeginHeader(XGraphics gfx, int number) { XRect rect = new XRect(50, 30, 104, 20); rect.X += 104 * (number % 7); XLinearGradientBrush brush = new XLinearGradientBrush(new XPoint(1, 1), new XPoint(3, 3), this.backColor, this.backColor2); XBrush b = XBrushes.Transparent; gfx.DrawRectangle(borderPen, b, rect); XFont font = new XFont("Verdana", 12, XFontStyle.Regular); gfx.DrawString($"{ZP.days[number]}", font, XBrushes.Navy, rect, XStringFormats.TopCenter); state = gfx.Save(); }
/// <summary>Renders the content found in Text</summary> /// <param name="gfx">XGraphics - Instance of the drawing surface </param> /// <param name="brush">XBrush - Line and Color to draw the bar code</param> /// <param name="font">XFont - Font to use to draw the text string</param> /// <param name="position">XPoint - Location to render the bar code</param> protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position) { XGraphicsState state = gfx.Save(); BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position); InitRendering(info); info.CurrPosInString = 0; info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size); RenderStart(info); foreach (byte c in Values) { RenderValue(info, (int)c); } RenderStop(info); if (TextLocation != TextLocation.None) { RenderText(info); } gfx.Restore(state); }
internal void RenderDiagonally(BorderType type, XUnit left, XUnit top, XUnit width, XUnit height) { XUnit borderWidth = GetWidth(type); if (borderWidth == 0) { return; } XGraphicsState state = _gfx.Save(); _gfx.IntersectClip(new XRect(left, top, width, height)); if (type == BorderType.DiagonalDown) { _gfx.DrawLine(GetPen(type), left, top, left + width, top + height); } else if (type == BorderType.DiagonalUp) { _gfx.DrawLine(GetPen(type), left, top + height, left + width, top); } _gfx.Restore(state); }
/// <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); }
// -------------------------------------------------------------------------------------------- #region Save and Restore /// <summary> /// Clones the current graphics state and push it on a stack. /// </summary> public void Save(XGraphicsState state) { // Before saving, the current transformation matrix must be completely realized. BeginGraphic(); RealizeTransform(); // Associate the XGraphicsState with the current PdgGraphicsState. this.gfxState.InternalState = state.InternalState; SaveState(); }
public void Restore(XGraphicsState state) { BeginGraphic(); RestoreState(state.InternalState); }