Example #1
0
 public void CharisTest()
 {
     var silFont = new EmbeddedFont("Charis SIL");
     Assert.IsTrue(FontInternals.IsInstalled("Charis SIL"));
     Assert.IsTrue(silFont.CanRedistribute);
     Assert.IsTrue(silFont.Serif);
 }
Example #2
0
 public void AbyssinicaTest()
 {
     Assert.IsTrue(FontInternals.IsInstalled("Abyssinica SIL"));
     var silFont = new EmbeddedFont("Abyssinica SIL");
     Assert.IsTrue(silFont.CanRedistribute);
     Assert.IsTrue(silFont.Serif);
 }
Example #3
0
 public void FreeFontTest()
 {
     Assert.IsTrue(FontInternals.IsInstalled("Arial"));
     var arialFont = new EmbeddedFont("Arial");
     Assert.IsTrue(arialFont.CanRedistribute);
     const string fontFilename = "Arial.ttf";
     Assert.IsTrue(fontFilename.ToLower().Equals(Path.GetFileName(arialFont.Filename).ToLower()));
 }
Example #4
0
 public void AndikaTest()
 {
     string fontName = "Andika Basic";
     if(Common.IsUnixOS())
     {
         fontName = "Andika";
     }
     var silFont = new EmbeddedFont(fontName);
     Assert.IsTrue(FontInternals.IsInstalled(fontName));
     Assert.IsTrue(silFont.CanRedistribute);
     Assert.IsFalse(silFont.Serif);
 }
Example #5
0
 // display warning dialog
 private void FontWarningDlg_Load(object sender, EventArgs e)
 {
     icnWarning.Image = SystemIcons.Warning.ToBitmap();
     EmbeddedFont curfont = new EmbeddedFont(MyEmbeddedFont);
     if (string.IsNullOrEmpty(curfont.Filename))
     {
         // show "missing font" UI (only option is to substitute)
         Text = String.Format(Resources.MissingFontTitle, MyEmbeddedFont);
         txtWarning.Text = String.Format(Resources.MissingFontWarning, MyEmbeddedFont, Languages);
         grpOptions.Text = Resources.EmbedFontOptions;
         //rdoEmbedFont.Visible = false;
         //rdoConvertToSILFont.Visible = false;
         lblSubstituteSILFont.Visible = true;
         lblSubstituteSILFont.Text = Resources.ConvertToSILFont;
         ddlSILFonts.Enabled = true;
     }
     else
     {
         // show "non SIL font" UI (radio buttons with the option to just embed)
         Text = Resources.FontWarningDlgTitle;
         txtWarning.Text = String.Format(Resources.EmbedFontsWarning, MyEmbeddedFont, Languages);
         grpOptions.Text = Resources.EmbedFontOptions;
         //rdoEmbedFont.Text = Resources.EmbedFont;
         //rdoConvertToSILFont.Text = Resources.ConvertToSILFont;
         lblSubstituteSILFont.Visible = true;
         lblSubstituteSILFont.Text = Resources.ConvertToSILFont;
         ddlSILFonts.Enabled = true;
     }
     if (ddlSILFonts.Items.Count == 0)
     {
         // update the possible replacements based on what's installed on this system
         ddlSILFonts.Items.AddRange(_silFonts);
         if (ddlSILFonts.Items.Count > 0)
         {
             ddlSILFonts.SelectedIndex = 0;
         }
     }
     if (RemainingIssues > 0)
     {
         chkRepeatAction.Visible = true;
         chkRepeatAction.Text = String.Format(Resources.RepeatAction, RemainingIssues);
         chkRepeatAction.Checked = RepeatAction;
     }
 }
