Example #1
0
		private static Set<NamedWritingSystem> GetNamedWritingSystemsFromLDFs(ILgWritingSystemFactory wsf,
			string[] fileList, Set<NamedWritingSystem> namedWritingSystems)
		{
			Set<string> names = new Set<string>();
			foreach (NamedWritingSystem nws in namedWritingSystems)
				names.Add(nws.IcuLocale);
			// Now add the ones from the XML files.
			foreach (string pathname in fileList)
			{
				string[] bits = pathname.Split('\\');
				string filename = bits[bits.Length - 1];
				bits = filename.Split('.');
				string icuLocale = bits[0]; // Name up to first '.'.
				// The first test excludes names like en.xml1.
				if (bits[1] == "xml" && !names.Contains(icuLocale.ToLowerInvariant()))
				{
					try
					{
						// This will get the language name from the XML language def. file. This
						// should be the same name the user chose to call the language when creating
						// its writing system.
						LanguageDefinitionFactory ldf = new LanguageDefinitionFactory(wsf, icuLocale);
						if (ldf.LanguageDefinition == null)
						{
							System.Diagnostics.Debug.WriteLine("The XML file for " + icuLocale +
								" did not parse properly.");
						}
						else
						{
							string displayName = ldf.LanguageDefinition.DisplayName;

							// REVIEW: These two lines are how we used to get the display name. Now we read
							// it from the language def. file (i.e. the .xml file). Will the name from the
							// XML file always be in the display locale?
							//Icu.UErrorCode err;
							//Icu.GetDisplayName(icuLocale, displayLocale, out displayName, out err);

							// If it can't find a name, the normal behavior is to return the icuLocale.
							// If that happens we leave this one out.
							// If anything worse happens (e.g., that might produce a bad error code),
							// the other checks we make here should detect it.
							if (displayName != null && displayName != icuLocale && displayName.Length != 0)
								namedWritingSystems.Add(new NamedWritingSystem(displayName, icuLocale));
						}
					}
					catch (FileNotFoundException e)
					{
						System.Diagnostics.Debug.WriteLine(e.Message);
						// LanguageDefinitionFactory can throw this error. Just ignore it.
					}
				}
			}
			return namedWritingSystems;
		}
		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.
		}
Example #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;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Set writing system and initialize some values for the dialog
		/// </summary>
		/// <param name="wsSelected">The writing system.</param>
		/// <returns><c>true</c> if successful, <c>false</c> if something went wrong.</returns>
		/// ------------------------------------------------------------------------------------
		internal protected bool TrySetupDialog(IWritingSystem wsSelected)
		{
			// for now, always set the displayWs to "en" so we read good information from LDFs (LT-8628)
			//m_displayWs = wsSelected.WritingSystemFactory.UserWs;
			m_displayWs = wsSelected.WritingSystemFactory.get_Engine("en").WritingSystem;
			LoadAvailableConverters();
			m_LanguageDefinitionFactory = new LanguageDefinitionFactory();
			m_NamedWritingSystemsDb = m_cache.LangProject.GetDbNamedWritingSystems();

			//set up the initial state of the following lists
			CreateLanguageDefinitionsFromNamedWss(m_listOrigLangDefs, wsSelected);
			CreateLanguageDefinitionsFromNamedWss(m_listFinalLangDefs, wsSelected);
			PopulateRelatedWSsListBox();
			int selectedIndex = IndexOfFinalLangDef(wsSelected.IcuLocale);
			SelectIndexOfListBoxRelatedWss(selectedIndex);
			EstablishCurrentLangDefFromSelectedIndex();
			SetupDialogFromCurrentLanguageDefinition();
			m_fNewRendering = false;

			return true;
		}
