diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index 0267e7743..3620ed00c 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -207,7 +207,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { //set css epubBook.resources.add( Resource( - "body{background:white;margin:0;}h2{color:#005a9c;text-align:left;}p{text-indent:2em;text-align:justify;}img{width:100%;height:100%;max-width: 100%;max-height:100%;}".encodeToByteArray(), + "body,div{background:white;margin:0 auto;}padding:0;outline:none;width:100%;}h2{color:#005a9c;text-align:left;}p{text-indent:2em;text-align:justify;}img{display:inline-block;width:100%;height:100%;max-width: 100%;max-height:100%;}".encodeToByteArray(), "css/style.css" ) ) diff --git a/epublib/src/main/java/me/ag2s/epublib/util/ResourceUtil.java b/epublib/src/main/java/me/ag2s/epublib/util/ResourceUtil.java index eccf1d657..b9425b4c8 100644 --- a/epublib/src/main/java/me/ag2s/epublib/util/ResourceUtil.java +++ b/epublib/src/main/java/me/ag2s/epublib/util/ResourceUtil.java @@ -60,9 +60,15 @@ public class ResourceUtil { private static String createHtml(String title, String txt) { StringBuilder body = new StringBuilder(); for (String s : txt.split("\\r?\\n")) { - s = s.trim(); + s=StringUtil.FixTrim(s); if (s.length() != 0) { - body.append("
").append(s).append("
"); + if(s.contains("") + body.append(s);//.append(""); + }else { + body.append("").append(s).append("
"); + } + } } diff --git a/epublib/src/main/java/me/ag2s/epublib/util/StringUtil.java b/epublib/src/main/java/me/ag2s/epublib/util/StringUtil.java index 677d6a157..b24a283dd 100644 --- a/epublib/src/main/java/me/ag2s/epublib/util/StringUtil.java +++ b/epublib/src/main/java/me/ag2s/epublib/util/StringUtil.java @@ -3,6 +3,8 @@ package me.ag2s.epublib.util; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Various String utility functions. @@ -271,4 +273,18 @@ public class StringUtil { } return text.substring(cPos + 1); } + public static String FixTrim(String s) { + if (s==null){ + return "null"; + } + Pattern r = Pattern.compile("^[\\s]{1,9}(.*?)[\\s]{1,9}$"); + Matcher m = r.matcher(s); + if (m.find()) { + s= m.group(1); + } + //移除GBK中文全角空格 + s = s.replace(" ", ""); + return s; + } + }