Пример #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;
		}
Пример #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;
		}
Пример #3
0
		public static string TextDirectionLanguageFile = null; //Set during testing

		/// <summary>
		/// Looks up the text direction for the specified language code in the appropriate .ldml file.
		/// This lookup will not work with Paratext, which does not yet use an .ldml file.
		/// </summary>
		/// <param name="language">ISO 639 language code.</param>
		/// <returns>Text direction (ltr or rtl), or ltr if not found.</returns>
		public static string GetTextDirection(string language)
		{
			string[] langCoun = language.Split('-');
			string direction = "ltr";
			try
			{
				if (AppDomain.CurrentDomain.FriendlyName.ToLower() == "paratext.exe" ||
					TextDirectionLanguageFile != null) // is paratext
				{
					string fileName = TextDirectionLanguageFile;
					if (fileName == null)
					{
						SettingsHelper settingsHelper = new SettingsHelper(Param.DatabaseName);
						fileName = settingsHelper.GetLanguageFilename();
					}
					foreach (string line in FileData.Get(fileName).Split(new[] { '\n' }))
					{
						if (line.StartsWith("RTL="))
						{
							direction = (line[4] == 'T') ? "rtl" : "ltr";
							break;
						}
					}
				}
				else
				{
					string wsPath;
					if (langCoun.Length < 2)
					{
						// try the language (no country code) (e.g, "en" for "en-US")
						wsPath = PathCombine(Common.GetLDMLPath(), langCoun[0] + ".ldml");
					}
					else
					{
						// try the whole language expression (e.g., "ggo-Telu-IN")
						wsPath = PathCombine(Common.GetLDMLPath(), language + ".ldml");
					}
					if (File.Exists(wsPath))
					{
						XmlDocument ldml = DeclareXMLDocument(false);
						ldml.Load(wsPath);
						var nsmgr = new XmlNamespaceManager(ldml.NameTable);
						nsmgr.AddNamespace("palaso", "urn://palaso.org/ldmlExtensions/v1");
						var node = ldml.SelectSingleNode("//orientation/@characters", nsmgr);
						if (node != null)
						{
							// get the text direction specified by the .ldml file
							direction = (node.Value.ToLower().Equals("right-to-left")) ? "rtl" : "ltr";
						}
					}
				}
			}
			catch
			{
				direction = "ltr";
			}
			return direction;
		}
Пример #4
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;
		}
Пример #5
0
        private void ExportThroughPathway_Load(object sender, EventArgs e)
        {
            try
            {
                AssignFolderDateTime();
                if (!Common.isRightFieldworksVersion())
                {
                    var message = LocalizationManager.GetString("ExportThroughPathway.ExportThroughPathwayLoad.Message", "Please download and install a Pathway version compatible with your software", "");
					string caption = LocalizationManager.GetString("ExportThroughPathway.ExportThroughPathwayLoad.ProjectName", "Incompatible Pathway Version", "");
					Utils.MsgBox(message, caption, MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    DialogResult = DialogResult.Cancel;
                    Close();
                }
                _isUnixOS = Common.UnixVersionCheck();
                PopulateFilesFromPreprocessingFolder();

                // Load the .ssf or .ldml as appropriate
                _settingsHelper = new SettingsHelper(DatabaseName);
                _settingsHelper.LoadValues();

                LoadDefaultSettings();

                // get the current organization
                Organization = Param.GetOrganization();

	            if (Organization == "")
	            {
		            // no organization set yet -- display the Select Organization dialog
		            var dlg = new SelectOrganizationDialog(InputType);
		            if (dlg.ShowDialog() == DialogResult.OK)
		            {
			            Organization = dlg.Organization;
			            PopulateFromSettings();
		            }
		            else
		            {
			            // User pressed cancel - exit out of the export process altogether
			            DialogResult = DialogResult.Cancel;
			            Close();
		            }
	            }
	            else
	            {
					if (DatabaseName == "{Project_Name}")
					{
						this.Text += " - " + InputType;
					}
	            }
                LoadAvailFormats();
                LoadAvailStylesheets();
                IsExpanded = false;
                ResizeDialog();
                SetOkStatus();
                chkHyphen.Enabled = false;
                chkHyphen.Checked = false;
                clbHyphenlang.Items.Clear();
                //Loads Hyphenation related settings
		        LoadHyphenationSettings();
	            LoadProperty();
                EnableUIElements();

                ShowHelp.ShowHelpTopic(this, _helpTopic, _isUnixOS, false);
                if (AppDomain.CurrentDomain.FriendlyName.ToLower().IndexOf("configurationtool") == -1)
                {
                    Common.databaseName = DatabaseName;
                }
            }
            catch { }
        }
Пример #6
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 + "\"");
     }
 }
Пример #7
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;
 }
Пример #8
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
                {
                }
            }
        }
Пример #9
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();
 }