private string ReplaceTemplate(object data, LineConfiguration config) { var template = config.Content; var value = template; if (template.Contains("{") && template.Contains("}")) { var propertyName = string.Empty; var matches = Regex.Match(template, @"{([^}]+)}"); if (matches.Groups.Count > 1) { propertyName = matches.Groups[1].Value; } propertyName = propertyName[0].ToString().ToUpper() + propertyName.Substring(1); value = value.Replace(template, data.GetPropertyValue(propertyName).ToString()); } if (config.UpperCase) { value = value.ToUpper(); } else if (config.LowerCase) { value = value.ToLower(); } return(value); }
private Font CreateFont(Graphics g, LineConfiguration template, string lineValue, Rectangle paperRect) { Font font; if (template.AutoSize) { font = AutosizeFont(g, template.FontName ?? DefaultFontName, template.FontSize, lineValue, paperRect.Width); } else { font = new Font(template.FontName ?? DefaultFontName, template.FontSize, GraphicsUnit.Point); } return(font); }
private PointF DrawLine(Graphics g, PointF lineOffset, object part, string lineValue, LineConfiguration template, Rectangle paperRect, Margin margins) { var font = CreateFont(g, template, lineValue, paperRect); var lineBounds = g.MeasureString(lineValue, font); var x = 0f; var y = lineOffset.Y; x += template.Margin.Left; y += template.Margin.Top; if (template.Barcode) { x = 0; y += 12; DrawBarcode128(lineValue, g, new Rectangle((int)x, (int)y, paperRect.Width, paperRect.Height / _labelProperties.LabelCount)); } else { switch (template.Position) { case LabelPosition.Right: x += paperRect.Width; break; case LabelPosition.Left: x += (int)lineBounds.Height; break; case LabelPosition.Center: x += (margins.Left + paperRect.Width - margins.Right) / 2 - lineBounds.Width / 2 + _labelProperties.LeftMargin; break; } if (template.Rotate > 0) { // rotated labels will start at the top of the label y = _labelStart[template.Label - 1].Y + template.Margin.Top; var state = g.Save(); g.ResetTransform(); g.RotateTransform(PrinterSettings.PartLabelTemplate.Identifier.Rotate); g.TranslateTransform(x, y, System.Drawing.Drawing2D.MatrixOrder.Append); g.DrawString(lineValue, font, Brushes.Black, new PointF(0, 0)); g.Restore(state); } else { g.DrawString(lineValue, font, Brushes.Black, new PointF(x, y)); } } font.Dispose(); // return the new drawing cursor position return(new PointF(0, y + lineBounds.Height * 0.65f)); }