Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 把英數字轉換成點字。
        /// </summary>
        /// <param name="text">一個英數字或英文標點符號。</param>
        /// <returns>若指定的字串是中文字且轉換成功,則傳回轉換之後的點字物件,否則傳回 null。</returns>
        private BrailleWord InternalConvert(string text)
        {
            if (String.IsNullOrEmpty(text))
            {
                return(null);
            }

            BrailleWord brWord = new BrailleWord();

            brWord.Text = text;

            string brCode = null;

            // 如果是刪節號
            if (text == "...")
            {
                brCode = m_Table.Find(text);
                brWord.AddCell(brCode);
                return(brWord);
            }

            // 處理英文字母和數字。
            if (text.Length == 1)
            {
                char ch = text[0];
                if (CharHelper.IsAsciiLetter(ch))
                {
                    brCode = m_Table.FindLetter(text);
                    if (!String.IsNullOrEmpty(brCode))
                    {
                        brWord.AddCell(brCode);
                        return(brWord);
                        // 註:大寫記號和連續大寫記號在完成一行之後才處理。
                    }
                    throw new Exception("找不到對應的點字: " + text);
                }
                if (CharHelper.IsAsciiDigit(ch))
                {
                    brCode = m_Table.FindDigit(text, false);                            // 一般數字取下位點。
                    if (!String.IsNullOrEmpty(brCode))
                    {
                        brWord.AddCell(brCode);
                        return(brWord);
                    }
                    throw new Exception("找不到對應的點字: " + text);
                }
            }

            // 處理編號。
            if (text == "#")
            {
                // # 沒有對應的點字碼,只是用它來代表編號數字的開始,
                // 以便後續處理編號用(將編號數字轉成上位點)。
                return(brWord);
            }

            brCode = m_Table.Find(text);
            if (!String.IsNullOrEmpty(brCode))
            {
                brWord.AddCell(brCode);
                return(brWord);
            }

            brWord = null;
            return(null);
        }