/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create columns.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private StringBuilder FormatSearchItemTabString(StringBuilder tabFormatBldr,
                                                        float columnStartPoint)
        {
            tabFormatBldr.Append(@"\tqr");
            while (m_createSearchItemTabs != CreateSearchItemTabs.Stop)
            {
                if (m_createSearchItemTabs == CreateSearchItemTabs.FirstTab)
                {
                    if (m_exportFormat == ExportFormat.TabDelimited)
                    {
                        m_beforeEnvTwipWidth += (int)columnStartPoint;
                    }

                    m_createSearchItemTabs = CreateSearchItemTabs.SecondTab;
                }
                else if (m_createSearchItemTabs == CreateSearchItemTabs.SecondTab)
                {
                    m_createSearchItemTabs = CreateSearchItemTabs.FinishedTabs;
                    m_beforeEnvTwipWidth  += kGapBetweenSrchItemAndPrecedingEnv;
                }

                tabFormatBldr.AppendFormat(ktxcell, m_beforeEnvTwipWidth);

                if (m_createSearchItemTabs == CreateSearchItemTabs.FinishedTabs)
                {
                    m_createSearchItemTabs = CreateSearchItemTabs.Stop;
                }
            }

            return(tabFormatBldr);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// RtfCreator constructor.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public RtfCreator(PaProject project, ExportTarget target, ExportFormat format,
                          DataGridView grid, WordListCache cache, string rtfEditor)
        {
            m_project      = project;
            m_exportTarget = target;
            m_exportFormat = format;
            m_grid         = grid;

            if (m_grid != null)
            {
                m_graphics = m_grid.CreateGraphics();

                // Store the dots per inch value from the grid's graphic object
                m_pixelsPerInch = m_graphics.DpiX;
            }

            m_cache                = cache;
            m_rtfEditor            = rtfEditor;
            m_createSearchItemTabs = CreateSearchItemTabs.FirstTab;
            m_rtfBldr              = new StringBuilder();

            // Default value is 1/8" gap between columns.
            m_colRightPadding = Properties.Settings.Default.RTFExportGapBetweenColumns;

            // Add support for highlighting the search item
            if (m_cache.IsForSearchResults)
            {
                Dictionary <int, int> colorReferences;
                RtfHelper.ColorTable(Properties.Settings.Default.QuerySearchItemBackColor, out colorReferences);
                m_searchItemColorRefNumber = colorReferences[Properties.Settings.Default.QuerySearchItemBackColor.ToArgb()];
            }

            // Sort the visible columns by their display order.
            m_sortedColumns = new SortedList <int, DataGridViewColumn>();
            foreach (DataGridViewColumn col in m_grid.Columns)
            {
                if (col.Visible && !(col is SilHierarchicalGridColumn))
                {
                    m_sortedColumns[col.DisplayIndex] = col;
                }
            }

            GetPaperAndMarginValues();
            CalculateColumnWidths();
            OutputRTFHeadingStuff();

            // This is only for running tests
            if (m_maxFieldWidths.Count > 0)
            {
                MakeFinalWidthAdjustments();
                m_rtfBldr.AppendFormat(@"\paperw{0}\paperh{1}", m_paperWidth, m_paperHeight);
                m_rtfBldr.AppendFormat(@"\margl{0}\margr{1}", m_leftMargin, m_rightMargin);
                m_rtfBldr.AppendFormat(@"\margt{0}\margb{1}", m_topMargin, m_bottomMargin);
                m_rtfBldr.AppendLine();

                OutputReportHeadingInformation();
                OutputColumnInformation();
                OutputDataRows();
                WriteToFileOrClipboard();
            }

            if (m_graphics != null)
            {
                m_graphics.Dispose();
            }
        }