Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
821938089 committed Dec 8, 2023
1 parent d8cc932 commit 27d27b8
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -32,6 +32,8 @@ public class MediaTypes {

public static final MediaType SVG = new MediaType("image/svg+xml", ".svg");

public static final MediaType WEBP = new MediaType("image/webp", ".webp");

// fonts
public static final MediaType TTF = new MediaType(
"application/x-truetype-font", ".ttf");
@@ -56,7 +58,7 @@ public class MediaTypes {
public static final MediaType UNKNOWN = new MediaType("application/octet-stream", "");

public static final MediaType[] mediaTypes = new MediaType[]{
XHTML, EPUB, JPG, PNG, GIF, CSS, SVG, TTF, NCX, XPGT, OPENTYPE, WOFF,
XHTML, EPUB, JPG, PNG, GIF, WEBP, CSS, SVG, TTF, NCX, XPGT, OPENTYPE, WOFF,
SMIL, PLS, JAVASCRIPT, MP3, MP4, OGG, UNKNOWN
};

@@ -69,7 +71,11 @@ public class MediaTypes {
}

public static boolean isBitmapImage(MediaType mediaType) {
return mediaType == JPG || mediaType == PNG || mediaType == GIF;
return mediaType == JPG || mediaType == PNG || mediaType == GIF || mediaType == WEBP;
}

public static boolean isImage(MediaType mediaType) {
return mediaType == JPG || mediaType == PNG || mediaType == GIF || mediaType == SVG || mediaType == WEBP;
}

/**
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ private static ArrayList<Element> ensureImageInfo(Resources resources,
//如果有图片资源未定义在 originItemElements ,则加入该图片信息得到 fixedElements 中
for (Resource resource : resources.getAll()) {
MediaType currentMediaType = resource.getMediaType();
if (currentMediaType == MediaTypes.JPG || currentMediaType == MediaTypes.PNG) {
if (MediaTypes.isImage(currentMediaType)) {
String imageHref = resource.getHref();
//确保该图片信息 resource 在原 originItemHrefSet 集合中没有出现过
if (!originItemHrefSet.contains(imageHref)) {

0 comments on commit 27d27b8

Please sign in to comment.