Ejemplo n.º 1
0
		public void PopulateFromLanguageClass()
		{
			//Extracts the locale filename from a given path
			int icuName = m_inputFilename.LastIndexOf("\\");
			string icuPortion = m_inputFilename.Substring(icuName+1);

			//Appears this maps the XML file to a LanguageDefinition class
			/////////////////
			ILgWritingSystemFactory wsf = LgWritingSystemFactoryClass.Create();

			LanguageDefinitionFactory langDefFactory = new LanguageDefinitionFactory(wsf, icuPortion);

			LanguageDefinition langDef = langDefFactory.InitializeFromXml(wsf, icuPortion) as LanguageDefinition;
			if (langDef == null)
			{
				throw new Exception("Unable to read and parse the input XML file " + m_inputFilename);
			}
			/////////////////

			int i=0;
			int cpua = langDef.PuaDefinitionCount;
			// if we have PUA characters in the LD file make an array of PUACharacters.  But be careful
			// to handle invalid definitions gracefully.
			if (langDef.PuaDefinitions != null && cpua != 0)
			{
				puaChars = new PUACharacter[cpua];
				foreach (CharDef charDef in langDef.PuaDefinitions)
				{
					try
					{
						puaChars[i] = new PUACharacter(charDef);
						++i;
					}
					catch
					{
					}
				}
			}
			if (i < cpua)
			{
				if (i == 0)
				{
					puaChars = null;
				}
				else
				{
					PUACharacter[] puaGoodChars = new PUACharacter[i];
					for (int ic = 0; ic < i; ++ic)
						puaGoodChars[ic] = puaChars[ic];
					puaChars = puaGoodChars;
				}
				if (LogFile.IsLogging())
					LogFile.AddErrorLine("Warning, " + (cpua - i) + " out of " + cpua +
						" PUA character definitions are invalid.");
			}
			baseLocale = langDef.BaseLocale;
			newLocale = langDef.XmlWritingSystem.WritingSystem.IcuLocale;
			localeResources = langDef.LocaleResources;
			// Get the collation elements, whether from the CollationElements element directly,
			// or from the WritingSystem element.
			collationElements = langDef.CollationElements;
			if (collationElements == null)
			{
				IWritingSystem lws = langDef.WritingSystem;
				int ccoll = lws.CollationCount;
				if (ccoll > 0)
					collationElements = lws.get_Collation(0).IcuRules;
			}
			localeWinLCID = langDef.XmlWritingSystem.WritingSystem.Locale.ToString();

			// make sure the newlocale has the proper case for each property:
			// lang, country and variant
			InstallLanguage.LocaleParser lp = new LocaleParser(newLocale);
			newLocale = lp.Locale;

			// Make sure the display names [Name, Country & Variant] have Unicode characters
			// greater than 7F converted to the \uxxxx format where xxxx is the unicode
			// hex value of the character.
			localeName    = ConvertToUnicodeNotation(langDef.LocaleName);
			localeScript  = ConvertToUnicodeNotation(langDef.LocaleScript);
			localeCountry = ConvertToUnicodeNotation(langDef.LocaleCountry);
			localeVariant = ConvertToUnicodeNotation(langDef.LocaleVariant);

			// Save the multilingual names of the writing system, together with the
			// ICU locale for each name.
			NameMultiUnicode rgName = langDef.XmlWritingSystem.Name;
			int cws = rgName.Count;
			// If we don't have a name, use the IcuLocale rather than going without a name.
			// Otherwise it won't register as a language in en.txt/res.
			if (cws == 0)
			{
				StringWithWs sw = new StringWithWs(langDef.XmlWritingSystem.WritingSystem.IcuLocale, "en");
				rgName.Add(sw);
				cws = 1;
			}
			m_rgNames = new System.Collections.ArrayList(cws);
			for (int iws = 0; iws < cws; ++iws)
			{
				StringWithWs x = rgName[iws];
				m_rgNames.Add(x);
			}

			// TODO - dlh
			// Once collationElements are handled, something will have to be checked there
			// as the current implementation assumes that it's in the valid format.

			wsf.Shutdown();		// This is (always) needed to balance creating the factory.
		}
