Exemplo n.º 1
0
        static string RenderLabel6()
        {
            var text  = "Lorem Ipsum is simply dummy text\nof the printing and typesetting industry.\nLorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book";
            var font1 = new ZplFont(fontWidth: 0, fontHeight: 20, fontName: "0");
            var font2 = new ZplFont(fontWidth: 0, fontHeight: 13, fontName: "0");

            var elements = new ZplElementBase[]
            {
                new ZplTextBlock(text, 10, 0, 400, 100, font1, NewLineConversionMethod.ToSpace),
                new ZplTextBlock(text, 10, 120, 400, 100, font1, NewLineConversionMethod.ToSpace),

                new ZplTextBlock(text, 10, 240, 400, 100, font2, NewLineConversionMethod.ToEmpty),

                new ZplFieldBlock(text, 10, 360, 400, font1, 4)
            };

            var renderEngine = new ZplEngine(elements);

            return(renderEngine.ToZplString(new ZplRenderOptions
            {
                //AddEmptyLineBeforeElementStart = true,
                SourcePrintDpi = 203,
                TargetPrintDpi = 203
            }));
        }
Exemplo n.º 2
0
        static string RenderLabel1()
        {
            var sampleText = "[_~^][LineBreak\n][The quick fox jumps over the lazy dog.]";
            var font       = new ZplFont(fontWidth: 50, fontHeight: 50);

            var elements = new ZplElementBase[]
            {
                new ZplTextField(sampleText, 50, 100, font),
                new ZplGraphicBox(400, 700, 100, 100, 5),
                new ZplGraphicBox(200, 700, 100, 200, 3, cornerRounding: 8),
                new ZplGraphicBox(450, 750, 100, 100, 50, LineColor.White),
                new ZplGraphicCircle(400, 700, 100, 5),
                new ZplGraphicDiagonalLine(400, 700, 100, 50, 5),
                new ZplGraphicDiagonalLine(400, 700, 50, 100, 5),
                new ZplGraphicSymbol(GraphicSymbolCharacter.Copyright, 600, 600, 50, 50),

                //Add raw zpl code
                new ZplRaw("^FO200, 200^GB300, 200, 10 ^FS")
            };

            var renderEngine = new ZplEngine(elements);

            return(renderEngine.ToZplString(new ZplRenderOptions
            {
                //AddEmptyLineBeforeElementStart = true,
                SourcePrintDpi = 203,
                TargetPrintDpi = 203
            }));
        }
Exemplo n.º 3
0
        static string RenderLabel5()
        {
            var font1 = new ZplFont(fontWidth: 0, fontHeight: 50, fontName: "0");
            var font2 = new ZplFont(fontWidth: 0, fontHeight: 50, fontName: "1");
            var font3 = new ZplFont(fontWidth: 0, fontHeight: 80, fontName: "A");
            var font4 = new ZplFont(fontWidth: 0, fontHeight: 50, fontName: "B");
            var font5 = new ZplFont(fontWidth: 0, fontHeight: 20, fontName: "C");
            var font6 = new ZplFont(fontWidth: 20, fontHeight: 0, fontName: "D");
            var font7 = new ZplFont(fontWidth: 20, fontHeight: 20, fontName: "D");
            var font8 = new ZplFont(fontWidth: 20, fontHeight: 0, fontName: "D", fieldOrientation: FieldOrientation.Rotated90);

            var elements = new ZplElementBase[]
            {
                new ZplTextField("Font1 Demo Text", 10, 0, font1),
                new ZplTextField("Font2 Demo Text", 10, 100, font2),
                new ZplTextField("Font3 Demo Text", 10, 200, font3),
                new ZplTextField("Font4 Demo Text", 10, 300, font4),
                new ZplTextField("Font5 Demo Text", 10, 400, font5),
                new ZplTextField("Font6 Demo Text", 10, 500, font6),
                new ZplTextField("Font7 Demo Text", 10, 600, font7),
                new ZplTextField("Font8 Demo Text", 900, 10, font8),
            };

            var renderEngine = new ZplEngine(elements);

            return(renderEngine.ToZplString(new ZplRenderOptions
            {
                //AddEmptyLineBeforeElementStart = true,
                SourcePrintDpi = 203,
                TargetPrintDpi = 203
            }));
        }
        ///<inheritdoc/>
        public override void Draw(ZplElementBase element)
        {
            if (element is ZplBarcodeEan13 barcode)
            {
                float x = barcode.PositionX;
                float y = barcode.PositionY;

                if (barcode.FieldTypeset != null)
                {
                    y -= barcode.Height;
                }

                var barcodeElement = new Barcode
                {
                    BarWidth  = barcode.ModuleWidth,
                    BackColor = Color.Transparent,
                    Height    = barcode.Height
                };

                var content = barcode.Content;
                if (content.Length < 12)
                {
                    var number = long.Parse(content);
                    content = number.ToString("D12");
                }
                else if (content.Length > 12)
                {
                    content = content.Substring(content.Length - 12, 12);
                }
                using var image = barcodeElement.Encode(TYPE.EAN13, content);
                this.DrawBarcode(this.GetImageData(image), barcode.Height, image.Width, barcode.FieldOrigin != null, x, y, barcode.FieldOrientation);
            }
        }
