コード例 #1
0
            public bool Parse(AojPrintXmlReader aojXmlReader)
            {
                #region  对传进来的读取器包含的Cell属性进行赋值
                //对传进来的读取器包含的Cell属性进行赋值
                Hashtable hstCell = aojXmlReader.Attributes;
                this.Id = AojUnitConvert.SafeToString(hstCell, "Id", "CellGroup");
                this.X = AojUnitConvert.SafeToInt(hstCell, "PositionX", 0);
                this.Y = AojUnitConvert.SafeToInt(hstCell, "PositionY", 0);
                this.Width = AojUnitConvert.SafeToInt(hstCell, "Width", 0);
                this.Height = AojUnitConvert.SafeToInt(hstCell, "Height", 0);

                this.ColSpan = AojUnitConvert.SafeToInt(hstCell, "ColSpan", 1);

                this.BorderStyle = AojUnitConvert.SafeToString(hstCell, "BorderStyle", this.BorderStyle);
                this.BorderWidth = AojUnitConvert.SafeToSingle(hstCell, "BorderWidth", this.BorderWidth);
                this.BorderColor = AojUnitConvert.SafeToString(hstCell, "BorderColor", this.BorderColor);
                this.BackgroundStyle = AojUnitConvert.SafeToString(hstCell, "BackStyle", this.BackgroundStyle);
                this.BackgroundColor = AojUnitConvert.SafeToString(hstCell, "BackColor", this.BackgroundColor);
                this.BackgroundShape = AojUnitConvert.SafeToString(hstCell, "Shape", this.BackgroundShape);

                this.Alignment = AojUnitConvert.SafeToString(hstCell, "Alignment", this.Alignment);
                this.FontDisplayFormat = AojUnitConvert.SafeToString(hstCell, "Format", this.FontDisplayFormat);
                #endregion

                while (aojXmlReader.Read())
                {
                    //碰到结束节点说明,本Cell的Tag已经读取结束
                    if (aojXmlReader.IsEndElement("Cell"))
                    {
                        break;
                    }
                    switch (aojXmlReader.TagType)
                    {
                        //读取Cell节点下的文本内容
                        case XmlNodeType.Text:
                            {
                                this.Value = aojXmlReader.TagContent;
                            }
                            break;
                        //读取Cell节点下的子节点下的属性
                        //Cell下面的Tag有:
                        //      Text
                        case XmlNodeType.Element:
                            {
                                if (aojXmlReader.TagName == "Text")
                                {
                                    Hashtable hstFont = aojXmlReader.Attributes;
                                    this.FontFamilyName = AojUnitConvert.SafeToString(hstFont, "Name", this.FontFamilyName);
                                    this.FontSize = AojUnitConvert.SafeToSingle(hstFont, "Size", this.FontSize);
                                    this.FontStyle = AojUnitConvert.SafeToInt(hstFont, "Style", this.FontStyle);
                                    this.FontColor = AojUnitConvert.SafeToString(hstFont, "Color", this.FontColor);
                                    this.ViewFormat = AojUnitConvert.SafeToInt(hstFont, "ViewFormat", this.ViewFormat);
                                }
                            }
                            break;
                    }
                }
                return true;
            }
コード例 #2
0
        public bool Parse(AojPrintXmlReader aojXmlReader)
        {
            #region 对传进来的读取器包含的Table属性进行赋值
            //对传进来的读取器包含的Table属性进行赋值
            Hashtable hstTable = aojXmlReader.Attributes;
            this.Id = AojUnitConvert.SafeToString(hstTable, "Id", "TableGroup");
            this.X = AojUnitConvert.SafeToInt(hstTable, "PositionX", 0);
            this.Y = AojUnitConvert.SafeToInt(hstTable, "PositionY", 0);
            this.Width = AojUnitConvert.SafeToInt(hstTable, "Width", 0);
            this.Height = AojUnitConvert.SafeToInt(hstTable, "Height", 0);

            _nCurrentX = this.X;
            _nCurrentY = this.Y;

            this.BorderStyle = AojUnitConvert.SafeToString(hstTable, "BorderStyle", this.BorderStyle);
            this.BorderWidth = AojUnitConvert.SafeToSingle(hstTable, "BorderWidth", this.BorderWidth);
            this.BorderColor = AojUnitConvert.SafeToString(hstTable, "BorderColor", this.BorderColor);
            this.BackgroundStyle = AojUnitConvert.SafeToString(hstTable, "BackStyle", this.BackgroundStyle);
            this.BackgroundColor = AojUnitConvert.SafeToString(hstTable, "BackColor", this.BackgroundColor);

            #endregion

            /**
             * 需要区分行列的情况
             * 表对象的格式指定是
             * 表名.列名.行名
             * 如:G1.c1.r2
             */
            while (aojXmlReader.Read())
            {
                if (aojXmlReader.IsEndElement("Table"))
                {
                    break;
                }
                switch (aojXmlReader.TagName)
                {
                    case "Column":
                        {
                            //读取列信息
                            _parseColumn(aojXmlReader);
                        }
                        break;
                    case "Row":
                        {
                            //读取行信息
                            _parseRow(aojXmlReader);
                            //横轴复位
                            _nCurrentX = this.X;
                        }
                        break;
                }
            }
            this._validateCell();
            return true;
        }
