示例#1
0
        //string xmlLine1 = "<Line Recurrence=2 LineSpacing=50 UnderLine=true><TextItem>text bla bla<TextItem></Line>";
        /// <summary>
        /// unused test function. parsing xml manually. use XmlPreprocess.Marshaling instead.
        /// </summary>
        /// <param name="xmlLine"></param>
        /// <returns></returns>
        public static Line ParseTextLine(string xmlLine)
        {
            Line item = new Line();

            XmlDocument xDoc = new XmlDocument();

            xDoc.LoadXml(xmlLine);

            /*if (xDoc.HasChildNodes) {
             *  foreach (XmlNode xn in xDoc.ChildNodes) {
             *      Console.WriteLine(" xn =" + xn.Name);
             *      Console.WriteLine(" xn attribs:" + xn.Attributes.Count);
             *
             *
             *      foreach (XmlAttribute xna in xn.Attributes) {
             *          Console.WriteLine("xn attr count:" + xna.GetType().ToString() );
             *          Console.WriteLine("axnode Name:" + xna.Name);
             *          Console.WriteLine("axn Value    :" + xna.Value);
             *      }
             *  }
             * }*/

            Console.WriteLine();
            foreach (XmlNode xNode in xDoc)
            {
                if (xNode.NodeType == XmlNodeType.Attribute)
                {
                    Console.WriteLine("xnode Attrib Name:" + xNode.Name);
                    Console.WriteLine("xnode Attrib Val :" + xNode.Value);
                }
                else if (xNode.NodeType == XmlNodeType.Document)
                {
                    Console.WriteLine("Document type follows..");
                }
                else if (xNode.NodeType == XmlNodeType.Element)
                {
                    Console.WriteLine("Element type follows..");
                    Console.WriteLine("xnode  ELEM Name:" + xNode.Name);
                }

                /*Console.WriteLine("xnode attr count:" + xNode.Attributes.Count);
                 * Console.WriteLine("xnode inner text:" + xNode.InnerText );
                 * Console.WriteLine("xnode child count:" + xNode.ChildNodes.Count );
                 * Console.WriteLine("xnode inner xml:" + xNode.InnerXml );
                 * Console.WriteLine("xnode outerXML :" + xNode.OuterXml );
                 * Console.WriteLine("xnode type:" + xNode.GetType().ToString());
                 */

                Console.WriteLine("attribs:" + xNode.Attributes.Count);
                foreach (XmlNode xn in xNode.Attributes)
                {
                    Console.WriteLine("xnode attribs Name:" + xn.Name);
                    Console.WriteLine("xnode attribs Value    :" + xn.Value);
                }

                foreach (XmlElement xe in xNode.ChildNodes)
                {
                    Console.WriteLine("xnode elem type:" + xe.GetType().ToString());
                    Console.WriteLine("xnode elem Name:" + xe.Name);
                    //Console.WriteLine("xnode elem Val :" + xe.Value);
                    Console.WriteLine("xnode elem childs" + xe.FirstChild.Value);
                }
            }
            Console.WriteLine(" name:" + xDoc.Name);
            Console.WriteLine(" type:" + xDoc.NodeType);
            //			StreamReader reader = new System.IO.StreamReader(
            //System.IO.Stream stream = System.IO.Stream;
            return(item);
        }
