Пример #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Write the Rtf string to an output file or the clipboard.
        /// </summary>
        /// <returns>true if the message was handled</returns>
        /// ------------------------------------------------------------------------------------
        private void WriteToFileOrClipboard()
        {
            var rtf = RtfHelper.TranslateUnicodeChars(m_rtfBldr.ToString());

            if (m_exportTarget == ExportTarget.Clipboard)
            {
                Clipboard.SetText(rtf, TextDataFormat.Rtf);
                return;
            }

            string filter = App.kstidFiletypeRTF + "|" + App.kstidFileTypeAllFiles;

            int filterIndex = 0;

            var caption = LocalizationManager.GetString("Views.WordLists.RtfExport.SaveFileDialogText", "Save RTF File",
                                                        "Save file dialog caption for specifying the rtf file exported to under RTF export");

            var filename = App.SaveFileDialog("rtf", filter, ref filterIndex, caption, string.Empty);

            if (filename != string.Empty)
            {
                try
                {
                    using (var sw = new StreamWriter(filename))
                        sw.Write(rtf);
                }
                catch (Exception ex)
                {
                    Utils.MsgBox(ex.Message);
                    return;
                }
                // Open the file with the specified RTF editor
                if (m_exportTarget == ExportTarget.FileAndOpen)
                {
                    OpenInEditor(filename);
                }
            }
        }
Пример #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Performs all the final steps (i.e. formatting all the information into a big RTF
        /// blob) for setting the text box's RTF.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void FormatRTF(string tabStopsString,
                               string firstLineTabStopsString, string subordinateTabStopsString)
        {
            StringBuilder         lines = new StringBuilder(m_rtf);
            Dictionary <int, int> colorReferences;
            Color clrFieldLabel = Properties.Settings.Default.RecordViewFieldLabelColor;

            lines.AppendLine();
            lines.AppendLine(RtfHelper.ColorTable(clrFieldLabel, out colorReferences));

            GetLargestFontInfo();
            m_fieldLabelColorRefNumber = colorReferences[clrFieldLabel.ToArgb()];

            for (int i = 0; i < m_rowsInCol1; i++)
            {
                lines.AppendLine(@"\pard\plain");

                if (m_useExactLineSpacing)
                {
                    // The default line spacing is usually larger than necessary, especially if
                    // one of the fonts is Doulos SIL. Therefore, scrunch them together a little.
                    lines.AppendFormat(@"\sl-{0}\slmult0", m_lineSpacing);
                }

                if (m_rtfFields[i].isInterlinearField)
                {
                    FormatInterlinearForRTF(m_rtfFields[i], lines,
                                            firstLineTabStopsString, subordinateTabStopsString);
                }
                else
                {
                    lines.AppendLine(tabStopsString);

                    int  dataFontNumber = m_fontNumbers[m_rtfFields[i].field];
                    int  dataFontSize   = m_fontSizes[m_rtfFields[i].field];
                    Font dataFont       = m_fonts[m_rtfFields[i].field];

                    lines.AppendFormat(kFmtOneLineOneCol, new object[] { m_fieldLabelColorRefNumber,
                                                                         m_uiFontSize, m_uiFontNumber, m_rtfFields[i].label });

                    lines.Append(ApplyFontStyle(dataFont, true));
                    lines.AppendFormat(kline, dataFontNumber, dataFontSize, m_rtfFields[i].fieldValue);
                    lines.Append(ApplyFontStyle(dataFont, false));

                    if (m_rowsInCol1 + i < m_rtfFields.Count)
                    {
                        lines.Append("\\tab ");
                        dataFontNumber = m_fontNumbers[m_rtfFields[m_rowsInCol1 + i].field];
                        dataFontSize   = m_fontSizes[m_rtfFields[m_rowsInCol1 + i].field];
                        dataFont       = m_fonts[m_rtfFields[m_rowsInCol1 + i].field];

                        lines.AppendFormat(kFmtOneLineOneCol, new object[] { m_fieldLabelColorRefNumber,
                                                                             m_uiFontSize, m_uiFontNumber, m_rtfFields[m_rowsInCol1 + i].label });

                        lines.Append(ApplyFontStyle(dataFont, true));
                        lines.AppendFormat(kline, dataFontNumber, dataFontSize,
                                           m_rtfFields[m_rowsInCol1 + i].fieldValue);
                        lines.Append(ApplyFontStyle(dataFont, false));
                    }

                    if (m_useExactLineSpacing)
                    {
                        // Add a zero width space at the end of the line using the largest font so all
                        // the lines will have uniform spacing between. I tried using a regular space
                        // but the RTF control ignored it. I also tried forcing the line spacing using
                        // the \slN RTF code, but that didn't seem to work either. It looked great in
                        // Word, but not the RichTextBox. Grrr!
                        lines.AppendFormat(@"\fs{0}\f{1} {2}", m_maxFontSize, m_maxFontNumber,
                                           kZeroWidthSpace);
                    }

                    lines.AppendLine(@"\par");
                }
            }

            lines.Append("}");
            Rtf = RtfHelper.TranslateUnicodeChars(lines.ToString());
        }