Exemplo n.º 5
0
        ///<inheritdoc/>
        public override void Draw(ZplElementBase element)
        {
            if (element is ZplDataMatrix dataMatrix)
            {
                float x = dataMatrix.PositionX;
                float y = dataMatrix.PositionY;

                if (dataMatrix.FieldTypeset != null)
                {
                    y -= dataMatrix.Height;
                }

                var writer = new DataMatrixWriter();
                var result = writer.encode(dataMatrix.Content, BarcodeFormat.DATA_MATRIX, 0, 0);

                int size = dataMatrix.Height;
                using var image = new SKBitmap(result.Width + size - 1, result.Height + size - 1);

                for (int row = 0; row < result.Height; row++)
                {
                    for (int col = 0; col < result.Width; col++)
                    {
                        var color = result[row, col] ? SKColors.Black : SKColors.White;
                        image.SetPixel(row, col, color);
                    }
                }

                using var resizedImage = image.Resize(new SKSizeI(image.Width * size, image.Height * size), SKFilterQuality.None);

                var png = resizedImage.Encode(SKEncodedImageFormat.Png, 100).ToArray();
                this.DrawBarcode(png, dataMatrix.Height, dataMatrix.Height, dataMatrix.FieldOrigin != null, x, y, dataMatrix.FieldOrientation);
            }
        }
        public override bool IsReverseDraw(ZplElementBase element)
        {
            if (element is ZplGraphicBox graphicBox)
            {
                return(graphicBox.ReversePrint);
            }

            return(false);
        }
        public override bool IsReverseDraw(ZplElementBase element)
        {
            if (element is ZplFieldBlock fieldBlock)
            {
                return(fieldBlock.ReversePrint);
            }

            return(false);
        }
Exemplo n.º 8
0
        public override bool IsReverseDraw(ZplElementBase element)
        {
            if (element is ZplTextField textField)
            {
                return(textField.ReversePrint);
            }

            return(false);
        }
Exemplo n.º 9
0
        static string RenderLabel2()
        {
            var elements = new ZplElementBase[]
            {
                new ZplReferenceGrid(),
            };

            var renderEngine = new ZplEngine(elements);

            return(renderEngine.ToZplString(new ZplRenderOptions
            {
                //AddEmptyLineBeforeElementStart = true,
                SourcePrintDpi = 203,
                TargetPrintDpi = 203
            }));
        }
        ///<inheritdoc/>
        public override void Draw(ZplElementBase element)
        {
            if (element is ZplRecallGraphic recallGraphic)
            {
                var imageData = this._printerStorage.GetFile(recallGraphic.StorageDevice, recallGraphic.ImageName);

                if (imageData.Length == 0)
                {
                    return;
                }

                var x = recallGraphic.PositionX;
                var y = recallGraphic.PositionY;

                this._skCanvas.DrawBitmap(SKBitmap.Decode(imageData), x, y);
            }
        }