示例#2
0
        /// <summary>
        /// parses a Line, Lien can consist of (one or more) TextItem, FillItem, BarcodeItem or ImageItem
        /// </summary>
        /// <param name="line"></param>
        /// <returns>printer command for Line-part of SPF-object</returns>
        private StringBuilder ParseLine(Line line)
        {
            if (line.Items == null || line.Items.Length <= 0)
            {
                return(null);
            }

            StringBuilder lineData        = new StringBuilder();
            List <object> textAndFillItem = new List <object>();
            List <int>    textWidth       = new List <int>();
            int           txtWidthSum     = 0;
            int           numFillItems    = 0;

            int  recurrence = 0;
            bool underline  = false;

            if (line.RecurrenceSpecified)
            {
                recurrence = line.Recurrence;
            }
            if (line.UnderlineSpecified)
            {
                underline = line.Underline;
            }

            lineData.Append(printer.LineFeed());

            if (line.LineSpacingSpecified)
            {
                lineData.Append(printer.LineSpacing(line.LineSpacing));
            }
            else
            {
                lineData.Append(printer.LineSpacingDefault());
            }
            if (underline)
            {
                lineData.Append(printer.UnderlineOn());
            }


            foreach (Object item in line.Items)
            {
                if (item.GetType() == typeof(ImageItem))
                {
                    ImageItem image = item as ImageItem;
                    lineData.Append(ParseImageItem(image));
                }
                if (item.GetType() == typeof(BarCodeItem))
                {
                    BarCodeItem bc = item as BarCodeItem;
                    lineData.Append(ParseBarCodeItem(bc));
                    lineData.Append(printer.AbsoluteHorizontalPosition(0));
                }
                if (item.GetType() == typeof(TextItem))
                {
                    TextItem txt = item as TextItem;
                    ParseTextItem(txt);                 //set some properties oft txt TextItem
                    textAndFillItem.Add(txt);
                    //textWidth.Add(txt.TextWidth);
                    txtWidthSum += txt.TextWidth;
                    //lineData.Append(ParseTextItem(txt));
                }
                if (item.GetType() == typeof(FillItem))
                {
                    FillItem fill = item as FillItem;
                    textAndFillItem.Add(fill);
                    numFillItems++;
                    //lineData.Append(ParseFillItem(fill));
                }
            }

            #region Append printer command for text and fill items (stored in textAndFillItem List).
            // quite simple when there are no fill items (else condition). Mixed lists will be parsed until the first
            // textItem with special position (indent, align center|right), appended and this is repeated with the remaining list items.
            if (numFillItems > 0)
            {
                Font   fillFont = printer.DefaultFont; //fill font will be font of previous text item or defaultfont
                int    i = 0, old_i = 0, remain = textAndFillItem.Count;
                int    leftPosAfter = 0;               //!?
                double fullSpace    = 0.0;
                int    specialTextPosInd;
                int    fillWidth   = 0;
                int    unusedWidth = 0;         //should always be 0 except when mixing fonts or fontB with Indent

                do
                {                       //try to arragne mixture fo text and fill items
                    specialTextPosInd = textAndFillItem.GetRange(old_i, remain).FindIndex(IsSpecialPosTextItem) + old_i;
                    if (specialTextPosInd < 0)
                    {                                              //no special positioned text in line
                        specialTextPosInd = textAndFillItem.Count; //parse all
                        fullSpace         = printer.DotsPerLine - leftPosAfter;
                    }
                    else
                    {
                        int leftPosTmp = ((TextItem)textAndFillItem[specialTextPosInd]).LeftPos;
                        fullSpace    = leftPosTmp - leftPosAfter;
                        leftPosAfter = leftPosTmp + ((TextItem)textAndFillItem[specialTextPosInd]).TextWidth;
                        txtWidthSum  = 0;
                        foreach (object item in textAndFillItem.GetRange(old_i, specialTextPosInd - old_i).FindAll(IsTextItem))
                        {
                            txtWidthSum += ((TextItem)item).TextWidth;
                        }
                        numFillItems = textAndFillItem.GetRange(old_i, specialTextPosInd - old_i).FindAll(delegate(object o) { return(o.GetType() == typeof(FillItem)); }).Count;
                    }

                    float fillSpace = ((float)fullSpace - txtWidthSum) / numFillItems + unusedWidth;//standard fill
                    //foreach (object item in textAndFillItem) {
                    for (i = old_i; i <= specialTextPosInd && i < textAndFillItem.Count; i++)
                    {
                        if (textAndFillItem[i].GetType() == typeof(TextItem))
                        {
                            TextItem txtItem = textAndFillItem[i] as TextItem;
                            lineData.Append(txtItem.TextPrinterData);
                            if (txtItem.FontSpecified)
                            {
                                fillFont = txtItem.Font;
                            }
                        }
                        else if (textAndFillItem[i].GetType() == typeof(FillItem))
                        {
                            lineData.Append(ParseFillItem((FillItem)textAndFillItem[i], (int)fillSpace, fillFont, out fillWidth));
                            unusedWidth = (int)fillSpace - fillWidth;
                        }
                    }
                    //if fillWidth < fillSpace (due to FontB in special cases) filling is not 100% excat

                    old_i  = specialTextPosInd + 1;             //first not printed item
                    remain = textAndFillItem.Count - i;
                } while (specialTextPosInd < textAndFillItem.Count && remain > 0);
            }
            else
            {                           //no fillitems
                if (textAndFillItem != null)
                {
                    int leftPos = 0;
                    foreach (Object item in textAndFillItem)
                    {
                        if (item.GetType() == typeof(TextItem))
                        {  //must be
                            TextItem txtItem = item as TextItem;
                            if (txtItem.LeftPos > 0)
                            {
                                txtItem.LeftPos = LeftPosText(leftPos, txtItem);
                                lineData.Append(printer.AbsoluteHorizontalPosition(txtItem.LeftPos));
                            }
                            lineData.Append(txtItem.TextPrinterData);
                            leftPos += txtItem.LeftPos + txtItem.TextWidth;
                        }
                    }
                }

                if (underline)
                {               //only fillitem free lines have to be underlined 'manually'
                    lineData.Append(printer.AbsoluteHorizontalPosition(0));
                    lineData.Append(printer.CharacterFont(printer.DefaultFont));
                    for (int i = 0; i < printer.MaxTab - 1; i++)
                    {
                        lineData.Append(" ");
                    }
                }
            }
            #endregion

            if (underline)
            {
                lineData.Append(printer.UnderlineOff());
            }

            if (recurrence > 0)
            {
                StringBuilder manyLines = new StringBuilder(lineData.Length * recurrence);
                for (int j = 0; j < recurrence; j++)
                {
                    manyLines.Append(lineData);
                }
                lineData.Append(manyLines);
            }

            return(lineData);
        }