} // InsertSpecialChar // ---------------------------------------------------------------------- public void InsertBreak(IRtfInterpreterContext context, RtfVisualBreakKind kind) { if (context != null) { DoInsertBreak(context, kind); } } // InsertBreak
} // DoBeginDocument // ---------------------------------------------------------------------- protected override void DoInsertText(IRtfInterpreterContext context, string text) { if (!context.CurrentTextFormat.IsHidden || this.settings.IsShowHiddenText) { this.plainText.Append(text); } } // DoInsertText
// ---------------------------------------------------------------------- public void InsertBreak( IRtfInterpreterContext context, RtfVisualBreakKind kind ) { if ( context != null ) { DoInsertBreak( context, kind ); } }
} // DoEndDocument private void EndParagraph(IRtfInterpreterContext context) { var finalParagraphAlignment = context.GetSafeCurrentTextFormat().Alignment; foreach (IRtfVisual alignedVisual in _pendingParagraphContent) { switch (alignedVisual.Kind) { case RtfVisualKind.Image: var image = (RtfVisualImage)alignedVisual; // ReSharper disable RedundantCheckBeforeAssignment if (image.Alignment != finalParagraphAlignment) { // ReSharper restore RedundantCheckBeforeAssignment image.Alignment = finalParagraphAlignment; } break; case RtfVisualKind.Text: var text = (RtfVisualText)alignedVisual; if (text.Format.Alignment != finalParagraphAlignment) { IRtfTextFormat correctedFormat = ((RtfTextFormat)text.Format).DeriveWithAlignment(finalParagraphAlignment); var correctedUniqueFormat = context.GetUniqueTextFormatInstance(correctedFormat); text.Format = correctedUniqueFormat; } break; } } _pendingParagraphContent.Clear(); } // EndParagraph
} // DoEndDocument // ---------------------------------------------------------------------- private void EndParagraph(IRtfInterpreterContext context) { RtfTextAlignment finalParagraphAlignment = context.GetSafeCurrentTextFormat().Alignment; foreach (IRtfVisual alignedVisual in pendingParagraphContent) { switch (alignedVisual.Kind) { case RtfVisualKind.Image: RtfVisualImage image = (RtfVisualImage)alignedVisual; if (image.Alignment != finalParagraphAlignment) { image.Alignment = finalParagraphAlignment; } break; case RtfVisualKind.Text: RtfVisualText text = (RtfVisualText)alignedVisual; if (text.Format.Alignment != finalParagraphAlignment) { IRtfTextFormat correctedFormat = ((RtfTextFormat)text.Format).DeriveWithAlignment(finalParagraphAlignment); IRtfTextFormat correctedUniqueFormat = context.GetUniqueTextFormatInstance(correctedFormat); text.Format = correctedUniqueFormat; } break; } } pendingParagraphContent.Clear(); } // EndParagraph
} // DoBeginDocument // ---------------------------------------------------------------------- protected override void DoInsertText( IRtfInterpreterContext context, string text ) { if ( !context.CurrentTextFormat.IsHidden || this.settings.IsShowHiddenText ) { this.plainText.Append( text ); } } // DoInsertText
} // DoInsertSpecialChar // ---------------------------------------------------------------------- protected override void DoInsertBreak(IRtfInterpreterContext context, RtfVisualBreakKind kind) { switch (kind) { case RtfVisualBreakKind.Line: plainText.Append(settings.LineBreakText); break; case RtfVisualBreakKind.Page: plainText.Append(settings.PageBreakText); break; case RtfVisualBreakKind.Paragraph: plainText.Append(settings.ParagraphBreakText); break; case RtfVisualBreakKind.Section: plainText.Append(settings.SectionBreakText); break; default: plainText.Append(settings.UnknownBreakText); break; } } // DoInsertBreak
} // DoInsertBreak // ---------------------------------------------------------------------- protected override void DoInsertImage(IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { string imageFormatText = settings.ImageFormatText; if (string.IsNullOrEmpty(imageFormatText)) { return; } string imageText = string.Format( CultureInfo.InvariantCulture, imageFormatText, format, width, height, desiredWidth, desiredHeight, scaleWidthPercent, scaleHeightPercent, imageDataHex); plainText.Append(imageText); } // DoInsertImage
} // InsertImage // ---------------------------------------------------------------------- public void EndDocument(IRtfInterpreterContext context) { if (context != null) { DoEndDocument(context); } } // EndDocument
} // Logger // ---------------------------------------------------------------------- protected override void DoBeginDocument(IRtfInterpreterContext context) { if (this.settings.Enabled && logger.IsInfoEnabled && !string.IsNullOrEmpty(this.settings.BeginDocumentText)) { Log(this.settings.BeginDocumentText); } } // DoBeginDocument
} // InsertText // ---------------------------------------------------------------------- public void InsertSpecialChar(IRtfInterpreterContext context, RtfVisualSpecialCharKind kind) { if (context != null) { DoInsertSpecialChar(context, kind); } } // InsertSpecialChar
// ---------------------------------------------------------------------- public void InsertSpecialChar( IRtfInterpreterContext context, RtfVisualSpecialCharKind kind ) { if ( context != null ) { DoInsertSpecialChar( context, kind ); } }
// ---------------------------------------------------------------------- public void InsertText( IRtfInterpreterContext context, string text ) { if ( context != null ) { DoInsertText( context, text ); } }
} // RtfInterpreterListenerBase // ---------------------------------------------------------------------- public void BeginDocument(IRtfInterpreterContext context) { if (context != null) { DoBeginDocument(context); } } // BeginDocument
} // Logger // ---------------------------------------------------------------------- protected override void DoBeginDocument( IRtfInterpreterContext context ) { if ( this.settings.Enabled && logger.IsInfoEnabled && !string.IsNullOrEmpty( this.settings.BeginDocumentText ) ) { Log( this.settings.BeginDocumentText ); } } // DoBeginDocument
// ---------------------------------------------------------------------- public void EndDocument( IRtfInterpreterContext context ) { if ( context != null ) { DoEndDocument( context ); } }
// ---------------------------------------------------------------------- public void BeginDocument( IRtfInterpreterContext context ) { if ( context != null ) { DoBeginDocument( context ); } }
} // BeginDocument // ---------------------------------------------------------------------- public void InsertText(IRtfInterpreterContext context, string text) { if (context != null) { DoInsertText(context, text); } } // InsertText
} // DoInsertBreak // ---------------------------------------------------------------------- protected virtual void DoInsertImage(IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { } // DoInsertImage
} // DoInsertImage // ---------------------------------------------------------------------- protected override void DoEndDocument(IRtfInterpreterContext context) { FlushPendingText(); EndParagraph(context); document = new RtfDocument(context, visualDocumentContent); visualDocumentContent = null; visualDocumentContent = null; } // DoEndDocument
// ---------------------------------------------------------------------- protected override void DoEndDocument( IRtfInterpreterContext context ) { FlushPendingText(); EndParagraph( context ); document = new RtfDocument( context, visualDocumentContent ); visualDocumentContent = null; visualDocumentContent = null; }
} // DoInsertImage // ---------------------------------------------------------------------- protected override void DoEndDocument(IRtfInterpreterContext context) { if (settings.Enabled && !string.IsNullOrEmpty(settings.EndDocumentText)) { WriteLine(settings.EndDocumentText); } CloseStream(); } // DoEndDocument
} // DoInsertSpecialChar // ---------------------------------------------------------------------- protected override void DoInsertBreak(IRtfInterpreterContext context, RtfVisualBreakKind kind) { if (settings.Enabled && logger.IsInfoEnabled && !string.IsNullOrEmpty(settings.BreakFormatText)) { Log(string.Format( CultureInfo.InvariantCulture, settings.BreakFormatText, kind)); } } // DoInsertBreak
} // Dispose // ---------------------------------------------------------------------- protected override void DoBeginDocument(IRtfInterpreterContext context) { EnsureDirectory(); OpenStream(); if (settings.Enabled && !string.IsNullOrEmpty(settings.BeginDocumentText)) { WriteLine(settings.BeginDocumentText); } } // DoBeginDocument
} // DoInsertText // ---------------------------------------------------------------------- protected override void DoInsertSpecialChar(IRtfInterpreterContext context, RtfVisualSpecialCharKind kind) { if (settings.Enabled && !string.IsNullOrEmpty(settings.SpecialCharFormatText)) { WriteLine(string.Format( CultureInfo.InvariantCulture, settings.SpecialCharFormatText, kind)); } } // DoInsertSpecialChar
} // Dispose // ---------------------------------------------------------------------- protected override void DoBeginDocument( IRtfInterpreterContext context ) { EnsureDirectory(); OpenStream(); if ( this.settings.Enabled && !string.IsNullOrEmpty( this.settings.BeginDocumentText ) ) { WriteLine( this.settings.BeginDocumentText ); } } // DoBeginDocument
} // DoInsertSpecialChar // ---------------------------------------------------------------------- protected override void DoInsertBreak(IRtfInterpreterContext context, RtfVisualBreakKind kind) { if (this.settings.Enabled && !string.IsNullOrEmpty(this.settings.BreakFormatText)) { WriteLine(string.Format( CultureInfo.InvariantCulture, this.settings.BreakFormatText, kind)); } } // DoInsertBreak
} // DoBeginDocument // ---------------------------------------------------------------------- protected override void DoInsertText(IRtfInterpreterContext context, string text) { if (context.CurrentTextFormat == null) { return; } if (!context.CurrentTextFormat.IsHidden || settings.IsShowHiddenText) { plainText.Append(text); } } // DoInsertText
// ---------------------------------------------------------------------- protected override void DoInsertBreak( IRtfInterpreterContext context, RtfVisualBreakKind kind ) { FlushPendingText(); visualDocumentContent.Add( new RtfVisualBreak( kind ) ); switch ( kind ) { case RtfVisualBreakKind.Paragraph: case RtfVisualBreakKind.Section: EndParagraph( context ); break; } }
} // DoInsertSpecialChar // ---------------------------------------------------------------------- protected override void DoInsertBreak(IRtfInterpreterContext context, RtfVisualBreakKind kind) { FlushPendingText(); visualDocumentContent.Add(new RtfVisualBreak(kind)); switch (kind) { case RtfVisualBreakKind.Paragraph: case RtfVisualBreakKind.Section: EndParagraph(context); break; } } // DoInsertBreak
// ---------------------------------------------------------------------- public void InsertImage( IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { if ( context != null ) { DoInsertImage( context, format, width, height, desiredWidth, desiredHeight, scaleWidthPercent, scaleHeightPercent, imageDataHex ); } }
} // InsertBreak // ---------------------------------------------------------------------- public void InsertImage(IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { if (context != null) { DoInsertImage(context, format, width, height, desiredWidth, desiredHeight, scaleWidthPercent, scaleHeightPercent, imageDataHex); } } // InsertImage
// ---------------------------------------------------------------------- public RtfDocument( IRtfInterpreterContext context, IRtfVisualCollection visualContent ) : this(context.RtfVersion, context.DefaultFont, context.FontTable, context.ColorTable, context.Generator, context.UniqueTextFormats, context.DocumentInfo, context.UserProperties, visualContent) { }
} // DoBeginDocument // ---------------------------------------------------------------------- protected override void DoInsertImage(IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex, String importFileName ) { int imageIndex = convertedImages.Count + 1; string fileName = settings.GetImageFileName(imageIndex, format); EnsureImagesPath(fileName); byte[] imageBuffer = RtfVisualImage.ToBinary(imageDataHex); Size imageSize; ImageFormat imageFormat; if (settings.ImageAdapter.TargetFormat == null) { using (var memory = new MemoryStream(imageBuffer)) using (var random = memory.AsRandomAccessStream()) { var image = new BitmapImage(); image.SetSource(random); imageFormat = ImageFormat.Jpeg; imageSize = new Size(image.PixelWidth, image.PixelHeight); } using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(fileName, FileMode.Create))) { binaryWriter.Write(imageBuffer); } } else { imageFormat = settings.ImageAdapter.TargetFormat; if (settings.ScaleImage) { imageSize = new Size( settings.ImageAdapter.CalcImageWidth(format, width, desiredWidth, scaleWidthPercent), settings.ImageAdapter.CalcImageHeight(format, height, desiredHeight, scaleHeightPercent)); } else { imageSize = new Size(width, height); } SaveImage(imageBuffer, format, fileName, imageSize); } convertedImages.Add(new RtfConvertedImageInfo(fileName, imageFormat, imageSize)); } // DoInsertImage
// ---------------------------------------------------------------------- public RtfDocument(IRtfInterpreterContext context, IRtfVisualCollection visualContent) : this(context.RtfVersion, context.DefaultFont, context.FontTable, context.ColorTable, context.Generator, context.UniqueTextFormats, context.DocumentInfo, context.UserProperties, visualContent ) { } // RtfDocument
} // DoInsertBreak // ---------------------------------------------------------------------- protected override void DoInsertImage( IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { FlushPendingText(); this.visualContent.Add( new RtfVisualImage( format, context.GetSafeCurrentTextFormat().Alignment, width, height, desiredWidth, desiredHeight, scaleWidthPercent, scaleHeightPercent, imageDataHex ) ); } // DoInsertImage
} // DoInsertBreak // ---------------------------------------------------------------------- protected override void DoInsertImage(IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex, string importFileName ) { FlushPendingText(); AppendAlignedVisual(new RtfVisualImage(format, context.GetSafeCurrentTextFormat().Alignment, width, height, desiredWidth, desiredHeight, scaleWidthPercent, scaleHeightPercent, imageDataHex, importFileName)); } // DoInsertImage
} // DoInsertText // ---------------------------------------------------------------------- protected override void DoInsertSpecialChar( IRtfInterpreterContext context, RtfVisualSpecialCharKind kind ) { switch ( kind ) { case RtfVisualSpecialCharKind.Tabulator: this.plainText.Append( this.settings.TabulatorText ); break; case RtfVisualSpecialCharKind.NonBreakingSpace: this.plainText.Append( this.settings.NonBreakingSpaceText ); break; case RtfVisualSpecialCharKind.EmSpace: this.plainText.Append( this.settings.EmSpaceText ); break; case RtfVisualSpecialCharKind.EnSpace: this.plainText.Append( this.settings.EnSpaceText ); break; case RtfVisualSpecialCharKind.QmSpace: this.plainText.Append( this.settings.QmSpaceText ); break; case RtfVisualSpecialCharKind.EmDash: this.plainText.Append( this.settings.EmDashText ); break; case RtfVisualSpecialCharKind.EnDash: this.plainText.Append( this.settings.EnDashText ); break; case RtfVisualSpecialCharKind.OptionalHyphen: this.plainText.Append( this.settings.OptionalHyphenText ); break; case RtfVisualSpecialCharKind.NonBreakingHyphen: this.plainText.Append( this.settings.NonBreakingHyphenText ); break; case RtfVisualSpecialCharKind.Bullet: this.plainText.Append( this.settings.BulletText ); break; case RtfVisualSpecialCharKind.LeftSingleQuote: this.plainText.Append( this.settings.LeftSingleQuoteText ); break; case RtfVisualSpecialCharKind.RightSingleQuote: this.plainText.Append( this.settings.RightSingleQuoteText ); break; case RtfVisualSpecialCharKind.LeftDoubleQuote: this.plainText.Append( this.settings.LeftDoubleQuoteText ); break; case RtfVisualSpecialCharKind.RightDoubleQuote: this.plainText.Append( this.settings.RightDoubleQuoteText ); break; default: this.plainText.Append( this.settings.UnknownSpecialCharText ); break; } } // DoInsertSpecialChar
} // DoBeginDocument // ---------------------------------------------------------------------- protected override void DoInsertImage(IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { int imageIndex = convertedImages.Count + 1; string fileName = settings.GetImageFileName(imageIndex, format); EnsureImagesPath(fileName); byte[] imageBuffer = RtfVisualImage.ToBinary(imageDataHex); Size imageSize; ImageFormat imageFormat; if (settings.ImageAdapter.TargetFormat == null) { using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(imageBuffer))) { imageFormat = image.RawFormat; imageSize = image.Size; } using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(fileName, FileMode.Create))) { binaryWriter.Write(imageBuffer); } } else { imageFormat = settings.ImageAdapter.TargetFormat; if (settings.ScaleImage) { imageSize = new Size( settings.ImageAdapter.CalcImageWidth(format, width, desiredWidth, scaleWidthPercent), settings.ImageAdapter.CalcImageHeight(format, height, desiredHeight, scaleHeightPercent)); } else { imageSize = new Size(width, height); } SaveImage(imageBuffer, format, fileName, imageSize); } convertedImages.Add(new RtfConvertedImageInfo(fileName, imageFormat, imageSize)); } // DoInsertImage
} // DoBeginDocument // ---------------------------------------------------------------------- protected override void DoInsertText(IRtfInterpreterContext context, string text) { if (this.settings.Enabled && logger.IsInfoEnabled && !string.IsNullOrEmpty(this.settings.TextFormatText)) { string msg = 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; } Log(string.Format( CultureInfo.InvariantCulture, this.settings.TextFormatText, msg, context.GetSafeCurrentTextFormat())); } } // DoInsertText
} // DoBeginDocument // ---------------------------------------------------------------------- protected override void DoInsertText( IRtfInterpreterContext context, string text ) { if ( this.settings.Enabled && logger.IsInfoEnabled && !string.IsNullOrEmpty( this.settings.TextFormatText ) ) { string msg = 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; } Log( string.Format( CultureInfo.InvariantCulture, this.settings.TextFormatText, msg, context.GetSafeCurrentTextFormat() ) ); } } // DoInsertText
} // DoBeginDocument // ---------------------------------------------------------------------- protected override void DoInsertText(IRtfInterpreterContext context, string text) { if (settings.Enabled && !string.IsNullOrEmpty(settings.TextFormatText)) { string msg = text; if (msg.Length > settings.TextMaxLength && !string.IsNullOrEmpty(settings.TextOverflowText)) { msg = msg.Substring(0, msg.Length - settings.TextOverflowText.Length) + settings.TextOverflowText; } WriteLine(string.Format( CultureInfo.InvariantCulture, settings.TextFormatText, msg, context.CurrentTextFormat)); } } // DoInsertText
} // DoBeginDocument // ---------------------------------------------------------------------- protected override void DoInsertText(IRtfInterpreterContext context, string text) { if (this.combineTextWithSameFormat) { IRtfTextFormat newFormat = context.GetSafeCurrentTextFormat(); if (!newFormat.Equals(this.pendingTextFormat)) { FlushPendingText(); } this.pendingTextFormat = newFormat; this.pendingText.Append(text); } else { this.visualContent.Add(new RtfVisualText(text, context.GetSafeCurrentTextFormat())); } } // DoInsertText
} // DoBeginDocument // ---------------------------------------------------------------------- protected override void DoInsertText(IRtfInterpreterContext context, string text) { if (combineTextWithSameFormat) { IRtfTextFormat newFormat = context.GetSafeCurrentTextFormat(); if (!newFormat.Equals(pendingTextFormat)) { FlushPendingText(); } pendingTextFormat = newFormat; pendingText.Append(text); } else { AppendAlignedVisual(new RtfVisualText(text, context.GetSafeCurrentTextFormat())); } } // DoInsertText
} // DoBeginDocument // ---------------------------------------------------------------------- protected override void DoInsertImage( IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { int imageIndex = this.convertedImages.Count + 1; string fileName = this.settings.GetImageFileName( imageIndex, format ); EnsureImagesPath( fileName ); byte[] imageBuffer = RtfVisualImage.ToBinary( imageDataHex ); Size imageSize; ImageFormat imageFormat; if ( this.settings.ImageAdapter.TargetFormat == null ) { using ( System.Drawing.Image image = System.Drawing.Image.FromStream( new MemoryStream( imageBuffer ) ) ) { imageFormat = image.RawFormat; imageSize = image.Size; } using ( BinaryWriter binaryWriter = new BinaryWriter( File.Open( fileName, FileMode.Create ) ) ) { binaryWriter.Write( imageBuffer ); } } else { imageFormat = this.settings.ImageAdapter.TargetFormat; if ( this.settings.ScaleImage ) { imageSize = new Size( this.settings.ImageAdapter.CalcImageWidth( format, width, desiredWidth, scaleWidthPercent ), this.settings.ImageAdapter.CalcImageHeight( format, height, desiredHeight, scaleHeightPercent ) ); } else { imageSize = new Size( width, height ); } SaveImage( imageBuffer, format, fileName, imageSize ); } this.convertedImages.Add( new RtfConvertedImageInfo( fileName, imageFormat, imageSize ) ); } // DoInsertImage
} // DoBeginDocument // ---------------------------------------------------------------------- protected override void DoInsertText( IRtfInterpreterContext context, string text ) { if ( this.combineTextWithSameFormat ) { IRtfTextFormat newFormat = context.GetSafeCurrentTextFormat(); if ( !newFormat.Equals( this.pendingTextFormat ) ) { FlushPendingText(); } this.pendingTextFormat = newFormat; this.pendingText.Append( text ); } else { this.visualContent.Add( new RtfVisualText( text, context.GetSafeCurrentTextFormat() ) ); } } // DoInsertText
} // DoInsertBreak // ---------------------------------------------------------------------- protected override void DoInsertImage(IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { if (settings.Enabled && !string.IsNullOrEmpty(settings.ImageFormatText)) { WriteLine(string.Format( CultureInfo.InvariantCulture, settings.ImageFormatText, format, width, height, desiredWidth, desiredHeight, scaleWidthPercent, scaleHeightPercent, imageDataHex, (imageDataHex.Length / 2))); } } // DoInsertImage
} // ConvertedImages // ---------------------------------------------------------------------- protected override void DoBeginDocument( IRtfInterpreterContext context ) { base.DoBeginDocument( context ); this.convertedImages.Clear(); } // DoBeginDocument
// ---------------------------------------------------------------------- protected override void DoInsertImage( IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { if ( settings.Enabled && !string.IsNullOrEmpty( settings.ImageFormatText ) ) { WriteLine( string.Format( CultureInfo.InvariantCulture, settings.ImageFormatText, format, width, height, desiredWidth, desiredHeight, scaleWidthPercent, scaleHeightPercent, imageDataHex, (imageDataHex.Length / 2) ) ); } }
// ---------------------------------------------------------------------- protected override void DoInsertSpecialChar( IRtfInterpreterContext context, RtfVisualSpecialCharKind kind ) { if ( settings.Enabled && !string.IsNullOrEmpty( settings.SpecialCharFormatText ) ) { WriteLine( string.Format( CultureInfo.InvariantCulture, settings.SpecialCharFormatText, kind ) ); } }
// ---------------------------------------------------------------------- protected override void DoBeginDocument( IRtfInterpreterContext context ) { document = null; visualDocumentContent = new RtfVisualCollection(); }
// ---------------------------------------------------------------------- private void EndParagraph( IRtfInterpreterContext context ) { RtfTextAlignment finalParagraphAlignment = context.GetSafeCurrentTextFormat().Alignment; foreach ( IRtfVisual alignedVisual in pendingParagraphContent ) { switch ( alignedVisual.Kind ) { case RtfVisualKind.Image: RtfVisualImage image = (RtfVisualImage)alignedVisual; // ReSharper disable RedundantCheckBeforeAssignment if ( image.Alignment != finalParagraphAlignment ) // ReSharper restore RedundantCheckBeforeAssignment { image.Alignment = finalParagraphAlignment; } break; case RtfVisualKind.Text: RtfVisualText text = (RtfVisualText)alignedVisual; if ( text.Format.Alignment != finalParagraphAlignment ) { IRtfTextFormat correctedFormat = ( (RtfTextFormat)text.Format ).DeriveWithAlignment( finalParagraphAlignment ); IRtfTextFormat correctedUniqueFormat = context.GetUniqueTextFormatInstance( correctedFormat ); text.Format = correctedUniqueFormat; } break; } } pendingParagraphContent.Clear(); }
// ---------------------------------------------------------------------- protected override void DoInsertText( IRtfInterpreterContext context, string text ) { if ( combineTextWithSameFormat ) { IRtfTextFormat newFormat = context.GetSafeCurrentTextFormat(); if ( !newFormat.Equals( pendingTextFormat ) ) { FlushPendingText(); } pendingTextFormat = newFormat; pendingText.Append( text ); } else { AppendAlignedVisual( new RtfVisualText( text, context.GetSafeCurrentTextFormat() ) ); } }
// ---------------------------------------------------------------------- protected override void DoInsertSpecialChar( IRtfInterpreterContext context, RtfVisualSpecialCharKind kind ) { FlushPendingText(); visualDocumentContent.Add( new RtfVisualSpecialChar( kind ) ); }
// ---------------------------------------------------------------------- protected override void DoInsertText( IRtfInterpreterContext context, string text ) { if ( settings.Enabled && !string.IsNullOrEmpty( settings.TextFormatText ) ) { string msg = text; if ( msg.Length > settings.TextMaxLength && !string.IsNullOrEmpty( settings.TextOverflowText ) ) { msg = msg.Substring( 0, msg.Length - settings.TextOverflowText.Length ) + settings.TextOverflowText; } WriteLine( string.Format( CultureInfo.InvariantCulture, settings.TextFormatText, msg, context.CurrentTextFormat ) ); } }
// ---------------------------------------------------------------------- protected override void DoInsertImage( IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { string imageFormatText = settings.ImageFormatText; if ( string.IsNullOrEmpty( imageFormatText ) ) { return; } string imageText = string.Format( CultureInfo.InvariantCulture, imageFormatText, format, width, height, desiredWidth, desiredHeight, scaleWidthPercent, scaleHeightPercent, imageDataHex ); plainText.Append( imageText ); }
// ---------------------------------------------------------------------- protected override void DoEndDocument( IRtfInterpreterContext context ) { if ( settings.Enabled && !string.IsNullOrEmpty( settings.EndDocumentText ) ) { WriteLine( settings.EndDocumentText ); } CloseStream(); }
// ---------------------------------------------------------------------- protected override void DoInsertText( IRtfInterpreterContext context, string text ) { if ( context.CurrentTextFormat == null ) { return; } if ( !context.CurrentTextFormat.IsHidden || settings.IsShowHiddenText ) { plainText.Append( text ); } }
// ---------------------------------------------------------------------- protected override void DoInsertBreak( IRtfInterpreterContext context, RtfVisualBreakKind kind ) { switch ( kind ) { case RtfVisualBreakKind.Line: plainText.Append( settings.LineBreakText ); break; case RtfVisualBreakKind.Page: plainText.Append( settings.PageBreakText ); break; case RtfVisualBreakKind.Paragraph: plainText.Append( settings.ParagraphBreakText ); break; case RtfVisualBreakKind.Section: plainText.Append( settings.SectionBreakText ); break; default: plainText.Append( settings.UnknownBreakText ); break; } }
// ---------------------------------------------------------------------- protected override void DoBeginDocument( IRtfInterpreterContext context ) { Clear(); }