コード例 #1
0
        public void SetupStyles()
        {
            m_stylesheet        = new TestFwStylesheet();
            m_wsf               = LgWritingSystemFactoryClass.Create();
            m_wsf.BypassInstall = true;

            // German
            IWritingSystem wsGerman = m_wsf.get_Engine("de");

            m_hvoGermanWs = wsGerman.WritingSystem;
            Assert.IsTrue(m_hvoGermanWs > 0, "Should have gotten an hvo for the German WS");
            // English
            IWritingSystem wsEnglish = m_wsf.get_Engine("en");

            m_hvoEnglishWs = wsEnglish.WritingSystem;
            Assert.IsTrue(m_hvoEnglishWs > 0, "Should have gotten an hvo for the English WS");
            Assert.IsTrue(m_hvoEnglishWs != m_hvoGermanWs, "Writing systems should have different IDs");

            // Create a couple of styles
            int          hvoStyle  = m_stylesheet.MakeNewStyle();
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Arial");
            m_stylesheet.PutStyle("StyleA", "bla", hvoStyle, 0, hvoStyle, 1, false, false,
                                  propsBldr.GetTextProps());

            hvoStyle = m_stylesheet.MakeNewStyle();
            propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Times New Roman");
            m_stylesheet.PutStyle("StyleB", "bla", hvoStyle, 0, hvoStyle, 1, false, false,
                                  propsBldr.GetTextProps());

            // Override the font size for each writing system and each style.
            List <FontOverride> fontOverrides = new List <FontOverride>(2);
            FontOverride        fo;

            fo.writingSystem = m_hvoGermanWs;
            fo.fontSize      = 13;
            fontOverrides.Add(fo);
            fo.writingSystem = m_hvoEnglishWs;
            fo.fontSize      = 21;
            fontOverrides.Add(fo);
            m_stylesheet.OverrideFontsForWritingSystems("StyleA", fontOverrides);

            fontOverrides.Clear();
            fo.writingSystem = m_hvoGermanWs;
            fo.fontSize      = 56;
            fontOverrides.Add(fo);
            fo.writingSystem = m_hvoEnglishWs;
            fo.fontSize      = 20;
            fontOverrides.Add(fo);
            m_stylesheet.OverrideFontsForWritingSystems("StyleB", fontOverrides);
        }
コード例 #2
0
		public void SetupStyles()
		{
			m_stylesheet = new TestFwStylesheet();
			m_wsf = LgWritingSystemFactoryClass.Create();
			m_wsf.BypassInstall = true;

			// German
			IWritingSystem wsGerman = m_wsf.get_Engine("de");
			m_hvoGermanWs = wsGerman.WritingSystem;
			Assert.IsTrue(m_hvoGermanWs > 0, "Should have gotten an hvo for the German WS");
			// English
			IWritingSystem wsEnglish = m_wsf.get_Engine("en");
			m_hvoEnglishWs = wsEnglish.WritingSystem;
			Assert.IsTrue(m_hvoEnglishWs > 0, "Should have gotten an hvo for the English WS");
			Assert.IsTrue(m_hvoEnglishWs != m_hvoGermanWs, "Writing systems should have different IDs");

			// Create a couple of styles
			int hvoStyle = m_stylesheet.MakeNewStyle();
			ITsPropsBldr propsBldr = TsPropsBldrClass.Create();
			propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Arial");
			m_stylesheet.PutStyle("StyleA", "bla", hvoStyle, 0, hvoStyle, 1, false, false,
				propsBldr.GetTextProps());

			hvoStyle = m_stylesheet.MakeNewStyle();
			propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Times New Roman");
			m_stylesheet.PutStyle("StyleB", "bla", hvoStyle, 0, hvoStyle, 1, false, false,
				propsBldr.GetTextProps());

			// Override the font size for each writing system and each style.
			List<FontOverride> fontOverrides = new List<FontOverride>(2);
			FontOverride fo;
			fo.writingSystem = m_hvoGermanWs;
			fo.fontSize = 13;
			fontOverrides.Add(fo);
			fo.writingSystem = m_hvoEnglishWs;
			fo.fontSize = 21;
			fontOverrides.Add(fo);
			m_stylesheet.OverrideFontsForWritingSystems("StyleA", fontOverrides);

			fontOverrides.Clear();
			fo.writingSystem = m_hvoGermanWs;
			fo.fontSize = 56;
			fontOverrides.Add(fo);
			fo.writingSystem = m_hvoEnglishWs;
			fo.fontSize = 20;
			fontOverrides.Add(fo);
			m_stylesheet.OverrideFontsForWritingSystems("StyleB", fontOverrides);
		}
