Click here to Skip to main content
15,881,852 members
Articles / Desktop Programming / Windows Forms

RichText Builder (StringBuilder for RTF)

Rate me:
Please Sign up or sign in to vote.
4.86/5 (102 votes)
12 Nov 2008CPOL4 min read 246.6K   9.9K   214  
RichText Builder - use in place of StringBuilder to output RTF.



namespace RTF
{
    using System;

    public partial class RTFBuilder
    {
        #region Nested type: RTFCell

        // ----------------------------------------------------------------------------------------
        //    _                ___        _..-._   Date: 12/11/08    23:46
        //    \`.|\..----...-'`   `-._.-'' _.-..'     
        //    /  ' `         ,       __.-'' 
        //    )/` _/     \   `-_,   /     Solution: RTFLib
        //    `-'" `"\_  ,_.-;_.-\_ ',    Project : RTFLib                                 
        //        _.-'_./   {_.'   ; /    Author  : Anton
        //       {_.-``-'         {_/     Assembly: 1.0.0.0
        //                                Copyright © 2005-2008, Rogue Trader/MWM
        //        Project Item Name:      RTFCell.cs - Code
        //        Purpose:                Cell In Table Row
        // ----------------------------------------------------------------------------------------
        /// <summary>
        /// Cell In Table Row
        /// </summary>
        public class RTFCell : IBuilderContent
        {
            #region Fields

            private RTFBuilder _builder;
            private RTFCellDefinition _cellDefinition;
            private bool _firstAccessContent;

            #endregion

            #region Constructor

            public RTFCell(RTFBuilder builder, RTFCellDefinition cellDefinition)
            {
                this._builder = builder;
                this._cellDefinition = cellDefinition;
                this._firstAccessContent = true;
            }

            #endregion

            #region Override Methods

            ~RTFCell()
            {
                this.Dispose(false);
            }

            #endregion

            #region Methods

            protected void Dispose(bool disposing)
            {
                if (disposing && this._builder != null)
                {
                    this._builder._sb.AppendLine("\\cell ");
                }
                this._builder = null;
                if (disposing)
                {
                    GC.SuppressFinalize(this);
                }
            }

            #endregion

            #region IBuilderContent Members

            public void Dispose()
            {
                this.Dispose(true);
            }

            public RTFBuilderbase Content
            {
                get
                {
                    if (this._firstAccessContent)
                    {
                        //par in table
                        switch (this._cellDefinition.Alignment)
                        {
                            case RTFAlignment.TopCenter:
                            case RTFAlignment.BottomCenter:
                            case RTFAlignment.MiddleCenter:
                                this._builder._sb.Append("\\qc ");
                                break;
                            case RTFAlignment.TopLeft:
                            case RTFAlignment.MiddleLeft:
                            case RTFAlignment.BottomLeft:
                                this._builder._sb.Append("\\ql ");
                                break;
                            case RTFAlignment.TopRight:
                            case RTFAlignment.BottomRight:
                            case RTFAlignment.MiddleRight:
                                this._builder._sb.Append("\\qr ");
                                break;
                        }
                        this._firstAccessContent = false;
                    }
                    return this._builder;
                }
            }

            #endregion
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Australia Australia
Interested in financial math and programming theory in general. Working on medical applications in spare time. Happy to get feedback.

Comments and Discussions