Example #5
0
		/// <summary>
		/// creates a clone of the current object.
		/// </summary>
		/// <returns></returns>
		object ICloneable.Clone()
		{
			LanguageDefinition clonedLangDef = null;
			using (MemoryStream stream = new MemoryStream())
			{
				using (XmlTextWriter xtw = new XmlTextWriter(stream, Encoding.UTF8))
				{
					Serialize(xtw);
					xtw.Flush();
					stream.Seek(0, SeekOrigin.Begin);
					using (XmlReader sr = XmlReader.Create(stream))
					{
						LanguageDefinitionFactory ldf = new LanguageDefinitionFactory();
						ldf.Deserialize(sr);
						clonedLangDef = ldf.LanguageDefinition as LanguageDefinition;
						clonedLangDef.m_icuLocaleOrig = this.m_icuLocaleOrig;
					}
				}
			}
			return clonedLangDef;
		}
        public void SerializeAndDeserialize()
        {
            IWritingSystem ws     = m_wsf.get_Engine("tl");
            int            wsIdTl = m_wsf.GetWsFromStr("tl");

            ws.Locale           = 13321;
            ws.DefaultMonospace = "Courier New";
            ws.DefaultSansSerif = "Arial";
            ws.DefaultBodyFont  = "Charis SIL";
            ws.DefaultSerif     = "Times New Roman";
            ws.set_Name(m_wsIdEn, "Tagalog");
            ws.set_Name(wsIdTl, "Tagalog");
            ws.set_Abbr(m_wsIdEn, "TGL");

            ICollation coll = CollationClass.Create();

            coll.WinLCID      = 1033;
            coll.WinCollation = "Latin1_General_CI_AI";
            coll.set_Name(m_wsIdEn, "Default Collation");
            coll.WritingSystemFactory = m_wsf;

            ws.set_Collation(0, coll);

            LanguageDefinition langDef = new LanguageDefinition(ws);

            langDef.BaseLocale = "en_US";
            langDef.XmlWritingSystem.WritingSystem.IcuLocale = "tl";
            langDef.LocaleName    = "Tagalog";
            langDef.LocaleScript  = "";
            langDef.LocaleCountry = "";
            langDef.LocaleVariant = "";
            langDef.XmlWritingSystem.WritingSystem.Locale = 13321;
            langDef.CollationElements = "\"&amp; B &lt; ...";
            langDef.ValidChars        = "abcdefg";
            langDef.LocaleResources   = @"
				zoneStrings {
					{
						'Europe/London',
						'Greenwich Mean Time',
				  }
				}"                ;
            CharDef[] charDefs = new CharDef[2];
            charDefs[0]            = new CharDef(0xF170, "COMBINING SNAKE BELOW;Mn;202;NSM;;;;");
            charDefs[1]            = new CharDef(0xF210, "LATIN SMALL LETTER P WITH STROKE;Ll;0;L;;;;");
            langDef.PuaDefinitions = charDefs;
            FileName[] fonts = new FileName[4];
            fonts[0]                  = new FileName("arial.ttf");
            fonts[1]                  = new FileName("arialbd.ttf");
            fonts[2]                  = new FileName("ariali.ttf");
            fonts[3]                  = new FileName("arialbi.ttf");
            langDef.Fonts             = fonts;
            langDef.Keyboard          = new FileName("Tagalog.kmx");
            langDef.EncodingConverter = new EncodingConverter("SIL_IPA93.tec.vbs", "SIL-IPA93.tec");

            string tmpFileName = Path.GetTempFileName();

            langDef.Serialize(tmpFileName);

            LanguageDefinitionFactory otherIcuWs = new LanguageDefinitionFactory();

            LanguageDefinitionFactory.WritingSystemFactory = m_wsf;
            otherIcuWs.Deserialize(tmpFileName);
            ILanguageDefinition newLangDef       = otherIcuWs.LanguageDefinition;
            IWritingSystem      deserializedWs   = newLangDef.WritingSystem;
            ICollation          deserializedColl = newLangDef.GetCollation(0);

            StreamReader reader = new StreamReader(tmpFileName);
            string       line   = reader.ReadLine();

            while (line != null)
            {
                Console.WriteLine(line);
                line = reader.ReadLine();
            }
            reader.Close();
            File.Delete(tmpFileName);

            Assert.AreEqual(ws.Locale, deserializedWs.Locale);
            Assert.AreEqual(ws.IcuLocale, deserializedWs.IcuLocale);
            Assert.AreEqual(ws.DefaultSansSerif, deserializedWs.DefaultSansSerif);
            Assert.AreEqual(ws.DefaultBodyFont, deserializedWs.DefaultBodyFont);
            Assert.AreEqual(ws.get_Name(m_wsIdEn), deserializedWs.get_Name(m_wsIdEn));
            Assert.AreEqual(coll.WinLCID, deserializedColl.WinLCID);
            Assert.AreEqual(coll.WinCollation, deserializedColl.WinCollation);
            // ENHANCE: Add ValidChars to the interface
            // Assert.AreEqual(ws.ValidChars, deserializedWs.ValidChars);
            Assert.AreEqual(coll.get_Name(m_wsIdEn), deserializedColl.get_Name(m_wsIdEn));
        }
		private LanguageDefinition CreateTempLanguageDefinitionFileFromWs(int hvoWs)
		{
			IWritingSystem ws = m_inMemoryCache.Cache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(hvoWs);
			string shortAbbr = ws.get_Abbr(InMemoryFdoCache.s_wsHvos.En);
			if (String.IsNullOrEmpty(shortAbbr))
			{
				// set default abbr, if not set.
				string enName = ws.LanguageName; // ws.get_Name(InMemoryFdoCache.s_wsHvos.En);
				ws.set_Abbr(InMemoryFdoCache.s_wsHvos.En, WritingSystemPropertiesDialog.CreateDefaultLanguageNameAbbr(enName));
			}
			// this is part of setup, so pretend this is how we actually loaded it.
			ws.Dirty = false;
			LanguageDefinitionFactory ldf = new LanguageDefinitionFactory(ws);
			LanguageDefinition langDef = ldf.LanguageDefinition as LanguageDefinition;
			DummyWritingSystemPropertiesDialog.SerializeToTempfile(langDef);
			return langDef;
		}
		/// <summary>
		///
		/// </summary>
		/// <param name="qwsf"></param>
		/// <param name="locale"></param>
		/// <returns></returns>
		internal static LanguageDefinition DeserializeLanguageDefFromTempfile(ILgWritingSystemFactory qwsf, string locale)
		{
			LanguageDefinitionFactory langDefFactory = new LanguageDefinitionFactory();
			if (LanguageDefinitionFactory.WritingSystemFactory == null)
				LanguageDefinitionFactory.WritingSystemFactory = qwsf;
			string filename;
			if (s_icuLocaleToTmpLangDefFiles.TryGetValue(locale, out filename) && File.Exists(filename))
			{
				langDefFactory.Deserialize(filename);
				return langDefFactory.LanguageDefinition as LanguageDefinition;
			}
			return null;
		}