コード例 #3
0
        public void NamedWritingSystemsWithDefaultListOfWritingSystems_WithFileList()
        {
            CheckDisposed();
            string arabicXml = DirectoryFinder.FWDataDirectory + @"\languages\ar_IQ.xml";

            if (!System.IO.File.Exists(arabicXml))
            {
                ILgWritingSystemFactory qwsf = m_mock.Cache.LanguageWritingSystemFactoryAccessor;
                // This particular test needs to actually use InstallLanguage
                bool saveBypass = qwsf.BypassInstall;
                qwsf.BypassInstall = false;
                IWritingSystem qws = qwsf.get_Engine("ar_IQ");
                qws.InstallLanguage(true);
                qwsf.BypassInstall = saveBypass;
                Assert.IsTrue(System.IO.File.Exists(arabicXml), "This test is useless if we can't get the Arabic XML file to get created.");
            }
            // Request the set of all writing systems in the database. Further request
            // English again, to check for removal of duplicates, Arabic (to check for
            // a valid ws that isn't in the database), and nonsense (to check one that's not
            // in ICU is omitted).
            Set <NamedWritingSystem> set = LangProject.GetAllNamedWritingSystems(m_lp, "en", new string[]
                                                                                 { DirectoryFinder.FWDataDirectory + @"\languages\en.xml",
                                                                                   arabicXml,
                                                                                   DirectoryFinder.FWDataDirectory + @"\languages\SillyXYZNonsense.xml" });

            Assert.AreEqual(8, set.Count);
            Assert.IsTrue(set.Contains(new NamedWritingSystem("English", "en")));
            Assert.IsTrue(set.Contains(new NamedWritingSystem("Spanish", "es")));
            Assert.IsTrue(set.Contains(new NamedWritingSystem("French", "fr")));
            Assert.IsTrue(set.Contains(new NamedWritingSystem("English IPA", "en-IPA")));
            Assert.IsTrue(set.Contains(new NamedWritingSystem("German", "de")));
            Assert.IsTrue(set.Contains(new NamedWritingSystem("Kalaba", "xkal")));
            Assert.IsTrue(set.Contains(new NamedWritingSystem("Urdu", "ur")));
            Assert.IsTrue(set.Contains(new NamedWritingSystem("Arabic (Iraq)", "ar_IQ")));
        }
コード例 #4
0
        private static ILgWritingSystem GetWsEngine(ILgWritingSystemFactory wsFactory, string langCode)
        {
            ILgWritingSystem result;

            if (s_wsMapper.TryGetValue(langCode, out result))
            {
                return(result);
            }

            return(wsFactory.get_Engine(langCode));
        }
コード例 #5
0
        int GetWritingSystem(XmlNode elt)
        {
            string wsId = XmlUtils.GetMandatoryAttributeValue(elt, "ws");
            int    ws   = m_wsf.get_Engine(wsId).Handle;

            if (ws == 0)
            {
                throw new Exception("writing system " + wsId + " not recognized");
            }
            return(ws);
        }
コード例 #6
0
ファイル: SimpleDataParser.cs プロジェクト: sillsdev/WorldPad
        int GetWritingSystem(XmlNode elt)
        {
            string icuCode = XmlUtils.GetManditoryAttributeValue(elt, "ws");
            int    ws      = m_wsf.get_Engine(icuCode).WritingSystem;

            if (ws == 0)
            {
                throw new Exception("writing system " + icuCode + " not recognized");
            }
            return(ws);
        }
コード例 #7
0
		public void Setup()
		{
			m_wsf = LgWritingSystemFactoryClass.Create();
			// This is typically run during the build process before InstallLanguage.exe has
			// been built, so we want to disable InstallLanguage for this test.
			m_wsf.BypassInstall = true;

			m_wsEn = m_wsf.get_Engine("en");
			m_wsIdEn = m_wsf.GetWsFromStr("en");
			m_wsEn.set_Name(m_wsIdEn, "English");
			m_wsEn.set_Abbr(m_wsIdEn, "ENG");
		}
