} // DoInsertImage // ---------------------------------------------------------------------- protected virtual void SaveImage(byte[] imageBuffer, RtfVisualImageFormat format, string fileName, Size size) { ImageFormat targetFormat = settings.ImageAdapter.TargetFormat; float scaleOffset = settings.ScaleOffset; float scaleExtension = settings.ScaleExtension; using (System.Drawing.Image image = System.Drawing.Image.FromStream( new MemoryStream(imageBuffer, 0, imageBuffer.Length))) { Bitmap convertedImage = new Bitmap(new Bitmap(size.Width, size.Height, image.PixelFormat)); Graphics graphic = Graphics.FromImage(convertedImage); graphic.CompositingQuality = CompositingQuality.HighQuality; graphic.SmoothingMode = SmoothingMode.HighQuality; graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; RectangleF rectangle = new RectangleF( scaleOffset, scaleOffset, size.Width + scaleExtension, size.Height + scaleExtension); if (settings.BackgroundColor.HasValue) { graphic.Clear(settings.BackgroundColor.Value); } graphic.DrawImage(image, rectangle); convertedImage.Save(fileName, targetFormat); } } // SaveImage
} // DoInsertImage // ---------------------------------------------------------------------- protected virtual void SaveImage(byte[] imageBuffer, RtfVisualImageFormat format, string fileName, Size size) { ImageFormat targetFormat = settings.ImageAdapter.TargetFormat; float scaleOffset = settings.ScaleOffset; float scaleExtension = settings.ScaleExtension; using (var memory = new MemoryStream(imageBuffer)) using (var random = memory.AsRandomAccessStream()) { //var convertedImage = new BitmapImage(); //convertedImage.SetSource(random); //Graphics graphic = Graphics.FromImage( convertedImage ); //graphic.CompositingQuality = CompositingQuality.HighQuality; //graphic.SmoothingMode = SmoothingMode.HighQuality; //graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; //RectangleF rectangle = new RectangleF( // scaleOffset, // scaleOffset, // size.Width + scaleExtension, // size.Height + scaleExtension ); //if ( settings.BackgroundColor.HasValue ) //{ // graphic.Clear( settings.BackgroundColor.Value ); //} //graphic.DrawImage( image, rectangle ); //convertedImage.Save( fileName, targetFormat ); } } // SaveImage
} // ResolveFileName public int CalcImageWidth(RtfVisualImageFormat format, int width, int desiredWidth, int scaleWidthPercent) { var imgScaleX = scaleWidthPercent / 100.0f; return((int)Math.Round((double)desiredWidth * imgScaleX / TwipsPerInch * DpiX)); } // CalcImageWidth
} // CalcImageWidth public int CalcImageHeight(RtfVisualImageFormat format, int height, int desiredHeight, int scaleHeightPercent) { var imgScaleY = scaleHeightPercent / 100.0f; return((int)Math.Round((double)desiredHeight * imgScaleY / TwipsPerInch * DpiY)); } // CalcImageHeight
} // DpiY public ImageFormat GetImageFormat(RtfVisualImageFormat rtfVisualImageFormat) { ImageFormat imageFormat = null; switch (rtfVisualImageFormat) { case RtfVisualImageFormat.Emf: imageFormat = ImageFormat.Emf; break; case RtfVisualImageFormat.Png: imageFormat = ImageFormat.Png; break; case RtfVisualImageFormat.Jpg: imageFormat = ImageFormat.Jpeg; break; case RtfVisualImageFormat.Wmf: imageFormat = ImageFormat.Wmf; break; case RtfVisualImageFormat.Bmp: imageFormat = ImageFormat.Bmp; break; } return(imageFormat); } // GetImageFormat
} // 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
} // DoInsertBreak // ---------------------------------------------------------------------- protected virtual void DoInsertImage(IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { } // DoInsertImage
// ---------------------------------------------------------------------- public RtfVisualImage( RtfVisualImageFormat format, RtfTextAlignment alignment, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex, String importFileName ) : base(RtfVisualKind.Image) { if (width <= 0) { throw new ArgumentException(Strings.InvalidImageWidth(width)); } if (height <= 0) { throw new ArgumentException(Strings.InvalidImageHeight(height)); } if (desiredWidth <= 0) { throw new ArgumentException(Strings.InvalidImageDesiredWidth(desiredWidth)); } if (desiredHeight <= 0) { throw new ArgumentException(Strings.InvalidImageDesiredHeight(desiredHeight)); } if (scaleWidthPercent <= 0) { throw new ArgumentException(Strings.InvalidImageScaleWidth(scaleWidthPercent)); } if (scaleHeightPercent <= 0) { throw new ArgumentException(Strings.InvalidImageScaleHeight(scaleHeightPercent)); } if (imageDataHex == null) { throw new ArgumentNullException("imageDataHex"); } if (importFileName == null) { throw new ArgumentNullException("importFileName"); } this.format = format; this.alignment = alignment; this.width = width; this.height = height; this.desiredWidth = desiredWidth; this.desiredHeight = desiredHeight; this.scaleWidthPercent = scaleWidthPercent; this.scaleHeightPercent = scaleHeightPercent; this.imageDataHex = imageDataHex; this.importFileName = importFileName; } // RtfVisualImage
} // ScaleExtension // ---------------------------------------------------------------------- public string GetImageFileName( int index, RtfVisualImageFormat rtfVisualImageFormat ) { string imageFileName = this.imageAdapter.ResolveFileName( index, rtfVisualImageFormat ); if ( !string.IsNullOrEmpty( this.imagesPath ) ) { imageFileName = Path.Combine( imagesPath, imageFileName ); } return imageFileName; } // GetImageFileName
// ---------------------------------------------------------------------- public string GetImageFileName(int index, RtfVisualImageFormat rtfVisualImageFormat) { string imageFileName = imageAdapter.ResolveFileName(index, rtfVisualImageFormat); if (!string.IsNullOrEmpty(imagesPath)) { imageFileName = Path.Combine(imagesPath, imageFileName); } return(imageFileName); } // GetImageFileName
} // GetImageFormat public string ResolveFileName(int index, RtfVisualImageFormat rtfVisualImageFormat) { var imageFormat = TargetFormat ?? GetImageFormat(rtfVisualImageFormat); return(string.Format( CultureInfo.InvariantCulture, FileNamePattern, index, GetFileImageExtension(imageFormat))); } // ResolveFileName
// ---------------------------------------------------------------------- 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
} // 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
} // 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
} // 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
private byte[] _imageDataBinary; // cached info only public RtfVisualImage( RtfVisualImageFormat format, RtfTextAlignment alignment, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) : base(RtfVisualKind.Image) { if (width <= 0) { throw new ArgumentException(Strings.InvalidImageWidth(width)); } if (height <= 0) { throw new ArgumentException(Strings.InvalidImageHeight(height)); } if (desiredWidth <= 0) { throw new ArgumentException(Strings.InvalidImageDesiredWidth(desiredWidth)); } if (desiredHeight <= 0) { throw new ArgumentException(Strings.InvalidImageDesiredHeight(desiredHeight)); } if (scaleWidthPercent <= 0) { throw new ArgumentException(Strings.InvalidImageScaleWidth(scaleWidthPercent)); } if (scaleHeightPercent <= 0) { throw new ArgumentException(Strings.InvalidImageScaleHeight(scaleHeightPercent)); } if (imageDataHex == null) { throw new ArgumentNullException(nameof(imageDataHex)); } Format = format; Alignment = alignment; Width = width; Height = height; DesiredWidth = desiredWidth; DesiredHeight = desiredHeight; ScaleWidthPercent = scaleWidthPercent; ScaleHeightPercent = scaleHeightPercent; ImageDataHex = imageDataHex; } // RtfVisualImage
private byte[] imageDataBinary; // cached info only #endregion Fields #region Constructors // ---------------------------------------------------------------------- public RtfVisualImage( RtfVisualImageFormat format, RtfTextAlignment alignment, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) : base(RtfVisualKind.Image) { if ( width <= 0 ) { throw new ArgumentException( Strings.InvalidImageWidth( width ) ); } if ( height <= 0 ) { throw new ArgumentException( Strings.InvalidImageHeight( height ) ); } if ( desiredWidth <= 0 ) { throw new ArgumentException( Strings.InvalidImageDesiredWidth( desiredWidth ) ); } if ( desiredHeight <= 0 ) { throw new ArgumentException( Strings.InvalidImageDesiredHeight( desiredHeight ) ); } if ( scaleWidthPercent <= 0 ) { throw new ArgumentException( Strings.InvalidImageScaleWidth( scaleWidthPercent ) ); } if ( scaleHeightPercent <= 0 ) { throw new ArgumentException( Strings.InvalidImageScaleHeight( scaleHeightPercent ) ); } if ( imageDataHex == null ) { throw new ArgumentNullException( "imageDataHex" ); } this.format = format; this.alignment = alignment; this.width = width; this.height = height; this.desiredWidth = desiredWidth; this.desiredHeight = desiredHeight; this.scaleWidthPercent = scaleWidthPercent; this.scaleHeightPercent = scaleHeightPercent; this.imageDataHex = imageDataHex; }
// ---------------------------------------------------------------------- public string GetImageFileName(int index, RtfVisualImageFormat rtfVisualImageFormat) { string imageFileName = imageAdapter.ResolveFileName(index, rtfVisualImageFormat); if (!string.IsNullOrEmpty(imagesPath)) { #if FILEIO imageFileName = Path.Combine(imagesPath, imageFileName); #else imageFileName = imagesPath.TrimEnd('\\') + "\\" + imageFileName.TrimStart('\\'); #endif } return(imageFileName); } // GetImageFileName
} // GetImageFormat // ---------------------------------------------------------------------- public string ResolveFileName(int index, RtfVisualImageFormat rtfVisualImageFormat) { ImageFormat imageFormat = this.targetFormat; if (imageFormat == null) { imageFormat = GetImageFormat(rtfVisualImageFormat); } return(string.Format( CultureInfo.InvariantCulture, this.fileNamePattern, index, GetFileImageExtension(imageFormat))); } // ResolveFileName
} // 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 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
} // GetImageFormat #endif // ---------------------------------------------------------------------- public string ResolveFileName(int index, RtfVisualImageFormat rtfVisualImageFormat) { #if DRAWING ImageFormat imageFormat = targetFormat ?? GetImageFormat(rtfVisualImageFormat); return(string.Format( CultureInfo.InvariantCulture, fileNamePattern, index, GetFileImageExtension(imageFormat))); #else return(string.Format( CultureInfo.InvariantCulture, fileNamePattern, index, rtfVisualImageFormat)); #endif } // ResolveFileName
} // NotifyInsertBreak // ---------------------------------------------------------------------- protected void NotifyInsertImage(RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { if (listeners != null) { foreach (IRtfInterpreterListener listener in listeners) { listener.InsertImage( context, format, width, height, desiredWidth, desiredHeight, scaleWidthPercent, scaleHeightPercent, imageDataHex); } } } // NotifyInsertImage
} // 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
// ---------------------------------------------------------------------- protected void NotifyInsertImage( RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { if ( listeners != null ) { foreach ( IRtfInterpreterListener listener in listeners ) { listener.InsertImage( context, format, width, height, desiredWidth, desiredHeight, scaleWidthPercent, scaleHeightPercent, imageDataHex ); } } }
// ---------------------------------------------------------------------- public int CalcImageHeight( RtfVisualImageFormat format, int height, int desiredHeight, int scaleHeightPercent) { float imgScaleY = scaleHeightPercent / 100.0f; return (int)Math.Round( (double)desiredHeight * imgScaleY / twipsPerInch * dpiY ); }
// ---------------------------------------------------------------------- public int CalcImageWidth( RtfVisualImageFormat format, int width, int desiredWidth, int scaleWidthPercent) { float imgScaleX = scaleWidthPercent / 100.0f; return (int)Math.Round( (double)desiredWidth * imgScaleX / twipsPerInch * dpiX ); }
} // DoInsertImage // ---------------------------------------------------------------------- protected virtual void SaveImage( byte[] imageBuffer, RtfVisualImageFormat format, string fileName, Size size ) { ImageFormat targetFormat = this.settings.ImageAdapter.TargetFormat; float scaleOffset = this.settings.ScaleOffset; float scaleExtension = this.settings.ScaleExtension; using ( System.Drawing.Image image = System.Drawing.Image.FromStream( new MemoryStream( imageBuffer, 0, imageBuffer.Length ) ) ) { Bitmap convertedImage = new Bitmap( new Bitmap( size.Width, size.Height, image.PixelFormat ) ); Graphics graphic = Graphics.FromImage( convertedImage ); graphic.CompositingQuality = CompositingQuality.HighQuality; graphic.SmoothingMode = SmoothingMode.HighQuality; graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; RectangleF rectangle = new RectangleF( scaleOffset, scaleOffset, size.Width + scaleExtension, size.Height + scaleExtension ); if ( this.settings.BackgroundColor.HasValue ) { graphic.Clear( this.settings.BackgroundColor.Value ); } graphic.DrawImage( image, rectangle ); convertedImage.Save( fileName, targetFormat ); } } // SaveImage
// ---------------------------------------------------------------------- protected override void DoVisitTag( IRtfTag tag ) { switch ( tag.Name ) { case RtfSpec.TagPictureFormatWinDib: case RtfSpec.TagPictureFormatWinBmp: format = RtfVisualImageFormat.Bmp; break; case RtfSpec.TagPictureFormatEmf: format = RtfVisualImageFormat.Emf; break; case RtfSpec.TagPictureFormatJpg: format = RtfVisualImageFormat.Jpg; break; case RtfSpec.TagPictureFormatPng: format = RtfVisualImageFormat.Png; break; case RtfSpec.TagPictureFormatWmf: format = RtfVisualImageFormat.Wmf; break; case RtfSpec.TagPictureWidth: width = tag.ValueAsNumber; desiredWidth = width; break; case RtfSpec.TagPictureHeight: height = tag.ValueAsNumber; desiredHeight = height; break; case RtfSpec.TagPictureWidthGoal: desiredWidth = tag.ValueAsNumber; if ( width == 0 ) { // hack to prevent WordPad documents which lack the \picw and \pich tags // from resulting in an exception due to undefined width/height width = desiredWidth; } break; case RtfSpec.TagPictureHeightGoal: desiredHeight = tag.ValueAsNumber; if ( height == 0 ) { // hack to prevent WordPad documents which lack the \picw and \pich tags // from resulting in an exception due to undefined width/height height = desiredHeight; } break; case RtfSpec.TagPictureWidthScale: scaleWidthPercent = tag.ValueAsNumber; break; case RtfSpec.TagPictureHeightScale: scaleHeightPercent = tag.ValueAsNumber; break; } }
// ---------------------------------------------------------------------- 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) ) ); } }
// ---------------------------------------------------------------------- public ImageFormat GetImageFormat( RtfVisualImageFormat rtfVisualImageFormat ) { ImageFormat imageFormat = null; switch ( rtfVisualImageFormat ) { case RtfVisualImageFormat.Emf: imageFormat = ImageFormat.Emf; break; case RtfVisualImageFormat.Png: imageFormat = ImageFormat.Png; break; case RtfVisualImageFormat.Jpg: imageFormat = ImageFormat.Jpeg; break; case RtfVisualImageFormat.Wmf: imageFormat = ImageFormat.Wmf; break; case RtfVisualImageFormat.Bmp: imageFormat = ImageFormat.Bmp; break; } return imageFormat; }
} // RtfHtmlConvertSettings public string GetImageUrl(int index, RtfVisualImageFormat rtfVisualImageFormat) { var imageFileName = ImageAdapter.ResolveFileName(index, rtfVisualImageFormat); return(imageFileName.Replace('\\', '/')); } // GetImageUrl
// ---------------------------------------------------------------------- public string ResolveFileName( int index, RtfVisualImageFormat rtfVisualImageFormat ) { ImageFormat imageFormat = targetFormat ?? GetImageFormat( rtfVisualImageFormat ); return string.Format( CultureInfo.InvariantCulture, fileNamePattern, index, GetFileImageExtension( imageFormat ) ); }
} // GetImageFormat // ---------------------------------------------------------------------- public string ResolveFileName( int index, RtfVisualImageFormat rtfVisualImageFormat ) { ImageFormat imageFormat = this.targetFormat; if ( imageFormat == null ) { imageFormat = GetImageFormat( rtfVisualImageFormat ); } return string.Format( CultureInfo.InvariantCulture, this.fileNamePattern, index, GetFileImageExtension( imageFormat ) ); } // ResolveFileName
// ---------------------------------------------------------------------- protected virtual void DoInsertImage( IRtfInterpreterContext context, RtfVisualImageFormat format, int width, int height, int desiredWidth, int desiredHeight, int scaleWidthPercent, int scaleHeightPercent, string imageDataHex ) { }
// ---------------------------------------------------------------------- public string GetImageUrl( int index, RtfVisualImageFormat rtfVisualImageFormat ) { string imageFileName = imageAdapter.ResolveFileName( index, rtfVisualImageFormat ); return imageFileName.Replace( '\\', '/' ); }
// ---------------------------------------------------------------------- public void Reset() { format = RtfVisualImageFormat.Bmp; width = 0; height = 0; desiredWidth = 0; desiredHeight = 0; scaleWidthPercent = 100; scaleHeightPercent = 100; imageDataHex = null; }
// ---------------------------------------------------------------------- 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 ); }