Exemple #1
0
        static void Conv2Kernel(double[][] inputSignal, double[][] kernel, double[][] y, int i, int cols, int rows,
                                int kCols, int kRows, int kCenterX, int kCenterY, ConvType type)
        {
            int ti = i;

            for (int j = 0; j < cols; ++j)              // columns
            {
                int    tj  = j;
                double sum = 0;
                for (int m = 0; m < kRows; ++m)      // kernel rows
                {
                    int mm = kRows - 1 - m;          // row index of flipped kernel
                    for (int n = 0; n < kCols; ++n)  // kernel columns
                    {
                        int nn = kCols - 1 - n;      // column index of flipped kernel
                        // index of input signal, used for checking boundary
                        int ii = i + (m - kCenterY); //+ m;
                        int jj = j + (n - kCenterX); //+ n;
                        // ignore input samples which are out of bound

                        if (ii >= 0 && ii < inputSignal.Length && jj >= 0 && jj < inputSignal[ii].Length)
                        {
                            sum += inputSignal[ii][jj] * kernel[mm][nn];
                        }
                    }
                }

                y[i][j] = sum;
            }
        }
 protected void SetConvTypeFromRbControls
 (
     RadioButton rbExpectsUnicode,
     RadioButton rbExpectsLegacy,
     RadioButton rbReturnsUnicode,
     RadioButton rbReturnsLegacy
 )
 {
     if (rbExpectsUnicode.Checked)
     {
         if (rbReturnsUnicode.Checked)
         {
             ConversionType = ConvType.Unicode_to_Unicode;
         }
         else
         {
             ConversionType = ConvType.Unicode_to_Legacy;
         }
     }
     else
     {
         if (rbReturnsUnicode.Checked)
         {
             ConversionType = ConvType.Legacy_to_Unicode;
         }
         else
         {
             ConversionType = ConvType.Legacy_to_Legacy;
         }
     }
 }
Exemple #3
0
 public AdaptItLookupAutoConfigDialog
 (
     IEncConverters aECs,
     string strDisplayName,
     string strFriendlyName,
     string strConverterIdentifier,
     ConvType eConversionType,
     string strLhsEncodingId,
     string strRhsEncodingId,
     int lProcessTypeFlags,
     bool bIsInRepository
 )
 {
     base.Initialize
     (
         aECs,
         AdaptItEncConverter.strHtmlFilename,
         strDisplayName,
         strFriendlyName,
         strConverterIdentifier,
         eConversionType,
         strLhsEncodingId,
         strRhsEncodingId,
         lProcessTypeFlags,
         bIsInRepository
     );
 }
Exemple #4
0
        public static NormConversionType NormalizeRhsConversionType(ConvType type)
        {
            NormConversionType eType = NormConversionType.eUnicode;

            switch (type)
            {
            case ConvType.Legacy_to_from_Legacy:
            case ConvType.Legacy_to_Legacy:
            case ConvType.Unicode_to_from_Legacy:
            case ConvType.Unicode_to_Legacy:
                eType = NormConversionType.eLegacy;
                break;

            case ConvType.Legacy_to_from_Unicode:
            case ConvType.Legacy_to_Unicode:
            case ConvType.Unicode_to_from_Unicode:
            case ConvType.Unicode_to_Unicode:
                eType = NormConversionType.eUnicode;
                break;

            default:
                // Debug.Assert();  // doesn't work for some reason!!??
                break;
            }
            ;

            return(eType);
        }
		public override void Initialize(string converterName, string converterSpec,
			ref string lhsEncodingID, ref string rhsEncodingID, ref ConvType conversionType,
			ref Int32 processTypeFlags, Int32 codePageInput, Int32 codePageOutput, bool bAdding)
		{
			base.Initialize(converterName, converterSpec, ref lhsEncodingID, ref rhsEncodingID, ref conversionType, ref processTypeFlags, codePageInput, codePageOutput, bAdding);

			if (bAdding)
			{
				// the only thing we want to add (now that the convType can be less than accurate)
				//  is to make sure it's bidirectional)
				if (EncConverters.IsUnidirectional(conversionType))
				{
					switch (conversionType)
					{
						case ConvType.Legacy_to_Legacy:
							conversionType = ConvType.Legacy_to_from_Legacy;
							break;
						case ConvType.Legacy_to_Unicode:
							conversionType = ConvType.Legacy_to_from_Unicode;
							break;
						case ConvType.Unicode_to_Legacy:
							conversionType = ConvType.Unicode_to_from_Legacy;
							break;
						case ConvType.Unicode_to_Unicode:
							conversionType = ConvType.Unicode_to_from_Unicode;
							break;
						default:
							break;
					}
				}
			}
		}
Exemple #6
0
 protected void InitializeFromThis
 (
     ref string strFriendlyName,
     ref string strConverterIdentifier,
     ref ConvType eConversionType,
     ref string strTestData
 )
 {
     if (String.IsNullOrEmpty(strFriendlyName))
     {
         strFriendlyName = m_strFriendlyName;
     }
     if (String.IsNullOrEmpty(strConverterIdentifier))
     {
         strConverterIdentifier = m_strConverterID;
     }
     if (String.IsNullOrEmpty(strTestData))
     {
         strTestData = "Test Data";
     }
     if (eConversionType == ConvType.Unknown)
     {
         eConversionType = m_eConversionType;
     }
 }
        protected static ConvType MakeUniDirectional(ConvType conversionType)
        {
            switch (conversionType)
            {
            case ConvType.Legacy_to_from_Legacy:
                conversionType = ConvType.Legacy_to_Legacy;
                break;

            case ConvType.Legacy_to_from_Unicode:
                conversionType = ConvType.Legacy_to_Unicode;
                break;

            case ConvType.Unicode_to_from_Legacy:
                conversionType = ConvType.Unicode_to_Legacy;
                break;

            case ConvType.Unicode_to_from_Unicode:
                conversionType = ConvType.Unicode_to_Unicode;
                break;

            default:
                break;
            }

            return(conversionType);
        }
        public Convertor(string type, int procNum)
        {
            type = type.ToLower();
            switch (type)
            {
            case "client": convType = ConvType.Client; break;

            case "server": convType = ConvType.Server; break;

            case "validate": convType = ConvType.Validate; break;
            }
            convType_    = (int)convType;
            this.procNum = procNum;

            protoPath = TempDir + type + "\\proto\\";
            codePath  = TempDir + type + "\\code\\";
            dllPath   = TempDir + type + "\\dll\\";
            dataPath  = TempDir + type + "\\data\\";

            EnsureDirectory(TempDir);
            EnsureDirectory(protoPath);
            EnsureDirectory(codePath);
            EnsureDirectory(dllPath);  ClearDirectory(dllPath);
            EnsureDirectory(dataPath);             //ClearDirectory(dataPath);
        }
		public AdaptItGuesserAutoConfigDialog
			(
			IEncConverters aECs,
			string strDisplayName,
			string strFriendlyName,
			string strConverterIdentifier,
			ConvType eConversionType,
			string strLhsEncodingId,
			string strRhsEncodingId,
			int lProcessTypeFlags,
			bool bIsInRepository
			)
		{
			base.Initialize
			(
			aECs,
			AdaptItGuesserEncConverter.strHtmlFilename,
			strDisplayName,
			strFriendlyName,
			strConverterIdentifier,
			eConversionType,
			strLhsEncodingId,
			strRhsEncodingId,
			lProcessTypeFlags,
			bIsInRepository
			);
		}
