/// <summary> /// load rtf /// </summary> /// <param name="reader">RTF text reader</param> public void Load(RTFReader reader) { MyNodes.Clear(); var groups = new Stack<RTFNodeGroup>(); RTFNodeGroup newGroup = null; RTFNode newNode = null; while (reader.ReadToken() != null) { if (reader.TokenType == RTFTokenType.GroupStart) { // begin group if (newGroup == null) { newGroup = this; } else { newGroup = new RTFNodeGroup(); newGroup.OwnerDocument = this; } if (newGroup != this) { var g = groups.Peek(); g.AppendChild(newGroup); } groups.Push(newGroup); } else if (reader.TokenType == RTFTokenType.GroupEnd) { // end group newGroup = groups.Pop(); newGroup.MergeText(); if (newGroup.FirstNode is RTFNode) { switch (newGroup.Keyword) { case RTFConsts.Fonttbl: // read font table ReadFontTable(newGroup); break; case RTFConsts.Colortbl: // read color table ReadColorTable(newGroup); break; case RTFConsts.Info: // read document information ReadDocumentInfo(newGroup); break; } } if (groups.Count > 0) { newGroup = groups.Peek(); } else { break; } //NewGroup.MergeText(); } else { // read content newNode = new RTFNode(reader.CurrentToken); newNode.OwnerDocument = this; newGroup.AppendChild(newNode); if (newNode.Keyword == RTFConsts.F) { var font = FontTable[newNode.Parameter]; if (font != null) { _myFontChartset = font.Encoding; } else { _myFontChartset = null; } //myFontChartset = RTFFont.GetRTFEncoding( NewNode.Parameter ); } else if (newNode.Keyword == RTFConsts.Af) { var font = FontTable[newNode.Parameter]; if (font != null) { _myAssociateFontChartset = font.Encoding; } else { _myAssociateFontChartset = null; } } } } // while( reader.ReadToken() != null ) while (groups.Count > 0) { newGroup = groups.Pop(); newGroup.MergeText(); } //this.UpdateInformation(); }
/// <summary> /// load rtf /// </summary> /// <param name="reader">RTF text reader</param> public void Load( RTFReader reader ) { myNodes.Clear(); System.Collections.Stack groups = new System.Collections.Stack(); RTFNodeGroup NewGroup = null ; RTFNode NewNode = null; while( reader.ReadToken() != null ) { if( reader.TokenType == RTFTokenType.GroupStart ) { // begin group if( NewGroup == null) { NewGroup = this ; } else { NewGroup = new RTFNodeGroup(); NewGroup.OwnerDocument = this ; } if( NewGroup != this ) { RTFNodeGroup g = ( RTFNodeGroup ) groups.Peek(); g.AppendChild( NewGroup ); } groups.Push( NewGroup ); } else if( reader.TokenType == RTFTokenType.GroupEnd ) { // end group NewGroup = ( RTFNodeGroup ) groups.Pop(); NewGroup.MergeText(); if (NewGroup.FirstNode is RTFNode) { switch (NewGroup.Keyword) { case RTFConsts._fonttbl: // read font table ReadFontTable(NewGroup); break; case RTFConsts._colortbl: // read color table ReadColorTable(NewGroup); break; case RTFConsts._info : // read document information ReadDocumentInfo(NewGroup); break; } } if (groups.Count > 0) { NewGroup = (RTFNodeGroup)groups.Peek(); } else { break; } //NewGroup.MergeText(); } else { // read content NewNode = new RTFNode( reader.CurrentToken ); NewNode.OwnerDocument = this ; NewGroup.AppendChild( NewNode ); if (NewNode.Keyword == RTFConsts._f ) { RTFFont font = this.FontTable[NewNode.Parameter]; if (font != null) { myFontChartset = font.Encoding; } else { myFontChartset = null; } //myFontChartset = RTFFont.GetRTFEncoding( NewNode.Parameter ); } else if (NewNode.Keyword == RTFConsts._af) { RTFFont font = this.FontTable[NewNode.Parameter]; if (font != null) { myAssociateFontChartset = font.Encoding; } else { myAssociateFontChartset = null; } } } }// while( reader.ReadToken() != null ) while( groups.Count > 0 ) { NewGroup = ( RTFNodeGroup ) groups.Pop(); NewGroup.MergeText(); } //this.UpdateInformation(); }
/// <summary> /// load rtf /// </summary> /// <param name="reader">RTF text reader</param> public void Load(RTFReader reader) { myNodes.Clear(); var groups = new System.Collections.Stack(); RTFNodeGroup NewGroup = null; RTFNode NewNode = null; while (reader.ReadToken() != null) { if (reader.TokenType == RTFTokenType.GroupStart) { // begin group if (NewGroup == null) { NewGroup = this; } else { NewGroup = new RTFNodeGroup(); NewGroup.OwnerDocument = this; } if (NewGroup != this) { var g = ( RTFNodeGroup )groups.Peek(); g.AppendChild(NewGroup); } groups.Push(NewGroup); } else if (reader.TokenType == RTFTokenType.GroupEnd) { // end group NewGroup = ( RTFNodeGroup )groups.Pop(); NewGroup.MergeText(); if (NewGroup.FirstNode is RTFNode) { switch (NewGroup.Keyword) { case RTFConsts._fonttbl: // read font table ReadFontTable(NewGroup); break; case RTFConsts._colortbl: // read color table ReadColorTable(NewGroup); break; case RTFConsts._info: // read document information ReadDocumentInfo(NewGroup); break; } } if (groups.Count > 0) { NewGroup = (RTFNodeGroup)groups.Peek(); } else { break; } //NewGroup.MergeText(); } else { // read content NewNode = new RTFNode(reader.CurrentToken); NewNode.OwnerDocument = this; NewGroup.AppendChild(NewNode); if (NewNode.Keyword == RTFConsts._f) { var font = FontTable[NewNode.Parameter]; if (font != null) { myFontChartset = font.Encoding; } else { myFontChartset = null; } //myFontChartset = RTFFont.GetRTFEncoding( NewNode.Parameter ); } else if (NewNode.Keyword == RTFConsts._af) { var font = FontTable[NewNode.Parameter]; if (font != null) { myAssociateFontChartset = font.Encoding; } else { myAssociateFontChartset = null; } } } } // while( reader.ReadToken() != null ) while (groups.Count > 0) { NewGroup = ( RTFNodeGroup )groups.Pop(); NewGroup.MergeText(); } //this.UpdateInformation(); }