Ejemplo n.º 2
0
		public void UserPromptOnMultipleLines_UpArrow()
		{
			CheckDisposed();
			// This problem only happens with the Graphite renderer so we need to select a
			// Graphite font
			ILgWritingSystemFactory wsf = Cache.LanguageWritingSystemFactoryAccessor;
			LanguageDefinitionFactory languageDefinitionFactory = new LanguageDefinitionFactory();
			ILanguageDefinition langDef = languageDefinitionFactory.InitializeFromXml(wsf, "en");
			langDef.WritingSystem.DefaultSerif = "Charis SIL";
			langDef.WritingSystem.FontVariation = "";
			try
			{
				// Save all changes and exit normally.
				// (Make sure tests don't clobber an existing *.xml file.)
				//langDef.Serialize(tmpFilename);
				langDef.SaveWritingSystem("en");
			}
			catch
			{
				Assert.Fail("Failed to set the charis font for the english writing system!");
			}
			Options.ShowEmptyParagraphPromptsSetting = true;
			m_draftForm.Width = 30; // set view narrow to make multiple-line user prompt

			// Clear the section headings and then refresh the view to show user prompts.
			IScrBook exodus = m_scr.ScriptureBooksOS[0];
			IScrSection section2 = exodus.SectionsOS[1];
			IScrSection section3 = exodus.SectionsOS[2];
			StTxtPara heading2Para = (StTxtPara)section2.HeadingOA.ParagraphsOS[0];
			StTxtPara heading3Para = (StTxtPara)section3.HeadingOA.ParagraphsOS[0];
			StTxtPara Content2LastPara = (StTxtPara)section2.ContentOA.ParagraphsOS[section2.ContentOA.ParagraphsOS.Count - 1];
			StTxtPara content3Para = (StTxtPara)section3.ContentOA.ParagraphsOS[0];
			heading2Para.Contents.Text = string.Empty;
			heading3Para.Contents.Text = string.Empty;
			Content2LastPara.Contents.Text = "Second content para";
			content3Para.Contents.Text = "Third content para";

			m_draftView.RefreshDisplay();

			// Make a selection in the second section head.
			m_draftView.TeEditingHelper.GoToLastSection();
			// Move down into the content and then back to the heading with the up arrow.
			// (This issue is only a problem when selecting the user prompt with the keyboard).
			m_draftView.RootBox.Activate(VwSelectionState.vssEnabled);
			m_draftView.OnKeyDown(new KeyEventArgs(Keys.Down));
			m_draftView.OnKeyDown(new KeyEventArgs(Keys.Up));

			Application.DoEvents();

			// get the hvo and tag of the current selection.
			ITsString tss;
			int ich;
			int hvo;
			int tag;
			int ws;
			bool assocPrev;
			m_draftView.RootBox.Selection.TextSelInfo(false, out tss, out ich, out assocPrev,
				out hvo, out tag, out ws);
			// Confirm that the selection is in the second section head
			Assert.AreEqual(heading3Para.Hvo, hvo);

			// Press up arrow.
			m_draftView.RootBox.Activate(VwSelectionState.vssEnabled);
			m_draftView.OnKeyDown(new KeyEventArgs(Keys.Up));

			// Confirm that the selection has moved up.
			m_draftView.RootBox.Selection.TextSelInfo(false, out tss, out ich, out assocPrev,
				out hvo, out tag, out ws);
			Assert.AreEqual(Content2LastPara.Hvo, hvo);
		}
