Ejemplo n.º 1
0
		/// <summary>
		/// Get the LangCode from the Database.ssf file and insert it in css file
		/// </summary>
		public static string ParaTextEthnologueCodeName()
		{
			string paraLangCode = string.Empty;
			if (AppDomain.CurrentDomain.FriendlyName.ToLower() == "paratext.exe") // is paratext00
			{
				// read Language Code from ssf
				SettingsHelper settingsHelper = new SettingsHelper(Param.DatabaseName);
				string fileName = settingsHelper.GetSettingsFilename();
				string xPath = "//ScriptureText/EthnologueCode";
				XmlNode xmlLangCode = Common.GetXmlNode(fileName, xPath);
				if (xmlLangCode == null) return string.Empty;
				if (xmlLangCode != null && xmlLangCode.InnerText != string.Empty)
				{
					paraLangCode = xmlLangCode.InnerText;
				}
			}
			return paraLangCode;
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Get the LangCode from the Database.ssf file and insert it in css file
		/// </summary>
		public static string ParaTextDcLanguage(string dataBaseName, bool hyphenlang)
		{
			string dcLanguage = string.Empty;
			if (AppDomain.CurrentDomain.FriendlyName.ToLower() == "paratext.exe") // is paratext00
			{
				// read Language Code from ssf
				SettingsHelper settingsHelper = new SettingsHelper(dataBaseName);
				string fileName = settingsHelper.GetSettingsFilename();
				string xPath = "//ScriptureText/EthnologueCode";
				XmlNode xmlLangCode = GetXmlNode(fileName, xPath);
				if (xmlLangCode != null && xmlLangCode.InnerText != string.Empty)
				{
					dcLanguage = xmlLangCode.InnerText;
				}
				xPath = "//ScriptureText/Language";
				XmlNode xmlLangNameNode = GetXmlNode(fileName, xPath);
				if (xmlLangNameNode != null && xmlLangNameNode.InnerText != string.Empty)
				{
					if (dcLanguage == string.Empty)
					{
						Dictionary<string, string> _languageCodes = new Dictionary<string, string>();
						_languageCodes = LanguageCodesfromXMLFile();
						if (_languageCodes.Count > 0)
						{
							foreach (
								var languageCode in
									_languageCodes.Where(
										languageCode => languageCode.Value.ToLower() == xmlLangNameNode.InnerText.ToLower()))
							{
								if (hyphenlang)
								{
									dcLanguage = _languageCodes.ContainsValue(languageCode.Key.ToLower())
										? _languageCodes.FirstOrDefault(x => x.Value == languageCode.Key.ToLower()).Key
										: languageCode.Key;
								}
								else
								{
									dcLanguage = languageCode.Key;
								}
								break;
							}
						}
					}
					dcLanguage += ":" + xmlLangNameNode.InnerText;
				}
			}
			return dcLanguage;
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Get the fontName from the Database.ssf file and insert it in css file
		/// </summary>
		public static string ParaTextFontName(string inputCssFileName)
		{
			string paraTextFontName = string.Empty;
			if (AppDomain.CurrentDomain.FriendlyName.ToLower() == "paratext.exe") // is paratext00
			{
				// read fontname from ssf
				StringBuilder newProperty = new StringBuilder();
				SettingsHelper settingsHelper = new SettingsHelper(Param.DatabaseName);
				string fileName = settingsHelper.GetSettingsFilename();
				string xPath = "//ScriptureText/DefaultFont";
				XmlNode xmlFont = Common.GetXmlNode(fileName, xPath);
				if (xmlFont == null || xmlFont.InnerText == string.Empty)
				{
					paraTextFontName = "Charis SIL";
				}
				else
				{
					paraTextFontName = xmlFont.InnerText;
				}
				if (inputCssFileName != string.Empty)
				{
					newProperty.AppendLine("div[lang='zxx']{ font-family: \"" + paraTextFontName + "\";}");
					newProperty.AppendLine("span[lang='zxx']{ font-family: \"" + paraTextFontName + "\";}");
					newProperty.AppendLine("@page{ font-family: \"" + paraTextFontName + "\";}");

					FileInsertText(inputCssFileName, newProperty.ToString());
				}
			}
			return paraTextFontName;
		}
Ejemplo n.º 4
0
 /// <summary>
 /// Add Properties for font and direction
 /// </summary>
 private void SetFontAndDirection()
 {
     CreateClass("\\Marker scrBody");
     _cssProp.Add("direction", Common.GetTextDirection(""));
     var settingsHelper = new SettingsHelper(Param.DatabaseName);
     var fontNode = Common.GetXmlNode(settingsHelper.GetSettingsFilename(), "//DefaultFont");
     if (fontNode != null)
     {
         _cssProp.Add("font-family", "\"" + fontNode.InnerText + "\"");
     }
 }
Ejemplo n.º 5
0
 protected static void WriteLanguageFontDirection(TextWriter cssFile)
 {
     if (WriterSettingsFile == null)
     {
         var settingsHelper = new SettingsHelper(Param.DatabaseName);
         WriterSettingsFile = settingsHelper.GetSettingsFilename();
     }
     var languageCodeNode = Common.GetXmlNode(WriterSettingsFile, "//EthnologueCode");
     var languageCode = "";
     var languageDirection = "ltr";
     var textAlign = "left";
     if (languageCodeNode != null)
     {
         languageCode = languageCodeNode.InnerText;
         languageDirection = Common.GetTextDirection(languageCode);
         if (languageCode.Contains("-"))
         {
             languageCode = languageCode.Split(new[] { '-' })[0];
         }
         if (languageDirection == "rtl")
         {
             textAlign = "right";
         }
     }
     var fontNode = Common.GetXmlNode(WriterSettingsFile, "//DefaultFont");
     var fontFamily = "";
     if (fontNode != null)
     {
         fontFamily = fontNode.InnerText;
     }
     var fontSizeNode = Common.GetXmlNode(WriterSettingsFile, "//DefaultFontSize");
     var fontSize = "10";
     if (fontSizeNode != null)
     {
         fontSize = fontSizeNode.InnerText;
     }
     if (languageCode != "" && (fontFamily != "" || languageDirection != "ltr"))
     {
         cssFile.Write("div[lang='{0}']", languageCode);
         cssFile.Write("{");
         if (fontFamily != "")
         {
             cssFile.Write(" font-family: \"{0}\";", fontFamily);
         }
         cssFile.Write(" font-size: {0}pt;", fontSize);
         if (languageDirection != "ltr")
         {
             cssFile.Write(" direction: {0}; text-align: {1};", languageDirection, textAlign);
         }
         cssFile.WriteLine("}");
         cssFile.Write("span[lang='{0}']", languageCode);
         cssFile.Write("{");
         if (fontFamily != "")
         {
             cssFile.Write(" font-family: \"{0}\";", fontFamily);
         }
         cssFile.WriteLine("}");
         cssFile.WriteLine();
     }
     WriterSettingsFile = null;
 }
Ejemplo n.º 6
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
                {
                }
            }
        }
Ejemplo n.º 7
0
 protected static void FindParatextProject()
 {
     if (!string.IsNullOrEmpty(Ssf)) return;
     RegistryHelperLite.RegEntryExists(RegistryHelperLite.ParatextKey, "Settings_Directory", "", out ParatextData);
     var sh = new SettingsHelper(Param.DatabaseName);
     Ssf = sh.GetSettingsFilename();
 }