// // DocumentFormatInfo.cs // // Author: Kees van Spelde // // Copyright (c) 2013-2018 Magic-Sessions. (www.magic-sessions.com) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; namespace MsgReader.Rtf { /// /// RTF Document format information /// internal class DocumentFormatInfo { #region Fields internal bool ReadText = true; private bool _subscript; private bool _superscript; #endregion #region Properties /// /// If this instance is created by Clone , return the parent instance /// public DocumentFormatInfo Parent { get; } /// /// Display left border line /// public bool LeftBorder { get; set; } /// /// Display top border line /// public bool TopBorder { get; set; } /// /// Display right border line /// public bool RightBorder { get; set; } /// /// Display bottom border line /// public bool BottomBorder { get; set; } /// /// Border line color /// public Color BorderColor { get; set; } /// /// Border line width /// public int BorderWidth { get; set; } /// /// Border style /// public DashStyle BorderStyle { get; set; } /// /// Border thicknes /// public bool BorderThickness { get; set; } /// /// Border spacing /// public int BorderSpacing { get; set; } /// /// Word wrap /// public bool Multiline { get; set; } /// /// Standard tab width /// public int StandTabWidth { get; set; } /// /// indent of first line in a paragraph /// [DefaultValue(0)] public int ParagraphFirstLineIndent { get; set; } /// /// Indent of wholly paragraph /// public int LeftIndent { get; set; } /// /// character spacing /// public int Spacing { get; set; } /// /// line spacing /// public int LineSpacing { get; set; } /// /// Current line spacing is multiple extractly line spacing. /// public bool MultipleLineSpacing { get; set; } /// /// Spacing before paragrah /// public int SpacingBefore { get; set; } /// /// Spacing after paragraph /// public int SpacingAfter { get; set; } /// /// Text alignment /// public RtfAlignment Align { get; set; } /// /// Page break /// public bool PageBreak { get; set; } /// /// Nest level in native rtf document /// public int NativeLevel { get; set; } public System.Drawing.Font Font { set { if (value == null) return; FontName = value.Name; FontSize = value.Size; Bold = value.Bold; Italic = value.Italic; Underline = value.Underline; Strikeout = value.Strikeout; } } /// /// Font name /// public string FontName { get; set; } /// /// Font size /// public float FontSize { get; set; } /// /// Bold style /// public bool Bold { get; set; } /// /// Italic style /// public bool Italic { get; set; } /// /// Underline style /// public bool Underline { get; set; } /// /// Strickout style /// public bool Strikeout { get; set; } /// /// Hidden text /// public bool Hidden { get; set; } /// /// Text color /// public Color TextColor { get; set; } /// /// Back color /// public Color BackColor { get; set; } /// /// Link /// public string Link { get; set; } /// /// Superscript /// public bool Superscript { get { return _superscript; } set { _superscript = value; if (_superscript) _subscript = false; } } /// /// Subscript /// public bool Subscript { get { return _subscript; } set { _subscript = value; if (_subscript) { _superscript = false; } } } /// /// List override id /// public int ListId { get; set; } /// /// No wrap in word /// public bool NoWwrap { get; set; } #endregion #region SetAlign public void SetAlign(StringAlignment align) { switch (align) { case StringAlignment.Center: Align = RtfAlignment.Center; break; case StringAlignment.Far: Align = RtfAlignment.Right; break; default: Align = RtfAlignment.Left; break; } } #endregion #region DocumentFormatInfo public DocumentFormatInfo() { NoWwrap = true; ListId = -1; Link = null; BackColor = Color.Empty; TextColor = Color.Black; Hidden = false; Strikeout = false; Underline = false; Italic = false; Bold = false; FontSize = 12f; FontName = SystemFonts.DefaultFont.Name; Align = RtfAlignment.Left; SpacingAfter = 0; SpacingBefore = 0; MultipleLineSpacing = false; LineSpacing = 0; Spacing = 0; LeftIndent = 0; ParagraphFirstLineIndent = 0; PageBreak = false; StandTabWidth = 100; BorderColor = Color.Black; Multiline = false; BorderSpacing = 0; BorderThickness = false; BorderStyle = DashStyle.Solid; BorderWidth = 0; BottomBorder = false; RightBorder = false; TopBorder = false; LeftBorder = false; Parent = null; } #endregion #region EqualsSettings public bool EqualsSettings(DocumentFormatInfo format) { if (format == this) return true; if (format == null) return false; if (Align != format.Align) return false; if (BackColor != format.BackColor) return false; if (Bold != format.Bold) return false; if (BorderColor != format.BorderColor) return false; if (LeftBorder != format.LeftBorder) return false; if (TopBorder != format.TopBorder) return false; if (RightBorder != format.RightBorder) return false; if (BottomBorder != format.BottomBorder) return false; if (BorderStyle != format.BorderStyle) return false; if (BorderThickness != format.BorderThickness) return false; if (BorderSpacing != format.BorderSpacing) return false; if (ListId != format.ListId) return false; if (FontName != format.FontName) return false; // ReSharper disable once CompareOfFloatsByEqualityOperator if (FontSize != format.FontSize) return false; if (Italic != format.Italic) return false; if (Hidden != format.Hidden) return false; if (LeftIndent != format.LeftIndent) return false; if (LineSpacing != format.LineSpacing) return false; if (Link != format.Link) return false; if (Multiline != format.Multiline) return false; if (NoWwrap != format.NoWwrap) return false; if (ParagraphFirstLineIndent != format.ParagraphFirstLineIndent) return false; if (Spacing != format.Spacing) return false; if (StandTabWidth != format.StandTabWidth) return false; if (Strikeout != format.Strikeout) return false; if (Subscript != format.Subscript) return false; if (Superscript != format.Superscript) return false; if (TextColor != format.TextColor) return false; if (Underline != format.Underline) return false; if (ReadText != format.ReadText) return false; return true; } #endregion #region Clone /// /// Clone instance /// /// new instance public DocumentFormatInfo Clone() { return (DocumentFormatInfo) MemberwiseClone(); } #endregion #region ResetText public void ResetText() { FontName = SystemFonts.DefaultFont.Name; Bold = false; Italic = false; Underline = false; Strikeout = false; TextColor = Color.Black; BackColor = Color.Empty; //Link = null ; Subscript = false; Superscript = false; Multiline = true; Hidden = false; LeftBorder = false; TopBorder = false; RightBorder = false; BottomBorder = false; BorderStyle = DashStyle.Solid; BorderSpacing = 0; BorderThickness = false; BorderColor = Color.Black ; } #endregion #region ResetParagraph public void ResetParagraph() { ParagraphFirstLineIndent = 0; Align = 0; ListId = -1; LeftIndent = 0; LineSpacing = 0; PageBreak = false; LeftBorder = false; TopBorder = false; RightBorder = false; BottomBorder = false; BorderStyle = DashStyle.Solid; BorderSpacing = 0; BorderThickness = false; BorderColor = Color.Black ; MultipleLineSpacing = false; SpacingBefore = 0; SpacingAfter = 0; } #endregion #region Reset public void Reset() { ParagraphFirstLineIndent = 0; LeftIndent = 0; LeftIndent = 0; Spacing = 0; LineSpacing = 0; MultipleLineSpacing = false; SpacingBefore = 0; SpacingAfter = 0; Align = 0; FontName = SystemFonts.DefaultFont.Name; FontSize = 12; Bold = false; Italic = false; Underline = false; Strikeout = false; TextColor = Color.Black; BackColor = Color.Empty; Link = null; Subscript = false; Superscript = false; ListId = -1; Multiline = true; NoWwrap = true; LeftBorder = false; TopBorder = false; RightBorder = false; BottomBorder = false; BorderStyle = DashStyle.Solid; BorderSpacing = 0; BorderThickness = false; BorderColor = Color.Black; ReadText = true; NativeLevel = 0; Hidden = false; } #endregion } }