コード例 #8
0
ファイル: TsStringSerializer.cs プロジェクト: vkarthim/liblcm
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Gets the ws handle for specified writing system identifier.
 /// </summary>
 /// <param name="wsId">The writing system identifier.</param>
 /// <param name="lgwsf">The writing system factory.</param>
 /// ------------------------------------------------------------------------------------
 internal static int GetWsForId(string wsId, ILgWritingSystemFactory lgwsf)
 {
     try
     {
         ILgWritingSystem ws = lgwsf.get_Engine(wsId);
         return(ws.Handle);
     }
     catch (Exception e)
     {
         throw new XmlSchemaException("Unable to create writing system: " + wsId, e);
     }
 }
コード例 #9
0
        public void Setup()
        {
            m_wsf = LgWritingSystemFactoryClass.Create();
            // This is typically run during the build process before InstallLanguage.exe has
            // been built, so we want to disable InstallLanguage for this test.
            m_wsf.BypassInstall = true;

            m_wsEn   = m_wsf.get_Engine("en");
            m_wsIdEn = m_wsf.GetWsFromStr("en");
            m_wsEn.set_Name(m_wsIdEn, "English");
            m_wsEn.set_Abbr(m_wsIdEn, "ENG");
        }
コード例 #10
0
        private int GetWsFromStr(string sWs)
        {
            int ws = m_wsf.GetWsFromStr(sWs);

            if (ws != 0)
            {
                return(ws);
            }
            // Add this writing system.
            ILgWritingSystem lgws = m_wsf.get_Engine(sWs);

            return(lgws.Handle);
        }
コード例 #11
0
        /// <summary>
        /// Translate the ICU locale string into the writing system id for the given
        /// writing system factory, adding it to the factory as needed.
        /// </summary>
        /// <param name="icuLocale"></param>
        /// <param name="wsf"></param>
        /// <returns></returns>
        static public int GetWsFromStr(string icuLocale, ILgWritingSystemFactory wsf)
        {
            int ws = wsf.GetWsFromStr(icuLocale);

            if (ws == 0)
            {
                // This adds the icuLocale as a new writing system to the factory.
                IWritingSystem lws = wsf.get_Engine(icuLocale);
                ws  = lws.WritingSystem;
                lws = null;
            }
            return(ws);
        }
コード例 #12
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Update the existing categories and terms with new localized strings.
        /// </summary>
        /// <param name="dlg">The progress dialog.</param>
        /// <param name="parameters">The parameters: 1) the BiblicalTermsLocalization object
        /// representing the contents of the XML file with the localized strings; 2) The ICU
        /// locale (string).</param>
        /// <returns>always null</returns>
        /// ------------------------------------------------------------------------------------
        protected object UpdateLocalization(IThreadedProgress dlg, params object[] parameters)
        {
            BiblicalTermsLocalization loc = (BiblicalTermsLocalization)parameters[0];
            string locale = (string)parameters[1];

            const int kcStepsToBuildLookupTable = 4;

            dlg.Position = 0;
            dlg.Minimum  = 0;
            dlg.Maximum  = loc.Categories.Count + loc.Terms.Count + kcStepsToBuildLookupTable;
            dlg.Title    = TeResourceHelper.GetResourceString("kstidLoadKeyTermsInDBCaption");
            dlg.Message  = TeResourceHelper.FormatResourceString("kstidLoadKeyTermsLocalizations",
                                                                 m_wsf.get_Engine(locale).LanguageName);

            m_wsDefault = m_servLoc.WritingSystemManager.GetWsFromStr("en");

            int hvoLocWs = loc.WritingSystemHvo = m_wsf.GetWsFromStr(locale);

            IEnumerable <ICmPossibility> categories = ((ILangProject)m_scr.Owner).KeyTermsList.PossibilitiesOS;

            foreach (CategoryLocalization localizedCategory in loc.Categories)
            {
                ICmPossibility category = categories.FirstOrDefault(
                    p => p.Abbreviation.get_String(m_wsDefault).Text == localizedCategory.Id);
                if (category != null)
                {
                    category.Name.set_String(hvoLocWs, localizedCategory.Gloss);
                }
                dlg.Step(1);
            }

            Dictionary <int, IChkTerm> termLookupTable =
                m_servLoc.GetInstance <IChkTermRepository>().AllInstances().ToDictionary(t => t.TermId);

            dlg.Step(kcStepsToBuildLookupTable);

            IChkTerm term;
            string   message = TeResourceHelper.GetResourceString("kstidLoadKeyTermsInDBStatus");

            foreach (TermLocalization localizedTerm in loc.Terms)
            {
                dlg.Message = string.Format(message, localizedTerm.Gloss);

                if (termLookupTable.TryGetValue(localizedTerm.Id, out term))
                {
                    SetLocalizedGlossAndDescription(term, localizedTerm, loc.WritingSystemHvo);
                }
                dlg.Step(1);
            }
            return(null);
        }
