} // DoTagFound // ---------------------------------------------------------------------- public void TextFound(IRtfText text) { if (text != null) { DoTextFound(text); } } // TextFound
} // VisitGroup public void VisitText(IRtfText text) { if (text != null) { DoVisitText(text); } } // VisitText
} // DoTagFound // ---------------------------------------------------------------------- public void TextFound( IRtfText text ) { if ( text != null ) { DoTextFound( text ); } } // TextFound
// ---------------------------------------------------------------------- public void VisitText( IRtfText text ) { if ( text != null ) { DoVisitText( text ); } }
} // DoTagFound // ---------------------------------------------------------------------- protected override void DoTextFound(IRtfText text) { if (curGroup == null) { return; } curGroup.WritableContents.Add(text); } // DoTextFound
} // DoTagFound // ---------------------------------------------------------------------- protected override void DoTextFound(IRtfText text) { if (this.curGroup == null) { throw new RtfStructureException(Strings.MissingGroupForNewText); } this.curGroup.WritableContents.Add(text); } // DoTextFound
} // DoTagFound // ---------------------------------------------------------------------- protected override void DoTextFound( IRtfText text ) { if ( this.curGroup == null ) { throw new RtfStructureException( Strings.MissingGroupForNewText ); } this.curGroup.WritableContents.Add( text ); } // DoTextFound
} // NotifyTagFound protected void NotifyTextFound(IRtfText text) { if (_listeners != null) { foreach (IRtfParserListener listener in _listeners) { listener.TextFound(text); } } } // NotifyTextFound
} // DoVisitTag // ---------------------------------------------------------------------- protected override void DoVisitText(IRtfText text) { if (text.Text.Contains("ZhihuPro_Uploaded_")) { importFileName = text.Text; } else { imageDataHex = text.Text; } } // DoVisitText
} // DoVisitTag // ---------------------------------------------------------------------- protected override void DoVisitText(IRtfText text) { if (RtfSpec.TagDelimiter.Equals(text.Text)) { colorTable.Add(new RtfColor(curRed, curGreen, curBlue)); curRed = 0; curGreen = 0; curBlue = 0; } else { throw new RtfColorTableFormatException(Strings.ColorTableUnsupportedText(text.Text)); } } // DoVisitText
} // DoVisitTag // ---------------------------------------------------------------------- protected override void DoVisitText( IRtfText text ) { if ( RtfSpec.TagDelimiter.Equals( text.Text ) ) { this.colorTable.Add( new RtfColor( curRed, curGreen, curBlue ) ); this.curRed = 0; this.curGreen = 0; this.curBlue = 0; } else { throw new RtfColorTableFormatException( Strings.ColorTableUnsupportedText( text.Text ) ); } } // DoVisitText
} // DoTagFound // ---------------------------------------------------------------------- protected override void DoTextFound(IRtfText text) { if (this.settings.Enabled && !string.IsNullOrEmpty(this.settings.ParseTextText)) { string msg = text.Text; if (msg.Length > this.settings.TextMaxLength && !string.IsNullOrEmpty(this.settings.TextOverflowText)) { msg = msg.Substring(0, msg.Length - this.settings.TextOverflowText.Length) + this.settings.TextOverflowText; } WriteLine(string.Format( CultureInfo.InvariantCulture, this.settings.ParseTextText, msg)); } } // DoTextFound
} // DoTagFound // ---------------------------------------------------------------------- protected override void DoTextFound(IRtfText text) { if (settings.Enabled && logger.IsInfoEnabled && !string.IsNullOrEmpty(settings.ParseTextText)) { string msg = text.Text; if (msg.Length > settings.TextMaxLength && !string.IsNullOrEmpty(settings.TextOverflowText)) { msg = msg.Substring(0, msg.Length - settings.TextOverflowText.Length) + settings.TextOverflowText; } Log(string.Format( CultureInfo.InvariantCulture, settings.ParseTextText, msg)); } } // DoTextFound
} // IRtfElementVisitor.VisitGroup // ---------------------------------------------------------------------- void IRtfElementVisitor.VisitText(IRtfText text) { switch (Context.State) { case RtfInterpreterState.Init: throw new RtfStructureException(Strings.InvalidInitTextState(text.Text)); case RtfInterpreterState.InHeader: Context.State = RtfInterpreterState.InDocument; break; case RtfInterpreterState.InDocument: break; } NotifyInsertText(text.Text); } // IRtfElementVisitor.VisitText
} // IRtfElementVisitor.VisitGroup // ---------------------------------------------------------------------- void IRtfElementVisitor.VisitText(IRtfText text) { switch (Context.State) { case RtfInterpreterState.Init: throw new RtfStructureException(Strings.InvalidInitTextState(text.Text)); case RtfInterpreterState.InHeader: // allow spaces in between header tables if (!string.IsNullOrEmpty(text.Text.Trim())) { Context.State = RtfInterpreterState.InDocument; } break; case RtfInterpreterState.InDocument: break; } NotifyInsertText(text.Text); } // IRtfElementVisitor.VisitText
} // IRtfElementVisitor.VisitGroup // ---------------------------------------------------------------------- void IRtfElementVisitor.VisitText(IRtfText text) { switch (Context.State) { case RtfInterpreterState.Init: throw new RtfStructureException(Strings.InvalidInitTextState(text.Text)); case RtfInterpreterState.InHeader: // allow spaces in between header tables // Added because untrimmed spaces were cause premature jump from header to document state and causing color problems. var t = text.Text != null?text.Text.Trim() : ""; if (!string.IsNullOrEmpty(t)) { Context.State = RtfInterpreterState.InDocument; } break; case RtfInterpreterState.InDocument: break; } NotifyInsertText(text.Text); } // IRtfElementVisitor.VisitText
} // DoVisitTag // ---------------------------------------------------------------------- protected override void DoVisitText( IRtfText text ) { this.fontNameBuffer.Append( text.Text ); } // DoVisitText
// ---------------------------------------------------------------------- void IRtfElementVisitor.VisitText( IRtfText text ) { switch ( Context.State ) { case RtfInterpreterState.Init: throw new RtfStructureException( Strings.InvalidInitTextState( text.Text ) ); case RtfInterpreterState.InHeader: Context.State = RtfInterpreterState.InDocument; break; case RtfInterpreterState.InDocument: break; } NotifyInsertText( text.Text ); }
// ---------------------------------------------------------------------- protected override void DoVisitText( IRtfText text ) { buffer.Append( text.Text ); }
} // Reset // ---------------------------------------------------------------------- protected override void DoVisitText(IRtfText text) { buffer.Append(text.Text); } // DoVisitText
} // DoTagFound protected override void DoTextFound(IRtfText text) { _curGroup?.WritableContents.Add(text); } // DoTextFound
// ---------------------------------------------------------------------- protected override void DoVisitText( IRtfText text ) { imageDataHex = text.Text; }
} // DoVisitTag // ---------------------------------------------------------------------- protected override void DoVisitText(IRtfText text) { imageDataHex = text.Text; } // DoVisitText
// ---------------------------------------------------------------------- void IRtfElementVisitor.VisitText( IRtfText text ) { switch ( Context.State ) { case RtfInterpreterState.Init: throw new RtfStructureException( Strings.InvalidInitTextState( text.Text ) ); case RtfInterpreterState.InHeader: // allow spaces in between header tables if ( !string.IsNullOrEmpty( text.Text.Trim() ) ) { Context.State = RtfInterpreterState.InDocument; } break; case RtfInterpreterState.InDocument: break; } NotifyInsertText( text.Text ); }
} // VisitGroupChildren protected virtual void DoVisitText(IRtfText text) { } // DoVisitText
} // DoVisitTag // ---------------------------------------------------------------------- protected override void DoVisitText(IRtfText text) { this.fontNameBuffer.Append(text.Text); } // DoVisitText
// ---------------------------------------------------------------------- protected virtual void DoVisitText( IRtfText text ) { }
// ---------------------------------------------------------------------- protected virtual void DoTextFound( IRtfText text ) { }
// ---------------------------------------------------------------------- protected override void DoTextFound( IRtfText text ) { if ( settings.Enabled && logger.IsInfoEnabled && !string.IsNullOrEmpty( settings.ParseTextText ) ) { string msg = text.Text; if ( msg.Length > settings.TextMaxLength && !string.IsNullOrEmpty( settings.TextOverflowText ) ) { msg = msg.Substring( 0, msg.Length - settings.TextOverflowText.Length ) + settings.TextOverflowText; } Log( string.Format( CultureInfo.InvariantCulture, settings.ParseTextText, msg ) ); } }
} // IRtfElementVisitor.VisitTag // ---------------------------------------------------------------------- void IRtfElementVisitor.VisitGroup(IRtfGroup group) { string groupDestination = group.Destination; switch (Context.State) { case RtfInterpreterState.Init: if (RtfSpec.TagRtf.Equals(groupDestination)) { VisitChildrenOf(group); } else { throw new RtfStructureException(Strings.InvalidInitGroupState(groupDestination)); } break; case RtfInterpreterState.InHeader: switch (groupDestination) { case RtfSpec.TagFontTable: fontTableBuilder.VisitGroup(group); break; case RtfSpec.TagColorTable: colorTableBuilder.VisitGroup(group); break; case RtfSpec.TagGenerator: // last group with a destination in header, but no need to process its contents Context.State = RtfInterpreterState.InDocument; IRtfText generator = group.Contents.Count == 3 ? group.Contents[2] as IRtfText : null; if (generator != null) { string generatorName = generator.Text; Context.Generator = generatorName.EndsWith(";") ? generatorName.Substring(0, generatorName.Length - 1) : generatorName; } else { throw new RtfInvalidDataException(Strings.InvalidGeneratorGroup(group.ToString())); } break; case RtfSpec.TagPlain: case RtfSpec.TagParagraphDefaults: case RtfSpec.TagSectionDefaults: case RtfSpec.TagUnderLineNone: case null: // <tags>: special tags commonly used to reset state in a beginning group. necessary to recognize // state transition form header to document in case no other mechanism detects it and the // content starts with a group with such a 'destination' ... // 'null': group without destination cannot be part of header, but need to process its contents Context.State = RtfInterpreterState.InDocument; if (!group.IsExtensionDestination) { VisitChildrenOf(group); } break; } break; case RtfInterpreterState.InDocument: switch (groupDestination) { case RtfSpec.TagUserProperties: userPropertyBuilder.VisitGroup(group); break; case RtfSpec.TagInfo: documentInfoBuilder.VisitGroup(group); break; case RtfSpec.TagUnicodeAlternativeChoices: IRtfGroup alternativeWithUnicodeSupport = group.SelectChildGroupWithDestination(RtfSpec.TagUnicodeAlternativeUnicode); if (alternativeWithUnicodeSupport != null) { // there is an alternative with unicode formatted content -> use this VisitChildrenOf(alternativeWithUnicodeSupport); } else { // try to locate the alternative without unicode -> only ANSI fallbacks IRtfGroup alternativeWithoutUnicode = // must be the third element if present group.Contents.Count > 2 ? group.Contents[2] as IRtfGroup : null; if (alternativeWithoutUnicode != null) { VisitChildrenOf(alternativeWithoutUnicode); } } break; case RtfSpec.TagHeader: case RtfSpec.TagHeaderFirst: case RtfSpec.TagHeaderLeft: case RtfSpec.TagHeaderRight: case RtfSpec.TagFooter: case RtfSpec.TagFooterFirst: case RtfSpec.TagFooterLeft: case RtfSpec.TagFooterRight: case RtfSpec.TagFootnote: case RtfSpec.TagStyleSheet: // groups we currently ignore, so their content doesn't intermix with // the actual document content break; case RtfSpec.TagPictureWrapper: VisitChildrenOf(group); lastGroupWasPictureWrapper = true; break; case RtfSpec.TagPictureWrapperAlternative: if (!lastGroupWasPictureWrapper) { VisitChildrenOf(group); } lastGroupWasPictureWrapper = false; break; case RtfSpec.TagPicture: imageBuilder.VisitGroup(group); NotifyInsertImage( imageBuilder.Format, imageBuilder.Width, imageBuilder.Height, imageBuilder.DesiredWidth, imageBuilder.DesiredHeight, imageBuilder.ScaleWidthPercent, imageBuilder.ScaleHeightPercent, imageBuilder.ImageDataHex, imageBuilder.ImportFileName); break; case RtfSpec.TagParagraphNumberText: case RtfSpec.TagListNumberText: NotifyInsertSpecialChar(RtfVisualSpecialCharKind.ParagraphNumberBegin); VisitChildrenOf(group); NotifyInsertSpecialChar(RtfVisualSpecialCharKind.ParagraphNumberEnd); break; default: if (!group.IsExtensionDestination) { // nested text group VisitChildrenOf(group); } break; } break; } } // IRtfElementVisitor.VisitGroup
} // DoTagFound // ---------------------------------------------------------------------- protected override void DoTextFound( IRtfText text ) { if ( this.settings.Enabled && !string.IsNullOrEmpty( this.settings.ParseTextText ) ) { string msg = text.Text; if ( msg.Length > this.settings.TextMaxLength && !string.IsNullOrEmpty( this.settings.TextOverflowText ) ) { msg = msg.Substring( 0, msg.Length - this.settings.TextOverflowText.Length ) + this.settings.TextOverflowText; } WriteLine( string.Format( CultureInfo.InvariantCulture, this.settings.ParseTextText, msg ) ); } } // DoTextFound
} // TextFound // ---------------------------------------------------------------------- protected virtual void DoTextFound(IRtfText text) { } // DoTextFound
// ---------------------------------------------------------------------- protected void NotifyTextFound( IRtfText text ) { if ( listeners != null ) { foreach ( IRtfParserListener listener in listeners ) { listener.TextFound( text ); } } }