Inheritance: IRtfTextFormat
Esempio n. 1
0
        } // DeriveWithSuperScript

        public RtfTextFormat DeriveWithSuperScript(bool super)
        {
            var copy = new RtfTextFormat(this);

            copy.FontSize    = Math.Max(1, FontSize * 2 / 3);
            copy.SuperScript = (super ? 1 : -1) * Math.Max(1, FontSize / 2);
            return(copy);
        } // DeriveWithSuperScript
        }         // DeriveWithSuperScript

        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithSuperScript(bool super)
        {
            RtfTextFormat copy = new RtfTextFormat(this);

            copy.fontSize    = Math.Max(1, (fontSize * 2) / 3);
            copy.superScript = (super ? 1 : -1) * Math.Max(1, fontSize / 2);
            return(copy);
        }         // DeriveWithSuperScript
Esempio n. 3
0
        }         // RtfDocument

        // ----------------------------------------------------------------------
        public RtfDocument(
            int rtfVersion,
            IRtfFont defaultFont,
            IRtfFontCollection fontTable,
            IRtfColorCollection colorTable,
            string generator,
            IRtfTextFormatCollection uniqueTextFormats,
            IRtfDocumentInfo documentInfo,
            IRtfDocumentPropertyCollection userProperties,
            IRtfVisualCollection visualContent
            )
        {
            if (rtfVersion != RtfSpec.RtfVersion1)
            {
                throw new RtfUnsupportedStructureException(Strings.UnsupportedRtfVersion(rtfVersion));
            }
            if (defaultFont == null)
            {
                throw new ArgumentNullException("defaultFont");
            }
            if (fontTable == null)
            {
                throw new ArgumentNullException("fontTable");
            }
            if (colorTable == null)
            {
                throw new ArgumentNullException("colorTable");
            }
            if (uniqueTextFormats == null)
            {
                throw new ArgumentNullException("uniqueTextFormats");
            }
            if (documentInfo == null)
            {
                throw new ArgumentNullException("documentInfo");
            }
            if (userProperties == null)
            {
                throw new ArgumentNullException("userProperties");
            }
            if (visualContent == null)
            {
                throw new ArgumentNullException("visualContent");
            }
            this.rtfVersion        = rtfVersion;
            this.defaultFont       = defaultFont;
            defaultTextFormat      = new RtfTextFormat(defaultFont, RtfSpec.DefaultFontSize);
            this.fontTable         = fontTable;
            this.colorTable        = colorTable;
            this.generator         = generator;
            this.uniqueTextFormats = uniqueTextFormats;
            this.documentInfo      = documentInfo;
            this.userProperties    = userProperties;
            this.visualContent     = visualContent;
        }         // RtfDocument
Esempio n. 4
0
        } // RtfDocument

        public RtfDocument(
            int rtfVersion,
            IRtfFont defaultFont,
            IRtfFontCollection fontTable,
            IRtfColorCollection colorTable,
            string generator,
            IRtfTextFormatCollection uniqueTextFormats,
            IRtfDocumentInfo documentInfo,
            IRtfDocumentPropertyCollection userProperties,
            IRtfVisualCollection visualContent
            )
        {
            if (rtfVersion != RtfSpec.RtfVersion1)
            {
                throw new RtfUnsupportedStructureException(Strings.UnsupportedRtfVersion(rtfVersion));
            }
            if (defaultFont == null)
            {
                throw new ArgumentNullException(nameof(defaultFont));
            }
            if (fontTable == null)
            {
                throw new ArgumentNullException(nameof(fontTable));
            }
            if (colorTable == null)
            {
                throw new ArgumentNullException(nameof(colorTable));
            }
            if (uniqueTextFormats == null)
            {
                throw new ArgumentNullException(nameof(uniqueTextFormats));
            }
            if (documentInfo == null)
            {
                throw new ArgumentNullException(nameof(documentInfo));
            }
            if (userProperties == null)
            {
                throw new ArgumentNullException(nameof(userProperties));
            }
            if (visualContent == null)
            {
                throw new ArgumentNullException(nameof(visualContent));
            }
            RtfVersion        = rtfVersion;
            DefaultFont       = defaultFont;
            DefaultTextFormat = new RtfTextFormat(defaultFont, RtfSpec.DefaultFontSize);
            FontTable         = fontTable;
            ColorTable        = colorTable;
            Generator         = generator;
            UniqueTextFormats = uniqueTextFormats;
            DocumentInfo      = documentInfo;
            UserProperties    = userProperties;
            VisualContent     = visualContent;
        } // RtfDocument
