示例#1
0
        public static string FixupUrl(string uri, string itemPath, Dictionary <string, string> newAbsolutePaths)
        {
            // special case, it's a link to anchor on same page
            if (uri[0] == '#')
            {
                return(uri);
            }

            // internal URLs are relative, so, if not relative
            // leave it alone
            Uri testUrl = null;

            if (!Uri.TryCreate(uri, UriKind.Relative, out testUrl))
            {
                return(uri);
            }

            var    fragments       = uri.Split(new char[] { '#' });
            var    path            = fragments[0];
            var    urlAbsolutePath = ZipUtils.RelativePathToAbsolute(itemPath, path);
            string newAbsolutePath = null;

            if (!newAbsolutePaths.TryGetValue(urlAbsolutePath, out newAbsolutePath))
            {
                // URL isn't in set to update
                return(uri);
            }
            var newRelativePath = ZipUtils.AbsolutePathToRelative(itemPath, newAbsolutePath);

            if (2 == fragments.Length)
            {
                newRelativePath += "#" + fragments[1];
            }
            return(newRelativePath);
        }
示例#2
0
        public void AddImagesTo(Epub.ImageUseIndex index)
        {
            string    itemPath = AbsolutePath.GetZipPath();
            XDocument doc      = null;

            try
            {
                doc = RawBytes.ToXhtml();
            }
            catch
            {
                System.Diagnostics.Trace.WriteLine($"XML Error with file {AbsolutePath}");
                return;
            }

            foreach (var element in FindImageElements(doc))
            {
                HashSet <EpubItem> set = null;
                var href            = element.GetImageHref();
                var urlAbsolutePath = ZipUtils.RelativePathToAbsolute(itemPath, href);
                if (!index.TryGetValue(urlAbsolutePath, out set))
                {
                    set = new HashSet <EpubItem>();
                    index.Add(urlAbsolutePath, set);
                }
                set.Add(this);
            }
        }
示例#3
0
        public EpubItem(XElement element, string opfFolder)
        {
            this.Id = element.Attribute("id").Value;
            string relativePath = element.Attribute("href").Value;

            this.AbsolutePath = ZipUtils.RelativePathToAbsolute(opfFolder, relativePath);
            this.MediaType    = element.Attribute("media-type").Value;
        }
示例#4
0
        public GuideReference(XElement element, string opfFolder, Dictionary <string, EpubItem> absolutePathIndex)
        {
            string   path = ZipUtils.RelativePathToAbsolute(opfFolder, element.Attribute("href").Value);
            EpubItem temp = null;

            absolutePathIndex.TryGetValue(path, out temp);
            Item     = temp;
            Title    = element.Attribute("title")?.Value;
            TypeName = element.Attribute("type").Value;
        }
示例#5
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();
        }