Exemple #10
0
        public CpAutoConfigDialog
        (
            IEncConverters aECs,
            string strDisplayName,
            string strFriendlyName,
            string strConverterIdentifier,
            ConvType eConversionType,
            string strLhsEncodingId,
            string strRhsEncodingId,
            int lProcessTypeFlags,
            bool bIsInRepository
        )
        {
            InitializeComponent();

            base.Initialize
            (
                aECs,
                CpEncConverter.strHtmlFilename,
                strDisplayName,
                strFriendlyName,
                strConverterIdentifier,
                eConversionType,
                strLhsEncodingId,
                strRhsEncodingId,
                lProcessTypeFlags,
                bIsInRepository
            );

            m_bQueryForConvType = false;             // the converter determines this itself.

            if (m_encInfos != null)
            {
                foreach (EncodingInfo encInfo in m_encInfos)
                {
                    // String str = String.Format("CodePage: {0}, DisplayName: {1}, Name: {2}", encInfo.CodePage, encInfo.DisplayName, encInfo.Name);
                    String str = Convert.ToString(encInfo.CodePage, 10);
                    comboBoxCodePageList.Items.Add(str);
                }
            }

            // if we're editing ...
            if (m_bEditMode)
            {
                int nIndex = comboBoxCodePageList.Items.IndexOf(ConverterIdentifier);
                if (nIndex != -1)
                {
                    comboBoxCodePageList.SelectedIndex = nIndex;
                    IsModified = false;
                }
            }
            else
            {
                int nIndex = comboBoxCodePageList.Items.IndexOf(cstrDefaultCodePageToSelect);
                if (nIndex != -1)
                {
                    comboBoxCodePageList.SelectedIndex = nIndex;
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// Get recommended managed name according to information obtained from ITypeInfo.
        /// Doesn't guarantee that the name is unique. Can be called multiple times
        /// GUID_ManagedName is also considered
        /// </summary>
        /// <returns>The recommended name</returns>
        public string GetRecommendedManagedName(TypeInfo type, ConvType convType, bool useDefaultNamespace)
        {
            if (convType == ConvType.EventInterface)
            {
                //
                // Special treatment for event interfaces
                // For coclass that are referring to external source interfaces, we can define the event interfaces
                // in local assemblies and the namespace will always be the namespace of the importing type lib
                //
                string tlbNamespace = GetNamespaceForTypeLib(type, m_typeLib);

                string docName = type.GetDocumentation() + "_Event";

                if (string.IsNullOrEmpty(tlbNamespace))
                {
                    return(docName);
                }
                else
                {
                    return(tlbNamespace + "." + docName);
                }
            }
            else
            {
                string name = GetManagedName(type, useDefaultNamespace);

                // Rule Engine
                string changeNameActionResult = GetChangeManagedNameActionResult(type, convType, name);
                if (convType == ConvType.CoClass)
                {
                    changeNameActionResult = changeNameActionResult + "Class";
                }
                return(changeNameActionResult);
            }
        }
Exemple #12
0
 private string GetChangeManagedNameActionResult(TypeInfo typeInfo,
                                                 ConvType convType, string oldName)
 {
     if (Settings.m_ruleSet != null)
     {
         ICategory           category = TypeCategory.GetInstance();
         TypeInfoMatchTarget target   = null;
         using (TypeAttr attr = typeInfo.GetTypeAttr())
         {
             TypeLibTypes.Interop.TYPEKIND kind = attr.typekind;
             target = new TypeInfoMatchTarget(typeInfo.GetContainingTypeLib(), typeInfo, kind);
         }
         AbstractActionManager actionManager   = RuleEngine.GetActionManager();
         List <Rule>           changeNameRules = Settings.m_ruleSet.GetRule(
             category, ChangeManagedNameActionDef.GetInstance(), target);
         if (changeNameRules.Count != 0)
         {
             if (changeNameRules.Count > 1)
             {
                 Output.WriteWarning(Resource.FormatString("Wrn_RuleMultipleMatch",
                                                           ChangeManagedNameActionDef.GetInstance()),
                                     WarningCode.Wrn_RuleMultipleMatch);
             }
             Rule   changeNameRule = changeNameRules[changeNameRules.Count - 1];
             int    namespaceSplit = oldName.LastIndexOf('.');
             string oldNamespace   = "";
             if (namespaceSplit != -1)
             {
                 oldNamespace = oldName.Substring(0, namespaceSplit + 1);
             }
             return(oldNamespace + (changeNameRule.Action as ChangeManagedNameAction).NewName);
         }
     }
     return(oldName);
 }
        // initialize an EncConverter which will tell us when we've hit a match. Uses ICU RegEx (though, there's
        //  no reason this couldn't be .Net regex...)
        protected IEncConverter InitSearchFontConverter(string strFindWhat, string strReplaceWith, Font font, bool bMatchCase)
        {
            // we're going to use a temporary ICU RegEx EncConverter to do our 'searching' for us.
            // get a blank ICU Regex converter that we can program with our FindWhat string
            // but, it may be null if ICU isn't installed
            System.Diagnostics.Debug.Assert(m_aECs != null);
            IEncConverter aIEC = null;

            try
            {
                aIEC = m_aECs.NewEncConverterByImplementationType(EncConverters.strTypeSILicuRegex);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("ICU doesn't appear to have been installed. This feature won't work without ICU.", ex);
            }

            // we search for different things depending on whether it's "Find" (only) vs. "Find & Replace"
            // delimit the replacement string with something we can detect, which we wouldn't otherwise expect
            //  to find in user text.
            string strConverterSpec = String.Format("{0}->{2}{1}{2}{3}", strFindWhat, strReplaceWith,
                                                    m_achDelimiter[0], (bMatchCase) ? " /i" : null);

            // Give it a friendly name that isn't likely to conflict with anything 'real' the user might name it.
            string   strName   = String.Format("{0} FindReplaceConverter", OfficeApp.cstrCaption);
            ConvType eConvType = ConvType.Unicode_to_Unicode;
            string   strDummy  = null;
            int      nProcType = (int)ProcessTypeFlags.ICURegularExpression;

            // initialize it so it's ready and put it in the current repository object (as a temporary converter)
            aIEC.Initialize(strName, strConverterSpec, ref strDummy, ref strDummy, ref eConvType,
                            ref nProcType, 0, 0, true);

            return(aIEC);
        }
Exemple #14
0
        public virtual void Initialize
        (
            IEncConverters aECs,
            string strFriendlyName,
            string strConverterIdentifier,
            ConvType eConversionType,
            string strTestData
        )
        {
            FriendlyName        = strFriendlyName;
            ConverterIdentifier = strConverterIdentifier;
            ConversionType      = eConversionType;

            m_aECs = aECs;
            m_aEC  = InitializeEncConverter;

            tabControl.Controls.Remove(tabPageAbout);
            tabControl.Controls.Remove(tabPageSetup);
            tabControl.Controls.Remove(tabPageAdvanced);

            // for 'test', it's possible that there may be some font mapping in the repository
            string strLhsName, strRhsName;

            if (m_aECs.GetFontMappingFromMapping(strFriendlyName, out strLhsName, out strRhsName))
            {
                ecTextBoxInput.Font  = CreateFontSafe(strLhsName, ecTextBoxInput.Font);
                ecTextBoxOutput.Font = CreateFontSafe(strRhsName, ecTextBoxOutput.Font);
            }

            ecTextBoxInput.Text = strTestData;
            buttonOK.Visible    = buttonApply.Visible = false;
            buttonCancel.Text   = "Close";

            helpProvider.SetHelpString(buttonCancel, Properties.Resources.CloseButtonHelpString);
        }
 protected void ResetFields()
 {
     ConversionType      = m_eOrigConvType;
     ConverterIdentifier = null;
     ProcessType         = 0;
     m_aEC = null;
 }
        protected DirectableEncConverter GetTempFixedValueConverter(string strFixedValue)
        {
            string        strName = String.Format("{0}{1}", cstrFixedStringConverterPrefix, strFixedValue);
            EncConverters aECs    = GetEncConverters;

            if (aECs != null)
            {
                IEncConverter aIEC = null;
                if (!aECs.ContainsKey(strName))
                {
                    aIEC = aECs.NewEncConverterByImplementationType(EncConverters.strTypeSILicuRegex);
                    ConvType eConvType = ConvType.Unicode_to_Unicode;
                    string   strDummy  = null;
                    int      nProcType = (int)ProcessTypeFlags.ICURegularExpression;
                    aIEC.Initialize(strName, String.Format(".+->{0}", strFixedValue), ref strDummy, ref strDummy,
                                    ref eConvType, ref nProcType, 0, 0, true);
                    aECs.Add(strName, aIEC);
                }
                else
                {
                    aIEC = aECs[strName];
                }

                return(new DirectableEncConverter(aIEC));
            }
            return(null);
        }
 /// <summary>
 /// The name represents a (TypeInfo, ConvType) pair and is unique to a type library. Used in SymbolTable
 /// </summary>
 private string GetInternalEncodedManagedName(TypeInfo typeInfo, ConvType convType)
 {
     using (TypeLibAttr typeLibAttr = typeInfo.GetContainingTypeLib().GetLibAttr())
     {
         return(typeInfo.GetDocumentation() + "[" + convType.ToString() + "," + typeLibAttr.guid + "]");
     }
 }
Exemple #18
0
        /// <summary>
        /// This is the base class for the two different AdaptIt EncConverters: the Lookup transducer and the
        /// Guesser API transducer. Since both of these types have the same configuration dialog, most of the
        /// implementation can be put into this class, while the subclasses are used for the specifics to
        /// each (if there is none, then you can just get rid of this class)
        /// </summary>
        public override void Initialize
        (
            IEncConverters aECs,
            string strHtmlFileName,
            string strDisplayName,
            string strFriendlyName,
            string strConverterIdentifier,
            ConvType eConversionType,
            string strLhsEncodingId,
            string strRhsEncodingId,
            int lProcessTypeFlags,
            bool bIsInRepository
        )
        {
            InitializeComponent();

            base.Initialize
            (
                aECs,
                strHtmlFileName,
                strDisplayName,
                strFriendlyName,
                strConverterIdentifier,
                eConversionType,
                strLhsEncodingId,
                strRhsEncodingId,
                lProcessTypeFlags,
                bIsInRepository
            );

            m_bQueryForConvType = false;                // don't need to do this for this converter type (or we do, but differently)

            if (m_bEditMode)
            {
                m_bLegacy = (strConverterIdentifier.IndexOf(cstrAdaptItWorkingDirLegacy) != -1);
            }

            if (m_bLegacy)
            {
                InitProjectNames(cstrAdaptItWorkingDirLegacy, true);
                radioButtonLegacy.Checked = true;
            }
            else
            {
                InitProjectNames(cstrAdaptItWorkingDirUnicode, false);
                radioButtonUnicode.Checked = true;
            }

            if (m_bEditMode)
            {
                int nIndex = listBoxProjects.Items.IndexOf(ProjectNameFromConverterSpec);
                if (nIndex != -1)
                {
                    listBoxProjects.SelectedIndex = nIndex;
                }

                IsModified = false;
            }
        }
Exemple #19
0
 public abstract bool Configure
 (
     IEncConverters aECs,
     string strFriendlyName,
     ConvType eConversionType,
     string strLhsEncodingID,
     string strRhsEncodingID
 );
Exemple #20
0
 public abstract void DisplayTestPage
 (
     IEncConverters aECs,
     string strFriendlyName,
     string strConverterIdentifier,
     ConvType eConversionType,
     string strTestData
 );
Exemple #21
0
        private bool ChaChaChaChaChanges(IEncConverter aEC, string strFileName, string strWord)
        {
            string   strDummy     = null;
            int      lProcessType = (int)SpellingFixerEC.SFProcessType;
            ConvType eConvType    = (m_bLegacy) ? ConvType.Legacy_to_Legacy : ConvType.Unicode_to_Unicode;

            aEC.Initialize("dummyname", strFileName, ref strDummy, ref strDummy, ref eConvType, ref lProcessType, 0, 0, true);
            return(aEC.Convert(strWord) != strWord);
        }
Exemple #22
0
        public IcuTranslitAutoConfigDialog(
            IEncConverters aECs,
            string strDisplayName,
            string strFriendlyName,
            string strConverterIdentifier,
            ConvType eConversionType,
            string strLhsEncodingId,
            string strRhsEncodingId,
            int lProcessTypeFlags,
            bool bIsInRepository)
        {
            Util.DebugWriteLine(this, "BEGIN");

            InitializeComponent();
            fillListBox();
            Util.DebugWriteLine(this, "Initialized component.");
            base.Initialize(
                aECs,
                IcuTranslitEncConverter.strHtmlFilename,
                strDisplayName,
                strFriendlyName,
                strConverterIdentifier,
                eConversionType,
                strLhsEncodingId,
                strRhsEncodingId,
                lProcessTypeFlags | (int)ProcessTypeFlags.ICUTransliteration | (int)ProcessTypeFlags.Transliteration,
                bIsInRepository);
            Util.DebugWriteLine(this, "Initialized base.");

            // if we're editing, then set the Converter Spec and say it's unmodified
            if (m_bEditMode)
            {
                Util.DebugWriteLine(this, "Edit mode");
                System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(ConverterIdentifier));
                //listBoxTranslitName.SelectedValue = ConverterIdentifier;
                for (int i = 0; i < lstTranslitIDs.Count; i++)
                {
                    if (lstTranslitIDs[i] == ConverterIdentifier)
                    {
                        listBoxTranslitName.SelectedIndex = i;
                        break;
                    }
                }
                IsModified = false;
            }

            LoadComboBoxFromSettings(comboBoxPreviousCustomTransliterators, Settings.Default.RecentCustomTransliterators);

            if (comboBoxPreviousCustomTransliterators.Items.Count > 0)
            {
                comboBoxPreviousCustomTransliterators.SelectedIndex = 0;
            }

            m_bInitialized = true;
            Util.DebugWriteLine(this, "END");
        }
		public CpAutoConfigDialog
			(
			IEncConverters aECs,
			string strDisplayName,
			string strFriendlyName,
			string strConverterIdentifier,
			ConvType eConversionType,
			string strLhsEncodingId,
			string strRhsEncodingId,
			int lProcessTypeFlags,
			bool bIsInRepository
			)
		{
			InitializeComponent();

			base.Initialize
			(
			aECs,
			CpEncConverter.strHtmlFilename,
			strDisplayName,
			strFriendlyName,
			strConverterIdentifier,
			eConversionType,
			strLhsEncodingId,
			strRhsEncodingId,
			lProcessTypeFlags,
			bIsInRepository
			);

			m_bQueryForConvType = false; // the converter determines this itself.

			if (m_encInfos != null)
				foreach (EncodingInfo encInfo in m_encInfos)
				{
					// String str = String.Format("CodePage: {0}, DisplayName: {1}, Name: {2}", encInfo.CodePage, encInfo.DisplayName, encInfo.Name);
					String str = Convert.ToString(encInfo.CodePage, 10);
					comboBoxCodePageList.Items.Add(str);
				}

			// if we're editing ...
			if (m_bEditMode)
			{
				int nIndex = comboBoxCodePageList.Items.IndexOf(ConverterIdentifier);
				if (nIndex != -1)
				{
					comboBoxCodePageList.SelectedIndex = nIndex;
					IsModified = false;
				}
			}
			else
			{
				int nIndex = comboBoxCodePageList.Items.IndexOf(cstrDefaultCodePageToSelect);
				if (nIndex != -1)
					comboBoxCodePageList.SelectedIndex = nIndex;
			}
		}
		/// <summary>
		/// This is the base class for the two different AdaptIt EncConverters: the Lookup transducer and the
		/// Guesser API transducer. Since both of these types have the same configuration dialog, most of the
		/// implementation can be put into this class, while the subclasses are used for the specifics to
		/// each (if there is none, then you can just get rid of this class)
		/// </summary>
		public override void Initialize
			(
			IEncConverters aECs,
			string strHtmlFileName,
			string strDisplayName,
			string strFriendlyName,
			string strConverterIdentifier,
			ConvType eConversionType,
			string strLhsEncodingId,
			string strRhsEncodingId,
			int lProcessTypeFlags,
			bool bIsInRepository
			)
		{
			InitializeComponent();

			base.Initialize
			(
			aECs,
			strHtmlFileName,
			strDisplayName,
			strFriendlyName,
			strConverterIdentifier,
			eConversionType,
			strLhsEncodingId,
			strRhsEncodingId,
			lProcessTypeFlags,
			bIsInRepository
			);

			m_bQueryForConvType = false;    // don't need to do this for this converter type (or we do, but differently)

			if (m_bEditMode)
				m_bLegacy = (strConverterIdentifier.IndexOf(cstrAdaptItWorkingDirLegacy) != -1);

			if (m_bLegacy)
			{
				InitProjectNames(cstrAdaptItWorkingDirLegacy, true);
				radioButtonLegacy.Checked = true;
			}
			else
			{
				InitProjectNames(cstrAdaptItWorkingDirUnicode, false);
				radioButtonUnicode.Checked = true;
			}

			if (m_bEditMode)
			{
				int nIndex = listBoxProjects.Items.IndexOf(ProjectNameFromConverterSpec);
				if (nIndex != -1)
					listBoxProjects.SelectedIndex = nIndex;

				IsModified = false;
			}
		}
Exemple #25
0
		public SelectConverter(EncConverters aECs, ConvType eConversionTypeFilter,
			string strChooseConverterDialogTitle, byte[] abyPreviewData, string strFontName)
		{
			m_byPreviewData = abyPreviewData;

			InitSelectConverter(aECs, eConversionTypeFilter, strChooseConverterDialogTitle, strFontName);

			// hide the preview box until requested
			textBoxDataPreview.Hide();
			tableLayoutPanel1.RowCount = 4;
		}
        public override void Initialize(
            string converterName,
            string converterSpec,
            ref string lhsEncodingID,
            ref string rhsEncodingID,
            ref ConvType conversionType,
            ref Int32 processTypeFlags,
            Int32 codePageInput,
            Int32 codePageOutput,
            bool bAdding)
        {
            Util.DebugWriteLine(this, "BEGIN");
            // let the base class have first stab at it
            base.Initialize(converterName, converterSpec, ref lhsEncodingID, ref rhsEncodingID,
                            ref conversionType, ref processTypeFlags, codePageInput, codePageOutput, bAdding);

            // the only thing we want to add (now that the convType can be less than accurate)
            //  is to make sure it's unidirectional
            switch (conversionType)
            {
            case ConvType.Legacy_to_from_Legacy:
                conversionType = ConvType.Legacy_to_Legacy;
                break;

            case ConvType.Legacy_to_from_Unicode:
                conversionType = ConvType.Legacy_to_Unicode;
                break;

            case ConvType.Unicode_to_from_Legacy:
                conversionType = ConvType.Unicode_to_Legacy;
                break;

            case ConvType.Unicode_to_from_Unicode:
                conversionType = ConvType.Unicode_to_Unicode;
                break;

            default:
                break;
            }

            // if we're supposedly adding this one, then clobber our copy of its last modified
            // (there was a problem with us instantiating lots of these things in a row and
            //  not detecting the change because the modified date was within a second of each
            //  other)
            if (bAdding)
            {
                Util.DebugWriteLine(this, "Adding");
                m_timeModified = DateTime.MinValue;

                // do the load at this point; not that we need it, but for checking that everything's okay.
                Load();
            }
            Util.DebugWriteLine(this, "END");
        }
        public IcuRegexAutoConfigDialog(
            IEncConverters aECs,
            string strDisplayName,
            string strFriendlyName,
            string strConverterIdentifier,
            ConvType eConversionType,
            string strLhsEncodingId,
            string strRhsEncodingId,
            int lProcessTypeFlags,
            bool bIsInRepository)
        {
#if VERBOSE_DEBUGGING
            Console.WriteLine("IcuRegexAutoConfigDialog ctor BEGIN");
#endif
            InitializeComponent();
#if VERBOSE_DEBUGGING
            Console.WriteLine("Initialized IcuRegexAutoConfigDialog component.");
#endif
            base.Initialize(
                aECs,
                IcuRegexEncConverter.strHtmlFilename,
                strDisplayName,
                strFriendlyName,
                strConverterIdentifier,
                eConversionType,
                strLhsEncodingId,
                strRhsEncodingId,
                lProcessTypeFlags | (int)ProcessTypeFlags.ICURegularExpression,
                bIsInRepository);
#if VERBOSE_DEBUGGING
            Console.WriteLine("Initialized base.");
#endif

            LoadComboBoxFromSettings(comboBoxPreviousSearches, Settings.Default.RecentRegExpressions);
            comboBoxPreviousSearches.SelectedIndex = 0;

            // if we're editing a CC table/spellfixer project, then set the Converter Spec and say it's unmodified
            if (m_bEditMode)
            {
#if VERBOSE_DEBUGGING
                Console.WriteLine("Edit mode");
#endif
                System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(ConverterIdentifier));
                InitRegexControls(ConverterIdentifier);

                IsModified = false;
            }

            m_bInitialized = true;
#if VERBOSE_DEBUGGING
            Console.WriteLine("IcuRegexAutoConfigDialog ctor END");
#endif
        }
Exemple #28
0
        public static float ConvertToFloat(byte[] value, ConvType type)
        {
            switch (type)
            {
            case ConvType.IEEE_11073_16bit_float:
                return(Common.tofloat_from11073_16bit_float(value));

            case ConvType.IEEE_11073_32bit_float:
                return(Common.tofloat_from11073_32bit_float(value));
            }
            return(0.0f);
        }
        public override void Initialize(string converterName, string converterSpec,
                                        ref string lhsEncodingID, ref string rhsEncodingID, ref ConvType conversionType,
                                        ref Int32 processTypeFlags, Int32 codePageInput, Int32 codePageOutput, bool bAdding)
        {
            base.Initialize
            (
                converterName,
                converterSpec,
                ref m_strLhsEncodingID, // since we may have already set these in the ctor, use our stored value and check for differences later
                ref m_strRhsEncodingID, // ibid
                ref m_eConversionType,  // ibid
                ref m_lProcessType,     // ibid
                codePageInput,
                codePageOutput,
                bAdding
            );

            // normally, the sub-classes can specify the encoding ID, but if it's different
            //  go with what the user gives us (unless it's null)
            if (!String.IsNullOrEmpty(lhsEncodingID) &&
                (String.Compare(m_strLhsEncodingID, lhsEncodingID, true) != 0))
            {
                m_strLhsEncodingID = lhsEncodingID;
            }

            if (!String.IsNullOrEmpty(rhsEncodingID) &&
                (String.Compare(m_strRhsEncodingID, rhsEncodingID, true) != 0))
            {
                m_strRhsEncodingID = rhsEncodingID;
            }

            if (ConversionType != conversionType)
            {
                m_eConversionType = conversionType;
            }

            ProcessType |= processTypeFlags;

#if UseXmlFilesForPlugins
            WorkingDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + m_strWorkingDirSuffix;
#else
            RegistryKey key = Registry.LocalMachine.OpenSubKey(EncConverters.HKLM_CNVTRS_SUPPORTED);
            if (key != null)
            {
                key = key.OpenSubKey(m_strImplType);
                if (key != null)
                {
                    WorkingDir = (string)key.GetValue(strExePathKey);
                }
            }
#endif
        }
		public override void Initialize(string converterName, string converterSpec,
			ref string lhsEncodingID, ref string rhsEncodingID, ref ConvType conversionType,
			ref Int32 processTypeFlags, Int32 codePageInput, Int32 codePageOutput, bool bAdding)
		{
			base.Initialize(converterName, converterSpec, ref lhsEncodingID, ref rhsEncodingID, ref conversionType, ref processTypeFlags, codePageInput, codePageOutput, bAdding );

			// we know that our CP input and output are "1252" and "65001" respectively
			// (unless specified)
			if( codePageInput == 0 )
				this.CodePageInput = 1252;
			if( codePageOutput == 0 )
				this.CodePageOutput = 1252;
		}
        public override bool Configure(
            IEncConverters aECs,
            string strFriendlyName,
            ConvType eConversionType,
            string strLhsEncodingID,
            string strRhsEncodingID)
        {
            IcuConvAutoConfigDialog form = new IcuConvAutoConfigDialog(
                aECs, m_strDisplayName, m_strFriendlyName,
                m_strConverterID, m_eConversionType, m_strLhsEncodingID, m_strRhsEncodingID,
                m_lProcessType, m_bIsInRepository);

            return(base.Configure(form));
        }
Exemple #32
0
        public void TestLatin_GreekTranslit()
        {
            IcuTranslitEncConverter conv = new IcuTranslitEncConverter();
            string   lhsEncoding         = "UNICODE";
            string   rhsEncoding         = "UNICODE";
            ConvType convType            = ConvType.Unicode_to_from_Unicode;
            int      procFlags           = (int)ProcessTypeFlags.ICUTransliteration;

            conv.Initialize("Latin-Greek", "Latin-Greek",
                            ref lhsEncoding, ref rhsEncoding, ref convType, ref procFlags, 0, 0, false);
            string output = conv.Convert(m_latinInput);

            Assert.AreEqual(m_greekOutput, output, "Latin-Greek transliterator should work properly!");
        }
Exemple #33
0
		public SelectConverter(EncConverters aECs, ConvType eConversionTypeFilter,
			string strChooseConverterDialogTitle, string strPreviewData, string strFontName)
		{
			m_strPreviewData = strPreviewData;

			InitSelectConverter(aECs, eConversionTypeFilter, strChooseConverterDialogTitle, strFontName);

			if (String.IsNullOrEmpty(strPreviewData))
				buttonPreview.Visible = false;

			// hide the preview box until requested
			textBoxDataPreview.Hide();
			tableLayoutPanel1.RowCount = 4;
		}
        public override void DisplayTestPage(
            IEncConverters aECs,
            string strFriendlyName,
            string strConverterIdentifier,
            ConvType eConversionType,
            string strTestData)
        {
            InitializeFromThis(ref strFriendlyName, ref strConverterIdentifier,
                               ref eConversionType, ref strTestData);

            IcuConvAutoConfigDialog form = new IcuConvAutoConfigDialog(aECs, strFriendlyName,
                                                                       strConverterIdentifier, eConversionType, strTestData);

            base.DisplayTestPage(form);
        }
Exemple #35
0
		protected bool          m_bIsInRepository;      // indicates whether this converter is in the static repository (true) or not (false)
		#endregion Member Variable Definitions

		#region Public Interface
		/// <summary>
		/// The class constructor. </summary>
		public EncConverter(string sProgId, string sImplementType)
		{
			m_strProgramID = sProgId;
			m_strImplementType = sImplementType;
			m_lProcessType = (Int32)ProcessTypeFlags.DontKnow;
			m_eConversionType = ConvType.Legacy_to_from_Unicode;
			m_bForward = true;
			m_eEncodingInput = EncodingForm.Unspecified;
			m_eEncodingOutput = EncodingForm.Unspecified;
			m_eNormalizeOutput = NormalizeFlags.None;
			m_nCodePageInput = 0;
			m_nCodePageOutput = 0;
			m_bDebugDisplayMode = false;
			m_bIsInRepository = false;
		}
		public override bool Configure
		(
		IEncConverters aECs,
		string strFriendlyName,
		ConvType eConversionType,
		string strLhsEncodingID,
		string strRhsEncodingID
		)
		{
			CcAutoConfigDialog form = new CcAutoConfigDialog(aECs, m_strDisplayName, m_strFriendlyName,
				m_strConverterID, m_eConversionType, m_strLhsEncodingID, m_strRhsEncodingID,
				m_lProcessType, m_bIsInRepository);

			return base.Configure(form);
		}
Exemple #37
0
        protected bool m_bIsInRepository;                       // indicates whether this converter is in the static repository (true) or not (false)
        #endregion Member Variable Definitions

        #region Public Interface
        /// <summary>
        /// The class constructor. </summary>
        public EncConverter(string sProgId, string sImplementType)
        {
            m_strProgramID      = sProgId;
            m_strImplementType  = sImplementType;
            m_lProcessType      = (Int32)ProcessTypeFlags.DontKnow;
            m_eConversionType   = ConvType.Legacy_to_from_Unicode;
            m_bForward          = true;
            m_eEncodingInput    = EncodingForm.Unspecified;
            m_eEncodingOutput   = EncodingForm.Unspecified;
            m_eNormalizeOutput  = NormalizeFlags.None;
            m_nCodePageInput    = 0;
            m_nCodePageOutput   = 0;
            m_bDebugDisplayMode = false;
            m_bIsInRepository   = false;
        }
 public IcuRegexAutoConfigDialog(
     IEncConverters aECs,
     string strFriendlyName,
     string strConverterIdentifier,
     ConvType eConversionType,
     string strTestData)
 {
     InitializeComponent();
     base.Initialize(
         aECs,
         strFriendlyName,
         strConverterIdentifier,
         eConversionType,
         strTestData);
 }
        protected bool m_bInitialized = false;          // set at the end of Initialize (to block certain events until we're ready for them)

        public CcAutoConfigDialog
        (
            IEncConverters aECs,
            string strDisplayName,
            string strFriendlyName,
            string strConverterIdentifier,
            ConvType eConversionType,
            string strLhsEncodingId,
            string strRhsEncodingId,
            int lProcessTypeFlags,
            bool bIsInRepository
        )
        {
            InitializeComponent();

            base.Initialize
            (
                aECs,
                CcEncConverter.strHtmlFilename,
                strDisplayName,
                strFriendlyName,
                strConverterIdentifier,
                eConversionType,
                strLhsEncodingId,
                strRhsEncodingId,
                lProcessTypeFlags,
                bIsInRepository
            );

            // if we're editing a CC table/spellfixer project, then set the Converter Spec and say it's unmodified
            if (m_bEditMode)
            {
                System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(ConverterIdentifier));
                textBoxFileSpec.Text = ConverterIdentifier;
                IsModified           = false;
            }

            // if we're editing a SpellFixer project, then the converter is managed by the SpellFixer
            //  project dialog, so we don't need to have an "Save in Repository" button.
            UpdateUI(!IsSpellFixerProject);

            m_bInitialized = true;

            helpProvider.SetHelpString(textBoxFileSpec, Properties.Resources.ConverterFileSpecHelpString);
            helpProvider.SetHelpString(buttonBrowse, Properties.Resources.BrowseFileSpecHelpString);
            helpProvider.SetHelpString(groupBoxExpects, Properties.Resources.ConvTypeExpectsHelpString);
            helpProvider.SetHelpString(groupBoxReturns, Properties.Resources.ConvTypeReturnsHelpString);
        }
