From 9cb511e8d827a02b7a5c29c636bd971d113f6d2e Mon Sep 17 00:00:00 2001 From: Antecer Date: Mon, 23 Nov 2020 19:40:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=AF=86=E5=88=AB=E5=AD=97?= =?UTF-8?q?=E4=BD=93=E7=BC=96=E7=A0=81=E8=8C=83=E5=9B=B4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/JsExtensions.kt | 6 ++---- .../io/legado/app/model/analyzeRule/QueryTTF.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index fb547c7ec..9810228fe 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -270,15 +270,13 @@ interface JsExtensions { fun replaceFont( text: String, font1: QueryTTF?, - font2: QueryTTF?, - start: Int, - end: Int + font2: QueryTTF? ): String { if (font1 == null || font2 == null) return text val contentArray = text.toCharArray() contentArray.forEachIndexed { index, s -> val oldCode = s.toInt() - if (oldCode in start until end) { + if (font1.InLimit(s)) { val code = font2.GetCodeByGlyf(font1.GetGlyfByCode(oldCode)) if(code != 0) contentArray[index] = code.toChar() } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/QueryTTF.java b/app/src/main/java/io/legado/app/model/analyzeRule/QueryTTF.java index 3348fad09..b7c47d7f1 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/QueryTTF.java +++ b/app/src/main/java/io/legado/app/model/analyzeRule/QueryTTF.java @@ -233,6 +233,8 @@ public class QueryTTF { public final Map CodeToGlyph = new HashMap<>(); public final Map GlyphToCode = new HashMap<>(); + private int LimitMix = 0; + private int LimitMax = 0; /** * 构造函数 @@ -475,6 +477,8 @@ public class QueryTTF { for (short b : Glyf.get(gid).xCoordinates) sb.append(b); for (short b : Glyf.get(gid).yCoordinates) sb.append(b); String val = sb.toString(); + if(LimitMix == 0) LimitMix = key; + LimitMax = key; CodeToGlyph.put(key, val); if (GlyphToCode.containsKey(val)) continue; GlyphToCode.put(val, key); @@ -564,6 +568,15 @@ public class QueryTTF { return glyfID; } + /** + * 判断Unicode值是否在字体范围内 + * @param code 传入Unicode十进制值 + * @return 返回bool查询结果 + */ + public boolean InLimit(char code){ + return (LimitMix <= code) && (code < LimitMax); + } + /** * 使用Unicode值获取轮廓数据 *