public BarCodeRenderInfo(XGraphics gfx, XBrush brush, XFont font, XPoint position) { Gfx = gfx; Brush = brush; Font = font; Position = position; }
///<summary>The pdfSharp version of drawstring. g is used for measurement. scaleToPix scales xObjects to pixels.</summary> public static void DrawStringX(XGraphics xg,Graphics g,double scaleToPix,string str,XFont xfont,XBrush xbrush,XRect xbounds, XStringAlignment sa) { //There are two coordinate systems here: pixels (used by us) and points (used by PdfSharp). //MeasureString and ALL related measurement functions must use pixels. //DrawString is the ONLY function that uses points. //pixels: Rectangle bounds=new Rectangle((int)(scaleToPix*xbounds.Left), (int)(scaleToPix*xbounds.Top), (int)(scaleToPix*xbounds.Width), (int)(scaleToPix*xbounds.Height)); FontStyle fontstyle=FontStyle.Regular; if(xfont.Style==XFontStyle.Bold) { fontstyle=FontStyle.Bold; } //pixels: (except Size is em-size) Font font=new Font(xfont.Name,(float)xfont.Size,fontstyle); //pixels: SizeF fit=new SizeF((float)(bounds.Width-rightPad),(float)(font.Height)); StringFormat format=StringFormat.GenericTypographic; //pixels: float pixelsPerLine=LineSpacingForFont(font.Name) * (float)font.Height; float lineIdx=0; int chars; int lines; //points: RectangleF layoutRectangle; for(int ix=0;ix<str.Length;ix+=chars) { if(bounds.Y+topPad+pixelsPerLine*lineIdx>bounds.Bottom) { break; } //pixels: g.MeasureString(str.Substring(ix),font,fit,format,out chars,out lines); //PdfSharp isn't smart enough to cut off the lower half of a line. //if(bounds.Y+topPad+pixelsPerLine*lineIdx+font.Height > bounds.Bottom) { // layoutH=bounds.Bottom-(bounds.Y+topPad+pixelsPerLine*lineIdx); //} //else { // layoutH=font.Height+2; //} //use points here: float adjustTextDown=10f;//this value was arrived at by trial and error. layoutRectangle=new RectangleF( (float)xbounds.X, //(float)(xbounds.Y+(float)topPad/scaleToPix+(pixelsPerLine/scaleToPix)*lineIdx), (float)(xbounds.Y+adjustTextDown+(pixelsPerLine/scaleToPix)*lineIdx), (float)xbounds.Width+50,//any amount of extra padding here will not cause malfunction 0);//layoutH); XStringFormat sf=XStringFormats.Default; sf.Alignment=sa; //sf.LineAlignment= XLineAlignment.Near; //xg.DrawString(str.Substring(ix,chars),xfont,xbrush,layoutRectangle,sf); xg.DrawString(str.Substring(ix,chars),xfont,xbrush,(double)layoutRectangle.Left,(double)layoutRectangle.Top,sf); lineIdx+=1; } }
/// <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); }
void ElliottsDiagramCalculation() { //Decide Zone for both figures from this calculation zone = "Non-Explosive Zone"; brush = XBrushes.Green; }
/// <summary> /// Draws the specified bar code. /// </summary> public void DrawBarCode(BarCodes.BarCode barcode, XBrush brush, XFont font, XPoint position) { barcode.Render(this, brush, font, position); }
/// <summary> /// Draws the specified text string. /// </summary> public void DrawString(string s, XFont font, XBrush brush, RectangleF layoutRectangle, XStringFormat format) { DrawString(s, font, brush, new XRect(layoutRectangle), format); }
/// <summary> /// Draws the specified text string. /// </summary> public void DrawString(string s, XFont font, XBrush brush, double x, double y, XStringFormat format) { DrawString(s, font, brush, new XRect(x, y, 0, 0), format); }
// ----- DrawString --------------------------------------------------------------------------- #if GDI /// <summary> /// Draws the specified text string. /// </summary> public void DrawString(string s, XFont font, XBrush brush, PointF point) { DrawString(s, font, brush, new XRect(point.X, point.Y, 0, 0), XStringFormats.Default); }
// ----- fill ----- /// <summary> /// Draws a graphical path. /// </summary> public void DrawPath(XBrush brush, XGraphicsPath path) { if (brush == null) throw new ArgumentNullException("brush"); if (path == null) throw new ArgumentNullException("path"); if (this.drawGraphics) { #if GDI if (this.targetContext == XGraphicTargetContext.GDI) this.gfx.FillPath(brush.RealizeGdiBrush(), path.gdipPath); #endif #if WPF if (this.targetContext == XGraphicTargetContext.WPF) this.dc.DrawGeometry(brush.RealizeWpfBrush(), null, path.pathGeometry); #endif } if (this.renderer != null) this.renderer.DrawPath(null, brush, path); }
/// <summary> /// Draws a closed cardinal spline defined by an array of points. /// </summary> public void DrawClosedCurve(XBrush brush, System.Windows.Point[] points) { DrawClosedCurve(null, brush, MakeXPointArray(points), XFillMode.Alternate, 0.5); }
/// <summary> /// Draws a pie defined by an ellipse. /// </summary> public void DrawPie(XPen pen, XBrush brush, double x, double y, double width, double height, double startAngle, double sweepAngle) { if (pen == null && brush == null) throw new ArgumentNullException("pen", PSSR.NeedPenOrBrush); if (this.drawGraphics) { #if GDI if (this.targetContext == XGraphicTargetContext.GDI) { this.gfx.FillPie(brush.RealizeGdiBrush(), (float)x, (float)y, (float)width, (float)height, (float)startAngle, (float)sweepAngle); this.gfx.DrawPie(pen.RealizeGdiPen(), (float)x, (float)y, (float)width, (float)height, (float)startAngle, (float)sweepAngle); } #endif #if WPF if (this.targetContext == XGraphicTargetContext.WPF) { #if !SILVERLIGHT System.Windows.Media.Brush wpfBrush = brush != null ? brush.RealizeWpfBrush() : null; System.Windows.Media.Pen wpfPen = pen != null ? pen.RealizeWpfPen() : null; System.Windows.Point center = new System.Windows.Point(x + width / 2, y + height / 2); System.Windows.Point startArc; ArcSegment arc = GeometryHelper.CreateArcSegment(x, y, width, height, startAngle, sweepAngle, out startArc); PathFigure figure = new PathFigure(); figure.StartPoint = center; figure.Segments.Add(new LineSegment(startArc, true)); figure.Segments.Add(arc); figure.IsClosed = true; PathGeometry geo = new PathGeometry(); geo.Figures.Add(figure); this.dc.DrawGeometry(wpfBrush, wpfPen, geo); #else // AGHACK #endif } #endif } if (this.renderer != null) this.renderer.DrawPie(pen, brush, x, y, width, height, startAngle, sweepAngle); }
/// <summary> /// Draws a pie defined by an ellipse. /// </summary> public void DrawPie(XPen pen, XBrush brush, int x, int y, int width, int height, int startAngle, int sweepAngle) { DrawPie(pen, brush, (double)x, (double)y, (double)width, (double)height, (double)startAngle, (double)sweepAngle); }
/// <summary> /// Draws a pie defined by an ellipse. /// </summary> public void DrawPie(XPen pen, XBrush brush, XRect rect, double startAngle, double sweepAngle) { DrawPie(pen, brush, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle); }
/// <summary> /// Draws a pie defined by an ellipse. /// </summary> public void DrawPie(XBrush brush, double x, double y, double width, double height, double startAngle, double sweepAngle) { if (brush == null) throw new ArgumentNullException("brush", PSSR.NeedPenOrBrush); if (this.drawGraphics) { #if GDI if (this.targetContext == XGraphicTargetContext.GDI) this.gfx.FillPie(brush.RealizeGdiBrush(), (float)x, (float)y, (float)width, (float)height, (float)startAngle, (float)sweepAngle); #endif #if WPF if (this.targetContext == XGraphicTargetContext.WPF) DrawPie(null, brush, x, y, width, height, startAngle, sweepAngle); #endif } if (this.renderer != null) this.renderer.DrawPie(null, brush, x, y, width, height, startAngle, sweepAngle); }
/// <summary> /// Draws a pie defined by an ellipse. /// </summary> public void DrawPie(XBrush brush, RectangleF rect, double startAngle, double sweepAngle) { DrawPie(brush, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle); }
/// <summary> /// Draws a closed cardinal spline defined by an array of points. /// </summary> public void DrawClosedCurve(XPen pen, XBrush brush, PointF[] points, XFillMode fillmode, double tension) { DrawClosedCurve(pen, brush, MakeXPointArray(points), fillmode, tension); }
/// <summary> /// Draws a closed cardinal spline defined by an array of points. /// </summary> public void DrawClosedCurve(XPen pen, XBrush brush, XPoint[] points, XFillMode fillmode, double tension) { if (pen == null && brush == null) throw new ArgumentNullException("pen and brush", PSSR.NeedPenOrBrush); int count = points.Length; if (count == 0) return; if (count < 2) throw new ArgumentException("Not enough points.", "points"); if (this.drawGraphics) { #if GDI if (this.targetContext == XGraphicTargetContext.GDI) { if (brush != null) this.gfx.FillClosedCurve(brush.RealizeGdiBrush(), MakePointFArray(points), (FillMode)fillmode, (float)tension); if (pen != null) { // The fillmode is not used by DrawClosedCurve this.gfx.DrawClosedCurve(pen.RealizeGdiPen(), MakePointFArray(points), (float)tension, (FillMode)fillmode); } } #endif #if WPF if (this.targetContext == XGraphicTargetContext.WPF) { #if !SILVERLIGHT tension /= 3; // Simply tried out. Not proofed why it is correct. PathFigure figure = new PathFigure(); figure.IsClosed = true; figure.StartPoint = new System.Windows.Point(points[0].x, points[0].y); if (count == 2) { figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[0], points[0], points[1], points[1], tension)); } else { figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[count - 1], points[0], points[1], points[2], tension)); for (int idx = 1; idx < count - 2; idx++) figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[idx - 1], points[idx], points[idx + 1], points[idx + 2], tension)); figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[count - 3], points[count - 2], points[count - 1], points[0], tension)); figure.Segments.Add(GeometryHelper.CreateCurveSegment(points[count - 2], points[count - 1], points[0], points[1], tension)); } PathGeometry geo = new PathGeometry(); geo.FillRule = fillmode == XFillMode.Alternate ? FillRule.EvenOdd : FillRule.Nonzero; geo.Figures.Add(figure); System.Windows.Media.Brush wpfBrush = brush != null ? brush.RealizeWpfBrush() : null; System.Windows.Media.Pen wpfPen = pen != null ? pen.RealizeWpfPen() : null; this.dc.DrawGeometry(wpfBrush, wpfPen, geo); #else // AGHACK #endif } #endif } if (this.renderer != null) this.renderer.DrawClosedCurve(pen, brush, points, tension, fillmode); }
/// <summary> /// Draws a closed cardinal spline defined by an array of points. /// </summary> public void DrawClosedCurve(XBrush brush, PointF[] points, XFillMode fillmode) { DrawClosedCurve(null, brush, MakeXPointArray(points), fillmode, 0.5); }
// ----- stroke and fill ----- /// <summary> /// Draws a graphical path. /// </summary> public void DrawPath(XPen pen, XBrush brush, XGraphicsPath path) { if (pen == null && brush == null) throw new ArgumentNullException("pen and brush", PSSR.NeedPenOrBrush); if (path == null) throw new ArgumentNullException("path"); if (this.drawGraphics) { #if GDI if (this.targetContext == XGraphicTargetContext.GDI) { if (brush != null) this.gfx.FillPath(brush.RealizeGdiBrush(), path.gdipPath); if (pen != null) this.gfx.DrawPath(pen.RealizeGdiPen(), path.gdipPath); } #endif #if WPF if (this.targetContext == XGraphicTargetContext.WPF) { System.Windows.Media.Brush wpfBrush = brush != null ? brush.RealizeWpfBrush() : null; System.Windows.Media.Pen wpfPen = pen != null ? pen.RealizeWpfPen() : null; this.dc.DrawGeometry(wpfBrush, wpfPen, path.pathGeometry); } #endif } if (this.renderer != null) this.renderer.DrawPath(pen, brush, path); }
/// <summary> /// Draws a closed cardinal spline defined by an array of points. /// </summary> public void DrawClosedCurve(XBrush brush, System.Windows.Point[] points, XFillMode fillmode, double tension) { DrawClosedCurve(null, brush, MakeXPointArray(points), fillmode, tension); }
/// <summary> /// Draws the specified text string. /// </summary> public void DrawString(string s, XFont font, XBrush brush, XPoint point, XStringFormat format) { DrawString(s, font, brush, new XRect(point.X, point.Y, 0, 0), format); }
/// <summary> /// Draws a closed cardinal spline defined by an array of points. /// </summary> public void DrawClosedCurve(XBrush brush, XPoint[] points, XFillMode fillmode, double tension) { DrawClosedCurve(null, brush, points, fillmode, tension); // if (brush == null) // throw new ArgumentNullException("brush"); // if (this.drawGraphics) // { //#if GDI // if (this.targetContext == XGraphicTargetContext.GDI) // this.gfx.FillClosedCurve(brush.RealizeGdiBrush(), MakePointFArray(points), (FillMode)fillmode, (float)tension); //#endif //#if WPF // if (this.targetContext == XGraphicTargetContext.WPF) // { // // throw new NotImplementedException("TODO"); // } //#endif // } // if (this.renderer != null) // this.renderer.DrawClosedCurve(null, brush, points, tension, fillmode); }
/// <summary> /// Draws the specified text string. /// </summary> public void DrawString(string s, XFont font, XBrush brush, XRect layoutRectangle) { DrawString(s, font, brush, layoutRectangle, XStringFormats.Default); }
/// <summary> /// Draws a closed cardinal spline defined by an array of points. /// </summary> public void DrawClosedCurve(XPen pen, XBrush brush, PointF[] points) { DrawClosedCurve(pen, brush, MakeXPointArray(points), XFillMode.Alternate, 0.5); }
/// <summary> /// Draws the specified text string. /// </summary> public void DrawString(string text, XFont font, XBrush brush, XRect layoutRectangle, XStringFormat format) { if (text == null) throw new ArgumentNullException("text"); if (font == null) throw new ArgumentNullException("font"); if (brush == null) throw new ArgumentNullException("brush"); if (format != null && format.LineAlignment == XLineAlignment.BaseLine && layoutRectangle.Height != 0) throw new InvalidOperationException("DrawString: With XLineAlignment.BaseLine the height of the layout rectangle must be 0."); if (text.Length == 0) return; if (format == null) format = XStringFormats.Default; if (this.drawGraphics) { #if GDI if (this.targetContext == XGraphicTargetContext.GDI) { RectangleF rect = layoutRectangle.ToRectangleF(); if (format.LineAlignment == XLineAlignment.BaseLine) { double lineSpace = font.GetHeight(this); int cellSpace = font.FontFamily.GetLineSpacing(font.Style); int cellAscent = font.FontFamily.GetCellAscent(font.Style); int cellDescent = font.FontFamily.GetCellDescent(font.Style); double cyAscent = lineSpace * cellAscent / cellSpace; cyAscent = lineSpace * font.cellAscent / font.cellSpace; rect.Offset(0, (float)-cyAscent); } this.gfx.DrawString(text, font.RealizeGdiFont(), brush.RealizeGdiBrush(), rect, format != null ? format.RealizeGdiStringFormat() : null); } #endif #if WPF if (this.targetContext == XGraphicTargetContext.WPF) { #if !SILVERLIGHT double x = layoutRectangle.X; double y = layoutRectangle.Y; double lineSpace = font.GetHeight(this); double cyAscent = lineSpace * font.cellAscent / font.cellSpace; double cyDescent = lineSpace * font.cellDescent / font.cellSpace; bool bold = (font.Style & XFontStyle.Bold) != 0; bool italic = (font.Style & XFontStyle.Italic) != 0; bool strikeout = (font.Style & XFontStyle.Strikeout) != 0; bool underline = (font.Style & XFontStyle.Underline) != 0; //FormattedText formattedText = new FormattedText(text, new CultureInfo("en-us"), // WPFHACK // FlowDirection.LeftToRight, font.typeface, font.Size, brush.RealizeWpfBrush()); FormattedText formattedText = FontHelper.CreateFormattedText(text, font.typeface, font.Size, brush.RealizeWpfBrush()); //formattedText.SetTextDecorations(TextDecorations.OverLine); switch (format.Alignment) { case XStringAlignment.Near: // nothing to do, this is the default //formattedText.TextAlignment = TextAlignment.Left; break; case XStringAlignment.Center: x += layoutRectangle.Width / 2; formattedText.TextAlignment = TextAlignment.Center; break; case XStringAlignment.Far: x += layoutRectangle.Width; formattedText.TextAlignment = TextAlignment.Right; break; } if (PageDirection == XPageDirection.Downwards) { switch (format.LineAlignment) { case XLineAlignment.Near: //y += cyAscent; break; case XLineAlignment.Center: // TODO use CapHeight. PDFlib also uses 3/4 of ascent y += -formattedText.Baseline + (cyAscent * 1 / 3) + layoutRectangle.Height / 2; //y += -formattedText.Baseline + (font.Size * font.Metrics.CapHeight / font.unitsPerEm / 2) + layoutRectangle.Height / 2; break; case XLineAlignment.Far: y += -formattedText.Baseline - cyDescent + layoutRectangle.Height; break; case XLineAlignment.BaseLine: y -= formattedText.Baseline; break; } } else { // TODOWPF: make unit test switch (format.LineAlignment) { case XLineAlignment.Near: //y += cyDescent; break; case XLineAlignment.Center: // TODO use CapHeight. PDFlib also uses 3/4 of ascent //y += -(cyAscent * 3 / 4) / 2 + rect.Height / 2; break; case XLineAlignment.Far: //y += -cyAscent + rect.Height; break; case XLineAlignment.BaseLine: // nothing to do break; } } //if (bold && !descriptor.IsBoldFace) //{ // // TODO: emulate bold by thicker outline //} //if (italic && !descriptor.IsBoldFace) //{ // // TODO: emulate italic by shearing transformation //} if (underline) { formattedText.SetTextDecorations(TextDecorations.Underline); //double underlinePosition = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlinePosition / font.cellSpace; //double underlineThickness = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlineThickness / font.cellSpace; //DrawRectangle(null, brush, x, y - underlinePosition, width, underlineThickness); } if (strikeout) { formattedText.SetTextDecorations(TextDecorations.Strikethrough); //double strikeoutPosition = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutPosition / font.cellSpace; //double strikeoutSize = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutSize / font.cellSpace; //DrawRectangle(null, brush, x, y - strikeoutPosition - strikeoutSize, width, strikeoutSize); } //this.dc.DrawText(formattedText, layoutRectangle.Location.ToPoint()); this.dc.DrawText(formattedText, new System.Windows.Point(x, y)); #else dc.DrawString(this, text, font, brush, layoutRectangle, format); #endif } #endif } if (this.renderer != null) this.renderer.DrawString(text, font, brush, layoutRectangle, format); }
/// <summary> /// Draws a closed cardinal spline defined by an array of points. /// </summary> public void DrawClosedCurve(XPen pen, XBrush brush, XPoint[] points) { DrawClosedCurve(pen, brush, points, XFillMode.Alternate, 0.5); }
/// <summary> /// Draws the specified data matrix code. /// </summary> public void DrawMatrixCode(BarCodes.MatrixCode matrixcode, XBrush brush, XPoint position) { matrixcode.Render(this, brush, position); }
/// <summary> /// Draws a closed cardinal spline defined by an array of points. /// </summary> public void DrawClosedCurve(XPen pen, XBrush brush, System.Windows.Point[] points, XFillMode fillmode) { DrawClosedCurve(pen, brush, MakeXPointArray(points), fillmode, 0.5); }
/// <summary> /// When defined in a derived class renders the code. /// </summary> protected internal abstract void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position);
/// <summary> /// Draws a closed cardinal spline defined by an array of points. /// </summary> public void DrawClosedCurve(XPen pen, XBrush brush, XPoint[] points, XFillMode fillmode) { DrawClosedCurve(pen, brush, points, fillmode, 0.5); }