Exemple #40
0
		public override void Initialize(string converterName, string converterSpec,
			ref string lhsEncodingID, ref string rhsEncodingID, ref ConvType conversionType,
			ref Int32 processTypeFlags, Int32 codePageInput, Int32 codePageOutput, bool bAdding)
		{
			base.Initialize
				(
				converterName,
				converterSpec,
				ref m_strLhsEncodingID, // since we may have already set these in the ctor, use our stored value and check for differences later
				ref m_strRhsEncodingID, // ibid
				ref m_eConversionType,  // ibid
				ref m_lProcessType,     // ibid
				codePageInput,
				codePageOutput,
				bAdding
				);

			// normally, the sub-classes can specify the encoding ID, but if it's different
			//  go with what the user gives us (unless it's null)
			if(     !String.IsNullOrEmpty(lhsEncodingID)
				&&  (String.Compare(m_strLhsEncodingID,lhsEncodingID,true) != 0) )
			{
				m_strLhsEncodingID = lhsEncodingID;
			}

			if(     !String.IsNullOrEmpty(rhsEncodingID)
				&&  (String.Compare(m_strRhsEncodingID,rhsEncodingID,true) != 0) )
			{
				m_strRhsEncodingID = rhsEncodingID;
			}

			if( ConversionType != conversionType )
				m_eConversionType = conversionType;

			ProcessType |= processTypeFlags;

#if UseXmlFilesForPlugins
			WorkingDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + m_strWorkingDirSuffix;
#else
			RegistryKey key = Registry.LocalMachine.OpenSubKey(EncConverters.HKLM_CNVTRS_SUPPORTED);
			if( key != null )
			{
				key = key.OpenSubKey(m_strImplType);
				if( key != null )
					WorkingDir = (string)key.GetValue(strExePathKey);
			}
#endif
		}
		protected bool m_bInitialized = false;  // set at the end of Initialize (to block certain events until we're ready for them)

		public CcAutoConfigDialog
			(
			IEncConverters aECs,
			string strDisplayName,
			string strFriendlyName,
			string strConverterIdentifier,
			ConvType eConversionType,
			string strLhsEncodingId,
			string strRhsEncodingId,
			int lProcessTypeFlags,
			bool bIsInRepository
			)
		{
			InitializeComponent();

			base.Initialize
			(
			aECs,
			CcEncConverter.strHtmlFilename,
			strDisplayName,
			strFriendlyName,
			strConverterIdentifier,
			eConversionType,
			strLhsEncodingId,
			strRhsEncodingId,
			lProcessTypeFlags,
			bIsInRepository
			);

			// if we're editing a CC table/spellfixer project, then set the Converter Spec and say it's unmodified
			if (m_bEditMode)
			{
				System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(ConverterIdentifier));
				textBoxFileSpec.Text = ConverterIdentifier;
				IsModified = false;
			}

			// if we're editing a SpellFixer project, then the converter is managed by the SpellFixer
			//  project dialog, so we don't need to have an "Save in Repository" button.
			UpdateUI(!IsSpellFixerProject);

			m_bInitialized = true;

			helpProvider.SetHelpString(textBoxFileSpec, Properties.Resources.ConverterFileSpecHelpString);
			helpProvider.SetHelpString(buttonBrowse, Properties.Resources.BrowseFileSpecHelpString);
			helpProvider.SetHelpString(groupBoxExpects, Properties.Resources.ConvTypeExpectsHelpString);
			helpProvider.SetHelpString(groupBoxReturns, Properties.Resources.ConvTypeReturnsHelpString);
		}
		public override void DisplayTestPage
			(
			IEncConverters aECs,
			string strFriendlyName,
			string strConverterIdentifier,
			ConvType eConversionType,
			string strTestData
			)
		{
			InitializeFromThis(ref strFriendlyName, ref strConverterIdentifier,
				ref eConversionType, ref strTestData);

			CcAutoConfigDialog form = new CcAutoConfigDialog(aECs, strFriendlyName,
				strConverterIdentifier, eConversionType, strTestData);

			base.DisplayTestPage(form);
		}
		protected string        m_strImplementType;     // needed for "EncConverters::AddConverterMap"; provided by sub-classes
		#endregion Member Variable Definitions

		#region Public Interface
		public EncConverterConfig
			(
			string strProgramID,
			string strDisplayName,
			string strHtmlFilename,
			ProcessTypeFlags eDefiningProcessType
			)
		{
			m_strProgramID = strProgramID;
			m_strDisplayName = strDisplayName;
			m_strHtmlFilename = strHtmlFilename;
			m_eDefiningProcessType = eDefiningProcessType;

			m_lProcessType = (Int32)ProcessTypeFlags.DontKnow;
			m_eConversionType = ConvType.Unknown;
			m_bIsInRepository = false;
		}
		public AdaptItGuesserAutoConfigDialog
			(
			IEncConverters aECs,
			string strFriendlyName,
			string strConverterIdentifier,
			ConvType eConversionType,
			string strTestData
			)
		{
			base.Initialize
			(
			aECs,
			strFriendlyName,
			strConverterIdentifier,
			eConversionType,
			strTestData
			);
		}
