// 當明眼字有變動 private void txtChar_TextChanged(object sender, EventArgs e) { if (m_IsUpdatingUI) { return; } if (String.IsNullOrEmpty(txtChar.Text)) { cboPhCode.Items.Clear(); cboPhCode.SelectedIndex = -1; txtBraille.Text = ""; return; } string word = txtChar.Text; Stack <char> charStack = new Stack <char>(word); List <BrailleWord> brWordList = m_BrProcessor.ConvertWord(charStack); if (brWordList != null && brWordList.Count > 0) { // 成功轉換成點字,字元會從串流中取出 m_BrWord.Clear(); m_BrWord = brWordList[0]; UpdateUI(); } else { // 字元無法判斷和處理,它會留存在串流中。 char ch = charStack.Pop(); MsgBoxHelper.ShowError("無法處理字元: " + ch); txtChar.Text = ""; } }
/// <summary> /// 將傳入的字串(字元)轉換成點字。 /// </summary> /// <param name="text">字串(一個字元)。</param> /// <returns>若指定的字串轉換成功,則傳回轉換之後的點字物件,否則傳回 null。</returns> protected virtual BrailleWord ConvertToBrailleWord(string text) { BrailleWord brWord = new BrailleWord(); brWord.Text = text; string brCode; brCode = BrailleTable.Find(text); if (!String.IsNullOrEmpty(brCode)) { brWord.AddCell(brCode); return(brWord); } brWord.Clear(); brWord = null; return(null); }
/// <summary> /// 把一個字元轉換成點字。 /// </summary> /// <param name="text">一個中文字或標點符號。</param> /// <returns>若指定的字串是中文字且轉換成功,則傳回轉換之後的點字物件,否則傳回 null。</returns> private BrailleWord InternalConvert(string text) { BrailleWord brWord = new BrailleWord { Text = text }; string brCode; if (text.Length == 1) { char ch = text[0]; // 如果輸入的明眼字是注音符號,就直接傳回注音的點字碼。 if (Zhuyin.IsBopomofo(ch)) { // 注意: 不要指定 brWord.PhoneticCode,因為注音符號本身只是個中文符號, // 它並不是中文字,沒有合法的注音組字字根,因此不可指定注音碼。 brCode = _brailleTable.FindPhonetic(text); brWord.AddCell(brCode); return(brWord); } // 如果輸入的明眼字是注音符號的音調記號,就直接傳回對應的點字碼。 if (Zhuyin.IsTone(ch)) { // 注意: 不要指定 brWord.PhoneticCode,因為音調記號本身只是個中文符號, // 它並不是中文字,沒有合法的注音組字字根,因此不可指定注音碼。 brCode = _brailleTable.FindTone(text); brWord.AddCell(brCode); return(brWord); } } // 嘗試取得該字的注音字根,若可成功取得,則將注音字根轉換成點字碼,並傳回 BrailleWord 物件。 string phcode = null; if (text.IsCJK()) // 若是漢字 { /* 2010-01-03: 不取得所有的注音字根,只取得一組預設的字根,且判斷是否為多音字。等到編輯時使用者要更換注音,才取出所有字根。 * // 取得破音字的所有組字字根,每一組字根長度固定為 4 個字元,不足者以全型空白填補。 * string[] phCodes = ZhuyinQueryHelper.GetZhuyinSymbols(text, true); * if (phCodes.Length > 0) * { * brWord.SetPhoneticCodes(phCodes); * phcode = phCodes[0]; // 指定第一組字根為預設的字根。 * } */ // 取得注音字根 string[] zhuyinCodes = ZhuyinConverter.GetZhuyin(text); //if (zhuyinCodes == null || zhuyinCodes.Length == 0) //{ // // 若 IFELanguage 無法轉換,就用內建的注音字根查詢功能。 // zhuyinCodes = ZhuyinQueryHelper.GetZhuyinSymbols(text, true); // 此方法會傳回一個中文字的所有注音字根。 //} if (zhuyinCodes.Length >= 1) { phcode = zhuyinCodes[0]; } if (!String.IsNullOrEmpty(phcode)) { // 設定多音字旗號屬性. brWord.IsPolyphonic = ZhuyinQueryHelper.IsPolyphonic(text); // TODO: 以下「將注音字根轉換成點字碼」的處理應可省略,因為 FixPhoneticCodes 會重新修正所有中文字的點字碼。 // 將注音字根轉換成點字碼 BrailleCellList cellList = CreatePhoneticCellList(phcode); if (cellList != null) { brWord.CellList.Assign(cellList); brWord.PhoneticCode = phcode; return(brWord); } } } // 不是中文字,或者無法取得注音字根. // 處理標點符號 string puncBrCode = _brailleTable.FindPunctuation(text); if (!String.IsNullOrEmpty(puncBrCode)) { brWord.AddCell(puncBrCode); return(brWord); } // 其它符號 brCode = _brailleTable.Find(text); if (!String.IsNullOrEmpty(brCode)) { brWord.AddCell(brCode); return(brWord); } brWord.Clear(); brWord = null; return(null); }