Example #6
0
        private bool AskUserAboutEachFont(string[] langArray, Dictionary<EmbeddedFont, string> nonSilFonts)
        {
            var dlg = new FontWarningDlg { RepeatAction = false, RemainingIssues = nonSilFonts.Count - 1 };
            // Handle the cases where the user wants to automatically process non-SIL / missing fonts
            if (_parent.NonSilFont == FontHandling.CancelExport)
            {
                // TODO: implement message box
                // Give the user a message indicating there's a non-SIL font in their writing system, and
                // to go fix the problem. Don't let them continue with the export.
                return false;
            }
            if (_parent.NonSilFont != FontHandling.PromptUser)
            {
                dlg.RepeatAction = true; // the handling picks up below...
                dlg.SelectedFont = _parent.DefaultFont;
            }
            foreach (var nonSilFont in nonSilFonts)
            {
                dlg.MyEmbeddedFont = nonSilFont.Key.Name;
                dlg.Languages = nonSilFont.Value;
                bool isMissing = (string.IsNullOrEmpty(nonSilFont.Key.Filename));
                bool isManualProcess = ((isMissing == false && _parent.NonSilFont == FontHandling.PromptUser) || (isMissing == true && _parent.MissingFont == FontHandling.PromptUser));
                if (dlg.RepeatAction)
                {
                    // user wants to repeat the last action - if the last action
                    // was to change the font, change this one as well
                    // (this is also where the automatic FontHandling takes place)
                    if ((!dlg.UseFontAnyway() && !nonSilFont.Key.Name.Equals(dlg.SelectedFont) && isManualProcess) || // manual "repeat this action" for non-SIL AND missing fonts
                        (isMissing == false && _parent.NonSilFont == FontHandling.SubstituteDefaultFont && !nonSilFont.Key.Name.Equals(_parent.DefaultFont)) || // automatic for non-SIL fonts
                        (isMissing == true && _parent.MissingFont == FontHandling.SubstituteDefaultFont && !nonSilFont.Key.Name.Equals(_parent.DefaultFont))) // automatic for missing fonts
                    {
                        // the user has chosen a different (SIL) font - 
                        // create a new EmbeddedFont and add it to the list
                        _embeddedFonts.Remove(nonSilFont.Key.Name);
                        var newFont = new EmbeddedFont(dlg.SelectedFont);
                        _embeddedFonts[dlg.SelectedFont] = newFont; // set index value adds if it doesn't exist
                        // also update the references in _langFontDictionary
                        foreach (var lang in langArray)
                        {
                            if (_langFontDictionary[lang] == nonSilFont.Key.Name)
                            {
                                _langFontDictionary[lang] = dlg.SelectedFont;
                            }
                        }
                    }
                    // the UseFontAnyway checkbox (and FontHandling.EmbedFont) cases fall through here -
                    // The current non-SIL font is ignored and embedded below
                    continue;
                }
                // sanity check - are there any SIL fonts installed?
                int count = dlg.BuildSILFontList();
                if (count == 0)
                {
                    // No SIL fonts found (returns a DialogResult.Abort):
                    // tell the user there are no SIL fonts installed, and allow them to Cancel
                    // and install the fonts now
					if (Utils.MsgBox(Resources.NoSILFontsMessage, Resources.NoSILFontsTitle,
                                         MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
                        == DialogResult.Cancel)
                    {
                        // user cancelled the operation - Cancel out of the whole .epub export
                        return false;
                    }
                    // user clicked OK - leave the embedded font list alone and continue the export
                    // (presumably the user has the proper rights to this font, even though it isn't
                    // an SIL font)
                    break;
                }
                // show the dialog
                DialogResult result = dlg.ShowDialog();
                if (result == DialogResult.OK)
                {
                    if (!dlg.UseFontAnyway() && !nonSilFont.Key.Name.Equals(dlg.SelectedFont))
                    {
                        // the user has chosen a different (SIL) font - 
                        // create a new EmbeddedFont and add it to the list
                        _embeddedFonts.Remove(nonSilFont.Key.Name);
                        var newFont = new EmbeddedFont(dlg.SelectedFont);
                        _embeddedFonts[dlg.SelectedFont] = newFont; // set index value adds if it doesn't exist
                        // also update the references in _langFontDictionary
                        foreach (var lang in langArray)
                        {
                            if (_langFontDictionary[lang] == nonSilFont.Key.Name)
                            {
                                _langFontDictionary[lang] = dlg.SelectedFont;
                            }
                        }
                    }
                }
                else if (result == DialogResult.Cancel)
                {
                    // User cancelled - Cancel out of the whole .epub export
                    return false;
                }
                // decrement the remaining issues for the next dialog display
                dlg.RemainingIssues--;
            }
            return true;
        }
Example #7
0
 private static void WriteMissingFontMessage(StringBuilder sb, EmbeddedFont embeddedFont)
 {
     sb.Append("/* missing embedded font: ");
     sb.Append(embeddedFont.Name);
     sb.AppendLine(" */");
 }
Example #8
0
 private static void WriteFontDeclarationBlock(StringBuilder sb, EmbeddedFont embeddedFont)
 {
     sb.AppendLine("@font-face {");
     sb.Append(" font-family : ");
     sb.Append("\"" + embeddedFont.Name + "\"");
     sb.AppendLine(";");
     sb.AppendLine(" font-weight : normal;");
     sb.AppendLine(" font-style : normal;");
     sb.AppendLine(" font-variant : normal;");
     sb.AppendLine(" font-size : all;");
     sb.Append(" src : url('");
     sb.Append(Path.GetFileName(embeddedFont.Filename));
     sb.AppendLine("');");
     sb.AppendLine("}");
 }
Example #9
0
        /// <summary>
        /// Returns the font families for the languages in _langFontDictionary.
        /// </summary>
        public void BuildFontsList()
        {
            // modifying the _langFontDictionary dictionary - let's make an array copy for the iteration
            int numLangs = _langFontDictionary.Keys.Count;
            var langs = new string[numLangs];
            _langFontDictionary.Keys.CopyTo(langs, 0);
            foreach (var language in langs)
            {
                string[] langCoun = language.Split('-');

                try
                {
                    // When no hyphen use entire value but when there is a hyphen, look for first part
                    var langTarget = langCoun.Length < 2 ? langCoun[0] : language;
                    string wsPath = Common.PathCombine(Common.GetLDMLPath(), langTarget + ".ldml");
                    if (File.Exists(wsPath))
                    {
                        var ldml = Common.DeclareXMLDocument(false);
                        ldml.Load(wsPath);
                        var nsmgr = new XmlNamespaceManager(ldml.NameTable);
                        nsmgr.AddNamespace("palaso", "urn://palaso.org/ldmlExtensions/v1");
                        var node = ldml.SelectSingleNode("//palaso:defaultFontFamily/@value", nsmgr);
                        if (node != null)
                        {
                            // build the font information and return
                            _langFontDictionary[language] = node.Value; // set the font used by this language
                            _embeddedFonts[node.Value] = new EmbeddedFont(node.Value);
                        }
                    }
                    else if (AppDomain.CurrentDomain.FriendlyName.ToLower() == "paratext.exe") // is paratext
                    {
                        var settingsHelper = new SettingsHelper(Param.DatabaseName);
                        string fileName = settingsHelper.GetSettingsFilename();
                        const string xPath = "//ScriptureText/DefaultFont";
                        XmlNode xmlFont = Common.GetXmlNode(fileName, xPath);
                        if (xmlFont != null)
                        {
                            // get the text direction specified by the .ssf file
                            _langFontDictionary[language] = xmlFont.InnerText; // set the font used by this language
                            _embeddedFonts[xmlFont.InnerText] = new EmbeddedFont(xmlFont.InnerText);
                        }
                    }
                    else
                    {
                        // Paratext case (no .ldml file) - fall back on Charis
                        _langFontDictionary[language] = "Charis SIL"; // set the font used by this language
                        _embeddedFonts["Charis SIL"] = new EmbeddedFont("Charis SIL");

                    }
                }
                catch
                {
                }
            }
        }
Example #10
0
 public void DaiBannaTest()
 {
     string fontName = "Dai Banna SIL Book";
     if (Common.IsUnixOS())
     {
         fontName = "dai-banna";
     }
     var silFont = new EmbeddedFont(fontName);
     if (!Common.IsUnixOS())
     {
         Assert.IsTrue(FontInternals.IsInstalled(fontName));
         Assert.IsTrue(silFont.CanRedistribute);
     }
     Assert.IsTrue(silFont.Serif);
 }
Example #11
0
 public void SophiaNubianTest()
 {
     var silFont = new EmbeddedFont("Sophia Nubian");
     Assert.IsTrue(FontInternals.IsInstalled("Sophia Nubian"));
     Assert.IsTrue(silFont.CanRedistribute);
     Assert.IsTrue(silFont.Serif);
 }
Example #12
0
 public void ScheharazadeTest()
 {
     var silFont = new EmbeddedFont("Scheherazade");
     Assert.IsTrue(FontInternals.IsInstalled("Scheherazade"));
     Assert.IsTrue(silFont.CanRedistribute);
     Assert.IsTrue(silFont.Serif);
 }
Example #13
0
 public void LibertineTest()
 {
     var font = new EmbeddedFont("Linux Libertine");
     if (FontInternals.IsInstalled("Linux Libertine"))
     {
         Assert.IsFalse(FontInternals.IsSILFont(font.Filename));
         Assert.IsTrue(font.CanRedistribute);
         Assert.IsTrue(font.Serif);
     }
 }
Example #14
0
 public void GentiumTest()
 {
     string fontName = "Gentium";
     if (Common.IsUnixOS())
     {
         fontName = "Gentiumbasic";
     }
     var silFont = new EmbeddedFont(fontName);
     if(!Common.IsUnixOS())
     {
         Assert.IsTrue(FontInternals.IsInstalled(fontName));
         Assert.IsTrue(silFont.CanRedistribute);
     }
     Assert.IsTrue(silFont.Serif);
 }