Beispiel #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));
        }
Beispiel #2
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);
                    }
                }
            }
        }