private static void DrawText(XGraphics gfx, string text, string font, string style, double size, string color, int width, int height, int x, int y) { XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Default); XFont fontStyle = null; switch (style) { case "Bold": fontStyle = new XFont(font, size, XFontStyle.Bold, options); break; case "Italic": fontStyle = new XFont(font, size, XFontStyle.Italic, options); break; case "Regular": fontStyle = new XFont(font, size, XFontStyle.Regular, options); break; case "Underline": fontStyle = new XFont(font, size, XFontStyle.Underline, options); break; case "Strikeout": fontStyle = new XFont(font, size, XFontStyle.Strikeout, options); break; case "BoldItalic": fontStyle = new XFont(font, size, XFontStyle.BoldItalic, options); break; default: break; } System.Drawing.Color fontColor = ConverterManager.HexToColorConverter(color); XBrush fontBrush = new XSolidBrush(new XColor { R = fontColor.R, G = fontColor.G, B = fontColor.B }); XRect fontRect = new XRect(x, y, width, height); XStringFormat fontFormat = new XStringFormat { Alignment = XStringAlignment.Center }; gfx.DrawString(text, fontStyle, fontBrush, fontRect, fontFormat); }
private static void DrawBadgeElement(Badge badge, XGraphics gfx) { var color = ConverterManager.HexToColorConverter(badge.ForegroundColor); XColor borderColor = new XColor { R = color.R, G = color.G, B = color.B }; color = ConverterManager.HexToColorConverter(badge.BackgroundColor); XColor backColor = new XColor { R = color.R, G = color.G, B = color.B }; color = ConverterManager.HexToColorConverter(badge.FontColor); XColor fontColor = new XColor { R = color.R, G = color.G, B = color.B }; XPen pen = new XPen(borderColor, double.Parse(badge.BorderWidth.ToString())); DrawRectangle(gfx, backColor, borderColor, pen, badge.Width, badge.Height, badge.PositionX1, badge.PositionY1); DrawText(gfx, badge.Value, badge.Font, badge.FontStyle, badge.FontSize, badge.FontColor, badge.Width, badge.Height, badge.PositionX1, badge.PositionY1); }
private static string DrawBadgeToPicture(BadgeType obj, ListBoxPrintBadge person) { String filename; // Create a temporary file var bmp = new Bitmap(obj.Width, obj.Height); var gfx = Graphics.FromImage(bmp); gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; if (person != null) { filename = String.Format("{0}_{1}_{2}.png", person.Id, person.F + person.IO, DefaultManager.Instance.CurrentDateTimeShortString); } else { filename = String.Format("{0}.png", DefaultManager.Instance.CurrentDateTimeShortString); } filename = DefaultManager.Instance.AbstractFilePath + @"\" + filename; foreach (var badge in obj.Badges.ToList()) { if (person != null) { badge.Value = badge.Value.Replace("$F$", person.F); badge.Value = badge.Value.Replace("$IO$", person.IO); badge.Value = badge.Value.Replace("$COMPANY$", person.Company); badge.Value = badge.Value.Replace("$CITY$", person.City); badge.Value = badge.Value.Replace("$COUNTRY$", person.Country); } else { badge.Value = badge.Value.Replace("$F$", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); badge.Value = badge.Value.Replace("$IO$", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); badge.Value = badge.Value.Replace("$COMPANY$", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); badge.Value = badge.Value.Replace("$CITY$", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); badge.Value = badge.Value.Replace("$COUNTRY$", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); } var color = ConverterManager.HexToColorConverter(badge.ForegroundColor); var borderColor = System.Drawing.Color.FromArgb(color.R, color.G, color.B); color = ConverterManager.HexToColorConverter(badge.BackgroundColor); var backColor = System.Drawing.Color.FromArgb(color.R, color.G, color.B); color = ConverterManager.HexToColorConverter(badge.FontColor); var fontColor = System.Drawing.Color.FromArgb(color.R, color.G, color.B); var brush = new SolidBrush(backColor); var pen = new System.Drawing.Pen(borderColor, float.Parse(badge.BorderWidth.ToString())); var rectangle = new Rectangle(badge.PositionX1, badge.PositionY1, badge.Width, badge.Height); gfx.FillRectangle(brush, rectangle); gfx.DrawRectangle(pen, rectangle); System.Drawing.Font font = null; switch (badge.FontStyle) { case "Bold": font = new System.Drawing.Font(badge.Font, (float)badge.FontSize, FontStyle.Bold); break; case "Italic": font = new System.Drawing.Font(badge.Font, (float)badge.FontSize, FontStyle.Italic); break; case "Regular": font = new System.Drawing.Font(badge.Font, (float)badge.FontSize, FontStyle.Regular); break; case "Underline": font = new System.Drawing.Font(badge.Font, (float)badge.FontSize, FontStyle.Underline); break; case "Strikeout": font = new System.Drawing.Font(badge.Font, (float)badge.FontSize, FontStyle.Strikeout); break; case "BoldItalic": font = new System.Drawing.Font(badge.Font, (float)badge.FontSize, FontStyle.Bold | FontStyle.Italic); break; default: break; } var rect = new RectangleF(badge.PositionX1, badge.PositionY1, badge.Width, badge.Height); brush = new SolidBrush(fontColor); var sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.Trimming = StringTrimming.Word; gfx.DrawString(badge.Value, font, brush, rect, sf); } gfx.Flush(); bmp.Save(filename, ImageFormat.Png); return(filename); }