Esempio n. 5
0
        }         // SuperScript

        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithSuperScript(int deviation)
        {
            if (superScript == deviation)
            {
                return(this);
            }

            RtfTextFormat copy = new RtfTextFormat(this);

            copy.superScript = deviation;
            return(copy);
        }         // DeriveWithSuperScript
        }         // IsHidden

        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithHidden(bool derivedHidden)
        {
            if (hidden == derivedHidden)
            {
                return(this);
            }

            RtfTextFormat copy = new RtfTextFormat(this);

            copy.hidden = derivedHidden;
            return(copy);
        }         // DeriveWithHidden
        }         // IsStrikeThrough

        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithStrikeThrough(bool derivedStrikeThrough)
        {
            if (strikeThrough == derivedStrikeThrough)
            {
                return(this);
            }

            RtfTextFormat copy = new RtfTextFormat(this);

            copy.strikeThrough = derivedStrikeThrough;
            return(copy);
        }         // DeriveWithStrikeThrough
        }         // Alignment

        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithAlignment(RtfTextAlignment derivedAlignment)
        {
            if (alignment == derivedAlignment)
            {
                return(this);
            }

            RtfTextFormat copy = new RtfTextFormat(this);

            copy.alignment = derivedAlignment;
            return(copy);
        }         // DeriveWithForegroundColor
        }         // IsItalic

        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithItalic(bool derivedItalic)
        {
            if (italic == derivedItalic)
            {
                return(this);
            }

            RtfTextFormat copy = new RtfTextFormat(this);

            copy.italic = derivedItalic;
            return(copy);
        }         // DeriveWithItalic
        }         // IsUnderline

        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithUnderline(bool derivedUnderline)
        {
            if (underline == derivedUnderline)
            {
                return(this);
            }

            RtfTextFormat copy = new RtfTextFormat(this);

            copy.underline = derivedUnderline;
            return(copy);
        }         // DeriveWithUnderline
        }         // IsNormal

        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveNormal()
        {
            if (IsNormal)
            {
                return(this);
            }

            RtfTextFormat copy = new RtfTextFormat(font, RtfSpec.DefaultFontSize);

            copy.alignment = alignment; // this is a paragraph property, keep it
            return(copy);
        }                               // DeriveNormal
        }         // IsBold

        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithBold(bool derivedBold)
        {
            if (bold == derivedBold)
            {
                return(this);
            }

            RtfTextFormat copy = new RtfTextFormat(this);

            copy.bold = derivedBold;
            return(copy);
        }         // DeriveWithBold
        }         // FontSize

        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithFontSize(int derivedFontSize)
        {
            if (derivedFontSize < 0 || derivedFontSize > 0xFFFF)
            {
                throw new ArgumentException(Strings.FontSizeOutOfRange(derivedFontSize));
            }
            if (fontSize == derivedFontSize)
            {
                return(this);
            }

            RtfTextFormat copy = new RtfTextFormat(this);

            copy.fontSize = derivedFontSize;
            return(copy);
        }         // DeriveWithFontSize
Esempio n. 14
0
        } // DeriveWithHidden

        public RtfTextFormat DeriveWithBackgroundColor(IRtfColor derivedBackgroundColor)
        {
            if (derivedBackgroundColor == null)
            {
                throw new ArgumentNullException(nameof(derivedBackgroundColor));
            }
            if (BackgroundColor.Equals(derivedBackgroundColor))
            {
                return(this);
            }

            var copy = new RtfTextFormat(this);

            copy.BackgroundColor = derivedBackgroundColor;
            return(copy);
        } // DeriveWithBackgroundColor
        }         // Font

        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithFont(IRtfFont rtfFont)
        {
            if (rtfFont == null)
            {
                throw new ArgumentNullException("rtfFont");
            }
            if (font.Equals(rtfFont))
            {
                return(this);
            }

            RtfTextFormat copy = new RtfTextFormat(this);

            copy.font = rtfFont;
            return(copy);
        }         // DeriveWithFont
        }         // ForegroundColor

        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithForegroundColor(IRtfColor derivedForegroundColor)
        {
            if (derivedForegroundColor == null)
            {
                throw new ArgumentNullException("derivedForegroundColor");
            }
            if (foregroundColor.Equals(derivedForegroundColor))
            {
                return(this);
            }

            RtfTextFormat copy = new RtfTextFormat(this);

            copy.foregroundColor = derivedForegroundColor;
            return(copy);
        }         // DeriveWithForegroundColor
        }         // SuperScript

        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithSuperScript(int deviation)
        {
            if (superScript == deviation)
            {
                return(this);
            }

            RtfTextFormat copy = new RtfTextFormat(this);

            copy.superScript = deviation;
            // reset font size
            if (deviation == 0)
            {
                copy.fontSize = (fontSize / 2) * 3;
            }
            return(copy);
        }         // DeriveWithSuperScript
