/// <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 Shapes() { string filename = "Shapes.pdf"; PdfDocument document = new PdfDocument(); //document.Options.ColorMode = PdfColorMode.Cmyk; // Set version to PDF 1.4 (Acrobat 5) because we use transparency. //if (document.Version < 14) // document.Version = 14; //PdfPage page = document.Pages[0]; //// Get an XGraphics object for drawing beneath the existing content //XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append); LayoutHelper helper = new LayoutHelper(document, XUnit.FromCentimeter(2.5), XUnit.FromCentimeter(29.7 - 2.5)); XUnit left = XUnit.FromCentimeter(2.5); helper.CreatePage(); XGraphics gfx = helper.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); document.Save(filename); LaunchPdf(filename); }
/// <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) { // Create the array to hold the values to be rendered this.Values = this.Code128Code == Code128Type.C ? new byte[this.text.Length / 2] : new byte[this.text.Length]; String buffer = String.Empty; for (Int32 index = 0; index < text.Length; index++) switch (this.Code128Code) { case Code128Type.A: if (text[index] < 32) this.Values[index] = (byte)(text[index] + 64); else if ((text[index] >= 32) && (text[index] < 64)) this.Values[index] = (byte)(text[index] - 32); else this.Values[index] = (byte)text[index]; break; case Code128Type.B: this.Values[index] = (byte)(text[index] - 32); break; case Code128Type.C: if ((text[index] >= '0') && (text[index] <= '9')) { buffer += text[index]; if (buffer.Length == 2) { this.Values[index / 2] = byte.Parse(buffer); buffer = String.Empty; } } else throw new ArgumentOutOfRangeException("Parameter text (string) can only contain numeric characters for Code 128 - Code C"); break; } if (this.Values == null) throw new InvalidOperationException("Text or Values must be set"); if (this.Values.Length == 0) throw new InvalidOperationException("Text or Values must have content"); for (int x = 0; x < this.Values.Length; x++) if (this.Values[x] > 102) throw new ArgumentOutOfRangeException(BcgSR.InvalidCode128(x)); XGraphicsState state = gfx.Save(); BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position); this.InitRendering(info); info.CurrPosInString = 0; info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size); this.RenderStart(info); foreach (byte c in this.Values) this.RenderValue(info, c); this.RenderStop(info); if (this.TextLocation != TextLocation.None) this.RenderText(info); gfx.Restore(state); }
public void Restore(IGraphicsState state) { Graphics.Restore((XGraphicsState)state.Raw); }
/// <summary> /// Draws all charts inside the ChartFrame. /// </summary> public void Draw(XGraphics gfx) { // Draw frame of ChartFrame. First shadow frame. const int dx = 5; const int dy = 5; gfx.DrawRoundedRectangle(XBrushes.Gainsboro, _location.X + dx, _location.Y + dy, _size.Width, _size.Height, 20, 20); XRect chartRect = new XRect(_location.X, _location.Y, _size.Width, _size.Height); XLinearGradientBrush brush = new XLinearGradientBrush(chartRect, XColor.FromArgb(0xFFD0DEEF), XColors.White, XLinearGradientMode.Vertical); XPen penBorder = new XPen(XColors.SteelBlue, 2.5); gfx.DrawRoundedRectangle(penBorder, brush, _location.X, _location.Y, _size.Width, _size.Height, 15, 15); XGraphicsState state = gfx.Save(); gfx.TranslateTransform(_location.X, _location.Y); // Calculate rectangle for all charts. Y-Position will be moved for each chart. int charts = _chartList.Count; const uint dxChart = 20; const uint dyChart = 20; const uint dyBetweenCharts = 30; XRect rect = new XRect(dxChart, dyChart, _size.Width - 2 * dxChart, (_size.Height - (charts - 1) * dyBetweenCharts - 2 * dyChart) / charts); // draw each chart in list foreach (Chart chart in _chartList) { RendererParameters parms = new RendererParameters(gfx, rect); parms.DrawingItem = chart; ChartRenderer renderer = GetChartRenderer(chart, parms); renderer.Init(); renderer.Format(); renderer.Draw(); rect.Y += rect.Height + dyBetweenCharts; } gfx.Restore(state); // // Calculate rectangle for all charts. Y-Position will be moved for each chart. // int charts = chartList.Count; // uint dxChart = 0; // uint dyChart = 0; // uint dyBetweenCharts = 0; // XRect rect = new XRect(dxChart, dyChart, // size.Width - 2 * dxChart, // (size.Height - (charts - 1) * dyBetweenCharts - 2 * dyChart) / charts); // // // draw each chart in list // foreach (Chart chart in chartList) // { // RendererParameters parms = new RendererParameters(gfx, rect); // parms.DrawingItem = chart; // // ChartRenderer renderer = GetChartRenderer(chart, parms); // renderer.Init(); // renderer.Format(); // renderer.Draw(); // // rect.Y += rect.Height + dyBetweenCharts; // } }
/// <summary> /// Draws the axis title. /// </summary> internal override void Draw() { AxisRendererInfo ari = (AxisRendererInfo)_rendererParms.RendererInfo; AxisTitleRendererInfo atri = ari._axisTitleRendererInfo; if (atri.AxisTitleText != "") { XGraphics gfx = _rendererParms.Graphics; if (atri.AxisTitleOrientation != 0) { XRect layout = atri.Rect; layout.X = -(layout.Width / 2); layout.Y = -(layout.Height / 2); double x = 0; switch (atri.AxisTitleAlignment) { case HorizontalAlignment.Center: x = atri.X + atri.Width / 2; break; case HorizontalAlignment.Right: x = atri.X + atri.Width - layout.Width / 2; break; case HorizontalAlignment.Left: default: x = atri.X; break; } double y = 0; switch (atri.AxisTitleVerticalAlignment) { case VerticalAlignment.Center: y = atri.Y + atri.Height / 2; break; case VerticalAlignment.Bottom: y = atri.Y + atri.Height - layout.Height / 2; break; case VerticalAlignment.Top: default: y = atri.Y; break; } XStringFormat xsf = new XStringFormat { Alignment = XStringAlignment.Center, LineAlignment = XLineAlignment.Center }; XGraphicsState state = gfx.Save(); gfx.TranslateTransform(x, y); gfx.RotateTransform(-atri.AxisTitleOrientation); gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, layout, xsf); gfx.Restore(state); } else { XStringFormat format = new XStringFormat(); switch (atri.AxisTitleAlignment) { case HorizontalAlignment.Center: format.Alignment = XStringAlignment.Center; break; case HorizontalAlignment.Right: format.Alignment = XStringAlignment.Far; break; case HorizontalAlignment.Left: default: format.Alignment = XStringAlignment.Near; break; } switch (atri.AxisTitleVerticalAlignment) { case VerticalAlignment.Center: format.LineAlignment = XLineAlignment.Center; break; case VerticalAlignment.Bottom: format.LineAlignment = XLineAlignment.Far; break; case VerticalAlignment.Top: default: format.LineAlignment = XLineAlignment.Near; break; } gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, atri.Rect, format); } } }
/// <summary> /// /// </summary> /// <param name="gfx"></param> public void EndBox(XGraphics gfx) { if (gfx != null) gfx.Restore(this._state); }
///<summary>The only instance of this command.</summary> ///<param name="doc" RhinoDoc></param> ///<param name="mode" Run mode></param> ///<returns>returns sucess if doc is successfully created </returns> protected override Result RunCommand(RhinoDoc doc, RunMode mode) { #region set all the file parameters pdfOptionForm = new PDFOptionForm(); Application.Run(pdfOptionForm); getSelectedOption = PDFOptionForm.optionsSelected; myUniqueFileName = string.Format(@"{0}" + ext, Guid.NewGuid()); string logFilePath = Rhino.ApplicationSettings.FileSettings.WorkingFolder + "\\Log-" + DateTime.Now.GetHashCode().ToString() + ".txt"; string curveType = "C"; try { string[] checkFileName = Rhino.ApplicationSettings.FileSettings.RecentlyOpenedFiles()[0].ToString().Split('\\'); int checklength = checkFileName.Length; rhinoFile = Rhino.ApplicationSettings.FileSettings.RecentlyOpenedFiles()[0].ToString().Split('\\')[--checklength]; } catch (FileNotFoundException fnf) { logFile(fnf.Message); } catch (IndexOutOfRangeException ioor) { logFile(ioor.Message); } string rhinoFileName = rhinoFile.Split('.')[0]; string filename = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + rhinoFileName + "-" + myUniqueFileName; #endregion Rhino.RhinoApp.RunScript("-_Save Enter", false); logFile("Process started for ---> " + rhinoFileName + "-" + myUniqueFileName); PdfDocument document = new PdfDocument(); PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XFont font = new XFont("Verdana", 20, XFontStyle.Bold); #region Check the selected curve GetObject go = new GetObject(); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.EnableSelPrevious(true); go.EnablePreSelect(true, false); go.GeometryFilter = ObjectType.AnyObject; GetResult result = go.GetMultiple(1, -1); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } RhinoApp.WriteLine("{0} objects are selected.", go.ObjectCount); #endregion // Process the list of objects logFile("Processing List of Object"); #region set the paramenters for Xgraph to process shapes List <GeometryBase> geoList = new List <GeometryBase>(); double minX, minY, maxX, maxY; minX = double.MaxValue; minY = double.MaxValue; maxX = double.MinValue; maxY = double.MinValue; List <Curve> curveList = new List <Curve>(); List <TextEntity> textEntityList = new List <TextEntity>(); List <Circle> circleList = new List <Circle>(); List <Polyline> polyList = new List <Polyline>(); Circle circleCurve; Polyline polygon; #endregion for (int i = 0; i < go.ObjectCount; i++) { // Check the type of the Object and process differently Curve curve = go.Object(i).Curve(); if (go.Object(i).Curve().TryGetCircle(out circleCurve)) { circleList.Add(circleCurve); } if (go.Object(i).Curve().TryGetPolyline(out polygon)) { polyList.Add(polygon); } if (curve != null) { curveList.Add(curve); } TextEntity te = go.Object(i).TextEntity(); if (te != null) { textEntityList.Add(te); } GeometryBase geo = go.Object(i).Geometry(); BoundingBox bbox = geo.GetBoundingBox(Rhino.Geometry.Plane.WorldXY); if (bbox.Min.X < minX) { minX = bbox.Min.X; } if (bbox.Min.Y < minY) { minY = bbox.Min.Y; } if (bbox.Max.X > maxX) { maxX = bbox.Max.X; } if (bbox.Max.Y > maxY) { maxY = bbox.Max.Y; } geoList.Add(geo); } page.Height = maxY - minY; page.Width = maxX - minX; foreach (GeometryBase g in geoList) { if (g.GetType().Equals(typeof(PolyCurve))) { //System.Windows.Forms.MessageBox.Show("PolyCurve changed"); PolyCurve polyCurve = (PolyCurve)g; curveType = "NC"; break; } else if (g.GetType().Equals(typeof(Curve))) { System.Windows.Forms.MessageBox.Show("Curve"); Curve curve = (Curve)g; } else if (g.GetType().Equals(typeof(TextEntity))) { System.Windows.Forms.MessageBox.Show("TextEntity"); TextEntity textEntity = (TextEntity)g; curveType = "T"; } } logFile("Checking the pattern"); if (curveType.Equals("C") || curveType.Equals("T")) { logFile("Objects processed sucessfully"); double x1, y1, width, height; logFile("Creating Circles on the PDF"); //Loop to draw the circles foreach (Circle c in circleList) { XPen pen = new XPen(XColors.Black, 0.5); x1 = c.BoundingBox.Min.X - minX; y1 = maxY - c.BoundingBox.Max.Y; width = c.BoundingBox.Max.X - c.BoundingBox.Min.X; height = c.BoundingBox.Max.Y - c.BoundingBox.Min.Y; gfx.DrawEllipse(XBrushes.Black, x1, y1, width, height); } //Loop used to draw rectangles foreach (Polyline p in polyList) { XPen pen = new XPen(XColors.Black, 0.5); x1 = p.BoundingBox.Min.X - minX; y1 = maxY - p.BoundingBox.Max.Y; width = p.BoundingBox.Max.X - p.BoundingBox.Min.X; height = p.BoundingBox.Max.Y - p.BoundingBox.Min.Y; XPoint p1 = new XPoint(x1, y1); XPoint p2 = new XPoint(x1 + width, y1); XPoint p3 = new XPoint(x1, y1 + height); XPoint p4 = new XPoint(x1 + width, y1 + height); XRect rect = new XRect(x1, y1, width, height); XPoint[] xPoint = new XPoint[] { p1, p2, p4, p3 }; //XPoint mid = new XPoint( (x1 + x1)/2); XGraphicsState gs = gfx.Save(); gfx.RotateAtTransform(-45, p1); gfx.DrawPolygon(pen, XBrushes.Black, xPoint, XFillMode.Alternate); gfx.Restore(gs); } #region Print the PDF as per the option selected if (getSelectedOption.Equals('N')) { logFile("Normal PDF feature was selected"); document.Save(filename); logFile("Document saved successfully - " + Rhino.ApplicationSettings.FileSettings.WorkingFolder); } if (getSelectedOption.Equals('C')) { logFile("Compressed PDF feature was selected"); CompressMyPdf(document); string compressedFileName = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + "C-" + rhinoFileName + "-" + myUniqueFileName; document.Save(compressedFileName); } if (getSelectedOption.Equals('E')) { logFile("Encrypted PDF feature was selected"); EncryptMyPdf(document); string encryptPdf = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + "E-" + rhinoFileName + "-" + myUniqueFileName; document.Save(encryptPdf); } if (getSelectedOption.Equals('P')) { logFile("Password Protection PDF feature was selected"); PasswordProtectMyPdf(document); string passwordProtectPdf = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + "PP-" + rhinoFileName + "-" + myUniqueFileName; document.Save(passwordProtectPdf); } #endregion logFile("Document saved successfully - " + Rhino.ApplicationSettings.FileSettings.WorkingFolder); logFile("Panel perforated successfully. Check File --> " + rhinoFileName + "-" + myUniqueFileName); System.Windows.Forms.MessageBox.Show(" <----SUCCESS----> " + Environment.NewLine + Environment.NewLine + " Pannels perforated Successfully. "); } else { System.Windows.Forms.MessageBox.Show(" ERROR! " + Environment.NewLine + Environment.NewLine + "The curve you have selected contains some invalid shape." + Environment.NewLine + " Please select the appropriate patterns. "); logFile("Please select the appropriate pattern"); } logFile("----------------- WAITING FOR THE NEXT PANEL PERFORATION ---------------------"); return(Result.Success); }
/// <summary> /// Draws the horizontal X axis. /// </summary> internal override void Draw() { XGraphics gfx = this.rendererParms.Graphics; ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo; AxisRendererInfo xari = cri.xAxisRendererInfo; double xMin = xari.MinimumScale; double xMax = xari.MaximumScale; double xMajorTick = xari.MajorTick; double xMinorTick = xari.MinorTick; double xMaxExtension = xari.MajorTick; // Draw tick labels. Each tick label will be aligned centered. int countTickLabels = (int)xMax; double tickLabelStep = xari.Width; if (countTickLabels != 0) { tickLabelStep = xari.Width / countTickLabels; } //XPoint startPos = new XPoint(xari.X + tickLabelStep / 2, xari.Y + /*xari.TickLabelsHeight +*/ xari.MajorTickMarkWidth); XPoint startPos = new XPoint(xari.X + tickLabelStep / 2, xari.Y + xari.TickLabelsHeight); if (xari.MajorTickMark != TickMarkType.None) { startPos.Y += xari.MajorTickMarkWidth; } foreach (XSeries xs in xari.XValues) { for (int idx = 0; idx < countTickLabels && idx < xs.Count; ++idx) { XValue xv = xs[idx]; if (xv != null) { string tickLabel = xv.Value; XSize size = gfx.MeasureString(tickLabel, xari.TickLabelsFont); XGraphicsState state = null; int margin = 0; if (xs.TextRotation != default) { state = gfx.Save(); margin = 20; gfx.RotateAtTransform(xs.TextRotation, new XPoint(startPos.X - size.Width / 2, startPos.Y + margin)); } gfx.DrawString(tickLabel, xari.TickLabelsFont, xari.TickLabelsBrush, startPos.X - size.Width / 2, startPos.Y + margin); if (xs.TextRotation != default && state != null) { gfx.Restore(state); } } startPos.X += tickLabelStep; } } // Draw axis. // First draw tick marks, second draw axis. double majorTickMarkStart = 0, majorTickMarkEnd = 0, minorTickMarkStart = 0, minorTickMarkEnd = 0; GetTickMarkPos(xari, ref majorTickMarkStart, ref majorTickMarkEnd, ref minorTickMarkStart, ref minorTickMarkEnd); LineFormatRenderer lineFormatRenderer = new LineFormatRenderer(gfx, xari.LineFormat); XPoint[] points = new XPoint[2]; // Minor ticks. if (xari.MinorTickMark != TickMarkType.None) { int countMinorTickMarks = (int)(xMax / xMinorTick); double minorTickMarkStep = xari.Width / countMinorTickMarks; startPos.X = xari.X; for (int x = 0; x <= countMinorTickMarks; x++) { points[0].X = startPos.X + minorTickMarkStep * x; points[0].Y = minorTickMarkStart; points[1].X = points[0].X; points[1].Y = minorTickMarkEnd; lineFormatRenderer.DrawLine(points[0], points[1]); } } // Major ticks. if (xari.MajorTickMark != TickMarkType.None) { int countMajorTickMarks = (int)(xMax / xMajorTick); double majorTickMarkStep = xari.Width; if (countMajorTickMarks != 0) { majorTickMarkStep = xari.Width / countMajorTickMarks; } startPos.X = xari.X; for (int x = 0; x <= countMajorTickMarks; x++) { points[0].X = startPos.X + majorTickMarkStep * x; points[0].Y = majorTickMarkStart; points[1].X = points[0].X; points[1].Y = majorTickMarkEnd; lineFormatRenderer.DrawLine(points[0], points[1]); } } // Axis. if (xari.LineFormat != null) { points[0].X = xari.X; points[0].Y = xari.Y; points[1].X = xari.X + xari.Width; points[1].Y = xari.Y; if (xari.MajorTickMark != TickMarkType.None) { points[0].X -= xari.LineFormat.Width / 2; points[1].X += xari.LineFormat.Width / 2; } lineFormatRenderer.DrawLine(points[0], points[1]); } // Draw axis title. AxisTitleRendererInfo atri = xari.axisTitleRendererInfo; if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0) { XRect rect = new XRect(xari.Rect.Right / 2 - atri.AxisTitleSize.Width / 2, xari.Rect.Bottom, atri.AxisTitleSize.Width, 0); gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, rect); } }
/// <summary> /// restore the state /// </summary> public override void RestoreState() { base.RestoreState(); FXGraphics.Restore(FGraphicsStateStack.Pop()); }
public bool generatePdf() { if (!File.Exists(scaleNamesPath)) { MessageBox.Show(scaleNamesPath + " is not a valid scale names file"); return(false); } string[] scaleNames = File.ReadAllLines(scaleNamesPath); PdfDocument pdf = new PdfDocument(); pdf.Info.Title = "My First PDF"; XFont font = new XFont("Microsoft Sans Serif", 12, XFontStyle.Regular); // Set all the page sizes and orientation PdfPage basicPage = pdf.AddPage(); basicPage.Orientation = PageOrientation.Landscape; basicPage.Width = XUnit.FromInch(11); basicPage.Height = XUnit.FromInch(8.5); XGraphics graphBasic = XGraphics.FromPdfPage(basicPage); PdfPage page2 = pdf.AddPage(); page2.Orientation = PageOrientation.Landscape; page2.Width = XUnit.FromInch(11); page2.Height = XUnit.FromInch(8.5); XGraphics graph2 = XGraphics.FromPdfPage(page2); PdfPage page3 = pdf.AddPage(); page3.Orientation = PageOrientation.Landscape; page3.Width = XUnit.FromInch(11); page3.Height = XUnit.FromInch(8.5); XGraphics graph3 = XGraphics.FromPdfPage(page3); PdfPage page4 = pdf.AddPage(); page4.Orientation = PageOrientation.Landscape; page4.Width = XUnit.FromInch(11); page4.Height = XUnit.FromInch(8.5); XGraphics graph4 = XGraphics.FromPdfPage(page4); PdfPage page5 = pdf.AddPage(); page5.Orientation = PageOrientation.Landscape; page5.Width = XUnit.FromInch(11); page5.Height = XUnit.FromInch(8.5); XGraphics gfx = XGraphics.FromPdfPage(page5); XGraphicsState gs = gfx.Save(); gfx.TranslateTransform(600, 750); gfx.RotateTransform(-90); gfx.TranslateTransform(-600, -750); XTextFormatter tf = new XTextFormatter(gfx); tf.DrawString(critOutputPrimary, font, XBrushes.Black, new XRect(800, 200, 500, 500), XStringFormats.TopLeft); gfx.Restore(gs); // If the person has too many entries on the crit items page // It overflows here to another page if (critOutputSecondary != "") { PdfPage page6 = pdf.AddPage(); page6.Orientation = PageOrientation.Landscape; page6.Width = XUnit.FromInch(11); page6.Height = XUnit.FromInch(8.5); XGraphics gfx2 = XGraphics.FromPdfPage(page6); XGraphicsState gs2 = gfx2.Save(); gfx2.TranslateTransform(600, 750); //gfx.ScaleTransform(0.6); gfx2.RotateTransform(-90); gfx2.TranslateTransform(-600, -750); XTextFormatter tf2 = new XTextFormatter(gfx2); tf2.DrawString(critOutputSecondary, font, XBrushes.Black, new XRect(800, 200, 500, 500), XStringFormats.TopLeft); //gfx.RotateTransform(-90); gfx2.Restore(gs2); } string[] userInfo = { "Name: " + testTaker.lastName + ", " + testTaker.firstName, "Gender: " + gender + " Address:______________________________", "Occupation:____________________ Date Tested: " + testTaker.date, "Education:_______ Age: " + testTaker.age + " Marital Status:________________", "Referred By:_________________________________________", "MMPI Code:_________________________________________" }; for (int i = 0; i < 6; i++) { graphBasic.DrawString(userInfo[i], font, XBrushes.Black, new XRect(430, (i * 15) + 15, 0, 0), XStringFormats.TopLeft); } // Logo in upper left graphBasic.DrawImage(XImage.FromFile(baseFolder + "logo.jpg"), new XRect(40, 15, 250, 110)); // Draw the charts onto the pdf try { graphBasic.DrawImage(XImage.FromFile(indivBasePath + "\\" + testTaker.lastName + testTaker.firstName + "1.png"), new XRect(30, 120, 760, 450)); graph2.DrawImage(XImage.FromFile(indivBasePath + "\\" + testTaker.lastName + testTaker.firstName + "2.png"), new XRect(-25, 0, 830, 615)); graph3.DrawImage(XImage.FromFile(indivBasePath + "\\" + testTaker.lastName + testTaker.firstName + "3.png"), new XRect(-25, 0, 830, 615)); graph4.DrawImage(XImage.FromFile(indivBasePath + "\\" + testTaker.lastName + testTaker.firstName + "4.png"), new XRect(-25, 0, 830, 615)); } catch (Exception) { MessageBox.Show("PDF Failed: Image in use - Try restarting the program"); return(false); } if (barLabel.Checked) { graph2.RotateAtTransform(-90, new XPoint(430, 430)); graph3.RotateAtTransform(-90, new XPoint(430, 430)); graph4.RotateAtTransform(-90, new XPoint(430, 430)); for (int i = 0; i < 26; i++) { graph2.DrawString(scaleNames[i], font, XBrushes.White, new XRect(330, (i * 28.66) + 41, 0, 0), XStringFormats.TopLeft); graph3.DrawString(scaleNames[i + 26], font, XBrushes.White, new XRect(328, (i * 28.66) + 41, 0, 0), XStringFormats.TopLeft); } for (int i = 0; i < 22; i++) { graph4.DrawString(scaleNames[i + 52], font, XBrushes.White, new XRect(328, (i * 33.96) + 43, 0, 0), XStringFormats.TopLeft); } } string pdfFilename = indivBasePath + testTaker.lastName + testTaker.firstName + ".pdf"; pdf.Save(pdfFilename); if (File.Exists(pdfFilename)) { MessageBox.Show("PDF Success at " + pdfFilename); } else { MessageBox.Show("PDF Failed at " + pdfFilename); return(false); } return(true); }
/// <summary> /// Renders the OMR code. /// </summary> protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, 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 pt = center - size / 2; XPoint pt = position - CodeBase.CalcDistance(AnchorType.TopLeft, Anchor, Size); uint value; uint.TryParse(Text, out value); #if true // HACK: Project Wallenwein: set LK value |= 1; _synchronizeCode = true; #endif if (_synchronizeCode) { XRect rect = new XRect(pt.X, pt.Y, _makerThickness, Size.Height); gfx.DrawRectangle(brush, rect); pt.X += 2 * _makerDistance; } for (int idx = 0; idx < 32; idx++) { if ((value & 1) == 1) { XRect rect = new XRect(pt.X + idx * _makerDistance, pt.Y, _makerThickness, Size.Height); gfx.DrawRectangle(brush, rect); } value = value >> 1; } gfx.Restore(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) { bool isxy = false; int count = sri.series.Elements.Count; XPoint[] points = new XPoint[count]; double v; PointX px = sri.series.Elements.getPointX(0); if (px != null) { isxy = true; for (int idx = 0; idx < count; idx++) { px = sri.series.Elements.getPointX(idx); if (double.IsNaN(px.yvalue)) { v = 0; } else { v = px.yvalue; } points[idx] = new XPoint(px.xvalue, v); } } if (!isxy) { for (int idx = 0; idx < count; idx++) { 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 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); #if true // 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); #endif }
/// <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); // thickness 1.001 (or any not natural number) is for drawing smoothing lines // in SmoothingMode.AntiAlias Graphics mode if you don't use RenderLinesByPolygons pen = new XPen(XColors.DarkGreen, 1.001); for (int idx = 0; idx < 360; idx += 10) { gfx.RotateTransform(10); gfx.DrawLine(pen//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("AltData/PDFsharp/PDFs/SomeLayout.pdf"), rcImage); gfx.Restore(state); }
static void Main() { // 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, XPageDirection.Downwards); gfx.DrawString("XPdfForm Sample", font, XBrushes.DarkGray, 15, 25, XStringFormats.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(document, 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, 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 * 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 const 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... const string filename = "XForms_tempfile.pdf"; document.Save(filename); // ...and start a viewer. Process.Start(filename); }
private void EndBox(XGraphics gfx) { gfx.Restore(state); }
public void EndBox(XGraphics gfx) { gfx.Restore(_state); }
// draws a single Paper Wallet in to a PdfSharp XForm private PdfSharp.Drawing.XForm getSingleWallet(PdfDocument doc, WalletBundle b, XImage imgArtwork, string address, string privkey, int numberWithinBatch, bool layoutDebugging) { WalletTemplate t = b.template; double width = t.widthMM; double height = t.heightMM; XUnit walletSizeWide = XUnit.FromMillimeter(width); XUnit walletSizeHigh = XUnit.FromMillimeter(height); PdfSharp.Drawing.XForm form = new PdfSharp.Drawing.XForm(doc, walletSizeWide, walletSizeHigh); using (XGraphics formGfx = XGraphics.FromForm(form)) { XGraphicsState state = formGfx.Save(); bool interpolateArtwork = true; bool interpolateQRcodes = false; // XImage imgArtwork is now provided by caller, so this process only has to be done ONCE - because the artwork does not change between Wallets in a run! //XImage imgArtwork = XImage.FromGdiPlusImage(b.getArtworkImage()); imgArtwork.Interpolate = interpolateArtwork; formGfx.DrawImage(imgArtwork, new RectangleF(0f, 0f, (float)walletSizeWide.Point, (float)walletSizeHigh.Point)); // draw the QR codes and legible-text things // Address // QR Bitmap bmpAddress = BtcAddress.QR.EncodeQRCode(address); XImage imgAddress = XImage.FromGdiPlusImage(bmpAddress); imgAddress.Interpolate = interpolateQRcodes; XUnit addressQrLeft = XUnit.FromMillimeter(t.addressQrLeftMM); XUnit addressQrTop = XUnit.FromMillimeter(t.addressQrTopMM); XUnit addressQrSize = XUnit.FromMillimeter(t.addressQrSizeMM); // only print Address QR if called for if (t.addressQrSizeMM > 0.1) { XRect addressQrRect = new XRect(addressQrLeft.Point, addressQrTop.Point, addressQrSize.Point, addressQrSize.Point); formGfx.DrawImage(imgAddress, addressQrRect); } // text address string addressSplitForLines = addressOrReferencePrep(address, t.addressTextCharsPerLine, t.addressTextContentVariant, numberWithinBatch); XFont fontAddress = new XFont(t.addressTextFontName, t.addressTextFontSize, t.addressTextFontStyle); XTextFormatter tf = new XTextFormatter(formGfx); XUnit addressTxtLeft = XUnit.FromMillimeter(t.addressTextLeftMM); XUnit addressTxtTop = XUnit.FromMillimeter(t.addressTextTopMM); XUnit addressTxtWidth = XUnit.FromMillimeter(t.addressTextWidthMM); XUnit addressTxtHeight = XUnit.FromMillimeter(t.addressTextHeightMM); XRect addressRect = new XRect(addressTxtLeft.Point, addressTxtTop.Point, addressTxtWidth.Point, addressTxtHeight.Point); tf.Alignment = XParagraphAlignment.Center; TextRotation addressTxtRotation = t.addressTextRotation; double addressTxtRotationDegrees = RotationMarkerToDegrees(addressTxtRotation); if (layoutDebugging) { formGfx.DrawRectangle(XBrushes.PowderBlue, addressRect); } XPoint rotateCentre = new XPoint(addressTxtLeft + (addressTxtWidth / 2), addressTxtTop + (addressTxtHeight / 2)); XPoint matrixRotatePoint = new XPoint(addressRect.X + (addressRect.Width / 2), addressRect.Y + (addressRect.Height / 2)); XMatrix rotateMatrix = new XMatrix(); rotateMatrix.RotateAtAppend(addressTxtRotationDegrees, rotateCentre); addressRect.Transform(rotateMatrix); if (layoutDebugging) { // draw a little tracer dot for where the centre of rotation is going to be double rotateDotSize = 2.0; formGfx.DrawEllipse(XBrushes.Red, rotateCentre.X - (rotateDotSize / 2), rotateCentre.Y - (rotateDotSize / 2), rotateDotSize, rotateDotSize); } // maybe even do some rotation of the lovely text! formGfx.Save(); formGfx.RotateAtTransform(addressTxtRotationDegrees, rotateCentre); if (layoutDebugging) { formGfx.DrawRectangle(XPens.OrangeRed, addressRect); } if (t.addressTextWidthMM > 0.1) { tf.DrawString(addressSplitForLines, fontAddress, t.GetBrushAddress, addressRect); } formGfx.Restore(); // Privkey // QR Bitmap bmpPrivkey = BtcAddress.QR.EncodeQRCode(privkey); XImage imgPrivkey = XImage.FromGdiPlusImage(bmpPrivkey); imgPrivkey.Interpolate = interpolateQRcodes; XUnit privkeyQrLeft = XUnit.FromMillimeter(t.privkeyQrLeftMM); XUnit privkeyQrTop = XUnit.FromMillimeter(t.privkeyQrTopMM); XUnit privkeyQrSize = XUnit.FromMillimeter(t.privkeyQrSizeMM); XRect privkeyQrRect = new XRect(privkeyQrLeft.Point, privkeyQrTop.Point, privkeyQrSize.Point, privkeyQrSize.Point); // only print privkey QR if specified - but you'd have to be an UTTER IDIOT to want to exclude this. Still, user input comes first! if (t.privkeyQrSizeMM > 0.1) { formGfx.DrawImage(imgPrivkey, privkeyQrRect); } // legible string privkeySplitForLines = lineSplitter(privkey, t.privkeyTextCharsPerLine); XFont fontPrivkey = new XFont(t.privkeyTextFontName, t.privkeyTextFontSize, t.privkeyTextFontStyle); XUnit privkeyTxtLeft = XUnit.FromMillimeter(t.privkeyTextLeftMM); XUnit privkeyTxtTop = XUnit.FromMillimeter(t.privkeyTextTopMM); XUnit privkeyTxtWidth = XUnit.FromMillimeter(t.privkeyTextWidthMM); XUnit privkeyTxtHeight = XUnit.FromMillimeter(t.privkeyTextHeightMM); TextRotation privkeyTxtRotation = t.privkeyTextRotation; double privkeyTxtRotationDegrees = RotationMarkerToDegrees(privkeyTxtRotation); XRect privkeyRect = new XRect(privkeyTxtLeft.Point, privkeyTxtTop.Point, privkeyTxtWidth.Point, privkeyTxtHeight.Point); if (layoutDebugging) { // draw a tracer rectangle for the original un-rotated text rectangle formGfx.DrawRectangle(XBrushes.PowderBlue, privkeyRect); } // rotate that lovely text around its middle when drawing! rotateCentre = new XPoint(privkeyTxtLeft + (privkeyTxtWidth / 2), privkeyTxtTop + (privkeyTxtHeight / 2)); matrixRotatePoint = new XPoint(privkeyRect.X + (privkeyRect.Width / 2), privkeyRect.Y + (privkeyRect.Height / 2)); rotateMatrix = new XMatrix(); rotateMatrix.RotateAtAppend(privkeyTxtRotationDegrees, rotateCentre); privkeyRect.Transform(rotateMatrix); if (layoutDebugging) { // draw a little tracer dot for where the centre of rotation is going to be double rotateDotSize = 2.0; formGfx.DrawEllipse(XBrushes.Red, rotateCentre.X - (rotateDotSize / 2), rotateCentre.Y - (rotateDotSize / 2), rotateDotSize, rotateDotSize); } formGfx.Save(); formGfx.RotateAtTransform(privkeyTxtRotationDegrees, rotateCentre); if (layoutDebugging) { formGfx.DrawRectangle(XPens.OrangeRed, privkeyRect); } // only print privkey text if specified. if (t.privkeyTextWidthMM > 0.1) { tf.DrawString(privkeySplitForLines, fontPrivkey, t.GetBrushPrivkey, privkeyRect); } formGfx.Restore(); } return(form); }
/// <summary> /// Creates the normal appearance form X object for the annotation that represents /// this acro form text field. /// </summary> void RenderAppearance() { #if true_ PdfFormXObject xobj = new PdfFormXObject(Owner); Owner.Internals.AddObject(xobj); xobj.Elements["/BBox"] = new PdfLiteral("[0 0 122.653 12.707]"); xobj.Elements["/FormType"] = new PdfLiteral("1"); xobj.Elements["/Matrix"] = new PdfLiteral("[1 0 0 1 0 0]"); PdfDictionary res = new PdfDictionary(Owner); xobj.Elements["/Resources"] = res; res.Elements["/Font"] = new PdfLiteral("<< /Helv 28 0 R >> /ProcSet [/PDF /Text]"); xobj.Elements["/Subtype"] = new PdfLiteral("/Form"); xobj.Elements["/Type"] = new PdfLiteral("/XObject"); string s = "/Tx BMC " + '\n' + "q" + '\n' + "1 1 120.653 10.707 re" + '\n' + "W" + '\n' + "n" + '\n' + "BT" + '\n' + "/Helv 7.93 Tf" + '\n' + "0 g" + '\n' + "2 3.412 Td" + '\n' + "(Hello ) Tj" + '\n' + "20.256 0 Td" + '\n' + "(XXX) Tj" + '\n' + "ET" + '\n' + "Q" + '\n' + "";//"EMC"; int length = s.Length; byte[] stream = new byte[length]; for (int idx = 0; idx < length; idx++) { stream[idx] = (byte)s[idx]; } xobj.CreateStream(stream); // Get existing or create new appearance dictionary PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary; if (ap == null) { ap = new PdfDictionary(_document); Elements[PdfAnnotation.Keys.AP] = ap; } // Set XRef to normal state ap.Elements["/N"] = xobj.Reference; //// HACK //string m = //"<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>" + '\n' + //"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 4.0-c321 44.398116, Tue Aug 04 2009 14:24:39\"> " + '\n' + //" <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"> " + '\n' + //" <rdf:Description rdf:about=\"\" " + '\n' + //" xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\"> " + '\n' + //" <pdf:Producer>PDFsharp 1.40.2150-g (www.pdfsharp.com) (Original: Powered By Crystal)</pdf:Producer> " + '\n' + //" </rdf:Description> " + '\n' + //" <rdf:Description rdf:about=\"\" " + '\n' + //" xmlns:xap=\"http://ns.adobe.com/xap/1.0/\"> " + '\n' + //" <xap:ModifyDate>2011-07-11T23:15:09+02:00</xap:ModifyDate> " + '\n' + //" <xap:CreateDate>2011-05-19T16:26:51+03:00</xap:CreateDate> " + '\n' + //" <xap:MetadataDate>2011-07-11T23:15:09+02:00</xap:MetadataDate> " + '\n' + //" <xap:CreatorTool>Crystal Reports</xap:CreatorTool> " + '\n' + //" </rdf:Description> " + '\n' + //" <rdf:Description rdf:about=\"\" " + '\n' + //" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"> " + '\n' + //" <dc:format>application/pdf</dc:format> " + '\n' + //" </rdf:Description> " + '\n' + //" <rdf:Description rdf:about=\"\" " + '\n' + //" xmlns:xapMM=\"http://ns.adobe.com/xap/1.0/mm/\"> " + '\n' + //" <xapMM:DocumentID>uuid:68249d89-baed-4384-9a2d-fbf8ace75c45</xapMM:DocumentID> " + '\n' + //" <xapMM:InstanceID>uuid:3d5f2f46-c140-416f-baf2-7f9c970cef1d</xapMM:InstanceID> " + '\n' + //" </rdf:Description> " + '\n' + //" </rdf:RDF> " + '\n' + //"</x:xmpmeta> " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //" " + '\n' + //"<?xpacket end=\"w\"?>"; //PdfDictionary mdict = (PdfDictionary)_document.Internals.GetObject(new PdfObjectID(32)); //length = m.Length; //stream = new byte[length]; //for (int idx = 0; idx < length; idx++) // stream[idx] = (byte)m[idx]; //mdict.Stream.Value = stream; #else PdfRectangle rect = Elements.GetRectangle(PdfAnnotation.Keys.Rect); XForm form = new XForm(_document, rect.Size); XGraphics gfx = XGraphics.FromForm(form); if (BackColor != XColor.Empty) { gfx.DrawRectangle(new XSolidBrush(BackColor), rect.ToXRect() - rect.Location); } // Draw Border if (!BorderColor.IsEmpty) { gfx.DrawRectangle(new XPen(BorderColor), rect.ToXRect() - rect.Location); } string text = Text; if (text.Length > 0) { var xRect = rect.ToXRect(); if ((Flags & PdfAcroFieldFlags.Comb) != 0 && MaxLength > 0) { var combWidth = xRect.Width / MaxLength; var format = XStringFormats.TopLeft; format.Comb = true; format.CombWidth = combWidth; gfx.Save(); gfx.IntersectClip(xRect); gfx.DrawString(text, Font, new XSolidBrush(ForeColor), xRect + new XPoint(0, 1.5), format); gfx.Restore(); } else { gfx.DrawString(Text, Font, new XSolidBrush(ForeColor), rect.ToXRect() - rect.Location + new XPoint(2, 0), XStringFormats.TopLeft); } } form.DrawingFinished(); form.PdfForm.Elements.Add("/FormType", new PdfLiteral("1")); // Get existing or create new appearance dictionary. PdfDictionary ap = Elements[PdfAnnotation.Keys.AP] as PdfDictionary; if (ap == null) { ap = new PdfDictionary(_document); Elements[PdfAnnotation.Keys.AP] = ap; } // Set XRef to normal state ap.Elements["/N"] = form.PdfForm.Reference; PdfFormXObject xobj = form.PdfForm; if (xobj.Stream == null) { xobj.CreateStream(new byte[] { }); } string s = xobj.Stream.ToString(); // Thank you Adobe: Without putting the content in 'EMC brackets' // the text is not rendered by PDF Reader 9 or higher. s = "/Tx BMC\n" + s + "\nEMC"; xobj.Stream.Value = new RawEncoding().GetBytes(s); #endif }
private static void DrawLayers(XGraphics gfx, IatRunConfiguration config, ComponentLayer componentLayer, double scaleFactor, IPcbLayer overlayLayer, IPcbLayer pasteLayer, IPcbLayer mechanicalLayer, double maxExtensionX, double maxExtensionY, Dictionary <string, List <Component> > componentGroup, List <XColor> colorsFromConfiguration) { var state = gfx.Save(); if (componentLayer == ComponentLayer.Top) { gfx.ScaleTransform(1, -1); gfx.TranslateTransform(1, -maxExtensionY); gfx.TranslateTransform(gfx.PdfPage.Width * 0.05, -gfx.PdfPage.Height * 0.05); gfx.TranslateTransform(1, -maxExtensionY * scaleFactor + maxExtensionY); gfx.ScaleTransform(scaleFactor); } else { gfx.ScaleTransform(-1, -1); gfx.TranslateTransform(-maxExtensionX, -maxExtensionY); gfx.TranslateTransform(-gfx.PdfPage.Width * 0.05, -gfx.PdfPage.Height * 0.05); gfx.TranslateTransform(-maxExtensionX * scaleFactor + maxExtensionX, -maxExtensionY * scaleFactor + maxExtensionY); gfx.ScaleTransform(scaleFactor); } XPen xpenPasteLayer = new XPen(XColors.Gray) { Width = 0.1, LineCap = XLineCap.Round, LineJoin = XLineJoin.Round }; foreach (PcbShape s in pasteLayer.PcbShapes) { DrawElement(gfx, s, xpenPasteLayer); } XPen xpenOverlayLayer = new XPen(XColors.Black) { Width = 0.1, LineCap = XLineCap.Round, LineJoin = XLineJoin.Round }; foreach (PcbShape s in overlayLayer.PcbShapes) { DrawElement(gfx, s, xpenOverlayLayer); } XPen xpenMechanicalOutlineLayer = new XPen(XColors.DarkRed) { Width = 0.1, LineCap = XLineCap.Round, LineJoin = XLineJoin.Round }; foreach (PcbShape s in mechanicalLayer.PcbShapes) { DrawElement(gfx, s, xpenMechanicalOutlineLayer); } int nrLines = config.OutputSettings.ComponentColors.Count; for (int lineIndex = 0; lineIndex < Math.Min(nrLines, componentGroup.Count); lineIndex++) { XPen xpenComponent = new XPen(colorsFromConfiguration[lineIndex]) { Width = 0.1, LineCap = XLineCap.Round, LineJoin = XLineJoin.Round }; XBrush xb = new XSolidBrush(colorsFromConfiguration[lineIndex]); double width = 0.5; double dotScaleFactor = (double)config.OutputSettings.DotScaleFactor; foreach (Component c in componentGroup.Values.ElementAt(lineIndex)) { double posX = (double)c.PositionX - width * dotScaleFactor / 2; double posY = (double)c.PositionY - width * dotScaleFactor / 2; double widthXY = width * dotScaleFactor; gfx.DrawRectangle(xpenComponent, xb, posX, posY, widthXY, widthXY); } } gfx.Restore(state); }
public override void PopClip() { _clipStack.Pop(); _g.Restore(); }
// create a preview public void CreatePreview() { XRect rect; XPen pen; PdfSharp.Pdf.PdfDocument document = new PdfSharp.Pdf.PdfDocument(); document.Info.Title = "Created with PDFsharp"; // Create an empty page PdfSharp.Pdf.PdfPage page = document.AddPage(); // Get an XGraphics object for drawing page.Size = PageSize.A5; page.Orientation = PageOrientation.Landscape; XGraphics gfx = XGraphics.FromPdfPage(page); 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); string kara = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Printex"); gfx.DrawImage(XPdfForm.FromFile(System.IO.Path.Combine(kara, "slother.pdf")), rcImage); gfx.Restore(state); }
/// <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) { // Create the array to hold the values to be rendered this.Values = this.Code128Code == Code128Type.C ? new byte[this.text.Length / 2] : new byte[this.text.Length]; String buffer = String.Empty; for (Int32 index = 0; index < text.Length; index++) { switch (this.Code128Code) { case Code128Type.A: if (text[index] < 32) { this.Values[index] = (byte)(text[index] + 64); } else if ((text[index] >= 32) && (text[index] < 64)) { this.Values[index] = (byte)(text[index] - 32); } else { this.Values[index] = (byte)text[index]; } break; case Code128Type.B: this.Values[index] = (byte)(text[index] - 32); break; case Code128Type.C: if ((text[index] >= '0') && (text[index] <= '9')) { buffer += text[index]; if (buffer.Length == 2) { this.Values[index / 2] = byte.Parse(buffer); buffer = String.Empty; } } else { throw new ArgumentOutOfRangeException("Parameter text (string) can only contain numeric characters for Code 128 - Code C"); } break; } } if (this.Values == null) { throw new InvalidOperationException("Text or Values must be set"); } if (this.Values.Length == 0) { throw new InvalidOperationException("Text or Values must have content"); } for (int x = 0; x < this.Values.Length; x++) { if (this.Values[x] > 102) { throw new ArgumentOutOfRangeException(BcgSR.InvalidCode128(x)); } } XGraphicsState state = gfx.Save(); BarCodeRenderInfo info = new BarCodeRenderInfo(gfx, brush, font, position); this.InitRendering(info); info.CurrPosInString = 0; info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size); this.RenderStart(info); foreach (byte c in this.Values) { this.RenderValue(info, c); } this.RenderStop(info); if (this.TextLocation != TextLocation.None) { this.RenderText(info); } gfx.Restore(state); }
/// <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 }
/// <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 = info.Center - this.size / 2; info.CurrPos = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size); if (TurboBit) RenderTurboBit(info, true); RenderStart(info); while (info.CurrPosInString < this.text.Length) { RenderNextChar(info); RenderGap(info, false); } RenderStop(info); if (TurboBit) RenderTurboBit(info, false); if (TextLocation != TextLocation.None) RenderText(info); gfx.Restore(state); }
public override void PdfDraw(XGraphics g) { XBrush brush = new XSolidBrush(Color.Black); XPen pen = new XPen(Color.Black); XPen pen2 = new XPen(Color.Gray); XStringFormat formatDec = new XStringFormat(); formatDec.Alignment = XStringAlignment.Near; formatDec.LineAlignment = XLineAlignment.Center; XStringFormat formatAlt = new XStringFormat(); formatAlt.Alignment = XStringAlignment.Center; formatAlt.LineAlignment = XLineAlignment.Center; XStringFormat formatNumber = new XStringFormat(); formatNumber.Alignment = XStringAlignment.Far; formatNumber.LineAlignment = XLineAlignment.Center; for (int i = 0; i < descriptionSplit.Count; i++) { g.DrawString(descriptionSplit[i], Settings.xfont, brush, new Point(Left + 2, Top + (int)((i + .5) * blockSize.Height)), formatDec); } if (Border) { g.DrawLine(new Pen(Color.FromArgb(128, 128, 128)), Left, Top + (descriptionSplit.Count * blockSize.Height), Left + Width - 1, Top + (descriptionSplit.Count * blockSize.Height)); } int itemCount = 1; int blockBegin = 0; for (int c = 0; c < Columns; c++) { int gridBegin = blockBegin * blockSize.Width; // Line separating columns if (Border) { g.DrawLine(new Pen(Color.FromArgb(128, 128, 128)), Left + gridBegin, Top + (descriptionSplit.Count * blockSize.Height), Left + gridBegin, Top + Height - 1); } for (int a = 0; a < NumberOfAlternatives; a++) { if (blocksForAlternatives == 1) // Place alternatives horizontally { g.DrawString(Alternatives[a], Settings.xfont, brush, new Point(Left + (int)(gridBegin + ((a + blocksForItemNames[c] + .5) * blockSize.Width)), Top + (int)((.5 + descriptionSplit.Count) * blockSize.Height)), formatAlt); } else // Place alternatives vertically { XGraphicsState gs = g.Save(); g.RotateAtTransform(90, new XPoint(Left + (int)(gridBegin + ((a + blocksForItemNames[c] + .5) * blockSize.Width)), Top + (int)((blocksForAlternatives + descriptionSplit.Count) * blockSize.Height))); formatAlt.Alignment = XStringAlignment.Far; g.DrawString(Alternatives[a], Settings.xfont, brush, new Point(Left + (int)(gridBegin + ((a + blocksForItemNames[c] + .5) * blockSize.Width)), Top + (int)((blocksForAlternatives + descriptionSplit.Count) * blockSize.Height)), formatAlt); g.Restore(gs); } for (int r = 0; r < columnSplit[c]; r++) { g.DrawRectangle(pen2, Left + gridBegin + ((a + blocksForItemNames[c]) * blockSize.Width) + 4, Top + (r + descriptionSplit.Count + blocksForAlternatives) * blockSize.Height + 4, blockSize.Width - 8, blockSize.Height - 8); } } for (int i = 0; i < columnSplit[c]; i++) { g.DrawString(Items[itemCount - 1].Name, Settings.xfont, brush, new Point(Left + gridBegin + (blocksForItemNames[c] * blockSize.Width), Top + (int)((i + descriptionSplit.Count + blocksForAlternatives + .5) * blockSize.Height)), formatNumber); itemCount++; } blockBegin += blocksForItemNames[c] + NumberOfAlternatives; } base.PdfDraw(g); }
/// <summary> /// Draws the content of the column plot area. /// </summary> internal override void Draw() { ChartRendererInfo cri = (ChartRendererInfo)_rendererParms.RendererInfo; XRect plotAreaBox = cri.plotAreaRendererInfo.Rect; if (plotAreaBox.IsEmpty) { return; } XGraphics gfx = _rendererParms.Graphics; double xMin = cri.xAxisRendererInfo.MinimumScale; double xMax = cri.xAxisRendererInfo.MaximumScale; double yMin = cri.yAxisRendererInfo.MinimumScale; double yMax = cri.yAxisRendererInfo.MaximumScale; LineFormatRenderer lineFormatRenderer; // Under some circumstances it is possible that no zero base line will be drawn, // e. g. because of unfavourable minimum/maximum scale and/or major tick, so force to draw // a zero base line if necessary. if (cri.yAxisRendererInfo.MajorGridlinesLineFormat != null || cri.yAxisRendererInfo.MinorGridlinesLineFormat != null) { if (yMin < 0 && yMax > 0) { XPoint[] points = new XPoint[2]; points[0].X = xMin; points[0].Y = 0; points[1].X = xMax; points[1].Y = 0; cri.plotAreaRendererInfo._matrix.TransformPoints(points); lineFormatRenderer = cri.yAxisRendererInfo.MinorGridlinesLineFormat != null ? new LineFormatRenderer(gfx, cri.yAxisRendererInfo.MinorGridlinesLineFormat) : new LineFormatRenderer(gfx, cri.yAxisRendererInfo.MajorGridlinesLineFormat); lineFormatRenderer.DrawLine(points[0], points[1]); } } // Draw columns XGraphicsState state = gfx.Save(); foreach (SeriesRendererInfo sri in cri.seriesRendererInfos) { foreach (ColumnRendererInfo column in sri._pointRendererInfos) { // Do not draw column if value is outside yMin/yMax range. Clipping does not make sense. if (IsDataInside(yMin, yMax, column.Point._value)) { gfx.DrawRectangle(column.FillFormat, column.Rect); } } } // Draw borders around column. // A border can overlap neighbor columns, so it is important to draw borders at the end. foreach (SeriesRendererInfo sri in cri.seriesRendererInfos) { foreach (ColumnRendererInfo column in sri._pointRendererInfos) { // Do not draw column if value is outside yMin/yMax range. Clipping does not make sense. if (IsDataInside(yMin, yMax, column.Point._value) && column.LineFormat.Width > 0) { lineFormatRenderer = new LineFormatRenderer(gfx, column.LineFormat); lineFormatRenderer.DrawRectangle(column.Rect); } } } gfx.Restore(state); }
public void Draw(XGraphics gfx, Map map) { TransformsProvider tp = new TransformsProvider(gfx); XRect rect = tp.FromCmsToPts(new XRect(this.Left, this.Top, this.Width, this.Height)); double geomScaleFactor; geomScaleFactor = tp.WorldToPaperScale(map.GetExtents(), rect); XRect geomFrame = tp.WorldToPaperRect(map.GetExtents(), rect); XGraphicsState state = gfx.Save(); gfx.TranslateTransform(geomFrame.X, geomFrame.Bottom); if (this._cacheIsEmpty) { foreach (Layer lyr in map.Layers) { if ((lyr) is VectorLayer) { if (this._overrideVectorLayerStyle) { this.DrawVectorLayer(gfx, map, geomScaleFactor, (VectorLayer)lyr, this._geomLineColorName, this._geomLineWidth, this._geomFillColorName); } else { if ((lyr as VectorLayer).Theme == null) { this.DrawVectorLayer(gfx, map, geomScaleFactor, (VectorLayer)lyr); } else { this.DrawThemeLayer(gfx, map, geomScaleFactor, (VectorLayer)lyr); } } } if (lyr is LabelLayer) { if (this._overrideLabelLayerStyle) { this.DrawLabelLayer(gfx, map, geomScaleFactor, (LabelLayer)lyr, _labelFontFamilyName, _labelFontSize, _labelFontStyle, _labelFontColorName); } else { LabelStyle simb = (lyr as LabelLayer).Style; this.DrawLabelLayer(gfx, map, geomScaleFactor, (LabelLayer)lyr, simb.Font.FontFamily.Name, simb.Font.Size, (XFontStyle)simb.Font.Style, simb.ForeColor.Name); } } } this._cacheIsEmpty = false; } else { foreach (PDFGeom g in this._geomCache) { if (g.FillStyle == null) { gfx.DrawPath(g.LineStyle, g.Geometry); } else if (g.LineStyle == null) { gfx.DrawPath(g.FillStyle, g.Geometry); } else { gfx.DrawPath(g.LineStyle, g.FillStyle, g.Geometry); } } foreach (PDFLabel l in this._labelCache) { gfx.DrawString(l.Text, l.Font, l.Brush, l.Point, XStringFormat.Center); } } gfx.Restore(state); _scale.Draw(gfx, geomScaleFactor); _geomarks.Draw(gfx, map.GetExtents(), rect); }