Ejemplo n.º 1
0
        public void ReadFile(String aFileName, BookInfo bookInfo)
        {
            Gutenberg.TextFormatter gbFormatter = new TextFormatter();

            Document   doc;
            FileStream stream = File.OpenRead(aFileName);

            try
            {
                doc = gbFormatter.ProcessTextBook(stream);
            }
            finally
            {
                stream.Close();
            }

            if (!string.IsNullOrEmpty(doc.Author))
            {
                bookInfo.Author = doc.Author;
            }
            if (!string.IsNullOrEmpty(doc.Title))
            {
                bookInfo.Title = doc.Title;
            }

            foreach (Chapter chapter in doc.Chapters)
            {
                TextBlockBuilder pageBlock = new TextBlockBuilder(m_Book);

                bool bPrintedPara = false;
                foreach (Paragraph para in chapter.Paragraphs)
                {
                    if (bPrintedPara)
                    {
                        pageBlock.Append(TagId.EOL);
                        pageBlock.Append(TagId.EOL);
                    }

                    foreach (char c in para.Text)
                    {
                        pageBlock.AppendChar(c);
                    }

                    bPrintedPara = true;
                }

                m_Book.AddTextPage(pageBlock.CreateLegacyTextObject());
            }
        }
Ejemplo n.º 2
0
        LegacyBBeBObject getNextPage()
        {
            if (m_TextBufferOffset >= m_TextBuffer.Length)
            {
                // All done
                return(null);
            }

            TextBlockBuilder pageBlock = new TextBlockBuilder(m_Book);

            // Convert ASCII to UTF-16LE and along the way we strip \r and null
            // and convert \n to 0xf5d2
            int lineCount = 0;
            int nls       = 0;

            while ((m_TextBufferOffset < m_TextBuffer.Length) && (lineCount < 200) &&
                   !((nls == 6) && (lineCount > 30)))
            {
                int b = m_TextBuffer[m_TextBufferOffset++] & 0x00ff;
                if ((b == 13) || (b == 0))
                {
                    // Skip \r and null values
                    continue;
                }
                else if (b == 10)
                {
                    pageBlock.Append(TagId.EOL);
                    lineCount++;
                    nls++;
                }
                else if (b == '<')
                {
                    if (((m_TextBufferOffset + 1) < m_TextBuffer.Length) &&
                        ((m_TextBuffer[m_TextBufferOffset + 1] & 0x00ff) == '>'))
                    {
                        if (((m_TextBuffer[m_TextBufferOffset] & 0x00ff) == 'i') ||
                            ((m_TextBuffer[m_TextBufferOffset] & 0x00ff) == 'I'))
                        {
                            pageBlock.Append(TagId.ItalicBegin);
                            m_TextBufferOffset += 2;
                        }
                        else if (((m_TextBuffer[m_TextBufferOffset] & 0x00ff) == 'b') ||
                                 ((m_TextBuffer[m_TextBufferOffset] & 0x00ff) == 'B'))
                        {
                            pageBlock.Append(TagId.FontWeight, LegacyBBeB.k_BoldFontWeight);
                            m_TextBufferOffset += 2;
                        }
                    }
                    else if (((m_TextBufferOffset + 2) < m_TextBuffer.Length) &&
                             ((m_TextBuffer[m_TextBufferOffset] & 0x00ff) == '/') &&
                             ((m_TextBuffer[m_TextBufferOffset + 2] & 0x00ff) == '>'))
                    {
                        if (((m_TextBuffer[m_TextBufferOffset + 1] & 0x00ff) == 'i') ||
                            ((m_TextBuffer[m_TextBufferOffset + 1] & 0x00ff) == 'I'))
                        {
                            pageBlock.Append(TagId.ItalicEnd);
                            m_TextBufferOffset += 3;
                        }
                        else if (((m_TextBuffer[m_TextBufferOffset + 1] & 0x00ff) == 'b') ||
                                 ((m_TextBuffer[m_TextBufferOffset + 1] & 0x00ff) == 'B'))
                        {
                            pageBlock.Append(TagId.FontWeight, LegacyBBeB.k_NormalFontWeight);
                            m_TextBufferOffset += 3;
                        }
                    }
                    else
                    {
                        pageBlock.AppendChar(b);
                    }
                }
                else
                {
                    pageBlock.AppendChar(b);
                    nls = 0;
                }
            }

            return(pageBlock.CreateLegacyTextObject());
        }