private bool SetFontLhs() { #if false // DEBUG fontDialog.Font = new Font("Annapurna", 12); #else fontDialog.Font = textBoxSample.Font; if (fontDialog.ShowDialog() != DialogResult.Cancel) { #endif textBoxSample.Font = fontDialog.Font; textBoxSampleReverse.Font = fontDialog.Font; SetFontClue(cstrLhsFontClue, fontDialog.Font); if (unicodeValuesWindowToolStripMenuItem.Checked) { if (IsLhsLegacy) { EncConverters aECs = new EncConverters(true); try { m_nCodePageLegacyLhs = aECs.CodePage(fontDialog.Font.Name); } catch { } } m_formDisplayUnicodeNamesLhs.Initialize(IsLhsLegacy, textBoxSample.Font, m_nCodePageLegacyLhs); } return true; #if true // !DEBUG } else return false; #endif }
private void SetFontRhs() { #if false // DEBUG fontDialog.Font = new Font("Arial Unicode MS", 12); #else fontDialog.Font = textBoxSampleForward.Font; if (fontDialog.ShowDialog() != DialogResult.Cancel) #endif { textBoxSampleForward.Font = fontDialog.Font; SetFontClue(cstrRhsFontClue, fontDialog.Font); // only do this if the lhs is *not* legacy and the rhs is if (unicodeValuesWindowToolStripMenuItem.Checked) { if (IsRhsLegacy) { EncConverters aECs = new EncConverters(true); try { m_nCodePageLegacyRhs = aECs.CodePage(fontDialog.Font.Name); } catch { } } m_formDisplayUnicodeNamesRhs.Initialize(IsRhsLegacy, textBoxSampleForward.Font, m_nCodePageLegacyRhs); } } }
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; }
internal bool LoadProject(string strProjectName) { // get the EncConverter that should have been added above by 'AddNewProject' button EncConverters aECs = new EncConverters(); IEncConverter aEC = aECs[FullName(strProjectName)]; if( aEC != null ) { m_strEncConverterName = aEC.Name; m_strConverterSpec = aEC.ConverterIdentifier; ECAttributes aECAttrs = aECs.Attributes(aEC.Name,AttributeType.Converter); string strFontName = aECAttrs[SpellingFixerEC.cstrAttributeFontToUse]; string sFontSize = aECAttrs[SpellingFixerEC.cstrAttributeFontSizeToUse]; m_strWordBoundaryDelimiter = aECAttrs[SpellingFixerEC.cstrAttributeWordBoundaryDelimiter]; m_strNonWordCharacters = aECAttrs[SpellingFixerEC.cstrAttributeNonWordChars]; // new in 1.2 (so it might not exist) if( m_strNonWordCharacters == null ) m_strNonWordCharacters = SpellingFixerEC.GetDefaultPunctuation; // if this was added (without having been made on this system), then // these properties doesn't get added automatically. Must go to edit mode! if((strFontName == null) || (sFontSize == null) || (m_strWordBoundaryDelimiter == null) ) { MessageBox.Show("It looks like this project was added to the repository incorrectly because it's missing some important properties. You'll need to edit it again to set the font, and other values."); DoEdit(aECs, aEC, strProjectName, strFontName, sFontSize); // make the "Update" button the default button this.AcceptButton = this.buttonAddNewProject; return false; } float fFontSize = (float)0.0; try { fFontSize = (float)Convert.ToSingle(sFontSize); } catch {} if( (strFontName != "") && (fFontSize != 0.0) ) m_font = new Font(strFontName,fFontSize); m_bLegacy = (aEC.ConversionType == ConvType.Legacy_to_Legacy); if( m_bLegacy ) m_cp = aECs.CodePage(strFontName); RegistryKey keyLastSFProject = Registry.CurrentUser.CreateSubKey(cstrProjectMemoryKey); keyLastSFProject.SetValue(cstrProjectMostRecentProject,strProjectName); return true; } return false; }
private void buttonAddNewProject_Click(object sender, System.EventArgs e) { // in case the Add New project button was default, change it to the OK button. this.AcceptButton = this.buttonOK; // get the delimiter for word boundaries and disallow the /"/ character m_strWordBoundaryDelimiter = this.textBoxWordBoundaryDelimiter.Text; if( m_strWordBoundaryDelimiter.IndexOf('"') != -1 ) { MessageBox.Show("Can't use the double-quote character for the word boundary delimiter",SpellingFixerEC.cstrCaption); return; } bool bRewriteCCTable = false; string strPunctuation = EncodePunctuationForCC(this.textBoxAddlPunctuation.Text); if(strPunctuation == null ) return; // it had a bad character else if( strPunctuation != m_strNonWordCharacters ) { // this means the file must be re-written bRewriteCCTable = true; m_strNonWordCharacters = strPunctuation; } if( (!m_bLegacy) != this.checkBoxUnicode.Checked ) { m_bLegacy = !this.checkBoxUnicode.Checked; bRewriteCCTable = true; } // check for existing EncConverter with this same project information string strCCTableSpec = null; string strPartialName = this.textBoxNewProjectName.Text; string strEncConverterName = FullName(strPartialName); EncConverters aECs = new EncConverters(); IEncConverter aEC = aECs[strEncConverterName]; if( aEC != null ) { // if we're *not* in edit mode if( this.buttonAddNewProject.Text == cstrAddNewProjectButtonText ) { if( MessageBox.Show(String.Format("A project already exists by the name {0}. Click 'Yes' to overwrite", this.textBoxNewProjectName.Text),SpellingFixerEC.cstrCaption, MessageBoxButtons.YesNoCancel) == DialogResult.Yes) { // take it out of the check box list checkedListBoxProjects.Items.Remove(strPartialName); strCCTableSpec = aEC.ConverterIdentifier; if( File.Exists(strCCTableSpec) ) { File.Delete(strCCTableSpec); strCCTableSpec = null; } // remove the existing one and we'll add a new one next aECs.Remove(aEC.Name); aEC = null; } else return; } else // edit mode { if( MessageBox.Show(String.Format("Do you want to update the '{0}' project?", this.textBoxNewProjectName.Text),SpellingFixerEC.cstrCaption, MessageBoxButtons.YesNoCancel) == DialogResult.Yes) { // take it out of the check box list checkedListBoxProjects.Items.Remove(strPartialName); // save the spec so that we don't make one below strCCTableSpec = aEC.ConverterIdentifier; // the remove the converter since we'll add it back again next aECs.Remove(aEC.Name); aEC = null; } else { // reset this in case we were just editing it. ResetNewProjectLook(); return; } } } // if we're aren't using the old cc table, then... if( strCCTableSpec == null ) { // now add it (put it in the normal 'MapsTables' folder in \pf\cf\sil\...) string strMapsTableDir = GetMapTableFolderPath; strCCTableSpec = strMapsTableDir + @"\" + strEncConverterName + ".cct"; if( File.Exists(strCCTableSpec) ) { // the converter doesn't exist, but a file with the name we would have // given it does... ask the user if they want to overwrite it. // TODO: this doesn't allow for complete flexibility. It might be nicer to // allow for any arbitrary name, but not if noone complains. if( MessageBox.Show(String.Format("A file exists by the name {0}. Click 'Yes' to overwrite", strCCTableSpec),SpellingFixerEC.cstrCaption, MessageBoxButtons.YesNoCancel) == DialogResult.Yes) { File.Delete(strCCTableSpec); #if WriteOnAdd // if the user goes to add the first record, it'd be better if the file didn't exist because now we do some // preliminary testing whether the CC table already changes a word before adding a new one, but this causes // a non-trapable error if there are no rules in the file. So just create it when it is actually needed CreateCCTable(strCCTableSpec,strEncConverterName,m_strNonWordCharacters, !this.m_bLegacy); #endif } } #if WriteOnAdd else CreateCCTable(strCCTableSpec,strEncConverterName,m_strNonWordCharacters, !this.m_bLegacy); #endif bRewriteCCTable = false; } // now add the EncConverter // TODO: EncConverters needs a new interface to get the defining encodingID from // a FontName (so we can use it in this call) just like we can 'try' to get the // code page given a font name (see 'CodePage' below) ConvType eConvType = (m_bLegacy) ? ConvType.Legacy_to_Legacy : ConvType.Unicode_to_Unicode; aECs.Add(strEncConverterName,strCCTableSpec,eConvType,null,null,SpellingFixerEC.SFProcessType); Font font = null; try { font = new Font(comboBoxFont.SelectedItem.ToString(),Convert.ToSingle(listBoxFontSize.SelectedItem)); } catch { MessageBox.Show("Couldn't create the selected font. Contact support"); return; } // add this 'displaying font' information to the converter as properties/attributes ECAttributes aECAttrs = aECs.Attributes(strEncConverterName,AttributeType.Converter); aECAttrs.Add(SpellingFixerEC.cstrAttributeFontToUse,font.Name); aECAttrs.Add(SpellingFixerEC.cstrAttributeFontSizeToUse, font.Size); aECAttrs.Add(SpellingFixerEC.cstrAttributeWordBoundaryDelimiter, m_strWordBoundaryDelimiter); aECAttrs.Add(SpellingFixerEC.cstrAttributeNonWordChars, m_strNonWordCharacters); // if it's not Unicode, then we need a code page in order to convert from wide to // narrow (when writing to the file). int cp = 0; if( m_bLegacy ) { // try to get the code page from EncConverters try { cp = aECs.CodePage(font.Name); } catch { // if it fails, it means we don't have a mapping, so add one here. // TODO: it would be nice to have an encoding, but I'm loath to query // the user for it here since it isn't extremely relevant to this app. cp = Convert.ToInt32(this.textBoxCP.Text); aECs.AddFont(font.Name,cp,null); } } if(bRewriteCCTable) // we are going to continue using the old file... so we must re-write it. { // if it was legacy encoded, then we need to convert the data to narrow using // the code page the user specified (or we got out of the repository) Encoding enc = null; if( m_bLegacy ) { if (cp == EncConverters.cnSymbolFontCodePage) cp = EncConverters.cnIso8859_1CodePage; enc = Encoding.GetEncoding(cp); } else enc = new UTF8Encoding(); DataTable myTable; if( SpellingFixerEC.InitializeDataTableFromCCTable(strCCTableSpec, enc, m_strWordBoundaryDelimiter, out myTable) ) { ReWriteCCTableHeader(strCCTableSpec,m_strNonWordCharacters,enc); SpellingFixerEC.AppendCCTableFromDataTable(strCCTableSpec, enc, m_strWordBoundaryDelimiter, m_strNonWordCharacters, myTable); } } // finally, add the new project to the now-visible checkbox list this.buttonOK.Enabled = checkedListBoxProjects.Visible = true; ClearClickedItems(); checkedListBoxProjects.Items.Add(strPartialName,CheckState.Checked); // reset this in case we were just editing it. ResetNewProjectLook(); }
private void DoEdit(EncConverters aECs, IEncConverter aEC, string strProjectName, string strFontName, string sFontSize) { this.textBoxNewProjectName.Text = strProjectName; this.textBoxWordBoundaryDelimiter.Text = m_strWordBoundaryDelimiter; // new in 1.2 (so it might not exist) this.textBoxAddlPunctuation.Text = this.DecodePunctuationForCC(m_strNonWordCharacters); this.listBoxFontSize.SelectedItem = sFontSize; this.comboBoxFont.SelectedItem = strFontName; m_bLegacy = (aEC.ConversionType == ConvType.Legacy_to_Legacy); this.checkBoxUnicode.Checked = !m_bLegacy; if( m_bLegacy ) { this.labelCP.Visible = this.textBoxCP.Visible = true; this.textBoxCP.Text = aECs.CodePage(strFontName).ToString(); } // update the "Add New Project" button to say "Update Project" this.groupBoxNewProject.Text = "Edit Project Settings"; this.buttonAddNewProject.Text = "Update &Project"; this.toolTips.SetToolTip(this.buttonAddNewProject, "Click to update the project information"); this.textBoxNewProjectName.ReadOnly = true; EnableAddNewProjectButton(); }
private void checkBoxUnicode_CheckedChanged(object sender, System.EventArgs e) { // check to see if the Add button should be enable. EnableAddNewProjectButton(); bool bIsLegacy = !this.checkBoxUnicode.Checked; this.labelCP.Visible = this.textBoxCP.Visible = bIsLegacy; // if it's a legacy encoding, then see if the repository already has a cp for // this font if( bIsLegacy ) { EncConverters aECs = new EncConverters(); int cp = (this.textBoxCP.Text != "") ? Convert.ToInt32(this.textBoxCP.Text) : 1252; try { if( (comboBoxFont.SelectedItem != null) && (comboBoxFont.SelectedItem.ToString() != "") ) cp = aECs.CodePage(comboBoxFont.SelectedItem.ToString()); } catch {} this.textBoxCP.Text = cp.ToString(); } }