Example #1
0
        public void Teardown()
        {
            if (m_wsf != null && Marshal.IsComObject(m_wsf))
            {
                m_wsf.Shutdown();
                Marshal.ReleaseComObject(m_wsf);
            }
            m_wsf = null;

            if (Marshal.IsComObject(m_cda))
            {
                Marshal.ReleaseComObject(m_cda);
            }
            m_cda = null;

            if (Marshal.IsComObject(m_mdc))
            {
                Marshal.ReleaseComObject(m_mdc);
            }
            m_mdc = null;

            if (Marshal.IsComObject(m_sda))
            {
                Marshal.ReleaseComObject(m_sda);
            }
            m_sda = null;

            m_layoutInventory = null;
            m_columnList      = null;
            m_layouts         = null;
            m_partInventory   = null;
        }
        public void Persistence()
        {
            ILgWritingSystemFactory wsf = LgWritingSystemFactoryClass.Create();

            try
            {
                int wsEng = 1;
                int wsFrn = 2;
                int wsGer = 3;
                wsf.AddWritingSystem(wsEng, "en");
                wsf.AddWritingSystem(wsFrn, "fr");
                wsf.AddWritingSystem(wsGer, "de");
                InterlinLineChoices choices = new InterlinLineChoices(wsFrn, wsEng);
                MakeStandardState(choices);
                string persist = choices.Persist(wsf);
                choices = InterlinLineChoices.Restore(persist, wsf, wsFrn, wsEng);

                Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[4].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[5].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[6].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[7].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[8].Flid);

                // Check writing systems assigned by default.
                Assert.AreEqual(wsFrn, choices[0].WritingSystem);
                Assert.AreEqual(wsEng, choices[5].WritingSystem);
                Assert.AreEqual(wsFrn, choices[2].WritingSystem);

                choices = new EditableInterlinLineChoices(0, wsEng);
                MakeStandardState(choices);
                choices.Add(InterlinLineChoices.kflidLexGloss, wsGer);
                Assert.AreEqual(InterlinLineChoices.kflidWord, choices[0].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidMorphemes, choices[1].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexEntries, choices[2].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[3].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexGloss, choices[4].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLexPos, choices[5].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidWordGloss, choices[6].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidWordPos, choices[7].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidFreeTrans, choices[8].Flid);
                Assert.AreEqual(InterlinLineChoices.kflidLitTrans, choices[9].Flid);

                Assert.AreEqual(wsGer, choices[4].WritingSystem);
            }
            finally
            {
                // we must shutdown and marshal this or else it could mess up other tests.
                wsf.Shutdown();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(wsf);
            }
        }
Example #3
0
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (components != null)
         {
             components.Dispose();
         }
     }
     base.Dispose(disposing);
     m_wsf.Shutdown();             // Not normally in View Dispose, but after closing ALL views.
 }
        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();
            }
        }
Example #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="comboWS">Combo box containing the list of writing systems</param>
        /// ------------------------------------------------------------------------------------
        private void RunWizard(ComboBox comboWS)
        {
            using (new WaitCursor(this))
            {
                using (WritingSystemWizard wiz = new WritingSystemWizard())
                {
                    ILgWritingSystemFactory wsf = LgWritingSystemFactoryClass.Create();
                    try
                    {
                        wiz.Init(wsf, m_helpTopicProvider);
                        if (comboWS == m_cbVernWrtSys)
                        {
                            wiz.PerformInitialSearch(m_txtName.Text.Trim());
                        }

                        if (wiz.ShowDialog() == DialogResult.OK)
                        {
                            UpdateLanguageCombos();
                            string target = wiz.WritingSystem().IcuLocale;
                            for (int i = 0; i < comboWS.Items.Count; ++i)
                            {
                                if (((NamedWritingSystem)comboWS.Items[i]).IcuLocale == target)
                                {
                                    comboWS.SelectedIndex = i;
                                    break;
                                }
                            }
                        }
                    }
                    finally
                    {
                        wsf.Shutdown();
                    }
                }
            }
        }
 public void TearDown()
 {
     m_wsf.Shutdown();
 }
Example #7
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.
        }
Example #8
0
 public void DestroyTheFactory()
 {
     m_wsf.Shutdown();
 }
        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();
            }
        }