Beispiel #1
0
        /// <summary>
        /// Adds the default word-forming character overrides to the list of valid
        /// characters for each vernacular writing system that is using the old
        /// valid characters representation.
        /// </summary>
        /// <param name="cache">The cache.</param>
        void AddDefaultWordformingOverridesIfNeeded(FdoCache cache)
        {
            ILgWritingSystemFactory lgwsf = cache.LanguageWritingSystemFactoryAccessor;

            foreach (ILgWritingSystem wsObj in cache.LangProject.VernWssRC)
            {
                IWritingSystem ws            = lgwsf.get_EngineOrNull(wsObj.Hvo);
                string         validCharsSrc = ws.ValidChars;
                if (!ValidCharacters.IsNewValidCharsString(validCharsSrc))
                {
                    LanguageDefinition langDef  = new LanguageDefinition(ws);
                    ValidCharacters    valChars = ValidCharacters.Load(langDef);
                    valChars.AddDefaultWordformingCharOverrides();

                    ws.ValidChars = langDef.ValidChars = valChars.XmlString;
                    using (new SuppressSubTasks(cache))
                    {
                        ws.SaveIfDirty(cache.DatabaseAccessor);
                    }
                    langDef.Serialize();
                }
            }
        }
        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));
        }