Exemplo n.º 11
0
        ///<inheritdoc/>
        public override void Draw(ZplElementBase element)
        {
            if (element is ZplImageMove imageMove)
            {
                var imageData = this._printerStorage.GetFile(imageMove.StorageDevice, imageMove.ObjectName);

                if (imageData.Length == 0)
                {
                    return;
                }

                var x = imageMove.PositionX;
                var y = imageMove.PositionY;

                this._skCanvas.DrawBitmap(SKBitmap.Decode(imageData), x, y);
            }
        }
Exemplo n.º 12
0
        static string RenderLabel4()
        {
            var elements = new ZplElementBase[]
            {
                new ZplDownloadGraphics('R', "TEST", File.ReadAllBytes("logo_sw.png")),
                new ZplRecallGraphic(0, 0, 'R', "TEST")
            };

            var renderEngine = new ZplEngine(elements);

            return(renderEngine.ToZplString(new ZplRenderOptions
            {
                //AddEmptyLineBeforeElementStart = true,
                SourcePrintDpi = 203,
                TargetPrintDpi = 203
            }));
        }
        ///<inheritdoc/>
        public override void Draw(ZplElementBase element)
        {
            if (element is ZplGraphicField graphicField)
            {
                var imageData = ByteHelper.HexToBytes(graphicField.Data);
                var image     = SKBitmap.Decode(imageData);

                var x = graphicField.PositionX;
                var y = graphicField.PositionY;

                var useFieldTypeset = graphicField.FieldTypeset != null;
                if (useFieldTypeset)
                {
                    y -= image.Height;
                }

                this._skCanvas.DrawBitmap(image, x, y);
            }
        }
Exemplo n.º 14
0
        ///<inheritdoc/>
        public override void Draw(ZplElementBase element)
        {
            if (element is ZplQrCode qrcode)
            {
                float x = qrcode.PositionX;
                float y = qrcode.PositionY;

                using var qrGenerator = new QRCodeGenerator();
                using var qrCodeData  = qrGenerator.CreateQrCode(qrcode.Content, this.Convert(qrcode.ErrorCorrectionLevel));
                using var qrCode      = new QRCode(qrCodeData);

                using Bitmap qrCodeImage = qrCode.GetGraphic(qrcode.MagnificationFactor, Color.Black, Color.Transparent, drawQuietZones: false);
                using (var ms = new MemoryStream())
                {
                    qrCodeImage.Save(ms, ImageFormat.Png);
                    var imageData = ms.ToArray();
                    this._skCanvas.DrawBitmap(SKBitmap.Decode(imageData), x, y);
                }
            }
        }
Exemplo n.º 15
0
        static string RenderLabel3()
        {
            var elements = new ZplElementBase[]
            {
                new ZplBarcode128("Barcode128", 10, 0),
                new ZplBarcode39("Barcode39", 10, 150),
                new ZplBarcodeAnsiCodabar("123456", 'a', 'd', 10, 300, 100),
                new ZplBarcodeEan13("123456789", 10, 450),
                new ZplBarcodeInterleaved2of5("123456789", 10, 600),
                new ZplQrCode("BinaryKits ZplUtility BinaryKits ZplUtility BinaryKits ZplUtility", 10, 800, magnificationFactor: 6)
            };

            var renderEngine = new ZplEngine(elements);

            return(renderEngine.ToZplString(new ZplRenderOptions
            {
                //AddEmptyLineBeforeElementStart = true,
                SourcePrintDpi = 203,
                TargetPrintDpi = 203
            }));
        }
        ///<inheritdoc/>
        public override void Draw(ZplElementBase element)
        {
            if (element is ZplGraphicCircle graphicCircle)
            {
                var radius = graphicCircle.Diameter / 2.0f;
                var border = (float)graphicCircle.BorderThickness;

                if (border > radius)
                {
                    border = radius;
                }

                using var skPaint   = new SKPaint();
                skPaint.Style       = SKPaintStyle.Stroke;
                skPaint.Color       = SKColors.Black;
                skPaint.StrokeWidth = border;

                var halfBorderThickness = border / 2.0f;

                var radiusMinusBorder = radius - halfBorderThickness;
                var offset            = halfBorderThickness + radiusMinusBorder;

                var x = graphicCircle.PositionX + offset;
                var y = graphicCircle.PositionY + offset;

                if (graphicCircle.FieldTypeset != null)
                {
                    y -= graphicCircle.Diameter;

                    //Fallback
                    if (y < radius)
                    {
                        y = radius;
                    }
                }

                this._skCanvas.DrawCircle(x, y, radiusMinusBorder, skPaint);
            }
        }
