Exemplo n.º 1
0
        public static EpubContentRef ParseContentMap(EpubBookRef bookRef)
        {
            var result = new EpubContentRef
            {
                Html     = new Dictionary <string, EpubTextContentFileRef>(),
                Css      = new Dictionary <string, EpubTextContentFileRef>(),
                Images   = new Dictionary <string, EpubByteContentFileRef>(),
                Fonts    = new Dictionary <string, EpubByteContentFileRef>(),
                AllFiles = new Dictionary <string, EpubContentFileRef>()
            };

            foreach (var manifestItem in bookRef.Schema.Package.Manifest)
            {
                var fileName        = manifestItem.Href;
                var contentMimeType = manifestItem.MediaType;
                var contentType     = GetContentTypeByContentMimeType(contentMimeType);
                switch (contentType)
                {
                case EpubContentType.XHTML_1_1:
                case EpubContentType.CSS:
                case EpubContentType.OEB1_DOCUMENT:
                case EpubContentType.OEB1_CSS:
                case EpubContentType.XML:
                case EpubContentType.DTBOOK:
                case EpubContentType.DTBOOK_NCX:
                    var epubTextContentFile = new EpubTextContentFileRef(bookRef)
                    {
                        FileName        = fileName,
                        ContentMimeType = contentMimeType,
                        ContentType     = contentType
                    };
                    switch (contentType)
                    {
                    case EpubContentType.XHTML_1_1:
                        result.Html[fileName] = epubTextContentFile;
                        break;

                    case EpubContentType.CSS:
                        result.Css[fileName] = epubTextContentFile;
                        break;
                    }

                    result.AllFiles[fileName] = epubTextContentFile;
                    break;

                default:
                    var epubByteContentFile = new EpubByteContentFileRef(bookRef)
                    {
                        FileName        = fileName,
                        ContentMimeType = contentMimeType,
                        ContentType     = contentType
                    };
                    switch (contentType)
                    {
                    case EpubContentType.IMAGE_GIF:
                    case EpubContentType.IMAGE_JPEG:
                    case EpubContentType.IMAGE_PNG:
                    case EpubContentType.IMAGE_SVG:
                        result.Images[fileName] = epubByteContentFile;
                        break;

                    case EpubContentType.FONT_TRUETYPE:
                    case EpubContentType.FONT_OPENTYPE:
                        result.Fonts[fileName] = epubByteContentFile;
                        break;
                    }

                    result.AllFiles[fileName] = epubByteContentFile;
                    break;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public static EpubContentRef ParseContentMap(EpubBookRef bookRef)
        {
            EpubContentRef result = new EpubContentRef
            {
                Html     = new Dictionary <string, EpubTextContentFileRef>(),
                Css      = new Dictionary <string, EpubTextContentFileRef>(),
                Images   = new Dictionary <string, EpubByteContentFileRef>(System.StringComparer.OrdinalIgnoreCase),
                Fonts    = new Dictionary <string, EpubByteContentFileRef>(),
                AllFiles = new Dictionary <string, EpubContentFileRef>()
            };

            foreach (EpubManifestItem manifestItem in bookRef.Schema.Package.Manifest)
            {
                string          fileName        = manifestItem.Href;
                string          contentMimeType = manifestItem.MediaType;
                EpubContentType contentType     = GetContentTypeByContentMimeType(contentMimeType);
                switch (contentType)
                {
                case EpubContentType.XHTML_1_1:
                case EpubContentType.CSS:
                case EpubContentType.OEB1_DOCUMENT:
                case EpubContentType.OEB1_CSS:
                case EpubContentType.XML:
                case EpubContentType.DTBOOK:
                case EpubContentType.DTBOOK_NCX:
                    EpubTextContentFileRef epubTextContentFile = new EpubTextContentFileRef(bookRef)
                    {
                        FileName        = fileName,
                        ContentMimeType = contentMimeType,
                        ContentType     = contentType
                    };
                    switch (contentType)
                    {
                    case EpubContentType.XHTML_1_1:
                        result.Html[fileName] = epubTextContentFile;
                        break;

                    case EpubContentType.CSS:
                        result.Css[fileName] = epubTextContentFile;
                        break;
                    }
                    result.AllFiles[fileName] = epubTextContentFile;
                    break;

                default:
                    EpubByteContentFileRef epubByteContentFile = new EpubByteContentFileRef(bookRef)
                    {
                        FileName        = fileName,
                        ContentMimeType = contentMimeType,
                        ContentType     = contentType
                    };
                    switch (contentType)
                    {
                    case EpubContentType.IMAGE_GIF:
                    case EpubContentType.IMAGE_JPEG:
                    case EpubContentType.IMAGE_PNG:
                    case EpubContentType.IMAGE_SVG:
                        result.Images[fileName] = epubByteContentFile;
                        break;

                    case EpubContentType.FONT_TRUETYPE:
                    case EpubContentType.FONT_OPENTYPE:
                        result.Fonts[fileName] = epubByteContentFile;
                        break;
                    }
                    result.AllFiles[fileName] = epubByteContentFile;
                    break;
                }
            }
            result.Cover = BookCoverReader.ReadBookCover(bookRef.Schema, result.Images);
            return(result);
        }