public RtfFormatLock(RtfBuilder builder)
            {
                Contract.Requires(builder != null);

                this.builder = builder;

                wrapped = new RtfFormatWrapper(builder);

                builder.isLocked = true;
            }
            public RtfFormatWrapper(RtfBuilder builder)
            {
                Contract.Requires(builder != null);

                this.builder = builder;

                if (builder.isLocked)
                {
                    return;
                }

                var buffer = builder.buffer;

                int oldLength = buffer.Length;

                if ((builder.fontStyle & FontStyle.Bold) == FontStyle.Bold)
                {
                    buffer.Append(@"\b");
                }
                if ((builder.fontStyle & FontStyle.Italic) == FontStyle.Italic)
                {
                    buffer.Append(@"\i");
                }
                if ((builder.fontStyle & FontStyle.Underline) == FontStyle.Underline)
                {
                    buffer.Append(@"\ul");
                }
                if ((builder.fontStyle & FontStyle.Strikeout) == FontStyle.Strikeout)
                {
                    buffer.Append(@"\strike");
                }

                if (builder.fontSize != builder.defaultFontSize)
                {
                    buffer.AppendFormat(@"\fs{0}", builder.fontSize);
                }
                if (builder.fontIndex != 0)
                {
                    buffer.AppendFormat(@"\f{0}", builder.fontIndex);
                }
                if (builder.foreColor != builder.defaultForeColor)
                {
                    buffer.AppendFormat(@"\cf{0}", builder.IndexOfColor(builder.foreColor));
                }
                if (builder.backColor != builder.defaultBackColor)
                {
                    buffer.AppendFormat(@"\highlight{0}", builder.IndexOfColor(builder.backColor));
                }

                if (buffer.Length > oldLength)
                {
                    buffer.Append(" ");
                }
            }