Esempio n. 1
0
        /// <summary>
        /// Set printer size in cm
        /// </summary>
        /// <param name="printerWidth">Width of the printer head</param>
        /// <param name="labelWidth">Size of the label (width)</param>
        /// <param name="labelHeight">Size of the label (height)</param>
        /// <param name="dpi">DPI of the screen</param>
        public void SetLabelPrinterSizeCm(double printerWidth, double labelWidth, double labelHeight)
        {
            var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static);
            int dpiX         = (int)dpiXProperty.GetValue(null, null);

            var dpiYProperty = typeof(SystemParameters).GetProperty("DpiY", BindingFlags.NonPublic | BindingFlags.Static);
            int dpiY         = (int)dpiXProperty.GetValue(null, null);

            SetLabelPrinterSizePixel(UnitHelper.CmToPx(printerWidth, dpiX), UnitHelper.CmToPx(labelWidth, dpiX), UnitHelper.CmToPx(labelHeight, dpiY));
        }
Esempio n. 2
0
        ///<summary>
        /// Render the control on a canvas
        ///</summary>
        /// <param name="canvas">Canvas formular</param>
        /// <param name="formular">Formular</param>
        /// <param name="command">Command instance</param>
        /// <param name="relative">Relative position</param>
        /// <param name="dpi">DPI</param>
        public override void Render(Canvas canvas, EPLFormular formular, EPLCommand command, Tuple <double, double> relative, int dpiX, int dpiY)
        {
            EPL.BarcodeCommand cmd = (EPL.BarcodeCommand)command;

            BarcodeBase barcode = null;

            switch (cmd.P4)
            {
            case "3":
                barcode = new RadBarcode39();
                break;

            case "1A":
                barcode = new RadBarcode128A();
                break;

            case "B":
                barcode = new RadBarcode128B();
                break;

            case "C":
                barcode = new RadBarcode128C();
                break;

            case "E80":
            case "E82":
            case "E85":
                barcode = new RadBarcodeEAN8();
                break;

            case "E30":
            case "E32":
            case "E35":
                barcode = new RadBarcodeEAN8();
                break;

            case "UA0":
                barcode = new RadBarcodeUPCA();
                break;

            case "UE0":
                barcode = new RadBarcodeUPCA();
                break;


            case "1":
            default:
                barcode = new RadBarcode128();
                break;
            }

            if (barcode != null)
            {
                barcode.ToolTip = cmd.CommandName;
                string displayText = cmd.Data ?? "--null--";

                barcode.FontFamily = new FontFamily("Consolas");

                if (displayText.StartsWith("\""))
                {
                    displayText = displayText.Remove(0, 1);
                }
                if (displayText.EndsWith("\""))
                {
                    displayText = displayText.Remove(displayText.Length - 1, 1);
                }

                barcode.Text = displayText;

                // Set coordinates
                int _x = 0;
                int _y = 0;

                if (int.TryParse(cmd.P1, out _x) && int.TryParse(cmd.P2, out _y))
                {
                    var coord = UnitHelper.DotToPixel(8, _x, _y, dpiX, dpiY);

                    if (relative != null)
                    {
                        Canvas.SetLeft(barcode, coord.Item1 + relative.Item1);
                        Canvas.SetTop(barcode, coord.Item2 + relative.Item2);
                    }
                    else
                    {
                        Canvas.SetLeft(barcode, coord.Item1);
                        Canvas.SetTop(barcode, coord.Item2);
                    }
                }

                // Set height, default will be 70 dots
                double bHeight = 70;
                double.TryParse(cmd.P7, out bHeight);
                barcode.Height = UnitHelper.DotToPixel(8, bHeight, dpiY) + 5;

                switch (cmd.P3)
                {
                case "1":
                    barcode.LayoutTransform = new RotateTransform(90);
                    break;

                case "2":
                    barcode.LayoutTransform = new RotateTransform(180);
                    break;

                case "3":
                    barcode.LayoutTransform = new RotateTransform(270);
                    break;
                }

                //block.FontSize = PointsToPixels(12);

                barcode.ShowText = true;

                canvas.Children.Add(barcode);

                barcode.Background = new SolidColorBrush(Colors.WhiteSmoke);

                canvas.UpdateLayout();
                barcode.UpdateLayout();

                int narrowBarWide = 1;
                if (int.TryParse(cmd.P5, out narrowBarWide))
                {
                    barcode.Width = barcode.ActualWidth * narrowBarWide;
                }

                // Must be under the width calculation, because otherwise it did not work...
                if (cmd.P8 != "B")
                {
                    barcode.ShowText = false;
                }

                barcode.ShowChecksum = false;
            }
        }