Exemple #45
0
		public ExeEncConverter
			(
			string  strProgramID,           // e.g. SilEncConverters31.ITrans (usually "typeof(<classname>).FullName")
			string  strImplType,            // e.g. "ITrans" (cf. SIL.tec)
			ConvType conversionType,        // e.g. ConvType.Legacy_to_Unicode
			string  lhsEncodingID,          // e.g. "ITrans" (c.f. "SIL-IPA93-2001")
			string  rhsEncodingID,          // e.g. "UNICODE"
			Int32   lProcessType,           // e.g. ProcessTypeFlags.UnicodeEncodingConversion
			string  strWorkingDirSuffix     // e.g. @"\SIL\Indic\ITrans"
			)
			: base(strProgramID,strImplType)
		{
			m_strImplType = strImplType;
			m_eConversionType = conversionType;
			m_strLhsEncodingID = lhsEncodingID;
			RightEncodingID = rhsEncodingID;
			ProcessType = lProcessType;
			m_strWorkingDirSuffix = strWorkingDirSuffix;
		}
		public TecAutoConfigDialog
			(
			IEncConverters aECs,
			string strFriendlyName,
			string strConverterIdentifier,
			ConvType eConversionType,
			string strTestData
			)
		{
			InitializeComponent();

			base.Initialize
			(
			aECs,
			strFriendlyName,
			strConverterIdentifier,
			eConversionType,
			strTestData
			);
		}
		public TecAutoConfigDialog
			(
			IEncConverters aECs,
			string strDisplayName,
			string strFriendlyName,
			string strConverterIdentifier,
			ConvType eConversionType,
			string strLhsEncodingId,
			string strRhsEncodingId,
			int lProcessTypeFlags,
			bool bIsInRepository
			)
		{
			InitializeComponent();

			base.Initialize
			(
			aECs,
			TecEncConverter.strHtmlFilename,
			strDisplayName,
			strFriendlyName,
			strConverterIdentifier,
			eConversionType,
			strLhsEncodingId,
			strRhsEncodingId,
			lProcessTypeFlags,
			bIsInRepository
			);

			// if we're editing a TECkit map, then set the Converter Spec and say it's unmodified
			if (m_bEditMode)
			{
				System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(ConverterIdentifier));
				textBoxFileSpec.Text = ConverterIdentifier;
				IsModified = false;
			}

			m_bInitialized = true;

			helpProvider.SetHelpString(textBoxFileSpec, Properties.Resources.ConverterFileSpecHelpString);
		}
