public BBeB ParseHTML(HtmlDocument doc, BindingParams bindingParams, TocEntry tocEntries) { m_Book = new BBeB(); byte[] thumb = File.ReadAllBytes(bindingParams.IconFile); setHeaderValues(thumb.Length); m_Book.MetaData = bindingParams.MetaData; m_Book.ThumbnailData = thumb; // Create our default Attribute objects createDefaultAttributeObjects(BBeB.ReaderPageWidth, BBeB.ReaderPageHeight); // cover page works, but it's ugly createCoverPage(); m_CurrentPage = createPage(); PageObject firstBookPage = m_CurrentPage; m_StartReadingBlock = null; m_StartReadingPage = null; addBookPage(m_CurrentPage); IHTMLDocument2 dom = (IHTMLDocument2)doc.DomDocument; IHTMLDOMNode domNode = (IHTMLDOMNode)dom.body; IHTMLDOMChildrenCollection children = (IHTMLDOMChildrenCollection)domNode.childNodes; TextBlockBuilder tbBuilder = new TextBlockBuilder(GetNextObjId(), m_CharMapper); foreach (IHTMLDOMNode child in children) { tbBuilder = ParseDomNode(child, tbBuilder); } PrintHTMLElementChildren(children); // If we have any text left then add it FlushTextToBlock(m_CurrentPage, tbBuilder, m_MainBodyTextAttr); finalizePage(m_CurrentPage); // Create the table of contents createTocPage(firstBookPage, tocEntries); m_TocObject.AddEntry(m_StartReadingPage.ID, m_StartReadingBlock.ID, "Start Reading"); // Also serialize the table of contents object m_TocObject.Serialize(); finalizeBook(); return(m_Book); }
public bool SaveDocument(BindingParams bindingParameters, TocEntry tocEntries, BBeBLib.Serializer.CharacterMapper charMapper, HtmlDocument document) { bool ret = false; string filename = bindingParameters.MetaData.BookInfo.Author + " - " + bindingParameters.MetaData.BookInfo.Title; SaveFileDialog dialog = new SaveFileDialog(); dialog.FileName = filename; dialog.Filter = "BBeB/LRF Files (*.lrf)|*.lrf"; if (dialog.ShowDialog() == DialogResult.OK) { Host.Status("Converting...."); Application.DoEvents(); HTMLToBbebTransform transformer = new HTMLToBbebTransform(charMapper); BBeB book = transformer.ParseHTML(document, bindingParameters, tocEntries); Host.Status("Saving...."); Application.DoEvents(); // Save book now File.Delete(dialog.FileName); BBeBLib.Serializer.BBeBSerializer serializer = new BBeBLib.Serializer.BBeBSerializer(); FileStream newLrfStream = File.OpenWrite(dialog.FileName); try { serializer.Serialize(newLrfStream, book); } catch (Exception ex) { // TODO Need to get these strings from a resource for localization purposes string msg = string.Format("Couldn't save file {0}\n{1}", dialog.FileName, ex.ToString()); MessageBox.Show(msg, "Error saving file!", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { newLrfStream.Close(); } Host.Status("Finished."); } return(ret); }
static void BindBook(string strInputFile) { FileInfo finfo = new FileInfo(strInputFile); if (finfo.Extension == ".xml") { XmlSerializer serializer = new XmlSerializer(typeof(BindingParams)); FileStream stream = File.OpenRead(strInputFile); try { BindingParams config = (BindingParams)serializer.Deserialize(stream); config.MetaData.Fixup(); BindBook(config); } finally { stream.Close(); } } }
static void BindBook(BindingParams config) { LegacyBBeB book = new LegacyBBeB(config.MetaData); book.BeginBook(); FileInfo bookFileInfo = new FileInfo(config.InputFile); if (string.Compare(bookFileInfo.Extension, ".html", true) == 0 || string.Compare(bookFileInfo.Extension, ".htm", true) == 0) { throw new ApplicationException("Can't parse HTML yet"); } else if (string.Compare(bookFileInfo.Extension, ".pdf", true) == 0) { throw new ApplicationException("Can't parse a PDF yet"); } else if (string.Compare(bookFileInfo.Extension, ".xml", true) == 0) { GutenbergReader reader = new GutenbergReader(book); reader.ReadFile(config.InputFile, config.MetaData.BookInfo); } else if (string.Compare(bookFileInfo.Extension, ".txt", true) == 0) { PseudoHtmlReader reader = new PseudoHtmlReader(book); reader.ReadFile(config.InputFile); } else { throw new ApplicationException("Can't handle file type: " + config.InputFile); } book.FinalizeBook(config.IconFile); book.WriteToFile(config.OutputFile); }
public BindingParamsProperties(BindingParams bindingParams) { m_Params = bindingParams; }