コード例 #1
0
        protected override int GetFieldY(Label label, PrintInfo printInfo)
        {
            int y;
            var fontSize        = printInfo.ToDotY(string.IsNullOrEmpty(FontSize) ? label.FontSize : FontSize);
            var kerning         = 0;
            var textBlockHeight = Content.Count() * (fontSize + kerning);

            switch (VerticalAlignment)
            {
            case VerticalAlignment.Bottom:
                y = (int)printInfo.LabelHeightDots - printInfo.ToDotY(MarginBottom) - textBlockHeight;
                break;

            case VerticalAlignment.Center:
                var marginTop    = printInfo.ToDotY(MarginTop);
                var marginBottom = printInfo.ToDotY(MarginBottom);
                y  = marginTop + (((int)printInfo.LabelHeightDots - marginBottom - marginTop) / 2);
                y -= (textBlockHeight / 2);
                break;

            // Default to .Top
            default:
                y = printInfo.ToDotY(MarginTop);
                break;
            }

            return(y);
        }
コード例 #2
0
        protected override string GetFieldContent(Label label, PrintInfo printInfo)
        {
            var zpl = new StringBuilder();

            // Set font options
            if (!string.IsNullOrEmpty(FontSize))
            {
                zpl.Append($"^CF{Font},{printInfo.ToDotY(FontSize)}");
            }
            else
            {
                zpl.Append($"^CF{label.Font},{printInfo.ToDotY(label.FontSize)}");
            }

            int    width         = (int)printInfo.LabelWidthDots - printInfo.ToDotX(MarginLeft) - printInfo.ToDotX(MarginRight);
            int    maxLines      = Content.Count();
            int    kerning       = 0;
            string justify       = GetJustification(HorizontalAlignment);
            int    hangingIndent = 0;

            // Field Block
            zpl.Append($"^FB{width},{maxLines},{kerning},{justify},{hangingIndent}");

            // Field Data
            zpl.Append($"^FD");
            zpl.Append(string.Join("\\&", Content.Select(c => c.Content)));

            return(zpl.ToString().Trim());
        }
コード例 #3
0
        private string Generate_CODE_128(PrintInfo printInfo)
        {
            var o = "N";                    // Orientation
            var h = printInfo.ToDotY(Size); // Height / dots
            var f = "Y";                    // Print interpretation line
            var g = "N";                    // Print interpretation line above code
            var e = "N";                    // UCC Check digit
            var m = "N";                    // Mode

            return($"^BC{o},{h},{f},{g},{e},{m}^FD{Content}");
        }
コード例 #4
0
        protected override string GetFieldContent(Label label, PrintInfo printInfo)
        {
            var width     = printInfo.LabelWidthDots - printInfo.ToDotX(MarginRight) - printInfo.ToDotX(MarginLeft);
            var height    = printInfo.LabelHeightDots - printInfo.ToDotY(MarginTop) - printInfo.ToDotY(MarginBottom);
            var thickness = printInfo.PointToDot(Convert.ToDouble(Thickness.Replace("pt", "")));
            var zpl       = new StringBuilder();
            var c         = BorderColor == BorderColor.Black ? "B" : "W";

            zpl.Append($"^GB{width},{height},{thickness},{c},{BorderRounding}");

            return(zpl.ToString().Trim());
        }
コード例 #5
0
        private string Generate_QR(PrintInfo printInfo)
        {
            var a = "N";  // Orientation
            var b = "2";  // Model (1:original, 2:enhanced)
            var c = 10;   // Magnification factor
            var errorCorrection = "QR";

            if (int.TryParse(Size, out int mag))
            {
                c = mag;
            }

            return($"^BQ{a},{b},{c}^FD{errorCorrection},{Content}");
        }
コード例 #6
0
        public string ToZPL(PrintInfo printInfo)
        {
            var zpl = new StringBuilder();

            zpl.AppendLine("^XA");

            foreach (var field in Content)
            {
                zpl.Append(field.Emit(this, printInfo));
            }

            zpl.AppendLine("^XZ");

            return(zpl.ToString().Trim());
        }
コード例 #7
0
        protected override string GetFieldContent(Label label, PrintInfo printInfo)
        {
            var zpl = new StringBuilder();

            switch (Type)
            {
            case BarcodeType.CODE_128:
                zpl.Append(Generate_CODE_128(printInfo));
                break;

            case BarcodeType.QR:
                zpl.Append(Generate_QR(printInfo));
                break;
            }

            return(zpl.ToString().Trim());
        }
コード例 #8
0
        internal string Emit(Label label, PrintInfo printInfo)
        {
            var zpl = new StringBuilder();

            if (!string.IsNullOrEmpty(Name))
            {
                zpl.AppendLine($"^FX {Name}");
            }

            zpl.Append($"^FO{GetFieldX(label, printInfo)},{GetFieldY(label, printInfo)}");

            zpl.Append(GetFieldContent(label, printInfo));

            zpl.Append($"^FS");

            zpl.AppendLine();
            zpl.AppendLine();

            return(zpl.ToString());
        }
コード例 #9
0
 protected abstract string GetFieldContent(Label label, PrintInfo printInfo);
コード例 #10
0
 protected abstract int GetFieldY(Label label, PrintInfo printInfo);
コード例 #11
0
 protected override int GetFieldY(Label label, PrintInfo printInfo)
 {
     return(printInfo.ToDotY(MarginTop));
 }
コード例 #12
0
 protected override int GetFieldX(Label label, PrintInfo printInfo)
 {
     return(printInfo.ToDotX(MarginLeft));
 }
コード例 #13
0
 protected override string GetFieldContent(Label label, PrintInfo printInfo)
 {
     return(Content);
 }