private Font GetSDFontFromElement(TextElement element) { GraphicsUnit unit = printArgs.Graphics.PageUnit; if(unit == GraphicsUnit.Display) { unit = GraphicsUnit.Millimeter; } return new Font(element.FontName, element.FontSize , (System.Drawing.FontStyle)Enum.Parse( typeof(System.Drawing.FontStyle), element.FontStyle.ToString()), unit); }
void DrawContentString(TextElement element) { //Implement TextWrap Font font = this.GetSDFontFromElement(element); Color fontColor = element.Foreground.ToSystemDrawingColor(); StringFormat fmt = new StringFormat(); if (element is Block) { fmt = this.GetFromBlock((Block)element); } SizeF textSize = printArgs.Graphics.MeasureString(element.Content.ToString(), font, (int)(this.printArgs.PageBounds.Width - this.currentX), fmt); if (textSize.Width < element.Bounds.Width) { textSize.Width = element.Bounds.Width; } if (textSize.Height < element.Bounds.Height) { textSize.Height = element.Bounds.Height; } RectangleF drawRect = new RectangleF(new PointF(this.CurrentX, this.CurrentY), textSize); element.Bounds = this.Rectangle2Rect(drawRect); if (element.Bounds.Bottom >= printArgs.PageBounds.Bottom) { printArgs.HasMorePages = true; _CurrentElement = element; dontDrawNow = true; return; } printArgs.Graphics.DrawString(element.Content.ToString(), font, new SolidBrush(fontColor), this.Rect2Rectangle(element.Bounds), fmt); this.currentY += element.Bounds.Height; this.currentX = printArgs.MarginBounds.Left; }