Ejemplo n.º 1
0
        public DomElementList ImportContent(DomDocument document)
        {
            DomElementList result = new DomElementList();

            ReadContent(
                _RTFDocument,
                document,
                result,
                new DocumentFormatInfo());
            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 添加一个替换多个元素的撤销信息
 /// </summary>
 /// <param name="container">容器对象</param>
 /// <param name="index">操作区域开始编号</param>
 /// <param name="oldElements">旧元素列表</param>
 /// <param name="newElements">新元素列表</param>
 public void AddReplaceElements(
     DomContainerElement container,
     int index,
     DomElementList oldElements,
     DomElementList newElements)
 {
     if (this.CanLog)
     {
         XTextUndoReplaceElements undo = new XTextUndoReplaceElements(
             container,
             index,
             oldElements,
             newElements);
         undo.Document = this.Document;
         undo.InGroup  = true;
         this.Add(undo);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 添加一个插入元素操作信息
 /// </summary>
 /// <param name="c">容器元素</param>
 /// <param name="index">插入的序号</param>
 /// <param name="element">插入的元素</param>
 public void AddInsertElement(DomContainerElement c, int index, DomElement element)
 {
     if (CanLog)
     {
         DomElementList list = new DomElementList();
         list.Add(element);
         XTextUndoReplaceElements undo = new XTextUndoReplaceElements(c, index, null, list);
         undo.Document = this.Document;
         undo.InGroup  = true;
         this.Add(undo);
         //XTextUndoInsertElement undo = new XTextUndoInsertElement();
         //undo.Document = this.myDocument ;
         //undo.Element = element ;
         //undo.Container = c ;
         //undo.Index = index ;
         //this.Add( undo );
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 添加一个删除多个元素的撤销信息
        /// </summary>
        /// <param name="c">容器对象</param>
        /// <param name="index">删除区域开始编号</param>
        /// <param name="list">删除的元素</param>
        public void AddRemoveElements(
            DomContainerElement c,
            int index,
            DomElementList list)
        {
            if (CanLog)
            {
                XTextUndoReplaceElements undo = new XTextUndoReplaceElements(c, index, list, null);
                undo.Document = this.Document;
                undo.InGroup  = true;
                this.Add(undo);

                //XTextUndoRemoveElements undo = new XTextUndoRemoveElements( );
                //undo.Document = this.myDocument ;
                //undo.Container = c ;
                //undo.Index = index ;
                //undo.Items.AddRange( list );
                //this.Add( undo );
            }
        }
Ejemplo n.º 5
0
 public DomTable()
 {
     Columns = new DomElementList();
 }
Ejemplo n.º 6
0
        private void ReadContent(
            RTFDomElement parentNode,
            DomDocument doc,
            DomElementList result,
            DocumentFormatInfo format)
        {
            if (format == null)
            {
                format = new DocumentFormatInfo();
            }
            //if ( parentNode == null || parentNode.Elements == null)
            //{
            //    System.Console.WriteLine("");
            //    return;
            //}
            foreach (RTFDomElement element in parentNode.Elements)
            {
                if (element is RTFDomHeader)
                {
                    if (((RTFDomHeader)element).HasContentElement)
                    {
                        XTextDocumentHeaderElement header = new XTextDocumentHeaderElement();
                        doc.PageSettings.HeaderDistance = (int)(GraphicsUnitConvert.FromTwips(
                                                                    (double)this._RTFDocument.HeaderDistance,
                                                                    GraphicsUnit.Inch) * 100.0);
                        result.Add(header);
                        ReadContent(element, doc, header.Elements, format);
                    }
                }
                else if (element is RTFDomFooter)
                {
                    if (((RTFDomFooter)element).HasContentElement)
                    {
                        XTextDocumentFooterElement footer = new XTextDocumentFooterElement();
                        doc.PageSettings.FooterDistance = (int)(GraphicsUnitConvert.FromTwips(
                                                                    (double)this._RTFDocument.FooterDistance,
                                                                    GraphicsUnit.Inch) * 100.0);
                        result.Add(footer);
                        ReadContent(element, doc, footer.Elements, format);
                    }
                }
                else if (element is RTFDomParagraph)
                {
                    RTFDomParagraph domP = (RTFDomParagraph)element;
                    //XTextParagraph p = new XTextParagraph();
                    //p.OwnerDocument = doc;
                    DocumentContentStyle style = ToDocumentContentStyle(
                        domP.Format,
                        doc.DocumentGraphicsUnit);
                    ReadContent(element, doc, result, domP.Format);

                    if (domP.IsTemplateGenerated == false ||
                        this.ImportTemplateGenerateParagraph)
                    {
                        DomParagraphFlagElement eof = new DomParagraphFlagElement();
                        eof.StyleIndex = doc.ContentStyles.GetStyleIndex(style);
                        result.Add(eof);
                    }
                }
                else if (element is RTFDomText)
                {
                    RTFDomText domText = (RTFDomText)element;
                    if (domText.Format.Hidden == false &&
                        domText.Text != null &&
                        domText.Text.Length > 0)
                    {
                        DocumentContentStyle style = ToDocumentContentStyle(
                            domText.Format,
                            doc.DocumentGraphicsUnit);
                        int si = doc.ContentStyles.GetStyleIndex(style);
                        result.AddRange(doc.CreateChars(domText.Text, si));
                    }
                }
                else if (element is RTFDomImage)
                {
                    // 插入图片
                    RTFDomImage     domImg = (RTFDomImage)element;
                    DomImageElement img    = new DomImageElement();
                    img.OwnerDocument = doc;
                    img.Image         = new XImageValue(domImg.Data);
                    DocumentContentStyle style = ToDocumentContentStyle(
                        domImg.Format,
                        doc.DocumentGraphicsUnit);
                    img.StyleIndex = doc.ContentStyles.GetStyleIndex(style);
                    img.Width      = GraphicsUnitConvert.FromTwips(domImg.Width, doc.DocumentGraphicsUnit);
                    img.Height     = GraphicsUnitConvert.FromTwips(domImg.Height, doc.DocumentGraphicsUnit);
                    result.Add(img);
                }


                else if (element is RTFDomShape)
                {
                }
                else if (element is RTFDomShapeGroup)
                {
                }
                else if (element is RTFDomLineBreak)
                {
                    // 软回车
                    result.Add(new DomLineBreakElement());// doc.CreateLineBreak());
                }

                else if (element.Elements != null &&
                         element.Elements.Count > 0)
                {
                    ReadContent(element, doc, result, format.Clone());
                }
            }//foreach
        }