Data URI 支持(EPUB)

pull/1614/head
131 3 years ago
parent 082e088eb4
commit 213196d26c
  1. 13
      epublib/src/main/java/me/ag2s/epublib/domain/Resources.java

@ -10,6 +10,9 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.util.Base64;
/** /**
* All the resources that make up the book. * All the resources that make up the book.
@ -314,8 +317,18 @@ public class Resources implements Serializable {
return null; return null;
} }
href = StringUtil.substringBefore(href, Constants.FRAGMENT_SEPARATOR_CHAR); href = StringUtil.substringBefore(href, Constants.FRAGMENT_SEPARATOR_CHAR);
Pattern dataUriRegex = Pattern.compile("data:([\\w/\\-\\.]+);base64,(.*)");
Matcher dataUriMatcher = dataUriRegex.matcher(href);
if (dataUriMatcher.find()) {
String dataUriMediaTypeString = dataUriMatcher.group(1);
MediaType dataUriMediaType = new MediaType(dataUriMediaTypeString, "." + StringUtil.substringAfterLast(dataUriMediaTypeString, '/'));
byte[] dataUriData = Base64.decode(dataUriMatcher.group(2), Base64.DEFAULT);
return new Resource(dataUriData, dataUriMediaType);
} else {
return resources.get(href); return resources.get(href);
} }
}
/** /**
* Gets the first resource (random order) with the give mediatype. * Gets the first resource (random order) with the give mediatype.

Loading…
Cancel
Save