コード例 #13
0
        public void WritingSystemsLists()
        {
            List <IWritingSystem> list = new List <IWritingSystem>();

            foreach (var x in Cache.LangProject.AllWritingSystems)
            {
                list.Add(x);
            }
            Assert.AreEqual(2, list.Count);

            ILgWritingSystemFactory factWs = Cache.ServiceLocator.GetInstance <ILgWritingSystemFactory>();

            Assert.LessOrEqual(list.Count, factWs.NumberOfWs, "factory list is at least as large as AllWritingSystems");
            Set <int> set = new Set <int>();

            using (ArrayPtr rgwsT = MarshalEx.ArrayToNative <int>(factWs.NumberOfWs))
            {
                factWs.GetWritingSystems(rgwsT, factWs.NumberOfWs);
                set.AddRange(MarshalEx.NativeToArray <int>(rgwsT, factWs.NumberOfWs));
            }
            int wsEn = factWs.GetWsFromStr("en");

            Assert.AreNotEqual(0, wsEn, "factory should contain English WS");
            int wsFr = factWs.GetWsFromStr("fr");

            Assert.AreNotEqual(0, wsFr, "factory should contain French WS");
            IWritingSystem eng = null;
            IWritingSystem frn = null;

            foreach (var x in list)
            {
                Assert.IsTrue(set.Contains(x.Handle), "AllWritingSystems should be a subset of the factory list");
                if (x.Handle == wsEn)
                {
                    eng = x;
                }
                else if (x.Handle == wsFr)
                {
                    frn = x;
                }
            }
            Assert.IsNotNull(eng, "AllWritingSystems should contain English");
            Assert.AreEqual("English", factWs.get_EngineOrNull(wsEn).LanguageName);
            Assert.AreEqual("English", eng.LanguageName);

            Assert.IsNotNull(frn, "AllWritingSystems should contain French");
            Assert.AreEqual("French", frn.LanguageName);
            Assert.AreEqual("French", factWs.get_Engine("fr").LanguageName);
        }
コード例 #14
0
        public void TestOverrideFontForWritingSystem_ForStyleWithNullProps()
        {
            TestFwStylesheet stylesheet = new TestFwStylesheet();
            int hvoNewStyle1            = stylesheet.MakeNewStyle();

            stylesheet.PutStyle("FirstStyle", "bla", hvoNewStyle1, 0, 0, 0, false, false, null);

            ILgWritingSystemFactory wsf = LgWritingSystemFactoryClass.Create();

            try
            {
                wsf.BypassInstall = true;
                IWritingSystem ws          = wsf.get_Engine("de");
                int            hvoGermanWs = ws.WritingSystem;
                Assert.IsTrue(hvoGermanWs > 0, "Should have gotten an hvo for the German WS");

                // Array of 1 struct, contains writing system and font size to override
                List <FontOverride> fontOverrides = new List <FontOverride>(1);
                FontOverride        aFontOverride;
                aFontOverride.writingSystem = hvoGermanWs;
                aFontOverride.fontSize      = 48;
                fontOverrides.Add(aFontOverride);
                stylesheet.OverrideFontsForWritingSystems("FirstStyle", fontOverrides);

                //check results
                IVwPropertyStore vwps = VwPropertyStoreClass.Create();
                vwps.Stylesheet           = stylesheet;
                vwps.WritingSystemFactory = wsf;

                ITsPropsBldr ttpBldr = TsPropsBldrClass.Create();
                ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "FirstStyle");
                ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoGermanWs);
                ITsTextProps ttp = ttpBldr.GetTextProps();

                LgCharRenderProps chrps = vwps.get_ChrpFor(ttp);
                ws.InterpretChrp(ref chrps);

                Assert.AreEqual(48, chrps.dympHeight / 1000);
            }
            finally
            {
                wsf.Shutdown();
            }
        }
コード例 #15
0
        private static ILgWritingSystem SafelyGetWritingSystem(FdoCache cache, ILgWritingSystemFactory wsFactory,
                                                               Language lang, out bool fIsVernacular)
        {
            fIsVernacular = lang.vernacularSpecified && lang.vernacular;
            ILgWritingSystem writingSystem = null;

            try
            {
                writingSystem = wsFactory.get_Engine(lang.lang);
            }
            catch (ArgumentException e)
            {
                IWritingSystem ws;
                WritingSystemServices.FindOrCreateSomeWritingSystem(cache, FwDirectoryFinder.TemplateDirectory, lang.lang,
                                                                    !fIsVernacular, fIsVernacular, out ws);
                writingSystem = ws;
                s_wsMapper.Add(lang.lang, writingSystem);                 // old id string -> new langWs mapping
            }
            return(writingSystem);
        }
