From 3e8f2f6f2893ca6b0ca6e6374e329c9e3bd6b6f3 Mon Sep 17 00:00:00 2001 From: vers-one <12114169+vers-one@users.noreply.github.com> Date: Mon, 3 Jun 2024 22:11:41 -0400 Subject: [PATCH] BMP image files support (#114) --- .../Unit/Readers/ContentReaderTests.cs | 97 ++++++++++--------- .../Content/Base/EpubContentType.cs | 5 + Source/VersOne.Epub/Readers/ContentReader.cs | 3 + 3 files changed, 61 insertions(+), 44 deletions(-) diff --git a/Source/VersOne.Epub.Test/Unit/Readers/ContentReaderTests.cs b/Source/VersOne.Epub.Test/Unit/Readers/ContentReaderTests.cs index 2348d06..c606555 100644 --- a/Source/VersOne.Epub.Test/Unit/Readers/ContentReaderTests.cs +++ b/Source/VersOne.Epub.Test/Unit/Readers/ContentReaderTests.cs @@ -52,199 +52,205 @@ public void ParseContentMapWithFullEpubSchemaTest() ( items: new List() { - new EpubManifestItem + new ( id: "item-html", href: "text.html", mediaType: "application/xhtml+xml" ), - new EpubManifestItem + new ( id: "item-dtb", href: "doc.dtb", mediaType: "application/x-dtbook+xml" ), - new EpubManifestItem + new ( id: "item-ncx", href: "toc.ncx", mediaType: "application/x-dtbncx+xml" ), - new EpubManifestItem + new ( id: "item-oeb", href: "oeb.html", mediaType: "text/x-oeb1-document" ), - new EpubManifestItem + new ( id: "item-xml", href: "file.xml", mediaType: "application/xml" ), - new EpubManifestItem + new ( id: "item-css", href: "styles.css", mediaType: "text/css" ), - new EpubManifestItem + new ( id: "item-oebcss", href: "oeb.css", mediaType: "text/x-oeb1-css" ), - new EpubManifestItem + new ( id: "item-js-1", href: "script1.js", mediaType: "application/javascript" ), - new EpubManifestItem + new ( id: "item-js-2", href: "script2.js", mediaType: "application/ecmascript" ), - new EpubManifestItem + new ( id: "item-js-3", href: "script3.js", mediaType: "text/javascript" ), - new EpubManifestItem + new ( id: "item-gif", href: "image.gif", mediaType: "image/gif" ), - new EpubManifestItem + new ( id: "item-jpg", href: "image.jpg", mediaType: "image/jpeg" ), - new EpubManifestItem + new ( id: "item-png", href: "image.png", mediaType: "image/png" ), - new EpubManifestItem + new ( id: "item-svg", href: "image.svg", mediaType: "image/svg+xml" ), - new EpubManifestItem + new ( id: "item-webp", href: "image.webp", mediaType: "image/webp" ), - new EpubManifestItem + new + ( + id: "item-bmp", + href: "image.bmp", + mediaType: "image/bmp" + ), + new ( id: "item-ttf-1", href: "font1.ttf", mediaType: "font/truetype" ), - new EpubManifestItem + new ( id: "item-ttf-2", href: "font2.ttf", mediaType: "font/ttf" ), - new EpubManifestItem + new ( id: "item-ttf-3", href: "font3.ttf", mediaType: "application/x-font-truetype" ), - new EpubManifestItem + new ( id: "item-otf-1", href: "font1.otf", mediaType: "font/opentype" ), - new EpubManifestItem + new ( id: "item-otf-2", href: "font2.otf", mediaType: "font/otf" ), - new EpubManifestItem + new ( id: "item-otf-3", href: "font3.otf", mediaType: "application/vnd.ms-opentype" ), - new EpubManifestItem + new ( id: "item-sfnt-1", href: "font.aat", mediaType: "font/sfnt" ), - new EpubManifestItem + new ( id: "item-sfnt-2", href: "font.sil", mediaType: "application/font-sfnt" ), - new EpubManifestItem + new ( id: "item-woff-1", href: "font1.woff", mediaType: "font/woff" ), - new EpubManifestItem + new ( id: "item-woff-2", href: "font2.woff", mediaType: "application/font-woff" ), - new EpubManifestItem + new ( id: "item-woff2", href: "font.woff2", mediaType: "font/woff2" ), - new EpubManifestItem + new ( id: "item-smil", href: "narration.smil", mediaType: "application/smil+xml" ), - new EpubManifestItem + new ( id: "item-mp3", href: "audio.mp3", mediaType: "audio/mpeg" ), - new EpubManifestItem + new ( id: "item-mp4", href: "audio.mp4", mediaType: "audio/mp4" ), - new EpubManifestItem + new ( id: "item-ogg-1", href: "audio1.opus", mediaType: "audio/ogg" ), - new EpubManifestItem + new ( id: "item-ogg-2", href: "audio2.opus", mediaType: "audio/ogg; codecs=opus" ), - new EpubManifestItem + new ( id: "item-video", href: "video.mp4", mediaType: "video/mp4" ), - new EpubManifestItem + new ( id: "item-cover", href: "cover.jpg", @@ -254,7 +260,7 @@ public void ParseContentMapWithFullEpubSchemaTest() EpubManifestProperty.COVER_IMAGE } ), - new EpubManifestItem + new ( id: "item-toc", href: "toc.html", @@ -264,31 +270,31 @@ public void ParseContentMapWithFullEpubSchemaTest() EpubManifestProperty.NAV } ), - new EpubManifestItem + new ( id: "item-remote-html", href: "https://example.com/books/123/test.html", mediaType: "application/xhtml+xml" ), - new EpubManifestItem + new ( id: "item-remote-css", href: "https://example.com/books/123/test.css", mediaType: "text/css" ), - new EpubManifestItem + new ( id: "item-remote-jpg", href: "https://example.com/books/123/image.jpg", mediaType: "image/jpeg" ), - new EpubManifestItem + new ( id: "item-remote-ttf", href: "https://example.com/books/123/font.ttf", mediaType: "font/truetype" ), - new EpubManifestItem + new ( id: "item-remote-mp3", href: "https://example.com/books/123/audio.mp3", @@ -312,6 +318,7 @@ public void ParseContentMapWithFullEpubSchemaTest() EpubLocalByteContentFileRef expectedPngFileRef = CreateLocalByteFileRef("image.png", EpubContentType.IMAGE_PNG, "image/png"); EpubLocalByteContentFileRef expectedSvgFileRef = CreateLocalByteFileRef("image.svg", EpubContentType.IMAGE_SVG, "image/svg+xml"); EpubLocalByteContentFileRef expectedWebpFileRef = CreateLocalByteFileRef("image.webp", EpubContentType.IMAGE_WEBP, "image/webp"); + EpubLocalByteContentFileRef expectedBmpFileRef = CreateLocalByteFileRef("image.bmp", EpubContentType.IMAGE_BMP, "image/bmp"); EpubLocalByteContentFileRef expectedTtf1FileRef = CreateLocalByteFileRef("font1.ttf", EpubContentType.FONT_TRUETYPE, "font/truetype"); EpubLocalByteContentFileRef expectedTtf2FileRef = CreateLocalByteFileRef("font2.ttf", EpubContentType.FONT_TRUETYPE, "font/ttf"); EpubLocalByteContentFileRef expectedTtf3FileRef = CreateLocalByteFileRef("font3.ttf", EpubContentType.FONT_TRUETYPE, "application/x-font-truetype"); @@ -360,6 +367,7 @@ public void ParseContentMapWithFullEpubSchemaTest() expectedPngFileRef, expectedSvgFileRef, expectedWebpFileRef, + expectedBmpFileRef, expectedCoverFileRef }; List expectedImagesRemote = new() @@ -412,6 +420,7 @@ public void ParseContentMapWithFullEpubSchemaTest() expectedPngFileRef, expectedSvgFileRef, expectedWebpFileRef, + expectedBmpFileRef, expectedTtf1FileRef, expectedTtf2FileRef, expectedTtf3FileRef, @@ -465,13 +474,13 @@ public void ParseContentMapWithRemoteTextContentFilesTest() ( items: new List() { - new EpubManifestItem + new ( id: "item-1", href: "https://example.com/books/123/test.html", mediaType: "application/xhtml+xml" ), - new EpubManifestItem + new ( id: "item-2", href: "https://example.com/books/123/test.css", @@ -515,13 +524,13 @@ public void ParseContentMapWithRemoteByteContentFilesTest() ( items: new List() { - new EpubManifestItem + new ( id: "item-1", href: "https://example.com/books/123/image.jpg", mediaType: "image/jpeg" ), - new EpubManifestItem + new ( id: "item-2", href: "https://example.com/books/123/font.ttf", @@ -565,7 +574,7 @@ public void ParseContentMapWithRemoteNavigationDocumentTest() ( items: new List() { - new EpubManifestItem + new ( id: "item-toc", href: "http://example.com/toc.html", diff --git a/Source/VersOne.Epub/Content/Base/EpubContentType.cs b/Source/VersOne.Epub/Content/Base/EpubContentType.cs index 8adabb1..1253ccd 100644 --- a/Source/VersOne.Epub/Content/Base/EpubContentType.cs +++ b/Source/VersOne.Epub/Content/Base/EpubContentType.cs @@ -70,6 +70,11 @@ public enum EpubContentType /// IMAGE_WEBP, + /// + /// A file with 'image/bmp' MIME type. + /// + IMAGE_BMP, + /// /// A file with either 'font/truetype', 'font/ttf', or 'application/x-font-truetype' MIME type. /// diff --git a/Source/VersOne.Epub/Readers/ContentReader.cs b/Source/VersOne.Epub/Readers/ContentReader.cs index 176f1a6..b76dd66 100644 --- a/Source/VersOne.Epub/Readers/ContentReader.cs +++ b/Source/VersOne.Epub/Readers/ContentReader.cs @@ -105,6 +105,7 @@ public EpubContentRef ParseContentMap(EpubSchema epubSchema, IZipFile epubFile) case EpubContentType.IMAGE_PNG: case EpubContentType.IMAGE_SVG: case EpubContentType.IMAGE_WEBP: + case EpubContentType.IMAGE_BMP: imagesLocal.Add(localByteContentFile); break; case EpubContentType.FONT_TRUETYPE: @@ -133,6 +134,7 @@ public EpubContentRef ParseContentMap(EpubSchema epubSchema, IZipFile epubFile) case EpubContentType.IMAGE_PNG: case EpubContentType.IMAGE_SVG: case EpubContentType.IMAGE_WEBP: + case EpubContentType.IMAGE_BMP: imagesRemote.Add(remoteByteContentFile); break; case EpubContentType.FONT_TRUETYPE: @@ -180,6 +182,7 @@ private static EpubContentType GetContentTypeByContentMimeType(string contentMim "image/png" => EpubContentType.IMAGE_PNG, "image/svg+xml" => EpubContentType.IMAGE_SVG, "image/webp" => EpubContentType.IMAGE_WEBP, + "image/bmp" => EpubContentType.IMAGE_BMP, "font/truetype" or "font/ttf" or "application/x-font-truetype" => EpubContentType.FONT_TRUETYPE, "font/opentype" or "font/otf" or "application/vnd.ms-opentype" => EpubContentType.FONT_OPENTYPE, "font/sfnt" or "application/font-sfnt" => EpubContentType.FONT_SFNT,