Example #1
0
        public XElement ToXElement(string opfFolder)
        {
            string href = Item == null
                ? string.Empty
                : ZipUtils.AbsolutePathToRelative(opfFolder, Item.AbsolutePath);
            var element = new XElement(Epub.PackageNs + "reference",
                                       new XAttribute("href", href),
                                       new XAttribute("type", TypeName)
                                       );

            if (Title != null)
            {
                element.Add(new XAttribute("title", Title));
            }
            return(element);
        }
Example #2
0
        public TocEntry(XElement element, string ncxFolder, Dictionary <string, EpubItem> absolutePathIndex)
        {
            Title = element.Element(Epub.ncxNs + "navLabel").Element(Epub.ncxNs + "text").Value;
            string src = element.Element(Epub.ncxNs + "content").Attribute("src").Value;

            int index = src.IndexOf("#");

            if (0 < index)
            {
                Anchor = src.Substring(index);
                src    = src.Substring(0, index);
            }

            Item     = absolutePathIndex[ZipUtils.RelativePathToAbsolute(ncxFolder, src)];
            Children = element.Elements(Epub.ncxNs + "navPoint")
                       .Select(e => new TocEntry(e, ncxFolder, absolutePathIndex))
                       .ToList();
        }
Example #3
0
        public void RemoveImageLink(string absolutePath)
        {
            string relativePath = ZipUtils.AbsolutePathToRelative(AbsolutePath.GetZipPath(), absolutePath);
            var    doc          = RawBytes.ToXhtml();
            bool   changed      = false;

            foreach (var element in FindImageElements(doc))
            {
                var href = element.GetImageHref();
                if (relativePath == href)
                {
                    doc.RemoveImage(element);
                    changed = true;
                }
            }
            if (changed)
            {
                RawBytes = doc.ToSBytes();
            }
        }
Example #4
0
        public XElement ToNavPoint(ref int playOrder, string ncxFolder)
        {
            ++playOrder;
            var navPoint = new XElement(Epub.ncxNs + "navPoint",
                                        new XAttribute("id", "body" + playOrder.ToString("D4")),
                                        new XAttribute("playOrder", playOrder),
                                        new XElement(Epub.ncxNs + "navLabel",
                                                     new XElement(Epub.ncxNs + "text", Title)
                                                     ),
                                        new XElement(Epub.ncxNs + "content",
                                                     new XAttribute("src", ZipUtils.AbsolutePathToRelative(ncxFolder, ContentSrc) + Anchor)
                                                     )
                                        );

            foreach (var e in Children)
            {
                navPoint.Add(e.ToNavPoint(ref playOrder, ncxFolder));
            }
            return(navPoint);
        }