Ejemplo n.º 3
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Check if we can go to next tab.
		/// </summary>
		/// -----------------------------------------------------------------------------------
		protected override bool ValidToGoForward()
		{
			if (CurrentStepNumber != 1)
				return true;

			// Don't leave the region/variant page if we don't have valid data.
			if (!m_regionVariantControl.CheckValid())
				return false;

			string caption = FwCoreDlgs.kstidNwsCaption;
			string strLoc = m_langDef.WritingSystem.IcuLocale;

			// Catch case where we are going to overwrite an existing writing system in the Db.
			if (m_langDef.IsWritingSystemInDb())
			{
				ILgWritingSystemFactory wsf = m_langDef.XmlWritingSystem.WritingSystem.WritingSystemFactory;
				int defWs = wsf.UserWs;
				int ws = wsf.GetWsFromStr(strLoc);
				IWritingSystem qws = wsf.get_EngineOrNull(ws);
				string strDispName = qws.get_UiName(defWs);

				string msg = string.Format(FwCoreDlgs.kstidCantOverwriteWsInDb,
					strDispName, strLoc, Environment.NewLine, m_langDef.DisplayName);
				MessageBox.Show(msg, caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				return false;
			}

			// Catch case where we are going to overwrite an existing LD.xml file.
			// This should be avoided by the callers to this dialog, but just in case, we'll
			// handle it here as well.
			if (m_langDef.IsLocaleInLanguagesDir())
			{
				string msg = string.Format(FwCoreDlgs.kstidLocaleAlreadyInLanguages,
					m_langDef.DisplayName, m_langDef.WritingSystem.IcuLocale, Environment.NewLine);
				DialogResult dr = MessageBox.Show(msg, FwCoreDlgs.ksWsAlreadyExists, MessageBoxButtons.YesNo,
					MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
				// If the user cancels, we don't leave the dialog.
				if (dr == DialogResult.Yes)
				{
					// We need to load the existing LD.xml file and then write it out to the
					// database, overwriting the original writing system. We then close the wizard.
					try
					{
						m_langDef = null;
						LanguageDefinitionFactory ldf = new LanguageDefinitionFactory();
						m_langDef = ldf.InitializeFromXml(m_wsf, strLoc) as LanguageDefinition;
						Debug.Assert(m_langDef != null);
						if (m_langDef != null)
						{
							m_langDef.SaveWritingSystem(strLoc);
						}
						DialogResult = DialogResult.OK;
						Visible = false;
					}
					catch
					{
						MessageBox.Show(FwCoreDlgs.kstidErrorSavingWs, caption,
							MessageBoxButtons.OK, MessageBoxIcon.Error);
						DialogResult = DialogResult.Cancel;
						Visible = false;
					}
				}
				return false;
			}
			return true;
		}
Ejemplo n.º 4
0
		/// <summary>
		/// Get the writing system code (int) for the given RFC4646 language code
		/// (string).
		/// </summary>
		public int GetWsFromRfcLang(string code, string sLdmlDir)
		{
			int ws;
			if (m_mapRFCtoWs.TryGetValue(code, out ws))
				return ws;
			string sWs = ConvertFromRFCtoICU(code);
			string sWsLower = sWs.ToLowerInvariant();
			if (!m_mapIcuLCToWs.TryGetValue(sWsLower, out ws))
			{
				// See if a compatible XML file exists defining this writing system.
				LanguageDefinition langDef;
				try
				{
					LanguageDefinitionFactory fact = new LanguageDefinitionFactory();
					langDef = fact.InitializeFromXml(
						m_cache.LanguageWritingSystemFactoryAccessor, sWs) as LanguageDefinition;
				}
				catch
				{
					langDef = null;
				}
				ILgWritingSystem lgws;
				if (langDef != null)
				{
					// ICU locale case may differ - keep existing XML based value
					string sICU = langDef.IcuLocaleOriginal;
					Debug.Assert(sWsLower == sICU.ToLowerInvariant());
					langDef.SaveWritingSystem(sICU, true);
					ws = m_cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(sICU);
					Debug.Assert(ws >= 1);
					lgws = LgWritingSystem.CreateFromDBObject(m_cache, ws);
				}
				else
				{
					WritingSystemDefinition wsd = null;
					if (!String.IsNullOrEmpty(sLdmlDir))
					{
						LdmlInFolderWritingSystemStore ldmlstore = new LdmlInFolderWritingSystemStore(sLdmlDir);
						foreach (WritingSystemDefinition wsdT in ldmlstore.WritingSystemDefinitions)
						{
							if (wsdT.RFC4646 == code)
							{
								wsd = wsdT;
								break;
							}
						}
					}
					// This creates a new writing system for the given key.
					IWritingSystem wrsy = m_cache.LanguageWritingSystemFactoryAccessor.get_Engine(sWs);
					m_cache.ResetLanguageEncodings();
					ws = wrsy.WritingSystem;
					Debug.Assert(ws >= 1);
					lgws = LgWritingSystem.CreateFromDBObject(m_cache, ws);
					lgws.ICULocale = sWs;
					if (wsd == null)
					{
						lgws.Abbr.UserDefaultWritingSystem = sWs;
						lgws.Name.UserDefaultWritingSystem = sWs;
					}
					else
					{
						lgws.Abbr.UserDefaultWritingSystem = wsd.Abbreviation;
						lgws.Name.UserDefaultWritingSystem = wsd.LanguageName;
						lgws.DefaultSerif = wsd.DefaultFontName;
						lgws.DefaultBodyFont = wsd.DefaultFontName;
						lgws.RightToLeft = wsd.RightToLeftScript;
						// TODO: collation, keyboard.
					}
					// Make sure XML file is written.  See LT-8743.
					wrsy.SaveIfDirty(m_cache.DatabaseAccessor);
				}
				m_rgnewWrtSys.Add(lgws);
				m_cache.LangProject.AnalysisWssRC.Add(ws);
				m_cache.LangProject.CurAnalysisWssRS.Append(ws);
				if (m_fUpdateVernWss)
				{
					m_cache.LangProject.VernWssRC.Add(ws);
					m_cache.LangProject.CurVernWssRS.Append(ws);
				}
				m_mapIcuLCToWs.Add(sWsLower, ws);
			}
			m_mapRFCtoWs.Add(code, ws);
			return ws;
		}