自动识别字体编码范围.

pull/504/head
Antecer 4 years ago
parent a0e908912e
commit 9cb511e8d8
  1. 6
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  2. 13
      app/src/main/java/io/legado/app/model/analyzeRule/QueryTTF.java

@ -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()
}

@ -233,6 +233,8 @@ public class QueryTTF {
public final Map<Integer, String> CodeToGlyph = new HashMap<>();
public final Map<String, Integer> 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值获取轮廓数据
*

Loading…
Cancel
Save