Esempio n. 18
0
        } // RtfTextFormat

        public RtfTextFormat(RtfTextFormat copy)
        {
            if (copy == null)
            {
                throw new ArgumentNullException(nameof(copy));
            }
            Font            = copy.Font; // enough because immutable
            FontSize        = copy.FontSize;
            SuperScript     = copy.SuperScript;
            IsBold          = copy.IsBold;
            IsItalic        = copy.IsItalic;
            IsUnderline     = copy.IsUnderline;
            IsStrikeThrough = copy.IsStrikeThrough;
            IsHidden        = copy.IsHidden;
            BackgroundColor = copy.BackgroundColor; // enough because immutable
            ForegroundColor = copy.ForegroundColor; // enough because immutable
            Alignment       = copy.Alignment;
        } // RtfTextFormat
        }         // GetHashCode

        // ----------------------------------------------------------------------
        private bool IsEqual(object obj)
        {
            RtfTextFormat compare = obj as RtfTextFormat;             // guaranteed to be non-null

            return
                (compare != null &&
                 font.Equals(compare.font) &&
                 fontSize == compare.fontSize &&
                 superScript == compare.superScript &&
                 bold == compare.bold &&
                 italic == compare.italic &&
                 underline == compare.underline &&
                 strikeThrough == compare.strikeThrough &&
                 hidden == compare.hidden &&
                 backgroundColor.Equals(compare.backgroundColor) &&
                 foregroundColor.Equals(compare.foregroundColor) &&
                 alignment == compare.alignment);
        }         // IsEqual
 // ----------------------------------------------------------------------
 public RtfTextFormat( RtfTextFormat copy )
 {
     if ( copy == null )
     {
         throw new ArgumentNullException( "copy" );
     }
     font = copy.font; // enough because immutable
     fontSize = copy.fontSize;
     superScript = copy.superScript;
     bold = copy.bold;
     italic = copy.italic;
     underline = copy.underline;
     strikeThrough = copy.strikeThrough;
     hidden = copy.hidden;
     backgroundColor = copy.backgroundColor; // enough because immutable
     foregroundColor = copy.foregroundColor; // enough because immutable
     alignment = copy.alignment;
 }
        }                                           // RtfTextFormat

        // ----------------------------------------------------------------------
        public RtfTextFormat(RtfTextFormat copy)
        {
            if (copy == null)
            {
                throw new ArgumentNullException("copy");
            }
            font            = copy.font;  // enough because immutable
            fontSize        = copy.fontSize;
            superScript     = copy.superScript;
            bold            = copy.bold;
            italic          = copy.italic;
            underline       = copy.underline;
            strikeThrough   = copy.strikeThrough;
            hidden          = copy.hidden;
            backgroundColor = copy.backgroundColor; // enough because immutable
            foregroundColor = copy.foregroundColor; // enough because immutable
            alignment       = copy.alignment;
        }                                           // RtfTextFormat
