private Manifest GenerateManifest(Document doc) { if (doc.HasChildren()) { ManifestItem CssElement = ManifestItem.Create(FileItemType.CSS); CssElement.Href = "css/document.css"; CssElement.Identifier = "document.css"; CssElement.Data = ReadBytesFromFile(HttpContext.Current.Server.MapPath("~/data/Epub") + "\\document.css"); CssElement.MediaType = "text/css"; manifest.Items.Add(CssElement); CsssContent += "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + CssElement.Href + "\"/>"; ManifestItem ImageElement = ManifestItem.Create(FileItemType.JPEG); ImageElement.Href = "httpatomoreillycomsourcemspimages741241.jpeg"; ImageElement.Identifier = "httpatomoreillycomsourcemspimages741241"; ImageElement.Data = ReadBytesFromFile(HttpContext.Current.Server.MapPath("~/data/Epub") + "\\httpatomoreillycomsourcemspimages741241.jpg"); ImageElement.MediaType = "image/jpeg"; manifest.Items.Add(ImageElement); ManifestItem HtmlElement = ManifestItem.Create(FileItemType.XHTML); HtmlElement.Href = "cover.html"; HtmlElement.Identifier = "cover"; HtmlElement.MediaType = "application/xhtml+xml"; HtmlElement.Data = ReadBytesFromFile(HttpContext.Current.Server.MapPath("~/data/Epub") + "\\cover.html"); manifest.Items.Add(HtmlElement); ItemRefList.Add(new ItemRef { IdRef = HtmlElement.Identifier, Linear = false }); GenerateManifestElementsRecursively(doc.Children); } manifest.Items[ElementIndex].Data = CreatexHtmlPage(); HtmlContent = string.Empty; CurrentCounter = 0; ChapterCounter = 0; ElementIndex = 0; return(manifest); }
private void GenerateManifestElementsRecursively(List <Element> Children) { foreach (Element Child in Children) { if (Child.Content != null) { switch (Child.ProposedFragmentType) { case FragmentType.Audio: break; case FragmentType.Css: ManifestItem CssElement = ManifestItem.Create(FileItemType.CSS); CssElement.Href = "css/css_style_" + CssCounter.ToString("000") + ".css"; CssElement.Identifier = "css_style_" + CssCounter.ToString("000"); CssElement.Data = Child.Content; CssElement.MediaType = "text/css"; manifest.Items.Add(CssElement); CsssContent += "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + CssElement.Href + "\"/>"; CssCounter++; break; case FragmentType.Data: break; case FragmentType.Font: ManifestItem FontElement = ManifestItem.Create(FileItemType.OTF); FontElement.Href = "font/epub.embedded.font_" + FontCounter.ToString("000") + ".otf"; FontElement.Identifier = "epub.embedded.font_" + FontCounter.ToString("000"); FontElement.Data = Child.Content; FontElement.MediaType = "font/opentype"; manifest.Items.Add(FontElement); FontCounter++; break; case FragmentType.Html: if (Child.Level == 2) { if (CurrentCounter != ChapterCounter) { manifest.Items[ElementIndex].Data = CreatexHtmlPage(); HtmlContent = string.Empty; CurrentCounter = ChapterCounter; } ChapterCounter++; ManifestItem HtmlElement = ManifestItem.Create(FileItemType.XHTML); HtmlElement.Href = "CH" + ChapterCounter.ToString("000") + ".xhtml"; HtmlElement.Identifier = "id" + ChapterCounter.ToString("000"); HtmlContent += Encoding.UTF8.GetString(Child.Content); HtmlTitleContent = Child.Name; HtmlElement.MediaType = "application/xhtml+xml"; manifest.Items.Add(HtmlElement); ElementIndex = manifest.Items.IndexOf(HtmlElement); ItemRefList.Add(new ItemRef { IdRef = HtmlElement.Identifier, Linear = true }); NavPoint Nav = new NavPoint(); Nav.Identifier = "id" + PlayCounter.ToString("00000"); Nav.PlayOrder = PlayCounter; Nav.LabelText = Child.Name; Nav.Content = HtmlElement.Href; Nav.Children = new List <NavPoint>(); navList.Add(Nav); NavIndex = navList.IndexOf(Nav); PlayCounter++; } else { if (Child.Level == 3) { if (Child.WidgetName.Contains("Section")) { HtmlContent += "<a id=\"" + Child.Name.Replace(" ", "-") + "\">" + Encoding.UTF8.GetString(Child.Content) + "</a>"; navList[NavIndex].Children.Add(new NavPoint() { Identifier = "id" + PlayCounter.ToString("00000"), PlayOrder = PlayCounter, LabelText = Child.Name, Content = manifest.Items[ElementIndex].Href + "#" + Child.Name.Replace(" ", "-") }); PlayCounter++; } else { HtmlContent += Encoding.UTF8.GetString(Child.Content); } } else { HtmlContent += Encoding.UTF8.GetString(Child.Content); } } break; case FragmentType.Image: if (Child.RawContent.Contains("PNG")) { ManifestItem ImageElement = ManifestItem.Create(FileItemType.PNG); ImageElement.Href = "images/img_" + ImgCounter.ToString("000") + ".png"; ImageElement.Identifier = "img_" + ImgCounter.ToString("000"); ImageElement.Data = Child.Content; ImageElement.MediaType = "image/png"; manifest.Items.Add(ImageElement); HtmlContent += "<p><img src=\"" + ImageElement.Href + "\" alt=\"" + Child.Name + "\"/></p>"; } else if (Child.RawContent.Contains("JPG")) { ManifestItem ImageElement = ManifestItem.Create(FileItemType.JPEG); ImageElement.Href = "images/img_" + ImgCounter.ToString("000") + ".jpg"; ImageElement.Identifier = "img_" + ImgCounter.ToString("000"); ImageElement.Data = Child.Content; ImageElement.MediaType = "image/jpeg"; manifest.Items.Add(ImageElement); HtmlContent += "<p><img src=\"" + ImageElement.Href + "\" alt=\"" + Child.Name + "\"/></p>"; } else if (Child.RawContent.Contains("GIF")) { ManifestItem ImageElement = ManifestItem.Create(FileItemType.GIF); ImageElement.Href = "images/img_" + ImgCounter.ToString("000") + ".gif"; ImageElement.Identifier = "img_" + ImgCounter.ToString("000"); ImageElement.Data = Child.Content; ImageElement.MediaType = "image/gif"; manifest.Items.Add(ImageElement); HtmlContent += "<p><img src=\"" + ImageElement.Href + "\" alt=\"" + Child.Name + "\"/></p>"; } ImgCounter++; break; case FragmentType.Meta: break; case FragmentType.Script: break; case FragmentType.Video: break; } } if (Child.HasChildren()) { GenerateManifestElementsRecursively(Child.Children); } } }