Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

RichText Builder (StringBuilder for RTF)

, 12 Nov 2008 CPOL
RichText Builder - use in place of StringBuilder to output RTF.



 

namespace RTF
{
    using System;
    using System.Drawing;

    public partial class RTFBuilder
    {
        #region Nested type: RTFParaWrap

        // ----------------------------------------------------------------------------------------
        //    _                ___        _..-._   Date: 12/11/08    23:36
        //    \`.|\..----...-'`   `-._.-'' _.-..'     
        //    /  ' `         ,       __.-'' 
        //    )/` _/     \   `-_,   /     Solution: RTFLib
        //    `-'" `"\_  ,_.-;_.-\_ ',    Project : RTFLib                                 
        //        _.-'_./   {_.'   ; /    Author  : Anton
        //       {_.-``-'         {_/     Assembly: 1.0.0.0
        //                                Copyright © 2005-2008, Rogue Trader/MWM
        //        Project Item Name:      RTFBuilder.RTFParaWrap.cs - Code
        //        Purpose:                Wraps RtfBuilderbase injecting appropriate rtf codes after paragraph append 
        // ----------------------------------------------------------------------------------------
        /// <summary>
        /// Wraps RtfBuilderbase injecting appropriate rtf codes after paragraph append 
        /// </summary>
        private class RTFParaWrap : IDisposable
        {
            #region Fields

            private readonly RTFBuilder _builder;

            #endregion

            #region Constructor

            public RTFParaWrap(RTFBuilder builder)
            {
                this._builder = builder;
                int len = this._builder._sb.Length;
                if (this._builder._sf.Alignment == StringAlignment.Center)
                {
                    this._builder._sb.Append("\\qc");
                }
                else if (this._builder._sf.Alignment == StringAlignment.Far)
                {
                    this._builder._sb.Append("\\qr");
                }
                if (this._builder._firstLineIndent > 0)
                {
                    this._builder._sb.Append("\\fi" + this._builder._firstLineIndent);
                }
                if (this._builder._lineIndent > 0)
                {
                    this._builder._sb.Append("\\li" + this._builder._lineIndent);
                }


                if (this._builder._sb.Length > len)
                {
                    this._builder._sb.Append(" ");
                }
            }

            #endregion

            #region Override Methods

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

            #endregion

            #region Methods

            protected void Dispose(bool disposing)
            {
                if ( this._builder != null && !this._builder._unwrapped)
                {
                    if (this._builder._sf.Alignment != StringAlignment.Near || this._builder._lineIndent > 0 || this._builder._firstLineIndent > 0)
                    {
                        this._builder._firstLineIndent = 0;
                        this._builder._lineIndent = 0;
                        this._builder._sf.Alignment = StringAlignment.Near;
                        this._builder._sb.Append("\\pard ");
                    }
                }
                if (disposing)
                {
                    GC.SuppressFinalize(this);
                }
            }

            #endregion

            #region IDisposable Members

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

            #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)

Share

About the Author

seeblunt

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 12 Nov 2008
Article Copyright 2008 by seeblunt
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid