예제 #1
0
        public IList <Action> GenerateActionsForPrinter(string text)
        {
            var actions = new List <Action>();

            try
            {
                var elements = XmlLoader.Load(text);
                var commands = Transpilator.TranspileElements(elements);

                actions.Add(() => Printer.WakeUp());
                actions.Add(() => Printer.Reset());
                actions.Add(() => Printer.SetLineSpacing(2));
                actions.Add(() => Printer.SetLetterSpacing(2));
                actions.Add(() => Printer.SetMarginLeft(20)); // if elgin

                foreach (var command in commands)
                {
                    if (!string.IsNullOrEmpty(command.Tag))
                    {
                        switch (command.Tag)
                        {
                        case "ad":
                            actions.Add(() => Printer.SetAlignRight());
                            actions.Add(() => Printer.WriteLine(command.Value));
                            break;

                        case "/ad":
                            actions.Add(() => Printer.SetAlignLeft());
                            break;

                        case "b":
                            actions.Add(() => Printer.BoldOn());
                            actions.Add(() => Printer.WriteLine(command.Value));
                            break;

                        case "/b":
                            actions.Add(() => Printer.BoldOff());
                            break;

                        case "c":
                            actions.Add(() => Printer.SetLineSpacing(0));
                            actions.Add(() => Printer.SetLetterSpacing(0));
                            actions.Add(() => Printer.WriteLine(command.Value));
                            break;

                        case "/c":
                            actions.Add(() => Printer.SetLineSpacing(2));
                            actions.Add(() => Printer.SetLetterSpacing(2));
                            break;

                        case "ce":
                            actions.Add(() => Printer.SetAlignCenter());
                            actions.Add(() => Printer.WriteLine(command.Value));
                            break;

                        case "/ce":
                            actions.Add(() => Printer.SetAlignLeft());
                            break;

                        case "l":
                            actions.Add(() => Printer.LineFeed());
                            break;

                        case "/l":
                            break;

                        case "sl":
                            actions.Add(() => Printer.LineFeed(byte.Parse(command.Value)));
                            break;

                        case "/sl":
                            break;

                        case "gui":
                            actions.Add(() => Printer.Guillotine());
                            break;

                        case "/gui":
                            break;

                        default:
                            actions.Add(() => Printer.WriteLine(command.Value));
                            break;
                        }
                    }
                    else
                    {
                        actions.Add(() => Printer.WriteLine(command.Value));
                    }
                }

                return(actions);
            }
            catch
            {
                return(null);
            }
        }
예제 #2
0
        public IList <Action> GenerateActionsForPrinter(string text)
        {
            var actions = new List <Action>();

            var elements = XmlLoader.Load(text);
            var commands = Transpilator.TranspileElements(elements);

            actions.Add(() => Printer.WakeUp());

            foreach (var command in commands)
            {
                if (!string.IsNullOrEmpty(command.Tag))
                {
                    switch (command.Tag)
                    {
                    case "ad":
                        actions.Add(() => Printer.SetAlignRight());
                        actions.Add(() => Printer.WriteLine(command.Value));
                        break;

                    case "/ad":
                        actions.Add(() => Printer.SetAlignLeft());
                        break;

                    case "s":
                        actions.Add(() => Printer.SetUnderline(2));
                        actions.Add(() => Printer.WriteToBuffer(command.Value));
                        break;

                    case "/s":
                        actions.Add(() => Printer.SetUnderline(0));
                        break;

                    case "b":
                        actions.Add(() => Printer.BoldOn());
                        actions.Add(() => Printer.WriteToBuffer(" " + command.Value));
                        break;

                    case "/b":
                        actions.Add(() => Printer.BoldOff());
                        break;

                    case "c":
                        actions.Add(() => Printer.WriteToBuffer(command.Value + " "));
                        break;

                    case "/c":
                        break;

                    case "ce":
                        actions.Add(() => Printer.SetAlignCenter());
                        actions.Add(() => Printer.WriteToBuffer(command.Value));
                        break;

                    case "/ce":
                        actions.Add(() => Printer.SetAlignLeft());
                        break;

                    case "l":
                        actions.Add(() => Printer.LineFeed());
                        break;

                    case "/l":
                        break;

                    case "sl":
                        actions.Add(() => Printer.LineFeed(byte.Parse(command.Value)));
                        break;

                    case "/sl":
                        break;

                    case "gui":
                        actions.Add(() => Printer.Guillotine());
                        break;

                    case "/gui":
                        break;

                    default:
                        actions.Add(() => Printer.WriteToBuffer(command.Value));
                        break;
                    }
                }
                else
                {
                    actions.Add(() => Printer.WriteToBuffer(command.Value));
                }

                actions.Add(() => Printer.SetAlignLeft());
            }

            return(actions);
        }
