Beispiel #1
0
 public BrailleDocument(string filename, BrailleProcessor processor, int cellsPerLine)
     : this()
 {
     m_FileName = filename;
     m_Processor = processor;
     m_CellsPerLine = cellsPerLine;
 }
        /// <summary>
        /// Get singleton instance.
        /// </summary>
        /// <returns></returns>
        public static BrailleProcessor GetInstance(ZhuyinReverseConverter zhuyinConverter = null)
        {
            if (s_Processor != null)
            {
                return(s_Processor);
            }

            if (zhuyinConverter == null)
            {
                // create default zhuyin reverse converter if not specified.
                zhuyinConverter = new ZhuyinReverseConverter(new ZhuyinReverseConversionProvider());
            }

            s_Processor = new BrailleProcessor(zhuyinConverter);
            return(s_Processor);
        }
 /// <summary>
 /// 從傳入的字串中取出原書頁碼。
 /// </summary>
 /// <param name="line"></param>
 /// <returns>若傳入的字串不是原書頁碼,則傳回 -1,否則傳回原書頁碼。</returns>
 public static int GetOrgPageNumber(string line)
 {
     if (BrailleProcessor.IsOrgPageNumber(line))
     {
         line = line.Remove(0, 36);
         try
         {
             return(Convert.ToInt32(line));
         }
         catch
         {
             throw new Exception("原書頁碼包含無效的數字: " + line);
         }
     }
     return(-1);
 }
Beispiel #4
0
 public BrailleDocument(BrailleProcessor processor, int cellsPerLine=BrailleConst.DefaultCellsPerLine)
     : this()
 {
     m_Processor = processor;
     m_CellsPerLine = cellsPerLine;
 }
 public BrailleDocument(string filename, BrailleProcessor processor, int cellsPerLine)
     : this(filename, processor)
 {
     m_CellsPerLine = cellsPerLine;
 }
 public BrailleDocument(BrailleProcessor processer, int cellsPerLine)
     : this(processer)
 {
     m_CellsPerLine = cellsPerLine;
 }
 public BrailleDocument(string filename, BrailleProcessor processor)
     : this(filename)
 {
     m_Processor = processor;
 }
 public BrailleDocument(BrailleProcessor processor)
     : this()
 {
     m_Processor = processor;
 }
        /// <summary>
        /// 將一行點字串列斷成多行。
        /// </summary>
        /// <param name="brLine">來源點字串列。</param>
        /// <param name="cellsPerLine">每行最大方數。</param>
        /// <param name="context">情境物件。</param>
        /// <returns>斷行之後的多行串列。若為 null 表示無需斷行(指定的點字串列未超過每行最大方數)。</returns>
        public List <BrailleLine> BreakLine(BrailleLine brLine, int cellsPerLine, ContextTagManager context)
        {
            if (context != null && context.IndentCount > 0) // 若目前位於縮排區塊中
            {
                // 每列最大方數要扣掉縮排數量,並於事後補縮排的空方。
                // NOTE: 必須在斷行之後才補縮排的空方!
                cellsPerLine -= context.IndentCount;
            }

            // 若指定的點字串列未超過每行最大方數,則無須斷行,傳回 null。
            if (brLine.CellCount <= cellsPerLine)
            {
                // 補縮排的空方。
                if (context != null && context.IndentCount > 0) // 若目前位於縮排區塊中
                {
                    this.Indent(brLine, context.IndentCount);
                }
                return(null);
            }

            List <BrailleLine> lines   = new List <BrailleLine>();
            BrailleLine        newLine = null;
            int  wordIndex             = 0;
            int  breakIndex            = 0;
            bool needHyphen            = false;
            bool isBroken = false; // 是否已經斷行了?
            int  indents  = 0;     // 第一次斷行時,不會有系統自斷加上的縮排,因此初始為 0。
            int  maxCells = cellsPerLine;;

            // 計算折行之後的縮排格數。
            indents = BrailleProcessor.CalcNewLineIndents(brLine);

            while (wordIndex < brLine.WordCount)
            {
                breakIndex = BrailleProcessor.CalcBreakPoint(brLine, maxCells, out needHyphen);

                newLine = brLine.Copy(wordIndex, breakIndex); // 複製到新行。
                if (needHyphen)                               // 是否要附加連字號?
                {
                    newLine.Words.Add(new BrailleWord("-", BrailleCellCode.Hyphen));
                }
                newLine.TrimEnd();                      // 去尾空白。

                // 如果是折下來的新行,就自動補上需要縮排的格數。
                if (isBroken)
                {
                    for (int i = 0; i < indents; i++)
                    {
                        newLine.Insert(0, BrailleWord.NewBlank());
                    }
                }

                brLine.RemoveRange(0, breakIndex);                                              // 從原始串列中刪除掉已經複製到新行的點字。
                wordIndex = 0;
                lines.Add(newLine);

                // 防錯:檢驗每個斷行後的 line 的方數是否超過每列最大方數。
                // 若超過,即表示之前的斷行處理有問題,須立即停止執行,否則錯誤會
                // 直到在雙視編輯的 Grid 顯示時才出現 index out of range,不易抓錯!
                System.Diagnostics.Debug.Assert(newLine.CellCount <= cellsPerLine, "斷行錯誤! 超過每列最大方數!");

                // 被折行之後的第一個字需要再根據規則調整。
                EnglishBrailleRule.ApplyCapitalRule(brLine); // 套用大寫規則。
                EnglishBrailleRule.ApplyDigitRule(brLine);   // 套用數字規則。

                isBroken = true;                             // 已經至少折了一行
                maxCells = cellsPerLine - indents;           // 下一行開始就要自動縮排,共縮 indents 格。
            }

            // 補縮排的空方。
            if (context != null && context.IndentCount > 0) // 若目前位於縮排區塊中
            {
                indents = context.IndentCount;
                foreach (BrailleLine aLine in lines)
                {
                    this.Indent(aLine, indents);
                }
            }

            return(lines);
        }