Exemple #48
0
		public override void Initialize(string converterName, string converterSpec,
			ref string lhsEncodingID, ref string rhsEncodingID, ref ConvType conversionType,
			ref Int32 processTypeFlags, Int32 codePageInput, Int32 codePageOutput, bool bAdding)
		{
			base.Initialize(converterName, converterSpec, ref lhsEncodingID, ref rhsEncodingID, ref conversionType, ref processTypeFlags, codePageInput, codePageOutput, bAdding );
			m_nCodePage = System.Convert.ToInt32(ConverterIdentifier);

			// the UTF8 code page is a special case: ConvType must be Uni <> Uni
			if( m_nCodePage == CP_UTF8 )
			{
				if( String.IsNullOrEmpty(LeftEncodingID) )
					lhsEncodingID = m_strLhsEncodingID = "utf-8";
				if( String.IsNullOrEmpty(RightEncodingID) )
					rhsEncodingID = m_strRhsEncodingID = EncConverters.strDefUnicodeEncoding;

				// This only works if we consider UTF8 to be unicode; not legacy
				conversionType = m_eConversionType = ConvType.Unicode_to_from_Unicode;
			}

			// the rest are all "UnicodeEncodingConversion"s (by definition). Also, use the word
			// "UNICODE" concatenated to the legacy encoding name
			else
			{
				processTypeFlags = m_lProcessType |= (int)ProcessTypeFlags.UnicodeEncodingConversion;
				if( String.IsNullOrEmpty(RightEncodingID) )
				{
					rhsEncodingID = m_strRhsEncodingID = EncConverters.strDefUnicodeEncoding;
					if( !String.IsNullOrEmpty(lhsEncodingID) )
						rhsEncodingID += " " + lhsEncodingID;
				}
			}

			// if it wasn't set above, then it's Legacy <> Unicode
			if( conversionType == ConvType.Unknown )
				conversionType = m_eConversionType = ConvType.Legacy_to_from_Unicode;

			// finally, it is also a "Code Page" conversion process type
			processTypeFlags = m_lProcessType |= (int)ProcessTypeFlags.CodePageConversion;
		}