Example #9
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);
		}
Example #10
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;
		}
		public void SerializeAndDeserialize()
		{
			IWritingSystem ws = m_wsf.get_Engine("tl");
			int wsIdTl = m_wsf.GetWsFromStr("tl");
			ws.Locale = 13321;
			ws.DefaultMonospace = "Courier New";
			ws.DefaultSansSerif = "Arial";
			ws.DefaultBodyFont = "Charis SIL";
			ws.DefaultSerif = "Times New Roman";
			ws.set_Name(m_wsIdEn, "Tagalog");
			ws.set_Name(wsIdTl, "Tagalog");
			ws.set_Abbr(m_wsIdEn, "TGL");

			ICollation coll = CollationClass.Create();
			coll.WinLCID = 1033;
			coll.WinCollation = "Latin1_General_CI_AI";
			coll.set_Name(m_wsIdEn, "Default Collation");
			coll.WritingSystemFactory = m_wsf;

			ws.set_Collation(0, coll);

			LanguageDefinition langDef = new LanguageDefinition(ws);
			langDef.BaseLocale = "en_US";
			langDef.XmlWritingSystem.WritingSystem.IcuLocale = "tl";
			langDef.LocaleName = "Tagalog";
			langDef.LocaleScript = "";
			langDef.LocaleCountry = "";
			langDef.LocaleVariant = "";
			langDef.XmlWritingSystem.WritingSystem.Locale = 13321;
			langDef.CollationElements = "\"&amp; B &lt; ...";
			langDef.ValidChars = "abcdefg";
			langDef.LocaleResources = @"
				zoneStrings {
					{
						'Europe/London',
						'Greenwich Mean Time',
				  }
				}";
			CharDef[] charDefs = new CharDef[2];
			charDefs[0] = new CharDef(0xF170, "COMBINING SNAKE BELOW;Mn;202;NSM;;;;");
			charDefs[1] = new CharDef(0xF210, "LATIN SMALL LETTER P WITH STROKE;Ll;0;L;;;;");
			langDef.PuaDefinitions = charDefs;
			FileName[] fonts = new FileName[4];
			fonts[0] = new FileName("arial.ttf");
			fonts[1] = new FileName("arialbd.ttf");
			fonts[2] = new FileName("ariali.ttf");
			fonts[3] = new FileName("arialbi.ttf");
			langDef.Fonts = fonts;
			langDef.Keyboard = new FileName("Tagalog.kmx");
			langDef.EncodingConverter = new EncodingConverter("SIL_IPA93.tec.vbs", "SIL-IPA93.tec");

			string tmpFileName = Path.GetTempFileName();
			langDef.Serialize(tmpFileName);

			LanguageDefinitionFactory otherIcuWs = new LanguageDefinitionFactory();
			LanguageDefinitionFactory.WritingSystemFactory = m_wsf;
			otherIcuWs.Deserialize(tmpFileName);
			ILanguageDefinition newLangDef = otherIcuWs.LanguageDefinition;
			IWritingSystem deserializedWs = newLangDef.WritingSystem;
			ICollation deserializedColl = newLangDef.GetCollation(0);

			StreamReader reader = new StreamReader(tmpFileName);
			string line = reader.ReadLine();
			while (line != null)
			{
				Console.WriteLine(line);
				line = reader.ReadLine();
			}
			reader.Close();
			File.Delete(tmpFileName);

			Assert.AreEqual(ws.Locale, deserializedWs.Locale);
			Assert.AreEqual(ws.IcuLocale, deserializedWs.IcuLocale);
			Assert.AreEqual(ws.DefaultSansSerif, deserializedWs.DefaultSansSerif);
			Assert.AreEqual(ws.DefaultBodyFont, deserializedWs.DefaultBodyFont);
			Assert.AreEqual(ws.get_Name(m_wsIdEn), deserializedWs.get_Name(m_wsIdEn));
			Assert.AreEqual(coll.WinLCID, deserializedColl.WinLCID);
			Assert.AreEqual(coll.WinCollation, deserializedColl.WinCollation);
		// ENHANCE: Add ValidChars to the interface
		// Assert.AreEqual(ws.ValidChars, deserializedWs.ValidChars);
			Assert.AreEqual(coll.get_Name(m_wsIdEn), deserializedColl.get_Name(m_wsIdEn));
		}