コード例 #3
0
        public bool Parse(AojPrintXmlReader aojXmlReader)
        {
            #region 属性的读取
            //对传进来的读取器包含的Image属性进行赋值
            Hashtable hstImage = aojXmlReader.Attributes;
            this.Id = AojUnitConvert.SafeToString(hstImage, "Id", "ImageGroup");
            this.X = AojUnitConvert.SafeToInt(hstImage, "PositionX", 0);
            this.Y = AojUnitConvert.SafeToInt(hstImage, "PositionY", 0);
            this.Width = AojUnitConvert.SafeToInt(hstImage, "Width", 0);
            this.Height = AojUnitConvert.SafeToInt(hstImage, "Height", 0);

            this.BorderStyle = AojUnitConvert.SafeToString(hstImage, "BorderStyle", this.BorderStyle);
            this.BorderWidth = AojUnitConvert.SafeToSingle(hstImage, "BorderWidth", this.BorderWidth);
            this.BorderColor = AojUnitConvert.SafeToString(hstImage, "BorderColor", this.BorderColor);
            this.BackgroundStyle = AojUnitConvert.SafeToString(hstImage, "BackStyle", this.BackgroundStyle);
            this.BackgroundColor = AojUnitConvert.SafeToString(hstImage, "BackColor", this.BackgroundColor);
            this.BackgroundShape = AojUnitConvert.SafeToString(hstImage, "Shape", this.BackgroundShape);

            this.ImageMode = AojUnitConvert.SafeToString(hstImage, "ImageMode", this.ImageMode);
            #endregion

            //图片存在形式是,文件路径还是base64格式的字符串
            ImageFlags imageFlags = AojUnitConvert.GetEnumType<ImageFlags,string>(this.ImageMode);

            #region 读取Base64编码的图片字符串或图片物理路径
            while (aojXmlReader.Read())
            {
                //读到Image结束节点后退出该循环
                if (aojXmlReader.IsEndElement("Image"))
                {
                    break;
                }

                switch (aojXmlReader.TagType)
                {
                    case XmlNodeType.Text:
                        {
                            //存储的图片字符串
                            this.Value = aojXmlReader.TagContent;
                        }
                        break;
                    case XmlNodeType.Element:
                        {
                             if (aojXmlReader.TagName == "Text")
                             {
                                 //存储的文件路径
                                 Hashtable hstText = aojXmlReader.Attributes;
                                 //读取路径,无效则为空
                                 this.Src = AojUnitConvert.SafeToString(hstText, "Src",string.Empty);
                             }
                        }
                        break;
                }
            }
            #endregion

            #region 读取图片并生成图片

            switch (imageFlags)
            {
                case ImageFlags.Cache:
                    {
                        //文件中Base64的存储模式
                        this.ImgPrint = AojUnitConvert.ImageFromBase64String(aojXmlReader.TagContent);
                    }
                    break;
                case ImageFlags.File:
                    {
                        //从Src中的读取图片
                        this.ImgPrint = AojUnitConvert.ImageFromFile(this.Src);
                    }
                    break;
                default:
                    {
                        this.ImgPrint = null;
                    }
                    break;
            }

            #endregion

            return true;
        }