Exemplo n.º 17
0
        ///<inheritdoc/>
        public override void Draw(ZplElementBase element)
        {
            if (element is ZplBarcode39 barcode)
            {
                float x = barcode.PositionX;
                float y = barcode.PositionY;

                if (barcode.FieldTypeset != null)
                {
                    y -= barcode.Height;
                }

                var barcodeElement = new Barcode
                {
                    BarWidth  = barcode.ModuleWidth,
                    BackColor = Color.Transparent,
                    Height    = barcode.Height
                };

                using var image = barcodeElement.Encode(TYPE.CODE39Extended, barcode.Content);
                this.DrawBarcode(this.GetImageData(image), barcode.Height, barcodeElement.Width, barcode.FieldOrigin != null, x, y, barcode.FieldOrientation);
            }
        }
Exemplo n.º 18
0
        public override ZplElementBase Analyze(string zplCommand)
        {
            // If next field number has been set and was not consumed by a field data
            // it has to be stored as a command so that it is handled when merging formats
            ZplElementBase element     = null;
            int?           fieldNumber = this.VirtualPrinter.NextFieldNumber;

            if (fieldNumber.HasValue)
            {
                this.VirtualPrinter.ClearNextFieldNumber();
                ZplElementBase dataElement = _fieldDataAnalyzer.Analyze(zplCommand);
                element = new ZplFieldNumber(fieldNumber.Value, dataElement);
            }

            this.VirtualPrinter.ClearNextElementPosition();
            this.VirtualPrinter.ClearNextElementFieldBlock();
            this.VirtualPrinter.ClearNextElementFieldData();
            this.VirtualPrinter.ClearNextElementFieldReverse();
            this.VirtualPrinter.ClearNextFont();
            this.VirtualPrinter.ClearComments();

            return(element);
        }
