protected override bool GetFontMapping(string strFriendlyName, out string strLhsFont, out string strRhsFont)
        {
            bool bRet = base.GetFontMapping(strFriendlyName, out strLhsFont, out strRhsFont);

            // if it's a spellfixer project (and we don't already have a font mapping from the repository),
            //  then use the SpellFixer project's font
            if (!bRet && IsSpellFixerProject)
            {
                System.Diagnostics.Debug.Assert(((EncConverters)m_aECs).ContainsKey(strFriendlyName));
                ECAttributes aECAttrs = m_aECs.Attributes(strFriendlyName, AttributeType.Converter);
                if (aECAttrs != null)
                {
                    strLhsFont = strRhsFont = aECAttrs[SpellFixerByReflection.cstrAttributeFontToUse];
                    bRet       = true;
                }
            }
            return(bRet);
        }
        private void tabControl_Selected(object sender, TabControlEventArgs e)
        {
            Util.DebugWriteLine(this, "BEGIN");
            if (e.TabPage == tabPageSetup)
            {
                buttonSaveInRepository.Visible = SetupTabSelected_MakeSaveInRepositoryVisible;
                SetupTabSelected(e);
            }
            // if it was modified, then we need to apply it or switch back to
            //  the setup tab (unless it was the about tab that was selected)
            else if (e.TabPage != tabPageAbout)
            {
                // Test or Advanced tab.
                // If the configuration was modified, then make the user go back
                if (IsModified && !OnApply())
                {
                    MessageBox.Show("You must configure the conversion process on the Setup tab first", EncConverters.cstrCaption);
                    tabControl.SelectTab(tabPageSetup);
                }
                else
                {
                    System.Diagnostics.Debug.Assert(!IsModified);
                    IEncConverter aEC = InitializeEncConverter;
                    if (aEC != null)
                    {
                        if (e.TabPage == tabPageTestArea)
                        {
                            string strLhsFont, strRhsFont;
                            if (GetFontMapping(aEC.Name, out strLhsFont, out strRhsFont))
                            {
                                if (!String.IsNullOrEmpty(strLhsFont))
                                {
                                    ecTextBoxInput.Font = new Font(strLhsFont, 14);
                                }

                                if (!String.IsNullOrEmpty(strRhsFont))
                                {
                                    ecTextBoxOutput.Font = new Font(strRhsFont, 14);
                                }
                            }

                            TestTabInputChanged();  // doesn't happen automatically the first time for some reason
                            checkBoxTestReverse.Visible = !EncConverters.IsUnidirectional(aEC.ConversionType);
                        }
                        else // if (e.TabPage == tabPageAdvanced)
                        {
                            m_bAdvancedTabVisited          = true;
                            dataGridViewProperties.Visible = labelProperties.Visible = false;   // pessimistic
                            if (String.IsNullOrEmpty(FriendlyName))
                            {
                                textBoxFriendlyName.Text = DefaultFriendlyName;
                                IsModified = true;
                            }
                            else
                            {
                                textBoxFriendlyName.Text = FriendlyName;

                                // we shouldn't get here with a temporary converter...
                                System.Diagnostics.Debug.Assert(FriendlyName.IndexOf(EncConverters.cstrTempConverterPrefix) != 0);

                                // load the grid with any existing converter property keys and their values
                                // (but only do this if this is already in the collection object (or there
                                //  won't be any properties by definition) and if there *are* any properties
                                //  (because many sub-classes don't have any properties)
                                EncConverters aECs  = (EncConverters)m_aECs;
                                ECAttributes  attrs = null;
                                if (aECs.ContainsKey(FriendlyName) &&
                                    ((attrs = m_aECs.Attributes(FriendlyName, AttributeType.Converter)) != null) &&
                                    (attrs.Count > 0))
                                {
                                    dataGridViewProperties.Visible = labelProperties.Visible = true;
                                    dataGridViewProperties.Rows.Clear();
                                    foreach (DictionaryEntry kvp in attrs)
                                    {
                                        object[] aos = new object[] { kvp.Key, kvp.Value };
                                        dataGridViewProperties.Rows.Add(aos);
                                    }
                                }
                            }

                            // certain sub-classes don't allow the friendly name to be modified (e.g. spellfixer)
                            textBoxFriendlyName.ReadOnly = ShouldFriendlyNameBeReadOnly;

                            // load the combo boxes with the existing Encoding names
                            comboBoxEncodingNamesLhs.Items.Clear();
                            comboBoxEncodingNamesRhs.Items.Clear();
                            foreach (string strEncodingName in m_aECs.Encodings)
                            {
                                comboBoxEncodingNamesLhs.Items.Add(strEncodingName);
                                comboBoxEncodingNamesRhs.Items.Add(strEncodingName);
                            }

                            // if the left-hand side Encoding name is already configured, then select that
                            if (!String.IsNullOrEmpty(LhsEncodingId))
                            {
                                if (!comboBoxEncodingNamesLhs.Items.Contains(LhsEncodingId))
                                {
                                    comboBoxEncodingNamesLhs.Items.Add(LhsEncodingId);
                                }
                                comboBoxEncodingNamesLhs.SelectedItem = LhsEncodingId;
                            }

                            // if the right-hand side Encoding name is already configured, then select that
                            if (!String.IsNullOrEmpty(RhsEncodingId))
                            {
                                if (!comboBoxEncodingNamesRhs.Items.Contains(RhsEncodingId))
                                {
                                    comboBoxEncodingNamesRhs.Items.Add(RhsEncodingId);
                                }
                                comboBoxEncodingNamesRhs.SelectedItem = RhsEncodingId;
                            }

                            // initialize the check boxes for the Process Types
                            checkBoxUnicodeEncodingConversion.Checked = ((ProcessType & (int)ProcessTypeFlags.UnicodeEncodingConversion) != 0);
                            checkBoxTransliteration.Checked           = ((ProcessType & (int)ProcessTypeFlags.Transliteration) != 0);
                            checkBoxICUTransliteration.Checked        = ((ProcessType & (int)ProcessTypeFlags.ICUTransliteration) != 0);
                            checkBoxICUConverter.Checked = ((ProcessType & (int)ProcessTypeFlags.ICUConverter) != 0);
                            checkBoxCodePage.Checked     = ((ProcessType & (int)ProcessTypeFlags.CodePageConversion) != 0);
                            checkBoxNonUnicodeEncodingConversion.Checked = ((ProcessType & (int)ProcessTypeFlags.NonUnicodeEncodingConversion) != 0);
                            checkBoxSpellingFixerProject.Checked         = ((ProcessType & (int)ProcessTypeFlags.SpellingFixerProject) != 0);
                            checkBoxICURegularExpression.Checked         = ((ProcessType & (int)ProcessTypeFlags.ICURegularExpression) != 0);
                            checkBoxPythonScript.Checked   = ((ProcessType & (int)ProcessTypeFlags.PythonScript) != 0);
                            checkBoxPerlExpression.Checked = ((ProcessType & (int)ProcessTypeFlags.PerlExpression) != 0);
                            checkBoxSpare1.Checked         = ((ProcessType & (int)ProcessTypeFlags.UserDefinedSpare1) != 0);
                            checkBoxSpare2.Checked         = ((ProcessType & (int)ProcessTypeFlags.UserDefinedSpare2) != 0);
                        }
                    }
                }
            }
        }