コード例 #16
0
		string TrimNonWordFormingChars(string test, ILgWritingSystemFactory wsf, bool atStart, bool atEnd)
		{
			return TsStringUtils.TrimNonWordFormingChars(TsStringUtils.MakeTss(test, wsf.get_Engine("en").Handle), wsf, atStart, atEnd).Text;
		}
コード例 #17
0
        public void TestOverrideFontsForWritingSystems_ForStyleWithProps()
        {
            TestFwStylesheet stylesheet = new TestFwStylesheet();
            int hvoNewStyle1            = stylesheet.MakeNewStyle();

            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, "Arial");
            propsBldr.SetIntPropValues((int)FwTextPropType.ktptFontSize,
                                       (int)FwTextPropVar.ktpvMilliPoint, 23000);
            stylesheet.PutStyle("FirstStyle", "bla", hvoNewStyle1, 0, 0, 0, false, false,
                                propsBldr.GetTextProps());

            ILgWritingSystemFactory wsf = LgWritingSystemFactoryClass.Create();

            try
            {
                wsf.BypassInstall = true;

                IWritingSystem wsFrench    = wsf.get_Engine("fr");
                int            hvoFrenchWs = wsFrench.WritingSystem;
                Assert.IsTrue(hvoFrenchWs > 0, "Should have gotten an HVO for the French WS");

                IWritingSystem wsGerman    = wsf.get_Engine("de");
                int            hvoGermanWs = wsGerman.WritingSystem;
                Assert.IsTrue(hvoGermanWs > 0, "Should have gotten an HVO for the German WS");

                IWritingSystem wsIngles    = wsf.get_Engine("en");
                int            hvoInglesWs = wsIngles.WritingSystem;
                Assert.IsTrue(hvoInglesWs > 0, "Should have gotten an HVO for the English WS");

                Assert.IsTrue(hvoFrenchWs != hvoGermanWs, "Should have gotten different HVOs for each WS");
                Assert.IsTrue(hvoInglesWs != hvoGermanWs, "Should have gotten different HVOs for each WS");
                Assert.IsTrue(hvoFrenchWs != hvoInglesWs, "Should have gotten different HVOs for each WS");

                // Array of structs, containing writing systems and font sizes to override.
                List <FontOverride> fontOverrides = new List <FontOverride>(2);
                FontOverride        aFontOverride;
                aFontOverride.writingSystem = hvoGermanWs;
                aFontOverride.fontSize      = 48;
                fontOverrides.Add(aFontOverride);
                aFontOverride.writingSystem = hvoInglesWs;
                aFontOverride.fontSize      = 34;
                fontOverrides.Add(aFontOverride);
                stylesheet.OverrideFontsForWritingSystems("FirstStyle", fontOverrides);

                //check results
                IVwPropertyStore vwps = VwPropertyStoreClass.Create();
                vwps.Stylesheet           = stylesheet;
                vwps.WritingSystemFactory = wsf;

                ITsPropsBldr ttpBldr = TsPropsBldrClass.Create();
                ttpBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "FirstStyle");
                ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoFrenchWs);
                ITsTextProps ttpFrench = ttpBldr.GetTextProps();
                ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoGermanWs);
                ITsTextProps ttpGerman = ttpBldr.GetTextProps();
                ttpBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, hvoInglesWs);
                ITsTextProps ttpIngles = ttpBldr.GetTextProps();

                LgCharRenderProps chrpsFrench = vwps.get_ChrpFor(ttpFrench);
                LgCharRenderProps chrpsGerman = vwps.get_ChrpFor(ttpGerman);
                LgCharRenderProps chrpsIngles = vwps.get_ChrpFor(ttpIngles);
                wsFrench.InterpretChrp(ref chrpsFrench);
                wsGerman.InterpretChrp(ref chrpsGerman);
                wsIngles.InterpretChrp(ref chrpsIngles);

                Assert.AreEqual(23, chrpsFrench.dympHeight / 1000);
                Assert.AreEqual(34, chrpsIngles.dympHeight / 1000);
                Assert.AreEqual(48, chrpsGerman.dympHeight / 1000);
            }
            finally
            {
                wsf.Shutdown();
            }
        }