예제 #3
0
        /// <summary>
        /// parses "FontStyle" for BlockText and TextItem
        /// </summary>
        /// <param name="txt">BlockText or TextItem</param>
        /// <param name="txtData">printer command previous to text</param>
        /// <param name="txtEndData">printer command after text</param>
        /// <returns>Font of text</returns>
        private Font ParseTextFontStyle(object txt, ref StringBuilder txtData, ref StringBuilder txtEndData)
        {
            Font txtFont = printer.DefaultFont;

            if (txt.GetType() != typeof(BlockText) && txt.GetType() != typeof(TextItem))
            {
                return(txtFont);
            }

            string fontData, fontSizeData, charSpacData, fontStyleData, underlinedData, invertedData;

            fontData = fontSizeData = charSpacData = fontStyleData = underlinedData = invertedData = String.Empty;

            //Codeverdopplung wegen "Fehlers" im XML Schema (da Attribut von komplexen Typ nicht möglich)
            //allerdings kann so der FontStyle von TextItem und BlockText unterschiedlich behandelt werden
            if (txt.GetType() == typeof(TextItem))
            {
                if (((TextItem)txt).FontSpecified)
                {
                    txtFont  = ((TextItem)txt).Font;
                    fontData = printer.CharacterFont(((TextItem)txt).Font);//print mode
                }
                if (((TextItem)txt).SizeSpecified)
                {
                    fontSizeData = printer.CharacterSize(((TextItem)txt).Size); //print mode
                }
                if (((TextItem)txt).CharacterspacingSpecified)
                {
                    charSpacData = printer.CharacterSpacing(((TextItem)txt).Characterspacing);
                }

                if (((TextItem)txt).StyleSpecified)
                {
                    if (((TextItem)txt).Style == Style.Bold)
                    {
                        fontStyleData = printer.BoldOn();
                        txtEndData.Append(printer.BoldOff());
                    }
                    else if (((TextItem)txt).Style == Style.Emphasized)
                    {
                        fontStyleData = printer.EmphasizedOn();
                        txtEndData.Append(printer.EmphasizedOff());  //print mode
                    }
                }
                if (((TextItem)txt).UnderlineSpecified)
                {
                    underlinedData = printer.UnderlineOn();
                    txtEndData.Append(printer.UnderlineOff());          //print mode
                }
                if (((TextItem)txt).InvertSpecified)
                {
                    invertedData = printer.InvertedOn();
                    txtEndData.Append(printer.InvertedOff());
                    //((TextItem)txt).Value =
                }
                //calculate text Width
                ((TextItem)txt).TextWidth = ((TextItem)txt).Value != null ? ((TextItem)txt).Value.Length * printer.GetCharWidth(txtFont) * printer.FontWidthFactor : 0;
                //reset to normal:
                txtEndData.Append(printer.CharacterFont(printer.DefaultFont));
                txtEndData.Append(printer.CharacterSize(1));
                txtEndData.Append(printer.CharacterSpacing(0));
            }
            else
            {
                if (((BlockText)txt).FontSpecified)
                {
                    txtFont  = ((BlockText)txt).Font;
                    fontData = printer.CharacterFont(((BlockText)txt).Font);//print mode
                }
                if (((BlockText)txt).SizeSpecified)
                {
                    fontSizeData = printer.CharacterSize(((BlockText)txt).Size); //print mode
                }
                if (((BlockText)txt).CharacterspacingSpecified)
                {
                    charSpacData = printer.CharacterSpacing(((BlockText)txt).Characterspacing);
                    txtEndData.Append(printer.CharacterSpacing(0));
                }
                if (((BlockText)txt).StyleSpecified)
                {
                    if (((BlockText)txt).Style == Style.Bold)
                    {
                        fontStyleData = printer.BoldOn();
                        txtEndData.Append(printer.BoldOff());
                    }
                    else if (((BlockText)txt).Style == Style.Emphasized)
                    {
                        fontStyleData = printer.EmphasizedOn();
                        txtEndData.Append(printer.EmphasizedOff());  //print mode
                    }
                }
                if (((BlockText)txt).UnderlineSpecified)
                {
                    underlinedData = printer.UnderlineOn();
                    txtEndData.Append(printer.UnderlineOff());          //print mode
                }
                if (((BlockText)txt).InvertSpecified)
                {
                    invertedData = printer.InvertedOn();
                    txtEndData.Append(printer.InvertedOff());
                }
            }

            //txtEndData.Append(printer.PrintMode(0));

            txtData.Append(fontData);
            txtData.Append(fontSizeData);
            txtData.Append(charSpacData);
            txtData.Append(fontStyleData);
            txtData.Append(underlinedData);
            txtData.Append(invertedData);

            return(txtFont);
        }