Exemplo n.º 19
0
 ///<inheritdoc/>
 public override bool CanDraw(ZplElementBase element)
 {
     return(element is ZplImageMove);
 }
        ///<inheritdoc/>
        public override void Draw(ZplElementBase element)
        {
            if (element is ZplFieldBlock fieldBlock)
            {
                float x = fieldBlock.PositionX;
                float y = fieldBlock.PositionY;

                var font = fieldBlock.Font;

                float fontSize = font.FontHeight > 0 ? font.FontHeight : font.FontWidth;
                var   scaleX   = 1.0f;
                if (font.FontWidth != 0 && font.FontWidth != fontSize)
                {
                    scaleX = (float)font.FontWidth / fontSize;
                }

                fontSize *= 0.95f;

                var typeface = SKTypeface.Default;
                if (font.FontName == "0")
                {
                    //typeface = SKTypeface.FromFile(@"swiss-721-black-bt.ttf");
                    typeface = SKTypeface.FromFamilyName("Arial", SKFontStyleWeight.Bold, SKFontStyleWidth.Normal, SKFontStyleSlant.Upright);
                }

                var textLines = fieldBlock.Text.ReplaceSpecialChars().Split(new[] { "\\&" }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var textLine in textLines)
                {
                    using var skPaint  = new SKPaint();
                    skPaint.Color      = SKColors.Black;
                    skPaint.Typeface   = typeface;
                    skPaint.TextSize   = fontSize;
                    skPaint.TextScaleX = scaleX;
                    //Reset the X point for the next row
                    x = fieldBlock.PositionX;

                    var textBounds        = new SKRect();
                    var textBoundBaseline = new SKRect();
                    skPaint.MeasureText(new string('A', fieldBlock.Text.Length), ref textBoundBaseline);
                    skPaint.MeasureText(textLine, ref textBounds);

                    switch (fieldBlock.TextJustification)
                    {
                    case TextJustification.Center:
                        var diff = fieldBlock.Width - textBounds.Width;
                        x += diff / 2;
                        break;

                    case TextJustification.Right:
                        diff = fieldBlock.Width - textBounds.Width;
                        x   += diff;
                        break;

                    case TextJustification.Left:
                    case TextJustification.Justified:
                    default:
                        break;
                    }

                    if (fieldBlock.FieldTypeset != null)
                    {
                        y -= textBounds.Height;
                    }

                    using (new SKAutoCanvasRestore(this._skCanvas))
                    {
                        SKMatrix matrix = SKMatrix.Empty;

                        if (fieldBlock.FieldOrigin != null)
                        {
                            switch (fieldBlock.Font.FieldOrientation)
                            {
                            case FieldOrientation.Rotated90:
                                matrix = SKMatrix.CreateRotationDegrees(90, x, y);
                                y     -= font.FontHeight - textBoundBaseline.Height;
                                break;

                            case FieldOrientation.Rotated180:
                                matrix = SKMatrix.CreateRotationDegrees(180, x, y);
                                x     -= textBounds.Width;
                                y     -= font.FontHeight - textBoundBaseline.Height;
                                break;

                            case FieldOrientation.Rotated270:
                                matrix = SKMatrix.CreateRotationDegrees(270, x, y);
                                x     -= textBounds.Width;
                                y     += textBoundBaseline.Height;
                                break;

                            case FieldOrientation.Normal:
                                y += textBoundBaseline.Height;
                                break;
                            }
                        }
                        else
                        {
                            switch (fieldBlock.Font.FieldOrientation)
                            {
                            case FieldOrientation.Rotated90:
                                matrix = SKMatrix.CreateRotationDegrees(90, x, y);
                                x     += textBoundBaseline.Height;
                                break;

                            case FieldOrientation.Rotated180:
                                matrix = SKMatrix.CreateRotationDegrees(180, x, y);
                                y     -= textBoundBaseline.Height;
                                break;

                            case FieldOrientation.Rotated270:
                                matrix = SKMatrix.CreateRotationDegrees(270, x, y);
                                x     -= textBoundBaseline.Height;
                                break;

                            case FieldOrientation.Normal:
                                y += textBoundBaseline.Height;
                                break;
                            }
                        }

                        if (matrix != SKMatrix.Empty)
                        {
                            this._skCanvas.SetMatrix(matrix);
                        }

                        this._skCanvas.DrawText(textLine, x, y, new SKFont(typeface, fontSize, scaleX, 0), skPaint);
                    }
                }
            }
        }
 ///<inheritdoc/>
 public override bool CanDraw(ZplElementBase element)
 {
     return(element is ZplFieldBlock);
 }
 public override bool CanDraw(ZplElementBase element)
 {
     return(element is ZplBarcodeEan13);
 }
 ///<inheritdoc/>
 public override bool CanDraw(ZplElementBase element)
 {
     return(element is ZplRecallGraphic);
 }
Exemplo n.º 24
0
 ///<inheritdoc/>
 public override bool CanDraw(ZplElementBase element)
 {
     return(element is ZplQrCode);
 }
Exemplo n.º 25
0
 ///<inheritdoc/>
 public virtual void Draw(ZplElementBase element, DrawerOptions options = null)
 {
     Draw(element);  // Most element just ignore the context
 }
Exemplo n.º 26
0
 ///<inheritdoc/>
 public override bool CanDraw(ZplElementBase element)
 {
     return(element is ZplDataMatrix);
 }
