// 初始化尺寸单位 // 如果尺寸太小,就只显示一个姓名 // parameters: // photo_ratio 照片宽高比。例如 0.7F public void Layout(Graphics g, PatronCardStyle style, int nWidth, int nHeight) { #if NO // 如果宽度大于高度,则照片在最左边 _nPhotoWidth = (int)((float)nHeight * style.PhotoRatio); if (_nPhotoWidth >= 100) { _nPhotoWidth = 100; } if (_nPhotoWidth > style.PhtoMaxWidth) { _nPhotoWidth = style.PhtoMaxWidth; } #endif _nPhotoWidth = 0; // 暂时不显示照片 _nTextWidth = nWidth - _nPhotoWidth; // 证号 _nBarcodeHeight = Math.Min(50, nHeight / 5); // 4 // 姓名 _nNameHeight = Math.Min(100, nHeight / 2); // 单位 _nDepartmentHeight = Math.Min(50, nHeight / 5); // 4 // TODO: 单位可以最多是两行 // 如果高度大于宽度,则照片在顶部 }
public void Paint(Graphics g, long x, long y, PatronCardStyle style) { g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; // 证条码号 StringFormat format = new StringFormat(); // (StringFormat)StringFormat.GenericTypographic.Clone(); // format.FormatFlags |= StringFormatFlags.FitBlackBox; format.Alignment = StringAlignment.Near; { RectangleF textRect = new RectangleF(x + _nPhotoWidth, y + 0, _nTextWidth, _nBarcodeHeight); Font font = new Font("微软雅黑", GetHeight(_nBarcodeHeight), FontStyle.Regular, GraphicsUnit.Pixel); g.DrawString( this.Barcode, font, new SolidBrush(style.BarcodeTextColor), textRect, format); } // 姓名 { RectangleF textRect = new RectangleF(x + _nPhotoWidth, y + _nBarcodeHeight, _nTextWidth, _nNameHeight); Font font = new Font("微软雅黑", GetHeight(_nNameHeight), style.NameFontStyle, GraphicsUnit.Pixel); g.DrawString( this.Name, font, new SolidBrush(style.NameTextColor), textRect, format); } // 单位 { RectangleF textRect = new RectangleF(x + _nPhotoWidth, y + _nBarcodeHeight + _nNameHeight, _nTextWidth, _nDepartmentHeight); Font font = new Font("微软雅黑", GetHeight(_nDepartmentHeight), FontStyle.Regular, GraphicsUnit.Pixel); g.DrawString( this.Department, font, new SolidBrush(style.DepartmentTextColor), textRect, format); } }
// 初始化尺寸单位 // 如果尺寸太小,就只显示一个姓名 // parameters: // photo_ratio 照片宽高比。例如 0.7F public void Layout(Graphics g, PatronCardStyle style, int nWidth, int nHeight) { // 如果宽度大于高度,则照片在最左边 _nPhotoWidth = (int)((float)nHeight * style.PhotoRatio); if (_nPhotoWidth >= 100) _nPhotoWidth = 100; if (_nPhotoWidth > style.PhtoMaxWidth) _nPhotoWidth = style.PhtoMaxWidth; _nTextWidth = nWidth - _nPhotoWidth; // 证号 _nBarcodeHeight = Math.Min(50, nHeight / 4); // 姓名 _nNameHeight = Math.Min(100, nHeight / 2); // 单位 _nDepartmentHeight = Math.Min(50, nHeight / 4); // TODO: 单位可以最多是两行 // 如果高度大于宽度,则照片在顶部 }
public void Paint(Graphics g, long x, long y, PatronCardStyle style) { g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; // 证条码号 StringFormat format = new StringFormat(); // (StringFormat)StringFormat.GenericTypographic.Clone(); // format.FormatFlags |= StringFormatFlags.FitBlackBox; format.Alignment = StringAlignment.Near; { RectangleF textRect = new RectangleF(x + _nPhotoWidth, y + 0, _nTextWidth, _nBarcodeHeight); using (Brush brush = new SolidBrush(style.BarcodeTextColor)) using (Font font = new Font("微软雅黑", GetHeight(_nBarcodeHeight), FontStyle.Regular, GraphicsUnit.Pixel)) { g.DrawString( this.Barcode, font, brush, textRect, format); } } // 姓名 { RectangleF textRect = new RectangleF(x + _nPhotoWidth, y + _nBarcodeHeight, _nTextWidth, _nNameHeight); using (Brush brush = new SolidBrush(style.NameTextColor)) using (Font font = new Font("微软雅黑", GetHeight(_nNameHeight), style.NameFontStyle, GraphicsUnit.Pixel)) { g.DrawString( this.Name, font, brush, textRect, format); } } // 单位 { RectangleF textRect = new RectangleF(x + _nPhotoWidth, y + _nBarcodeHeight + _nNameHeight, _nTextWidth, _nDepartmentHeight); using (Brush brush = new SolidBrush(style.DepartmentTextColor)) using (Font font = new Font("微软雅黑", GetHeight(_nDepartmentHeight), FontStyle.Regular, GraphicsUnit.Pixel)) { g.DrawString( this.Department, font, brush, textRect, format); } } }