Esempio n. 1
0
        private void DrawLabel(Graphics g, LabelContent content, Rectangle paperRect)
        {
            var rightMargin = 0;
            var leftMargin  = 0;

            // allow vertical binNumber to be written, if provided
            if (!string.IsNullOrEmpty(PrinterSettings.PartLabelTemplate.Identifier.Content) && PrinterSettings.PartLabelTemplate.Identifier.Position == LabelPosition.Right)
            {
                rightMargin = 25;
            }
            if (!string.IsNullOrEmpty(PrinterSettings.PartLabelTemplate.Identifier.Content) && PrinterSettings.PartLabelTemplate.Identifier.Position == LabelPosition.Left)
            {
                leftMargin = 25;
            }
            var margins = new Margin(leftMargin, rightMargin, 0, 0);

            // process template values
            content.Line1      = content.Line1 ?? ReplaceTemplate(content.Part, PrinterSettings.PartLabelTemplate.Line1);
            content.Line2      = content.Line2 ?? ReplaceTemplate(content.Part, PrinterSettings.PartLabelTemplate.Line2);
            content.Line3      = content.Line3 ?? ReplaceTemplate(content.Part, PrinterSettings.PartLabelTemplate.Line3);
            content.Line4      = content.Line4 ?? ReplaceTemplate(content.Part, PrinterSettings.PartLabelTemplate.Line4);
            content.Identifier = content.Identifier ?? ReplaceTemplate(content.Part, PrinterSettings.PartLabelTemplate.Identifier);

            // merge any adjascent template lines together
            MergeLines(g, PrinterSettings.PartLabelTemplate, content, paperRect, margins);
            var line1Position      = DrawLine(g, new PointF(_labelStart[PrinterSettings.PartLabelTemplate.Line1.Label - 1].X, _labelStart[PrinterSettings.PartLabelTemplate.Line1.Label - 1].Y), content.Part, content.Line1, PrinterSettings.PartLabelTemplate.Line1, paperRect, margins);
            var line2Position      = DrawLine(g, line1Position, content.Part, content.Line2, PrinterSettings.PartLabelTemplate.Line2, paperRect, margins);
            var line3Position      = DrawLine(g, line2Position, content.Part, content.Line3, PrinterSettings.PartLabelTemplate.Line3, paperRect, margins);
            var line4Position      = DrawLine(g, line3Position, content.Part, content.Line4, PrinterSettings.PartLabelTemplate.Line4, paperRect, margins);
            var identifierPosition = DrawLine(g, line4Position, content.Part, content.Identifier, PrinterSettings.PartLabelTemplate.Identifier, paperRect, margins);
        }
Esempio n. 2
0
 /// <summary>
 /// Merge all adjascent template lines
 /// </summary>
 /// <param name="template"></param>
 /// <param name="content"></param>
 /// <param name="paperRect"></param>
 /// <param name="margins"></param>
 private void MergeLines(Graphics g, PartLabelTemplate template, LabelContent content, Rectangle paperRect, Margin margins)
 {
     if (template.Line1.Content == template.Line2.Content)
     {
         MergeLines(g, content.Line1, content.Line2, paperRect, margins, out var newLine, out var newLine2);
         content.Line1 = newLine;
         content.Line2 = newLine2;
     }
     if (template.Line2.Content == template.Line3.Content)
     {
         MergeLines(g, content.Line2, content.Line3, paperRect, margins, out var newLine, out var newLine2);
         content.Line2 = newLine;
         content.Line3 = newLine2;
     }
     if (template.Line3.Content == template.Line4.Content)
     {
         MergeLines(g, content.Line3, content.Line4, paperRect, margins, out var newLine, out var newLine2);
         content.Line3 = newLine;
         content.Line4 = newLine2;
     }
 }
Esempio n. 3
0
        public Image PrintLabel(LabelContent content, PrinterOptions options)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            _labelProperties = GetLabelDimensions(PrinterSettings.LabelName);
            var doc = CreatePrinterDocument(options);
            var g   = Graphics.FromImage(_printImage);

            DrawLabel(g, content, _paperRect);

            // for debugging label layout
            if (options.ShowDiagnostic)
            {
                DrawDebug(g);
            }

            if (!options.GenerateImageOnly)
            {
                doc.Print();
            }
            return(_printImage);
        }
Esempio n. 4
0
 public Image PrintLabel(LabelContent content)
 {
     return(PrintLabel(content, PrinterOptions.None));
 }