} // 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
} // RtfDocument // ---------------------------------------------------------------------- public RtfDocument( int rtfVersion, IRtfFont defaultFont, RtfFontCollection fontTable, IList <IRtfColor> colorTable, string generator, IList <IRtfTextFormat> uniqueTextFormats, IRtfDocumentInfo documentInfo, IList <IRtfDocumentProperty> userProperties, IList <IRtfVisual> 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
} // Alignment // ---------------------------------------------------------------------- public RtfTextFormat DeriveWithAlignment(RtfTextAlignment derivedAlignment) { if (alignment == derivedAlignment) { return(this); } RtfTextFormat copy = new RtfTextFormat(this); copy.alignment = derivedAlignment; return(copy); } // DeriveWithForegroundColor
} // 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
} // IsUnderline // ---------------------------------------------------------------------- public RtfTextFormat DeriveWithUnderline(bool derivedUnderline) { if (underline == derivedUnderline) { return(this); } RtfTextFormat copy = new RtfTextFormat(this); copy.underline = derivedUnderline; return(copy); } // DeriveWithUnderline
} // IsItalic // ---------------------------------------------------------------------- public RtfTextFormat DeriveWithItalic(bool derivedItalic) { if (italic == derivedItalic) { return(this); } RtfTextFormat copy = new RtfTextFormat(this); copy.italic = derivedItalic; return(copy); } // DeriveWithItalic
} // IsBold // ---------------------------------------------------------------------- public RtfTextFormat DeriveWithBold(bool derivedBold) { if (bold == derivedBold) { return(this); } RtfTextFormat copy = new RtfTextFormat(this); copy.bold = derivedBold; return(copy); } // DeriveWithBold
} // 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
} // 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
} // 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
} // 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
} // 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
} // 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
} // 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