private bool CheckHasCover()
        {
            // check if book has cover
            Contents.Meta meta = Book.Metadata.Metas.SingleOrDefault(m => m.Name == "cover");
            if (meta != null)
            {
                // get manifest item
                Contents.Item item = Book.Manifest.Items.Where(i => i.Id.Equals(meta.Content)).SingleOrDefault();
                if (item == null)
                {
                    return(false);
                }

                string path = Book.GetFilePath(item.Href);
                if (path == null)
                {
                    return(false);
                }

                // read stream
                Stream s = IsolatedStorageHelper.ReadZipStream(path);
                if (s != null)
                {
                    // load cover
                    _coverBitmapImage = new BitmapImage();
                    _coverBitmapImage.SetSource(s);

                    if (_coverImage != null) // book can be load before OnApplyTemplate
                    {
                        _coverImage.Source = _coverBitmapImage;
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        private int ParseItemRef(Contents.ItemRef itemRef, ref int startLocation)
        {
            // find corresponding item
            Contents.Item item = _ePubViewer.Book.Manifest.Items.Where(i => i.Id == itemRef.Idref).SingleOrDefault();
            if (item == null || item.MediaType != XhtmlMediaType) // check mediatype
            {
                Debug.WriteLine(String.Format(CultureInfo.InvariantCulture, "Warning: EPubReader.Parseer.ParseItemRef - Manifest does not contains ItemRef with Id \"{0}\"", itemRef.Idref));
                return(0);
            }

            // read file
            string path = _ePubViewer.Book.GetFilePath(HttpUtility.UrlDecode(item.Href));

            if (path == null)
            {
                Debug.WriteLine(String.Format(CultureInfo.InvariantCulture, "Warning: EPubReader.Parseer.ParseItemRef - EPub does not contain page file \"{0}\"", item.Href));
                return(0);
            }
            string content = IsolatedStorageHelper.ReadZipString(path);

            // read html
            HtmlDocument htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(content);

            List <Elements.BaseElement> elements = new List <Elements.BaseElement>();

            ParseNodeChilds(htmlDoc.DocumentNode.SelectSingleNode(HtmlBodyPath), ref elements);

            if (elements.Count > 0)
            {
                _ePubViewer.Book.ItemElementsContainers.Add(
                    new ItemElementsContainer()
                {
                    Item          = item,
                    Elements      = new Collection <Elements.BaseElement>(elements),
                    StartLocation = startLocation
                }
                    ); // push ItemElementsContainers
            }

            return(elements.Count);
        }
Beispiel #3
0
        private void ParseToc()
        {
            Contents.Item item = _ePubViewer.Book.Manifest.Items.Where(i => (i.Id == "ncx" || i.Id == "ncxtoc") && i.MediaType == "application/x-dtbncx+xml").OrderBy(i => i.Id).FirstOrDefault();
            if (item == null)
            {
                return; // book doesn't contains toc manifest item
            }

            string path = _ePubViewer.Book.GetFilePath(item.Href);

            if (path == null)
            {
                return; // book doesn't contains toc file
            }

            string content = IsolatedStorageHelper.ReadZipString(path);

            // WP does not support DOCTYPE
            string contentCleaned = Regex.Replace(content, "<!DOCTYPE[^>]*>", String.Empty);

            _ePubViewer.Book.Toc = new Tocs.Toc(XDocument.Parse(contentCleaned).Elements(Tocs.Toc.DaisyOrgNcxNameSpace + "ncx"));
        }