Exemplo n.º 27
0
        ///<inheritdoc/>
        public override void Draw(ZplElementBase element, DrawerOptions options)
        {
            if (element is ZplTextField textField)
            {
                float x = textField.PositionX;
                float y = textField.PositionY;

                var font = textField.Font;

                float fontSize = font.FontHeight > 0 ? font.FontHeight : font.FontWidth;
                var   scaleX   = 1.0f;
                if (font.FontWidth != 0 && font.FontWidth != fontSize)
                {
                    scaleX = (float)font.FontWidth / fontSize;
                }

                fontSize *= 0.95f;

                var typeface = options.FontLoader(font.FontName);

                using var skPaint  = new SKPaint();
                skPaint.Color      = SKColors.Black;
                skPaint.Typeface   = typeface;
                skPaint.TextSize   = fontSize;
                skPaint.TextScaleX = scaleX;

                var    textBounds        = new SKRect();
                var    textBoundBaseline = new SKRect();
                string DisplayText       = textField.Text.ReplaceSpecialChars();
                skPaint.MeasureText(new string('A', DisplayText.Length), ref textBoundBaseline);
                skPaint.MeasureText(DisplayText, ref textBounds);

                if (textField.FieldTypeset != null)
                {
                    y -= textBounds.Height;
                }

                using (new SKAutoCanvasRestore(this._skCanvas))
                {
                    SKMatrix matrix = SKMatrix.Empty;

                    if (textField.FieldOrigin != null)
                    {
                        switch (textField.Font.FieldOrientation)
                        {
                        case Label.FieldOrientation.Rotated90:
                            matrix = SKMatrix.CreateRotationDegrees(90, x, y);
                            y     -= font.FontHeight - textBoundBaseline.Height;
                            break;

                        case Label.FieldOrientation.Rotated180:
                            matrix = SKMatrix.CreateRotationDegrees(180, x, y);
                            x     -= textBounds.Width;
                            y     -= font.FontHeight - textBoundBaseline.Height;
                            break;

                        case Label.FieldOrientation.Rotated270:
                            matrix = SKMatrix.CreateRotationDegrees(270, x, y);
                            x     -= textBounds.Width;
                            y     += textBoundBaseline.Height;
                            break;

                        case Label.FieldOrientation.Normal:
                            y += textBoundBaseline.Height;
                            break;
                        }
                    }
                    else
                    {
                        switch (textField.Font.FieldOrientation)
                        {
                        case Label.FieldOrientation.Rotated90:
                            matrix = SKMatrix.CreateRotationDegrees(90, x, y);
                            x     += textBoundBaseline.Height;
                            break;

                        case Label.FieldOrientation.Rotated180:
                            matrix = SKMatrix.CreateRotationDegrees(180, x, y);
                            y     -= textBoundBaseline.Height;
                            break;

                        case Label.FieldOrientation.Rotated270:
                            matrix = SKMatrix.CreateRotationDegrees(270, x, y);
                            x     -= textBoundBaseline.Height;
                            break;

                        case Label.FieldOrientation.Normal:
                            y += textBoundBaseline.Height;
                            break;
                        }
                    }

                    if (matrix != SKMatrix.Empty)
                    {
                        this._skCanvas.SetMatrix(matrix);
                    }

                    this._skCanvas.DrawText(DisplayText, x, y, new SKFont(typeface, fontSize, scaleX, 0), skPaint);
                }
            }
        }
Exemplo n.º 28
0
 ///<inheritdoc/>
 public override bool CanDraw(ZplElementBase element)
 {
     return(element.GetType() == typeof(ZplTextField));
 }
Exemplo n.º 29
0
 ///<inheritdoc/>
 public override void Draw(ZplElementBase element)
 {
     Draw(element, new DrawerOptions());
 }
 ///<inheritdoc/>
 public override bool CanDraw(ZplElementBase element)
 {
     return(element is ZplGraphicField);
 }