Пример #3
0
        public void DoTest()
        {
            EncConverters.WriteStorePath(@"C:\Program Files\Common Files\SIL\Converters\Repository" + EncConverters.strDefXmlFilename);                // start from this each time

            GetECs.AddConversionMap("UEC", null, ConvType.Unicode_to_from_Unicode, "SIL.asdgtecForm",
                                    null, null, ProcessTypeFlags.DontKnow);

            string strMapPath = @"C:\Code\EC\Setup\MapsTables\";

            GetECs.Add("Greek<>Unicode", strMapPath + "SILGreek.tec", ConvType.Legacy_to_from_Unicode,
                       null, "Unicode Greek", ProcessTypeFlags.UnicodeEncodingConversion);

            string mapName = "Annapurna", fontName = "Annapurna",
                   encodingName = "SIL-ANNAPURNA_05-2002", becomes = "Unicode Devanagari",
                   aliasName = "SIL-ANNAPURNA_05";

            // first add TECkit spec
            GetECs.AddConversionMap(mapName, strMapPath + "ann2Unicode.cct",
                                    ConvType.Legacy_to_Unicode, EncConverters.strTypeSILcc, encodingName, becomes,
                                    ProcessTypeFlags.UnicodeEncodingConversion);
            Debug.Assert(GetECs[mapName].LeftEncodingID == encodingName);
            Debug.Assert(GetECs[mapName].RightEncodingID == becomes);

            // GetECs.Remove(mapName);

            GetECs.AddAlias(encodingName, aliasName);
            GetECs.AddAlias(aliasName, "asgd");
            try
            {
                // can't add a second alias with the same name
                GetECs.AddAlias(becomes, "asgd");
            }
            catch (COMException e)
            {
                Debug.Assert(e.ErrorCode == (int)ErrStatus.InvalidAliasName);
            }

            // then add a CC spec
            GetECs.AddConversionMap(mapName, strMapPath + "Annapurna.tec",
                                    ConvType.Legacy_to_from_Unicode, EncConverters.strTypeSILtec, aliasName, becomes,
                                    ProcessTypeFlags.UnicodeEncodingConversion);
            Debug.Assert(GetECs[mapName].LeftEncodingID == encodingName);
            Debug.Assert(GetECs[mapName].RightEncodingID == becomes);

            // then overwrite the TECkit spec (fixing the unirange
            GetECs.AddConversionMap("Annapurna<>Unicode", strMapPath + "Annapurna.tec",
                                    ConvType.Legacy_to_from_Unicode, EncConverters.strTypeSILtec, aliasName, becomes,
                                    ProcessTypeFlags.UnicodeEncodingConversion);

            GetECs.AddFont(fontName, 1252, encodingName);

            ECAttributes aAttributes = GetECs.Attributes(encodingName, AttributeType.EncodingID);

            aAttributes.Add("FontName", fontName);

            aAttributes = GetECs.Attributes(fontName, AttributeType.FontName);
            aAttributes.Add("Keyman Keyboard", "DevRom");

            GetECs.AddImplementation("Encode::Registry", "SIL.utr22c", "Encode::UTR22", null, -3);
            GetECs.AddImplementation("Encode::Registry", EncConverters.strTypeSILtec, "Encode::TECkit", null, 3);
            GetECs.AddImplementation("Encode::Registry", "cp", "Encode::WinCP", null, 5);
            GetECs.AddImplementation("Encode::Registry", "Private.dictconv", "SIL::DictConv", null, 0);

            /*
             * GetECs.Clear();
             *
             * string strFontName = "Annapurna";
             * string strMapName = "Annapurna";
             * encodingName = "SIL-ANNAPURNA_05-2002";
             * GetECs.AddConversionMap(strMapName, strMapPath + "Annapurna.tec",
             *      ConvType.Legacy_to_from_Unicode, EncConverters.strTypeSILtec,encodingName,null,
             *      ProcessTypeFlags.UnicodeEncodingConversion);
             * GetECs.AddFont(strFontName, 1252, encodingName);
             * GetECs.AddAlias("SIL-ANNAPURNA_05-2002","Annapurna");
             * GetECs.AddAlias("SIL-ANNAPURNA_05-2002","Annapurna");  // make sure it doesn't happen twice
             * GetECs.AddAlias("SIL-ANNAPURNA_05-2002","SIL-ANNAPURNA_05");
             * GetECs.Remove("Annapurna2");
             * GetECs.Clear();
             * foreach(IEncConverter aEC in GetECs.Values)
             * {
             *      MessageBox.Show(aEC.Name);
             * }
             * foreach(IEncConverter aEC in GetECs.Values)
             * {
             *      MessageBox.Show(aEC.Name);
             * }
             */

            string strMapName = "IPA93";

            GetECs.AddConversionMap(strMapName, strMapPath + "SIL-IPA93.tec",
                                    ConvType.Legacy_to_from_Unicode, EncConverters.strTypeSILtec, "SIL-IPA93-2002", "Unicode IPA",
                                    ProcessTypeFlags.UnicodeEncodingConversion);

            string strFontName = "SILDoulous IPA93";

            encodingName = "SIL-IPA93-2002";
            GetECs.AddFont(strFontName, 42, encodingName);

            strFontName = "SILManuscript IPA93";
            GetECs.AddFont(strFontName, 42, encodingName);

            strFontName = "SILSophia IPA93";
            GetECs.AddFont(strFontName, 42, encodingName);

            strMapName = "UniDevanagri<>UniIPA";
            GetECs.AddConversionMap(strMapName, strMapPath + "UDev2UIpa.tec",
                                    ConvType.Unicode_to_from_Unicode, EncConverters.strTypeSILtec, becomes, "Unicode IPA",
                                    ProcessTypeFlags.Transliteration);

            strFontName = "Doulous SIL";
            GetECs.AddUnicodeFontEncoding(strFontName, "Unicode IPA");
            GetECs.AddUnicodeFontEncoding(strFontName, "Unicode Greek");

            GetECs.AddFontMapping("IPA93", "SILDoulous IPA93", "Doulous SIL");

            GetECs.AddConversionMap("Annapurna<>IPA93", null, ConvType.Legacy_to_from_Legacy,
                                    EncConverters.strTypeSILcomp, null, null, ProcessTypeFlags.Transliteration);

            GetECs.AddCompoundConverterStep("Annapurna<>IPA93", "Annapurna", true, NormalizeFlags.None);
            GetECs.AddCompoundConverterStep("Annapurna<>IPA93", strMapName, true, NormalizeFlags.FullyComposed);
            GetECs.AddCompoundConverterStep("Annapurna<>IPA93", "IPA93", false, NormalizeFlags.FullyDecomposed);

            strMapName = "Devanagri<>Latin(ICU)";
            GetECs.AddConversionMap(strMapName, "Devanagari-Latin", ConvType.Unicode_to_from_Unicode,
                                    "ICU.trans", "Unicode Devanagari", null, ProcessTypeFlags.ICUTransliteration);

            strMapName = "UTF-8<>UTF-16";
            GetECs.Add(strMapName, "UTF-8", ConvType.Unicode_to_from_Unicode,
                       null, null, ProcessTypeFlags.ICUConverter);

            GetECs.Add(strMapName, "65001", ConvType.Unicode_to_from_Unicode,
                       null, null, ProcessTypeFlags.CodePageConversion);

            GetECs.AddConversionMap(strMapName, "EncodingFormConversionRequest",
                                    ConvType.Unicode_to_from_Unicode, EncConverters.strTypeSILtecForm, null, null,
                                    ProcessTypeFlags.DontKnow);

/*
 *                      foreach(string aConverterName in GetECs.EnumByProcessType(ProcessTypeFlags.ICUConverter) )
 *                      {
 *                              MessageBox.Show(aConverterName);
 *                      }
 *
 *                      EncConverters aNewECs = GetECs.ByEncodingID("SIL-ANNAPURNA_05-2002",ProcessTypeFlags.UnicodeEncodingConversion);
 *                      foreach(IEncConverter aEC in aNewECs.Values)
 *                      {
 *                              MessageBox.Show(aEC.Name);
 *                      }
 *                      aNewECs = GetECs.ByEncodingID("SIL-ANNAPURNA_05-2002",ProcessTypeFlags.Transliteration);
 *                      foreach(IEncConverter aEC in aNewECs.Values)
 *                      {
 *                              MessageBox.Show(aEC.Name);
 *                      }
 *
 *                      aNewECs = GetECs.ByFontName("SILDoulous IPA93", ProcessTypeFlags.DontKnow);
 *                      foreach(IEncConverter aEC in aNewECs.Values)
 *                      {
 *                              MessageBox.Show(aEC.Name);
 *                      }
 */
            try
            {
                GetECs.RemoveAlias("SIL-ANNAPURNA_05");
            }
            catch (COMException e)
            {
                MessageBox.Show(e.Message);
            }
            try
            {
                // this *should* fail because we've already removed it by the alias name
                GetECs.Remove("Annapurna");
            }
            // what isn't this working???
            catch (COMException e)
            {
                MessageBox.Show(e.Message);
                // System.Diagnostics.Debug.Assert(e.);
                // Assert(e == ErrStatus.NoAliasName);
            }

            /*
             * ECAttributes aAttrs = GetECs.Attributes(strMapName,AttributeType.Converter);
             * aAttrs.Add("test attribute","test value");
             * aAttrs.Remove("Copyright");
             * aAttrs.AddNonPersist("non-persist add", "test");
             * aAttrs.RemoveNonPersist("TECkitCompilerVersion");
             * foreach(DictionaryEntry aAttr in aAttrs)
             * {
             *      MessageBox.Show("Property: " + aAttr.Key + " = " + aAttr.Value);
             * }
             *
             * GetECs.Remove(strMapName);
             */
        }