コード例 #18
0
ファイル: StringUtilsTest.cs プロジェクト: sillsdev/WorldPad
		string TrimNonWordFormingChars(string test, ILgWritingSystemFactory wsf)
		{
			return StringUtils.TrimNonWordFormingChars(StringUtils.MakeTss(test, wsf.get_Engine("en").WritingSystem), wsf).Text;
		}
コード例 #19
0
ファイル: StringUtilsTest.cs プロジェクト: sillsdev/WorldPad
		bool FindWordFormInString(string wordForm, string source,
			ILgWritingSystemFactory wsf, out int ichMin, out int ichLim)
		{
			int ws = wsf.get_Engine("en").WritingSystem;
			ITsString tssWordForm = StringUtils.MakeTss(wordForm, ws);
			ITsString tssSource = StringUtils.MakeTss(source, ws);
			return StringUtils.FindWordFormInString(tssWordForm, tssSource, wsf, out ichMin, out ichLim);
		}
コード例 #20
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the ws handle for specified writing system identifier.
		/// </summary>
		/// <param name="wsId">The writing system identifier.</param>
		/// <param name="lgwsf">The writing system factory.</param>
		/// ------------------------------------------------------------------------------------
		internal static int GetWsForId(string wsId, ILgWritingSystemFactory lgwsf)
		{
			try
			{
				ILgWritingSystem ws = lgwsf.get_Engine(wsId);
				return ws.Handle;
			}
			catch (ArgumentException e)
			{
				throw new XmlSchemaException("Unable to create writing system: " + wsId, e);
			}
		}
コード例 #21
0
		private static ILgWritingSystem GetWsEngine(ILgWritingSystemFactory wsFactory, string langCode)
		{
			ILgWritingSystem result;
			if (s_wsMapper.TryGetValue(langCode, out result))
				return result;

			return wsFactory.get_Engine(langCode);
		}
コード例 #22
0
        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));
        }
コード例 #23
0
		private static bool TryGetWsEngine(ILgWritingSystemFactory wsFact, string langCode, out ILgWritingSystem wsEngine)
		{
			wsEngine = null;
			try
			{
				wsEngine = wsFact.get_Engine(langCode);
			}
			catch (ArgumentException e)
			{
				Debug.Assert(false, "We hit the non-existant ws in AdjustPunctStringForCharacter().");
				return false;
			}
			return true;
		}
コード例 #24
0
		private static ILgWritingSystem SafelyGetWritingSystem(FdoCache cache, ILgWritingSystemFactory wsFactory,
			Language lang, out bool fIsVernacular)
		{
			fIsVernacular = lang.vernacularSpecified && lang.vernacular;
			ILgWritingSystem writingSystem = null;
			try
			{
				writingSystem = wsFactory.get_Engine(lang.lang);
			}
			catch (ArgumentException e)
			{
				IWritingSystem ws;
				WritingSystemServices.FindOrCreateSomeWritingSystem(cache, FwDirectoryFinder.TemplateDirectory, lang.lang,
					!fIsVernacular, fIsVernacular, out ws);
				writingSystem = ws;
				s_wsMapper.Add(lang.lang, writingSystem); // old id string -> new langWs mapping
			}
			return writingSystem;
		}
コード例 #25
0
ファイル: XmlHelperClasses.cs プロジェクト: sillsdev/WorldPad
		/// <summary>
		/// Translate the ICU locale string into the writing system id for the given
		/// writing system factory, adding it to the factory as needed.
		/// </summary>
		/// <param name="icuLocale"></param>
		/// <param name="wsf"></param>
		/// <returns></returns>
		static public int GetWsFromStr(string icuLocale, ILgWritingSystemFactory wsf)
		{
			int ws = wsf.GetWsFromStr(icuLocale);
			if (ws == 0)
			{
				// This adds the icuLocale as a new writing system to the factory.
				IWritingSystem lws = wsf.get_Engine(icuLocale);
				ws = lws.WritingSystem;
				lws = null;
			}
			return ws;
		}
コード例 #26
0
		bool FindWordFormInString(string wordForm, string source,
			ILgWritingSystemFactory wsf, out int ichMin, out int ichLim)
		{
			var ws = wsf.get_Engine("en").Handle;
			var tssWordForm = TsStringUtils.MakeTss(wordForm, ws);
			var tssSource = TsStringUtils.MakeTss(source, ws);
			return TsStringUtils.FindWordFormInString(tssWordForm, tssSource, wsf, out ichMin, out ichLim);
		}