コード例 #4
0
        public bool Parse(AojPrintXmlReader aojXmlReader)
        {
            //Paper节点访问后得到的属性
            Hashtable hstPaper = aojXmlReader.Attributes;
            //如果本paper没有Id则默认为Group
            this._id = AojUnitConvert.SafeToString(hstPaper, "Id", "PaperGroup");
            this._width = AojUnitConvert.SafeToInt(hstPaper, "Width", 596);
            this._height = AojUnitConvert.SafeToInt(hstPaper, "Height", 840);
            this._paperSizeName = AojUnitConvert.SafeToString(hstPaper, "PaperSizeName", "A4");
            this._orientation = AojUnitConvert.SafeToString(hstPaper, "Orientation", "Portrait");
            this._margin = AojUnitConvert.SafeToInt(hstPaper, "Margin", 1);

            while (aojXmlReader.Read())
            {
                //当读取器读到结束节点为AojPaper时,说明一张页面已经读取完毕
                //然后由AojPrint类,继续读取进行下一轮的Paper创建
                if (aojXmlReader.IsEndElement("AojPaper"))
                {
                    break;
                }
                switch (aojXmlReader.TagName)
                {
                    case "Label":
                        {
                            //读到Label节点时,进行Label节点属性的读取
                            AojPrintLabel printLabel = new AojPrintLabel();
                            printLabel.Parse(aojXmlReader);
                            this._objectArray.Add(printLabel);
                        }
                        break;
                    case "Image":
                        {
                            //读到Image节点时,进行Image节点属性的读取
                            AojPrintImage printImage = new AojPrintImage();
                            printImage.Parse(aojXmlReader);
                            this._objectArray.Add(printImage);
                        }
                        break;
                    case "Table":
                        {
                            //读到Table节点时,进行Table节点属性的读取
                            AojPrintTable printTable = new AojPrintTable();
                            printTable.Parse(aojXmlReader);
                            this._objectArray.Add(printTable);
                        }
                        break;
                    default:  //查找自定义插件中的对象
                        {
                            AojPrintSettings settings= AojPrintSettings.CreateInstance();
                            KeyValuePair<string,object> CurrentPlugin =settings.lstPlugin.Find((plk) => plk.Key == aojXmlReader.TagName);
                            if (CurrentPlugin.Value is IAojPrintObjectParse)
                            {
                                IAojPrintObjectParse aojPluginObject= (IAojPrintObjectParse)CurrentPlugin.Value;
                                //用此类库Parse完后保存在对象集合中
                                aojPluginObject.Parse(aojXmlReader);
                                this._objectArray.Add(aojPluginObject);
                                //因为该类对象的所有操作后,属性系统都为引用,因此要Clone一下
                                this._objectArray = (ArrayList)this._objectArray.Clone();
                            }
                        }
                        break;
                }
            }
            return true;
        }
コード例 #5
0
        private void _parseRow(AojPrintXmlReader _aojXmlReader)
        {
            Row r = new Row();
            Hashtable hstRow = _aojXmlReader.Attributes;
            r.Height = AojUnitConvert.SafeToInt(hstRow, "Height", 0);
            this.Rows.Add(r);

            //当前某行的单元格起始index
            int _cellStart = 0;

            while (_aojXmlReader.Read())
            {
                 //碰到结束节点说明,本Label的Tag已经读取结束
                if (_aojXmlReader.IsEndElement("Row"))
                {
                    break;
                }
                switch (_aojXmlReader.TagType)
                {
                    case XmlNodeType.Element:
                        {
                            Cell cell = new Cell();
                            //设定当前列
                            cell.CurrentColumn = _cellStart;
                            if (cell.Parse(_aojXmlReader))
                            {
                                cell.X = cell.X != 0 ? cell.X : _nCurrentX;
                                cell.Y = cell.Y != 0 ? cell.Y : _nCurrentY;
                                //设置宽度   考虑组合行的关系
                                //处理表格合并打印
                                //
                                if (cell.ColSpan != 1)
                                {
                                    for (int iIndex = 0; iIndex < cell.ColSpan; iIndex++)
                                    {
                                        //
                                        if (_cellStart + 1 > this.Columns.Count)
                                        {
                                            break;
                                        }
                                        //当前cell的宽度为合并的几个单元格宽度的和
                                        cell.Width += this.Columns[_cellStart].Width;
                                        _cellStart += 1;
                                    }
                                }
                                else
                                {
                                    cell.Width = this.Columns[_cellStart].Width;
                                    _cellStart += 1;
                                }
                                //横坐标根据单元格宽度增长,直到转行(新行)时复位
                                _nCurrentX += cell.Width;
                                //列高
                                cell.Height = r.Height;
                                //当前所在行
                                cell.CurrentRow = this.Rows.Count - 1;
                                this.Cells.Add(cell);
                            }
                            else
                            {
                                cell = null;
                            }
                        }
                        break;
                }
            }
            //当前Row的横坐标
            _nCurrentY += r.Height;
        }
コード例 #6
0
 private void _parseColumn(AojPrintXmlReader _aojXmlReader)
 {
     if (_aojXmlReader.IsEndElement("Column"))
     {
         return;
     }
     Column col = new Column();
     Hashtable hstCol = _aojXmlReader.Attributes;
     col.Id = AojUnitConvert.SafeToString(hstCol, "Id", "ColumnGroup");
     col.Width = AojUnitConvert.SafeToInt(hstCol, "Width", 0);
     this.Columns.Add(col);
 }