Example #12
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets (or makes) the writing system. If there isn't already one with this locale id,
		/// we assume there is an XML language definition we can load.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public IWritingSystem EnsureRealWs(ILgWritingSystemFactory wsf)
		{
			if (wsf.GetWsFromStr(m_icuLocale) == 0)
			{
				// Need to create a new writing system from the XML file.
				LanguageDefinitionFactory ldf =
					new LanguageDefinitionFactory(wsf, m_icuLocale);
				string pathname = DirectoryFinder.LanguagesDirectory + "\\" + m_icuLocale + ".xml";
				ldf.Deserialize(pathname);
				ldf.LanguageDefinition.SaveWritingSystem(m_icuLocale);
			}
			return wsf.get_EngineOrNull(wsf.GetWsFromStr(m_icuLocale));
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Finds or creates the writing system.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="icuLocale">The icu locale.</param>
		/// <returns>The writing system</returns>
		/// ------------------------------------------------------------------------------------
		private LgWritingSystem FindOrCreateWs(FdoCache cache, string icuLocale)
		{
			// Look to see if the writing system already exists in the database
			foreach (LgWritingSystem ws in cache.LanguageEncodings)
			{
				if (LanguageDefinition.SameLocale(ws.ICULocale, icuLocale))
					return ws;
			}

			// Create a new writing system based on the one noted in the XML file.
			// Load it in from the XML and save into the database.
			LanguageDefinitionFactory ldf =
				new LanguageDefinitionFactory(cache.LanguageWritingSystemFactoryAccessor, icuLocale);
			ldf.LanguageDefinition.SaveWritingSystem(icuLocale);
			cache.ResetLanguageEncodings();
			// search again. It better be there now!
			foreach (LgWritingSystem ws in cache.LanguageEncodings)
			{
				if (LanguageDefinition.SameLocale(ws.ICULocale, icuLocale))
					return ws;
			}
			Debug.Assert(false);
			return null;
		}