Example #1
0
        protected bool InitConsts(TaskList tasks, string destFilePath, bool silent, Preferences prefs, string sKey)
        {
            // Load Settings
            int fontSize = prefs.GetProfileInt("Preferences", "HtmlFontSize", 2);

            m_BaseFontSize = HtmlFontConversion.PointsFromHtml((HtmlFontSize)fontSize);

            var installedFont   = prefs.GetProfileString(sKey, "InstalledFont", "");
            var defaultHtmlFont = prefs.GetProfileString("Preferences", "HtmlFont", "Verdana");

            if (string.IsNullOrEmpty(installedFont))
            {
                installedFont = defaultHtmlFont;
            }

            bool useOtherFont = prefs.GetProfileBool(sKey, "UseOtherFont", false);

            var optionsDlg = new PDFExporterOptionsForm(m_FontMappings)
            {
                InstalledFont         = installedFont,
                OtherFontFile         = prefs.GetProfileString(sKey, "OtherFontFile", ""),
                UseOtherFont          = prefs.GetProfileBool(sKey, "UseOtherFont", false),
                ApplyFontToAllContent = prefs.GetProfileBool(sKey, "ApplyFontToAllContent", true),
                UseWatermarkImage     = prefs.GetProfileBool(sKey, "UseWatermarkImage", false),
                WatermarkImagePath    = prefs.GetProfileString(sKey, "WatermarkImagePath", "")
            };

            if (!silent && (optionsDlg.ShowDialog() == DialogResult.Cancel))
            {
                return(false);
            }

            // Clear the installed font setting if it's the same
            // as the default so changes to the default will be picked up
            if (string.Compare(optionsDlg.InstalledFont, defaultHtmlFont, true) == 0)
            {
                prefs.DeleteProfileEntry(sKey, "InstalledFont");
            }
            else
            {
                prefs.WriteProfileString(sKey, "InstalledFont", optionsDlg.InstalledFont);
            }

            prefs.WriteProfileBool(sKey, "UseOtherFont", optionsDlg.UseOtherFont);
            prefs.WriteProfileString(sKey, "OtherFontFile", optionsDlg.OtherFontFile);
            prefs.WriteProfileBool(sKey, "ApplyFontToAllContent", optionsDlg.ApplyFontToAllContent);
            prefs.WriteProfileBool(sKey, "UseWatermarkImage", optionsDlg.UseWatermarkImage);
            prefs.WriteProfileString(sKey, "WatermarkImagePath", optionsDlg.WatermarkImagePath);

            m_ApplyBaseFontToAllContent = optionsDlg.ApplyFontToAllContent;

            if (optionsDlg.UseOtherFont && m_FontMappings.RegisterFile(optionsDlg.OtherFontFile))
            {
                m_BaseFontName = m_FontMappings.GetFontFromFileName(optionsDlg.OtherFontFile);
            }
            else
            {
                m_BaseFontName = optionsDlg.InstalledFont;
            }

            RegisterFont(m_BaseFontName);             // always

            if (optionsDlg.UseWatermarkImage)
            {
                m_WatermarkImagePath = optionsDlg.WatermarkImagePath;
            }
            else
            {
                m_WatermarkImagePath = "";
            }

            BuildAttributeList(tasks);

            return(true);
        }
        protected bool InitConsts(TaskList tasks, string destFilePath, bool silent, Preferences prefs, string sKey)
        {
            // Create base font
            var  installedFontFile = prefs.GetProfileString(sKey, "InstalledFontFile", "");
            var  otherFontFile     = prefs.GetProfileString(sKey, "OtherFontFile", "");
            bool useOtherFont      = prefs.GetProfileBool(sKey, "UseOtherFont", false);

            int fontSize = prefs.GetProfileInt("Preferences", "HtmlFontSize", 2);

            m_BaseFontSize = HtmlFontConversion.PointsFromHtml((HtmlFontSize)fontSize);

            var htmlFont = prefs.GetProfileString("Preferences", "HtmlFont", "Verdana");
            var defaultInstalledFontFile = PDFExporterForm.GetFileNameFromFont(htmlFont);

            if (string.IsNullOrEmpty(installedFontFile))
            {
                installedFontFile = defaultInstalledFontFile;
            }

            var fontDlg = new PDFExporterForm(installedFontFile, otherFontFile, useOtherFont);

            if (!silent && (fontDlg.ShowDialog() == DialogResult.Cancel))
            {
                return(false);
            }

            // Clear the installed font setting if it's the same
            // as the default so changes to the default will be picked up
            if (string.Compare(fontDlg.InstalledFontPath, defaultInstalledFontFile, true) == 0)
            {
                prefs.DeleteProfileEntry(sKey, "InstalledFontFile");
            }
            else
            {
                prefs.WriteProfileString(sKey, "InstalledFontFile", fontDlg.InstalledFontPath);
            }

            prefs.WriteProfileString(sKey, "OtherFontFile", fontDlg.OtherFontPath);
            prefs.WriteProfileBool(sKey, "UseOtherFont", fontDlg.UseOtherFont);

            m_BaseFont = BaseFont.CreateFont(fontDlg.SelectedFontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

            // Build attribute list
            m_AvailAttributes = new List <TaskAttribute>();

            var attribs = tasks.GetAvailableAttributes();

            foreach (var attrib in attribs)
            {
                switch (attrib)
                {
                case Task.Attribute.Comments:
                    m_WantComments = true;
                    break;

                case Task.Attribute.HtmlComments:
                    m_WantComments = true;
                    break;

                case Task.Attribute.Position:
                    m_WantPosition = true;
                    break;

//              case Task.Attribute.CustomAttribute:
//                  // TODO
//                  break;

                case Task.Attribute.MetaData:
                    // Not a user attribute
                    break;

                case Task.Attribute.ProjectName:
                    // Not a task attribute
                    break;

                case Task.Attribute.Color:
                    // handled separately
                    break;

                case Task.Attribute.Title:
                    // handled separately
                    break;

                default:
                    m_AvailAttributes.Add(new TaskAttribute(attrib, m_Trans.Translate(TaskList.GetAttributeName(attrib))));
                    break;
                }
            }

            m_AvailAttributes.Sort((a, b) => String.Compare(a.Name, b.Name));

            return(true);
        }