예제 #1
0
        /// <summary>
        /// 編排指定的列。此函式會將指定的列斷行。
        /// </summary>
        /// <param name="brDoc">點字文件。</param>
        /// <param name="lineIndex">欲重新編排的列索引。</param>
        /// <returns>傳回編排後的列數。</returns>
        public int FormatLine(BrailleDocument brDoc, int lineIndex, ContextTagManager context)
        {
            BrailleLine brLine = brDoc.Lines[lineIndex];

            RemoveContextTagsButTitle(brLine);   // 清除情境標籤,除了標題標籤。

            if (brLine.WordCount == 0)
            {
                brDoc.RemoveLine(lineIndex);
                return(0);
            }

            List <BrailleLine> newLines;

            newLines = BreakLine(brLine, brDoc.CellsPerLine, context);

            if (newLines == null)   // 沒有斷行?
            {
                return(1);
            }

            // 移除原始的 line
            brLine.Clear();
            brDoc.RemoveLine(lineIndex);

            // 加入斷行後的 lines
            brDoc.Lines.InsertRange(lineIndex, newLines);

            return(newLines.Count);
        }
예제 #2
0
        /// <summary>
        /// 根據起始列索引更新起始的 BrailleLine 物件。
        /// </summary>
        /// <param name="brDoc"></param>
        /// <returns></returns>
        public bool UpdateLineObject(BrailleDocument brDoc)
        {
            if (m_BeginLineIndex < 0 || m_BeginLineIndex >= brDoc.LineCount)
            {
                return(false);
            }

            m_BeginLine = brDoc.Lines[m_BeginLineIndex];
            return(true);
        }
예제 #3
0
        /// <summary>
        /// 編排點字文件。
        /// </summary>
        public void FormatDocument(BrailleDocument doc)
        {
            ContextTagManager context = new ContextTagManager();

            int index = 0;

            while (index < doc.Lines.Count)
            {
                ProcessIndentTags(doc, index, context);
                index += FormatLine(doc, index, context);
            }
        }
예제 #4
0
        /// <summary>
        /// 從現存的雙視點字檔案載入(反序列化)成新的 BailleDocument 物件。
        /// </summary>
        /// <param name="filename">檔名</param>
        /// <returns>新的 BailleDocument 物件</returns>
        public static BrailleDocument LoadBrailleFile(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("檔案不存在: " + filename);
            }

            BrailleDocument brDoc = null;

            string jsonStr = File.ReadAllText(filename);
            brDoc = JsonHelper.Deserialize<BrailleDocument>(jsonStr);
            return brDoc;
        }
예제 #5
0
        /// <summary>
        /// 將指定的列與下一列相結合(下一列附加至本列)。
        /// </summary>
        /// <param name="brDoc">點字文件。</param>
        /// <param name="lineIndex">本列的列索引。</param>
        public void JoinNextLine(BrailleDocument brDoc, int lineIndex)
        {
            BrailleLine brLine = brDoc.Lines[lineIndex];

            // 將下一列附加至本列,以結合成一列。
            int nextIndex = lineIndex + 1;

            if (nextIndex < brDoc.Lines.Count)
            {
                brLine.Append(brDoc.Lines[nextIndex]);
                brDoc.Lines.RemoveAt(nextIndex);
            }
        }
예제 #6
0
        /// <summary>
        /// 從現存的雙視點字檔案載入(反序列化)成新的 BailleDocument 物件。
        /// </summary>
        /// <param name="filename">檔名</param>
        /// <returns>新的 BailleDocument 物件</returns>
        public static BrailleDocument LoadBrailleFile(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("檔案不存在: " + filename);
            }

            BrailleDocument brDoc = null;

            // 舊版的 .btx 反序列化.
            if (Path.GetExtension(filename).Equals(".btx", StringComparison.CurrentCultureIgnoreCase))
            {
                using (FileStream fs = new FileStream(filename, FileMode.Open))
                {
                    BinaryReader br = new BinaryReader(fs);

                    int fileVersion = br.ReadInt32();
                    int lineCount   = br.ReadInt32();
                    int reserved1   = br.ReadInt32();
                    int reserved2   = br.ReadInt32();

                    IFormatter fmter = new BinaryFormatter();
                    brDoc = (BrailleDocument)fmter.Deserialize(fs);
                    br.Close();

                    // 設定新增的屬性:BrailleWord.IsPolyphnic。等到 .btx 正式除役,這裡就不需要了。
                    foreach (BrailleLine brLine in brDoc.Lines)
                    {
                        foreach (BrailleWord brWord in brLine.Words)
                        {
                            if (!String.IsNullOrEmpty(brWord.PhoneticCode))
                            {
                                brWord.IsPolyphonic = ZhuyinQueryHelper.IsPolyphonic(brWord.Text);
                            }
                        }
                    }

                    return(brDoc);
                }
            }

            string jsonStr = File.ReadAllText(filename);

            brDoc = JsonHelper.Deserialize <BrailleDocument>(jsonStr);
            return(brDoc);
        }
예제 #7
0
        /// <summary>
        /// 更新頁標題的起始列索引。
        /// </summary>
        /// <param name="brDoc"></param>
        /// <returns></returns>
        public bool UpdateLineIndex(BrailleDocument brDoc)
        {
            if (m_BeginLine == null)
            {
                return(false);
            }

            int idx = brDoc.Lines.IndexOf(m_BeginLine);

            if (idx < 0)
            {
                return(false);
            }
            m_BeginLine      = brDoc.Lines[idx];
            m_BeginLineIndex = idx;
            return(true);
        }
예제 #8
0
        public void SetTitleLine(BrailleDocument brDoc, int index)
        {
            m_TitleLine = brDoc.Lines[index];
            m_TitleLine.RemoveContextTags();         // 移除所有情境標籤(這裡主要是把標題標籤拿掉)。

            m_BeginLineIndex = index + 1;            // 從下一列開始就是使用此標題。

            if (m_BeginLineIndex >= brDoc.LineCount) // 標題列就是文件的最後一列?
            {
                //System.Diagnostics.Trace.WriteLine("BraillePageTitle.SetTitleLine: 標題列後面沒有文字內容!");
                m_BeginLineIndex = -1;
                m_BeginLine      = null;
                return;
            }

            m_BeginLine = brDoc.Lines[m_BeginLineIndex];
        }
예제 #9
0
        /// <summary>
        /// 處理縮排情境標籤:碰到縮排標籤時,將縮排次數更新至 ContextTagManager 物件,並移除此縮排標籤。
        ///
        /// NOTE: 縮排標籤必須位於列首,一列可有多個連續縮排標籤,例如:<縮排><縮排>。
        /// </summary>
        /// <param name="brDoc"></param>
        /// <param name="lineIndex"></param>
        /// <param name="context">情境物件。</param>
        /// <returns></returns>
        public void ProcessIndentTags(BrailleDocument brDoc, int lineIndex, ContextTagManager context)
        {
            BrailleLine brLine  = brDoc.Lines[lineIndex];
            int         wordIdx = 0;
            ContextTag  ctag;

            while (brLine.WordCount > 0)
            {
                ctag = context.Parse(brLine[0].Text, ContextTagNames.Indent);
                if (ctag != null)
                {
                    brLine.RemoveAt(wordIdx);
                }
                else
                {
                    break;
                }
            }
        }
예제 #10
0
 public BraillePageTitle(BrailleDocument brDoc, int index) : this()
 {
     SetTitleLine(brDoc, index);
 }