} // 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; // 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(); } // EndParagraph
// ---------------------------------------------------------------------- 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
} // Alignment // ---------------------------------------------------------------------- public RtfTextFormat DeriveWithAlignment(RtfTextAlignment derivedAlignment) { if (alignment == derivedAlignment) { return(this); } RtfTextFormat copy = new RtfTextFormat(this); copy.alignment = derivedAlignment; return(copy); } // DeriveWithForegroundColor
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; }
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
// ---------------------------------------------------------------------- public RtfTextFormat( IRtfTextFormat copy ) { if ( copy == null ) { throw new ArgumentNullException( "copy" ); } font = copy.Font; // enough because immutable fontSize = copy.FontSize; superScript = copy.SuperScript; bold = copy.IsBold; italic = copy.IsItalic; underline = copy.IsUnderline; strikeThrough = copy.IsStrikeThrough; hidden = copy.IsHidden; backgroundColor = copy.BackgroundColor; // enough because immutable foregroundColor = copy.ForegroundColor; // enough because immutable alignment = copy.Alignment; }
// ---------------------------------------------------------------------- public RtfTextFormat DeriveWithAlignment( RtfTextAlignment derivedAlignment ) { if ( alignment == derivedAlignment ) { return this; } RtfTextFormat copy = new RtfTextFormat( this ); copy.alignment = derivedAlignment; return copy; }