Exemple #49
0
		public override void Initialize(string converterName, string converterSpec,
			ref string lhsEncodingID, ref string rhsEncodingID, ref ConvType conversionType,
			ref Int32 processTypeFlags, Int32 codePageInput, Int32 codePageOutput, bool bAdding)
		{
			base.Initialize(converterName, converterSpec, ref lhsEncodingID, ref rhsEncodingID, ref conversionType, ref processTypeFlags, codePageInput, codePageOutput, bAdding );

			m_bLegacy = (EncConverter.NormalizeLhsConversionType(conversionType) == NormConversionType.eLegacy);

			// get the filespec to the project file and the knowledge base
			//  (the KB path *is* the converter spec)
			m_strKnowledgeBaseFileSpec = converterSpec;
			string strProjectFolder = Path.GetDirectoryName(converterSpec);
			m_strProjectFileSpec = String.Format(@"{0}\{1}", strProjectFolder, cstrAdaptItProjectFilename);

			if( bAdding )
			{
				// if we're supposedly adding this one, then clobber our copy of its last modified
				// (there was a problem with us instantiating lots of these things in a row and
				//  not detecting the change because the modified date was within a second of each
				//  other)
				m_timeModifiedKB = m_timeModifiedProj = DateTime.MinValue;
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Automatically configures.
		/// </summary>
		/// <param name="rIEncConverter">The encoding converter.</param>
		/// <param name="eConversionTypeFilter">The conversion type filter.</param>
		/// <param name="strFriendlyName">Friendly name of the string.</param>
		/// <param name="strLhsEncodingID">.</param>
		/// <param name="strRhsEncodingID">.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		private bool AutoConfigureEx
			(
			IEncConverter rIEncConverter,
			ConvType eConversionTypeFilter,
			ref string strFriendlyName,
			string strLhsEncodingID,
			string strRhsEncodingID
			)
		{

			const string strTempConverterPrefix = "Temporary converter: ";
			try
			{
				// get the configuration interface for this type
				IEncConverterConfig rConfigurator = rIEncConverter.Configurator;

				// call its Configure method to do the UI
				if (rConfigurator.Configure(m_encConverters, strFriendlyName, eConversionTypeFilter, strLhsEncodingID, strRhsEncodingID))
				{
					// if this is just a temporary converter (i.e. it isn't being added permanentally to the
					//  repository), then just make up a name so the caller can use it.
					if (!rConfigurator.IsInRepository)
					{
						DateTime dt = DateTime.Now;
						strFriendlyName = String.Format(strTempConverterPrefix + "id: '{0}', created on '{1}' at '{2}'", rConfigurator.ConverterIdentifier, dt.ToLongDateString(), dt.ToLongTimeString());

						// in this case, the Configurator didn't update the name
						rIEncConverter.Name = strFriendlyName;

						// one final thing missing: for this 'client', we have to put it into the 'this' collection
						AddToCollection(rIEncConverter, strFriendlyName);
					}
					else
					{
						// else, if it was in the repository, then it should also be (have been) updated in
						//  the collection already, so just get its name so we can return it.
						strFriendlyName = rConfigurator.ConverterFriendlyName;
					}

					return true;
				}
				else if (rConfigurator.IsInRepository && !String.IsNullOrEmpty(rConfigurator.ConverterFriendlyName))
				{
					// if the user added it to the repository and then *cancelled* it (i.e. so Configure
					//  returns false), then it *still* is in the repository and we should therefore return
					//  true.
					strFriendlyName = rConfigurator.ConverterFriendlyName;
					return true;
				}
			}
			catch
			{
#if DEBUG
				throw;
#endif
			}

			return false;
		}
Exemple #51
0
		protected void ResetFields()
		{
			ConversionType = m_eOrigConvType;
			ConverterIdentifier = null;
			ProcessType = 0;
			m_aEC = null;
		}
		/// <summary></summary>
		public CnvtrDataComboItem(string name, ConvType type)
		{
			m_itemName = name;
			m_type = type;
		}
        private IInstruction ComputeExtensionTypeAndMask(ConvType destinationType, ref uint mask)
        {
            switch (destinationType) {
                case ConvType.I1:
                    mask = 0xff;
                    return IR.Instruction.SignExtendedMoveInstruction;
                case ConvType.I2:
                    mask = 0xffff;
                    return IR.Instruction.SignExtendedMoveInstruction;
                case ConvType.I4:
                    mask = 0xffffffffu;
                    break;
                case ConvType.I8:
                    break;
                case ConvType.U1:
                    mask = 0xff;
                    return IR.Instruction.ZeroExtendedMoveInstruction;
                case ConvType.U2:
                    mask = 0xffff;
                    return IR.Instruction.ZeroExtendedMoveInstruction;
                case ConvType.U4:
                    mask = 0xffffffffu;
                    break;
                case ConvType.U8:
                    break;
                case ConvType.R4:
                    break;
                case ConvType.R8:
                    break;
                case ConvType.I:
                    break;
                case ConvType.U:
                    break;
                case ConvType.Ptr:
                    break;
                default:
                    Debug.Assert (false);
                    throw new NotSupportedException ();
            }

            return null;
        }
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets the type of the converter in the combobox for the currently selected encoding
		/// converter.
		/// </summary>
		/// <param name="setConvType">Type of the selected converter.</param>
		/// ------------------------------------------------------------------------------------
		private void SetConverterType(ConvType setConvType)
		{
			for (int i = 0; i < cboConversion.Items.Count; i++)
			{
				if (((CnvtrDataComboItem)cboConversion.Items[i]).Type == setConvType)
				{
					cboConversion.SelectedIndex = i;
					break;
				}
			}
		}
		internal bool OpenDocument(string strMapName)
		{
			if (Program.Modified)
				CheckForSaveDirtyFile();

			InitCharacterMapDialogs();

			bool bModified = false;

			// if we are dealing with a real file...
			m_strMapNameReal = strMapName;

			// check to see if it exists (the alternate exception isn't very helpful)
			if (!File.Exists(m_strMapNameReal))
			{
				MessageBox.Show(String.Format("The file '{0}' doesn't exist!", m_strMapNameReal, cstrCaption));
				return false;
			}

			// otherwise, determine the .tec filename
			m_strTecNameReal = m_strMapNameReal.Remove(m_strMapNameReal.Length - 3, 3) + "tec";
			Program.AddFilenameToTitle(m_strMapNameReal);

			// and put it's contents into the editor.
			this.richTextBoxMapEditor.Lines = File.ReadAllLines(m_strMapNameReal, m_enc);

			// see if our 'clues' are in the file
			ConvType eConvType = ConvType.Unknown;
			bool bLhsFontFound = false;
			bool bRhsFontFound = false;
			bool bCodePointFormSizeHasBeenSetLhs = false;
			bool bCodePointFormSizeHasBeenSetRhs = false;
			m_nCodePageLegacyLhs = 0;
			m_nCodePageLegacyRhs = 0;

			foreach (string strLine in richTextBoxMapEditor.Lines)
			{
				int nIndex = strLine.IndexOf(cstrConvTypeClue);
				if (nIndex != -1)
				{
					string strConvType = strLine.Substring(nIndex + cstrConvTypeClue.Length);

					foreach (string asName in Enum.GetNames(typeof(ConvType)))
					{
						if (asName == strConvType)
						{
							eConvType = (ConvType)Enum.Parse(typeof(ConvType), strConvType);
							break;
						}
					}
				}

				nIndex = strLine.IndexOf(cstrLhsFontClue);
				if (nIndex != -1)
				{
					int nDelimiter = strLine.LastIndexOf(';');
					int nLen = nDelimiter - (nIndex + cstrLhsFontClue.Length);
					string strFontName = strLine.Substring(nIndex + cstrLhsFontClue.Length, nLen);
					string strFontSize = strLine.Substring(nDelimiter + 1);
					float emSize = Convert.ToSingle(strFontSize);
					Font font = Program.GetSafeFont(strFontName, emSize);
					textBoxSample.Font = font;
					textBoxSampleReverse.Font = font;
					bLhsFontFound = true;
				}

				nIndex = strLine.IndexOf(cstrRhsFontClue);
				if (nIndex != -1)
				{
					int nDelimiter = strLine.LastIndexOf(';');
					int nLen = nDelimiter - (nIndex + cstrRhsFontClue.Length);
					string strFontName = strLine.Substring(nIndex + cstrRhsFontClue.Length, nLen);
					string strFontSize = strLine.Substring(nDelimiter + 1);
					float emSize = Convert.ToSingle(strFontSize);
					Font font = Program.GetSafeFont(strFontName, emSize);
					textBoxSampleForward.Font = font;
					bRhsFontFound = true;
				}

				nIndex = strLine.IndexOf(cstrLhsCodePageClue);
				if (nIndex != -1)
				{
					string strCodePage = strLine.Substring(nIndex + cstrLhsCodePageClue.Length);
					try
					{
						m_nCodePageLegacyLhs = Convert.ToInt32(strCodePage);
					}
					catch { }
				}

				nIndex = strLine.IndexOf(cstrRhsCodePageClue);
				if (nIndex != -1)
				{
					string strCodePage = strLine.Substring(nIndex + cstrRhsCodePageClue.Length);
					try
					{
						m_nCodePageLegacyRhs = Convert.ToInt32(strCodePage);
					}
					catch { }
				}

				nIndex = strLine.IndexOf(cstrMainFormClue);
				if (nIndex != -1)
				{
					try
					{
						string strXYWH = strLine.Substring(nIndex + cstrMainFormClue.Length);
						string[] aStrBounds = strXYWH.Split(new char[] { ',' });
						Rectangle rectBounds = new Rectangle
						(
							Int32.Parse(aStrBounds[0]),
							Int32.Parse(aStrBounds[1]),
							Int32.Parse(aStrBounds[2]),
							Int32.Parse(aStrBounds[3])
						);

						if (SetBounds(this, ref rectBounds))
							SetBoundsClue(cstrMainFormClue, rectBounds);
					}
					catch { }
				}

				// search for the character map window location (what used to be the 'code point' window)
				string strClue = cstrCodePointFormClueLhs;
				nIndex = strLine.IndexOf(cstrCodePointFormClueLhs);
				if (nIndex != -1)
				{
					try
					{
						string strXYWH = strLine.Substring(nIndex + strClue.Length);
						string[] aStrBounds = strXYWH.Split(new char[] { ',' });
						Rectangle rectBounds = new Rectangle
						(
							Int32.Parse(aStrBounds[0]),
							Int32.Parse(aStrBounds[1]),
							Int32.Parse(aStrBounds[2]),
							Int32.Parse(aStrBounds[3])
						);

						if (SetBounds(m_formDisplayUnicodeNamesLhs, ref rectBounds))
							SetBoundsClue(strClue, rectBounds);
						bCodePointFormSizeHasBeenSetLhs = true;
					}
					catch { }
				}

				nIndex = strLine.IndexOf(cstrCodePointFormClueRhs);
				if (nIndex != -1)
				{
					try
					{
						string strXYWH = strLine.Substring(nIndex + cstrCodePointFormClueRhs.Length);
						string[] aStrBounds = strXYWH.Split(new char[] { ',' });
						Rectangle rectBounds = new Rectangle
						(
							Int32.Parse(aStrBounds[0]),
							Int32.Parse(aStrBounds[1]),
							Int32.Parse(aStrBounds[2]),
							Int32.Parse(aStrBounds[3])
						);

						if (SetBounds(m_formDisplayUnicodeNamesRhs, ref rectBounds))
							SetBoundsClue(cstrCodePointFormClueRhs, rectBounds);
						bCodePointFormSizeHasBeenSetRhs = true;
					}
					catch { }
				}
			}

			// if we didn't find the ConvType, then query for it
			bool bUserCancelled = false;
			if (eConvType == ConvType.Unknown)
				bUserCancelled = !QueryConvType();
			else
				ConversionType = eConvType;

			InitTempVars();

			if (!bUserCancelled && !bLhsFontFound)
			{
				// for legacy encodings, prompt for the font.
				MessageBox.Show("Select the font for the left-hand side encoding", cstrCaption);
				bUserCancelled |= !SetFontLhs();
			}
			else if (unicodeValuesWindowToolStripMenuItem.Checked)
			{
				if (IsLhsLegacy && (m_nCodePageLegacyLhs == 0))
				{
					EncConverters aECs = new EncConverters(true);
					try
					{
						m_nCodePageLegacyLhs = aECs.CodePage(textBoxSample.Font.Name);
					}
					catch { }
				}

				m_formDisplayUnicodeNamesLhs.Initialize(IsLhsLegacy, textBoxSample.Font, m_nCodePageLegacyLhs);
			}

			if (!bUserCancelled && !bRhsFontFound)
			{
				// for legacy encodings, prompt for the font.
				MessageBox.Show("Select the font for the right-hand side encoding", cstrCaption);
				SetFontRhs();
			}
			else if (unicodeValuesWindowToolStripMenuItem.Checked)
			{
				if (IsRhsLegacy && (m_nCodePageLegacyRhs == 0))
				{
					EncConverters aECs = new EncConverters(true);
					try
					{
						m_nCodePageLegacyRhs = aECs.CodePage(textBoxSampleForward.Font.Name);
					}
					catch { }
				}

				m_formDisplayUnicodeNamesRhs.Initialize(IsRhsLegacy, textBoxSampleForward.Font, m_nCodePageLegacyRhs);
			}

			if (!bCodePointFormSizeHasBeenSetLhs)
			{
				Point ptLocation = new Point(Location.X + Bounds.Size.Width, Location.Y);
				m_formDisplayUnicodeNamesLhs.Location = ptLocation;
			}

			if (!bCodePointFormSizeHasBeenSetRhs)
			{
				Point ptLocation = new Point(m_formDisplayUnicodeNamesLhs.Location.X, m_formDisplayUnicodeNamesLhs.Location.Y + m_formDisplayUnicodeNamesLhs.Bounds.Size.Height);
				m_formDisplayUnicodeNamesRhs.Location = ptLocation;
			}

			if (!bLhsFontFound || !bRhsFontFound || !bCodePointFormSizeHasBeenSetLhs || !bCodePointFormSizeHasBeenSetRhs)
			{
				// initialize it with our clues
				string strPrefixHeader = cstrOpeningHeader + String.Format("v{1} on {2}.{0};   {3}{4}{0};   {5}{6};{7}{0};   {8}{9};{10}{0}{11}{0}{12}{0}{13}{0}",
					Environment.NewLine,
					Application.ProductVersion,
					DateTime.Now.ToShortDateString(),
					cstrConvTypeClue,
					m_eConvType.ToString(),
					cstrLhsFontClue,
					textBoxSample.Font.Name,
					textBoxSample.Font.Size,
					cstrRhsFontClue,
					textBoxSampleForward.Font.Name,
					textBoxSampleForward.Font.Size,
					BoundsClueString(cstrMainFormClue, Bounds),
					BoundsClueString(cstrCodePointFormClueLhs, m_formDisplayUnicodeNamesLhs.Bounds),
					BoundsClueString(cstrCodePointFormClueRhs, m_formDisplayUnicodeNamesRhs.Bounds));

				strPrefixHeader += AddCodePageClue(cstrLhsCodePageClue, m_nCodePageLegacyLhs);
				strPrefixHeader += AddCodePageClue(cstrRhsCodePageClue, m_nCodePageLegacyRhs);
				strPrefixHeader += String.Format("{0}", Environment.NewLine);

				this.richTextBoxMapEditor.Text = strPrefixHeader + SkipPast0900Header;
				bModified = true;
			}

			// so it re-creates for this "new" map
			m_aEC = null;
			Program.Modified = bModified;

			return true;
		}
Exemple #56
0
		public virtual void Initialize
			(
			IEncConverters aECs,
			string strFriendlyName,
			string strConverterIdentifier,
			ConvType eConversionType,
			string strTestData
			)
		{
			FriendlyName = strFriendlyName;
			ConverterIdentifier = strConverterIdentifier;
			ConversionType = eConversionType;

			m_aECs = aECs;
			m_aEC = InitializeEncConverter;

			tabControl.Controls.Remove(tabPageAbout);
			tabControl.Controls.Remove(tabPageSetup);
			tabControl.Controls.Remove(tabPageAdvanced);

			// for 'test', it's possible that there may be some font mapping in the repository
			string strLhsName, strRhsName;
			if (m_aECs.GetFontMappingFromMapping(strFriendlyName, out strLhsName, out strRhsName))
			{
				ecTextBoxInput.Font = CreateFontSafe(strLhsName, ecTextBoxInput.Font);
				ecTextBoxOutput.Font = CreateFontSafe(strRhsName, ecTextBoxOutput.Font);
			}

			ecTextBoxInput.Text = strTestData;
			buttonOK.Visible = buttonApply.Visible = false;
			buttonCancel.Text = "Close";

			helpProvider.SetHelpString(buttonCancel, Properties.Resources.CloseButtonHelpString);

		}
Exemple #57
0
		protected void SetConvTypeFromRbControls
			(
			RadioButton rbExpectsUnicode,
			RadioButton rbExpectsLegacy,
			RadioButton rbReturnsUnicode,
			RadioButton rbReturnsLegacy
			)
		{
			if (rbExpectsUnicode.Checked)
			{
				if (rbReturnsUnicode.Checked)
				{
					ConversionType = ConvType.Unicode_to_Unicode;
				}
				else
				{
					ConversionType = ConvType.Unicode_to_Legacy;
				}
			}
			else
			{
				if (rbReturnsUnicode.Checked)
				{
					ConversionType = ConvType.Legacy_to_Unicode;
				}
				else
				{
					ConversionType = ConvType.Legacy_to_Legacy;
				}
			}
		}
Exemple #58
0
		public virtual void Initialize
			(
			IEncConverters aECs,
			string strHtmlFileName,
			string strDisplayName,
			string strFriendlyName,
			string strConverterIdentifier,
			ConvType eConversionType,
			string strLhsEncodingId,
			string strRhsEncodingId,
			int lProcessTypeFlags,
			bool bIsInRepository
			)
		{
			m_strOriginalFriendlyName = FriendlyName = strFriendlyName;
			ConverterIdentifier = strConverterIdentifier;
			LhsEncodingId = strLhsEncodingId;
			RhsEncodingId = strRhsEncodingId;
			m_eOrigConvType = ConversionType = eConversionType;
			ProcessType = lProcessTypeFlags;
			IsInRepository = bIsInRepository;

			m_aECs = aECs;

			// if the identifier is given, then it means we're editing.
			// (which means our button says *Update* rather than "Save in system repository"
			//  and we should ask during OnOK whether they want to update or not)
			m_bEditMode = !String.IsNullOrEmpty(ConverterIdentifier);

			// if we're editing, then it starts out clean
			IsModified = !m_bEditMode;

			// if we're editing, then we already have this converter in the collection (even if it's
			//  temporary)
			if (m_bEditMode)
			{
				m_aEC = m_aECs[FriendlyName];
				if (FriendlyName.IndexOf(EncConverters.cstrTempConverterPrefix) == 0)
					FriendlyName = m_strOriginalFriendlyName = null;
			}

			// this parameter seems the most confusing and yet is a crucial part of EncConverters
			//  so if this is *given* to us, then just use those values rather than prompting the user
			//  for them (e.g. FW knows that the BulkEdits are Unicode_to_(from_)Unicode, so we don't
			//  have to bother the user with it.
			// If we're in 'edit' mode, it is often because the user has mis-configured these parameters
			//  so if edit mode, then query for the ConvType value.
			if ((ConversionType == ConvType.Unknown) || m_bEditMode)
			{
				m_bQueryForConvType = true;
				SetConvTypeControls();
			}

			this.Text = strDisplayName;

			// get the help for the about tab
			RegistryKey keyRoot = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\SIL\SilEncConverters31", false);
			if (keyRoot != null)
			{
				string strXmlFilePath = (string)keyRoot.GetValue("RootDir");
				if (strXmlFilePath[strXmlFilePath.Length - 1] != '\\')
					strXmlFilePath += '\\';
				strXmlFilePath += @"help\" + strHtmlFileName;
				System.Diagnostics.Debug.Assert(System.IO.File.Exists(strXmlFilePath), String.Format("Can find '{0}'. If this is a development machine, you need to add the following reg key to see the About help files: HLKM\\SOFTWARE\\SIL\\SilEncConverters31\\[RootDir] = '<parent folder where the 'help' sub-folder exists>' along with a trailing slash (e.g. \"C:\\fw\\lib\\release\\\")", strHtmlFileName));
				this.webBrowserHelp.Url = new Uri(strXmlFilePath);
			}
#if DEBUG
			else
				throw new ApplicationException(@"Can't read the HLKM\SOFTWARE\SIL\SilEncConverters31\[RootDir] registry key!");
#endif

			ecTextBoxInput.Text = "Test Data";
		}
		public FallbackAutoConfigDialog
			(
			IEncConverters aECs,
			string strDisplayName,
			string strFriendlyName,
			string strConverterIdentifier,
			ConvType eConversionType,
			string strLhsEncodingId,
			string strRhsEncodingId,
			int lProcessTypeFlags,
			bool bIsInRepository
			)
		{
			if (aECs.Count == 0)
			{
				MessageBox.Show("Unable to find any existing converters! You must add some before attempting to chain them together.");
				return;
			}

			InitializeComponent();

			base.Initialize
			(
			aECs,
			FallbackEncConverter.strHtmlFilename,
			strDisplayName,
			strFriendlyName,
			strConverterIdentifier,
			eConversionType,
			strLhsEncodingId,
			strRhsEncodingId,
			lProcessTypeFlags,
			bIsInRepository
			);

			// if we're editing ...
			if (m_bEditMode)
			{
				System.Diagnostics.Debug.Assert(m_aEC != null);
				System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(ConverterIdentifier));

				labelCompoundConverterName.Text = FriendlyName;

				if (m_aEC != null)
				{
					QueryStepData();    // get the data about the steps

					if (    ((m_astrStepFriendlyNames != null) && (m_astrStepFriendlyNames.Length == 2))
						&&  ((m_abDirectionForwards != null) && (m_abDirectionForwards.Length == 2)))
					{
						m_strPrimaryConverter = m_astrStepFriendlyNames[(int)PrimaryFallbackEnum.ePrimary];
						m_strFallbackConverter = m_astrStepFriendlyNames[(int)PrimaryFallbackEnum.eFallback];
						checkBoxReversePrimary.Checked = !m_abDirectionForwards[(int)PrimaryFallbackEnum.ePrimary];
						checkBoxReverseFallback.Checked = !m_abDirectionForwards[(int)PrimaryFallbackEnum.eFallback];
					}
				}

				IsModified = false;
			}

			// in any case, populate the combo boxes with the full list of available converters
			foreach (IEncConverter aEC in aECs.Values)
			{
				// don't let the primary-fallback converter be put into the lists
				if (strFriendlyName != aEC.Name)
				{
					comboBoxPrimary.Items.Add(aEC.Name);
					comboBoxFallback.Items.Add(aEC.Name);

					// if this is either the primary or the fallback, then also get the bidi status
					if (m_strPrimaryConverter == aEC.Name)
					{
						comboBoxPrimary.SelectedItem = m_strPrimaryConverter;   // select it in the combo box

						if (EncConverters.IsUnidirectional(aEC.ConversionType))
							checkBoxReversePrimary.Enabled = false;
					}
					else if (m_strFallbackConverter == aEC.Name)
					{
						comboBoxFallback.SelectedItem = m_strFallbackConverter; // select it in the combo box

						if (EncConverters.IsUnidirectional(aEC.ConversionType))
							checkBoxReverseFallback.Enabled = false;
					}
				}
			}

			// in case we set teh selected item in that last code, we don't want to treat that as the steady state situation
			//  (i.e. ignore the resultant SelectedItemChange event until after we're finished.
			m_bIgnoreSelItemChgWhileLoading = false;
		}
Exemple #60
0
		/// --------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:EncoderInfo"/> class.
		/// </summary>
		/// <param name="name">The name of the encoding converter.</param>
		/// <param name="method">The method, e.g. CC table, TecKit, etc.</param>
		/// <param name="fileName">Name of the file containing the conversion table, etc.</param>
		/// <param name="fromToType">Type of conversion, e.g. from legacy to Unicode.</param>
		/// --------------------------------------------------------------------------------
		public EncoderInfo(string name, ConverterType method, string fileName, ConvType fromToType)
		{
			m_name = name;
			m_method = method;
			m_fileName = fileName;
			m_fromToType = fromToType;
		}