Esempio n. 3
0
        ///<summary>
        /// Render the control on a canvas
        ///</summary>
        /// <param name="canvas">Canvas formular</param>
        /// <param name="formular">Formular</param>
        /// <param name="command">Command instance</param>
        /// <param name="relative">Relative position</param>
        /// <param name="dpi">DPI</param>
        public override void Render(Canvas canvas, EPLFormular formular, EPLCommand command, Tuple <double, double> relative, int dpiX, int dpiY)
        {
            EPL.TextCommand cmd = (EPL.TextCommand)command;

            TextBlock block = new TextBlock();

            block.FontFamily = new FontFamily("Consolas");
            block.ToolTip    = cmd.CommandName;
            string displayText = cmd.Data ?? "--null--";

            if (displayText.StartsWith("\""))
            {
                displayText = displayText.Remove(0, 1);
            }
            if (displayText.EndsWith("\""))
            {
                displayText = displayText.Remove(displayText.Length - 1, 1);
            }

            block.Text = displayText;

            // Set coordinates
            int _x = 0;
            int _y = 0;

            if (int.TryParse(cmd.P1, out _x) && int.TryParse(cmd.P2, out _y))
            {
                var coord = UnitHelper.DotToPixel(8, _x, _y, dpiX, dpiY);

                if (relative != null)
                {
                    Canvas.SetLeft(block, coord.Item1 + relative.Item1);
                    Canvas.SetTop(block, coord.Item2 + relative.Item2);
                }
                else
                {
                    Canvas.SetLeft(block, coord.Item1);
                    Canvas.SetTop(block, coord.Item2);
                }
            }

            switch (cmd.P3)
            {
            case "1":
                block.LayoutTransform = new RotateTransform(90);
                break;

            case "2":
                block.LayoutTransform = new RotateTransform(180);
                break;

            case "3":
                block.LayoutTransform = new RotateTransform(270);
                break;
            }

            //block.FontSize = PointsToPixels(12);

            if (cmd.P7 == "R")
            {
                block.Foreground = new SolidColorBrush(Colors.White);
                block.Background = new SolidColorBrush(Colors.Black);
            }

            canvas.Children.Add(block);
        }
Esempio n. 4
0
        /// <summary>
        /// Render the current EPL formular
        /// </summary>
        public void Render()
        {
            if (eplFormular == null)
            {
                eplFormular           = new EPLFormular(this, editor.Text);
                eplFormular.Processor = Processor;
            }

            errors.Clear();
            eplFormular.Load(editor.Text);
            textMarkerService.RemoveAll(m => true);

            labelCanvas.Children.Clear();
            renderGrid.Children.Clear();
            renderGrid.Children.Add(labelCanvas);

            generatedEPLEditor.Text = eplFormular.GetEPLCode();

            // Render
            var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static);
            int dpiX         = (int)dpiXProperty.GetValue(null, null);

            var dpiYProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static);
            int dpiY         = (int)dpiXProperty.GetValue(null, null);

            Tuple <double, double> relativePosition = new Tuple <double, double>(0, 0);
            Tuple <double, double> absoltePosition  = new Tuple <double, double>(0, 0);

            // Label size
            double labelHeightPx  = UnitHelper.CmToPx(1.9, dpiX);
            double labelWidthPx   = UnitHelper.CmToPx(5.7, dpiY);
            double printerWidthPx = UnitHelper.CmToPx(10, dpiX);

            foreach (var command in eplFormular.Commands)
            {
                if (command is RCommand)
                {
                    double _x = 0;
                    double _y = 0;

                    if (double.TryParse((command as RCommand).P1, out _x) && double.TryParse((command as RCommand).P2, out _y))
                    {
                        relativePosition = new Tuple <double, double>(UnitHelper.DotToPixel(8, _x, dpiX), UnitHelper.DotToPixel(8, _y, dpiY));

                        absoltePosition = new Tuple <double, double>
                                          (
                            relativePosition.Item1,
                            relativePosition.Item2 + 5
                                          );
                    }
                }
                else if (command is LabelHeightCommand)
                {
                    if (double.TryParse(((LabelHeightCommand)command).P1, out labelHeightPx))
                    {
                        labelHeightPx = UnitHelper.DotToPixel(8, (int)labelHeightPx, dpiY);
                        SetLabelPrinterSizePixel(printerWidthPx, labelHeightPx, labelWidthPx);

                        absoltePosition = new Tuple <double, double>
                                          (
                            ((printerWidthPx / 2) - (labelWidthPx / 2)),
                            relativePosition.Item2 + 5
                                          );
                    }
                }
                else if (command is LabelWidthCommand)
                {
                    if (double.TryParse(((LabelWidthCommand)command).P1, out labelWidthPx))
                    {
                        labelWidthPx = UnitHelper.DotToPixel(8, (int)labelWidthPx, dpiX);
                        SetLabelPrinterSizePixel(printerWidthPx, labelWidthPx, labelHeightPx);

                        absoltePosition = new Tuple <double, double>
                                          (
                            ((printerWidthPx / 2) - (labelWidthPx / 2)),
                            relativePosition.Item2 + 5
                                          );
                    }
                }
                else
                {
                    var uiFactory = UIControlFactory.Get(command.GetType());

                    if (uiFactory != null)
                    {
                        // Render on UI
                        uiFactory.Render(this.renderGrid, eplFormular, command, absoltePosition, dpiX, dpiY);
                    }
                }
            }
        }