Esempio n. 22
0
		} // SuperScript

		// ----------------------------------------------------------------------
		public RtfTextFormat DeriveWithSuperScript( int deviation )
		{
			if ( this.superScript == deviation )
			{
				return this;
			}

			RtfTextFormat copy = new RtfTextFormat( this );
			copy.superScript = deviation;
			return copy;
		} // DeriveWithSuperScript
        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithUnderline( bool derivedUnderline )
        {
            if ( underline == derivedUnderline )
            {
                return this;
            }

            RtfTextFormat copy = new RtfTextFormat( this );
            copy.underline = derivedUnderline;
            return copy;
        }
 // ----------------------------------------------------------------------
 public RtfTextFormat DeriveWithSuperScript( bool super )
 {
     RtfTextFormat copy = new RtfTextFormat( this );
     copy.fontSize = Math.Max( 1, ( fontSize * 2 ) / 3 );
     copy.superScript = ( super ? 1 : -1 ) * Math.Max( 1, fontSize / 2 );
     return copy;
 }
        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithSuperScript( int deviation )
        {
            if ( superScript == deviation )
            {
                return this;
            }

            RtfTextFormat copy = new RtfTextFormat( this );
            copy.superScript = deviation;
            // reset font size
            if ( deviation == 0 )
            {
                copy.fontSize = ( fontSize / 2 ) * 3;
            }
            return copy;
        }
        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithStrikeThrough( bool derivedStrikeThrough )
        {
            if ( strikeThrough == derivedStrikeThrough )
            {
                return this;
            }

            RtfTextFormat copy = new RtfTextFormat( this );
            copy.strikeThrough = derivedStrikeThrough;
            return copy;
        }
        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithItalic( bool derivedItalic )
        {
            if ( italic == derivedItalic )
            {
                return this;
            }

            RtfTextFormat copy = new RtfTextFormat( this );
            copy.italic = derivedItalic;
            return copy;
        }
        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithHidden( bool derivedHidden )
        {
            if ( hidden == derivedHidden )
            {
                return this;
            }

            RtfTextFormat copy = new RtfTextFormat( this );
            copy.hidden = derivedHidden;
            return copy;
        }
        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithForegroundColor( IRtfColor derivedForegroundColor )
        {
            if ( derivedForegroundColor == null )
            {
                throw new ArgumentNullException( "derivedForegroundColor" );
            }
            if ( foregroundColor.Equals( derivedForegroundColor ) )
            {
                return this;
            }

            RtfTextFormat copy = new RtfTextFormat( this );
            copy.foregroundColor = derivedForegroundColor;
            return copy;
        }
        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithFontSize( int derivedFontSize )
        {
            if ( derivedFontSize < 0 || derivedFontSize > 0xFFFF )
            {
                throw new ArgumentException( Strings.FontSizeOutOfRange( derivedFontSize ) );
            }
            if ( fontSize == derivedFontSize )
            {
                return this;
            }

            RtfTextFormat copy = new RtfTextFormat( this );
            copy.fontSize = derivedFontSize;
            return copy;
        }
        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithFont( IRtfFont rtfFont )
        {
            if ( rtfFont == null )
            {
                throw new ArgumentNullException( "rtfFont" );
            }
            if ( font.Equals( rtfFont ) )
            {
                return this;
            }

            RtfTextFormat copy = new RtfTextFormat( this );
            copy.font = rtfFont;
            return copy;
        }
        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithBold( bool derivedBold )
        {
            if ( bold == derivedBold )
            {
                return this;
            }

            RtfTextFormat copy = new RtfTextFormat( this );
            copy.bold = derivedBold;
            return copy;
        }
        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveWithAlignment( RtfTextAlignment derivedAlignment )
        {
            if ( alignment == derivedAlignment )
            {
                return this;
            }

            RtfTextFormat copy = new RtfTextFormat( this );
            copy.alignment = derivedAlignment;
            return copy;
        }
        // ----------------------------------------------------------------------
        public RtfTextFormat DeriveNormal()
        {
            if ( IsNormal )
            {
                return this;
            }

            RtfTextFormat copy = new RtfTextFormat( font, RtfSpec.DefaultFontSize );
            copy.alignment = alignment; // this is a paragraph property, keep it
            return copy;
        }
 // ----------------------------------------------------------------------
 public void Reset()
 {
     state = RtfInterpreterState.Init;
     rtfVersion = RtfSpec.RtfVersion1;
     defaultFontId = "f0";
     fontTable.Clear();
     colorTable.Clear();
     generator = null;
     uniqueTextFormats.Clear();
     textFormatStack.Clear();
     currentTextFormat = null;
     documentInfo.Reset();
     userProperties.Clear();
 }
 // ----------------------------------------------------------------------
 public void PopCurrentTextFormat()
 {
     if ( textFormatStack.Count == 0 )
     {
         throw new RtfStructureException( Strings.InvalidTextContextState );
     }
     currentTextFormat = (RtfTextFormat)textFormatStack.Pop();
 }