From eee6570f3233cffeafda5f656899012fcb4d0820 Mon Sep 17 00:00:00 2001 From: ag2s20150909 Date: Tue, 6 Apr 2021 09:25:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87=E6=8E=92?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/cache/CacheViewModel.kt | 2 +- .../java/me/ag2s/epublib/util/ResourceUtil.java | 10 ++++++++-- .../java/me/ag2s/epublib/util/StringUtil.java | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) 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; + } + }