Compare commits

..

1 Commits

7 changed files with 38 additions and 86 deletions

Binary file not shown.

View File

@ -1 +1 @@
{"x86_64":"70374d614c6370f39ecc33c3a4a71886","arm64-v8a":"4231b5852366a17ef66bfc47c9e1e9bd","armeabi-v7a":"3c6edf29c6cc021e2a335f17c80c9a18","x86":"d0d33c9f93b4be1141214456757db621","version":"126.0.6478.72"} {"x86":"4d5fe1bc02fc4fb6665f67432cc73fbd","arm64-v8a":"f2c2fce1963d94a69a94df6fd1192516","armeabi-v7a":"159a459afb43d5673797fcf56a25bcfe","x86_64":"bccadd9e510731eb5256234707df67ea","version":"126.0.6478.71"}

View File

@ -13,7 +13,7 @@
* 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源!
**2024/02/27** **2024/02/27**
* 更新cronet: 126.0.6478.72 * 更新cronet: 126.0.6478.71
* 更新cronet: 123.0.6312.80 * 更新cronet: 123.0.6312.80
* 更新cronet: 123.0.6312.40 * 更新cronet: 123.0.6312.40

View File

@ -57,7 +57,6 @@ import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.net.URLEncoder import java.net.URLEncoder
import java.nio.charset.Charset import java.nio.charset.Charset
import java.security.MessageDigest
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Date import java.util.Date
import java.util.Locale import java.util.Locale
@ -749,68 +748,45 @@ interface JsExtensions : JsEncodeUtils {
//******************文件操作************************// //******************文件操作************************//
/** /**
* 解析字体Base64数据,返回字体解析类 * 解析字体,返回字体解析类
*/ */
fun queryBase64TTF(data: String?): QueryTTF? { fun queryBase64TTF(base64: String?): QueryTTF? {
log("queryBase64TTF(String)方法已过时,并将在未来删除请无脑使用queryTTF(Any)替代,新方法支持传入 url、本地文件、base64、ByteArray 自动判断&自动缓存特殊情况需禁用缓存请传入第二可选参数false:Boolean") base64DecodeToByteArray(base64)?.let {
return queryTTF(data) return QueryTTF(it)
}
return null
} }
/** /**
* 返回字体解析类 * 返回字体解析类
* @param data 支持url,本地文件,base64,ByteArray,自动判断,自动缓存 * @param str 支持url,本地文件,base64,自动判断,自动缓存
* @param useCache 可选开关缓存,不传入该值默认开启缓存
*/ */
@OptIn(ExperimentalStdlibApi::class) fun queryTTF(str: String?): QueryTTF? {
fun queryTTF(data: Any?, useCache: Boolean): QueryTTF? { str ?: return null
try { try {
var key: String? = null val key = md5Encode16(str)
var qTTF: QueryTTF? var qTTF = CacheManager.getQueryTTF(key)
when (data) { if (qTTF != null) return qTTF
is String -> { val font: ByteArray? = when {
if (useCache) { str.isAbsUrl() -> AnalyzeUrl(str, source = getSource()).getByteArray()
key = MessageDigest.getInstance("SHA-256").digest(data.toByteArray()).toHexString() str.isContentScheme() -> Uri.parse(str).readBytes(appCtx)
qTTF = CacheManager.getQueryTTF(key) str.startsWith("/storage") -> File(str).readBytes()
if (qTTF != null) return qTTF else -> base64DecodeToByteArray(str)
}
val font: ByteArray? = when {
data.isContentScheme() -> Uri.parse(data).readBytes(appCtx)
data.startsWith("/storage") -> File(data).readBytes()
data.isAbsUrl() -> AnalyzeUrl(data, source = getSource()).getByteArray()
else -> base64DecodeToByteArray(data)
}
font ?: return null
qTTF = QueryTTF(font)
}
is ByteArray -> {
if (useCache) {
key = MessageDigest.getInstance("SHA-256").digest(data).toHexString()
qTTF = CacheManager.getQueryTTF(key)
if (qTTF != null) return qTTF
}
qTTF = QueryTTF(data)
}
else -> return null
} }
if (key != null) CacheManager.put(key, qTTF) font ?: return null
qTTF = QueryTTF(font)
CacheManager.put(key, qTTF) // debug注释掉
return qTTF return qTTF
} catch (e: Exception) { } catch (e: Exception) {
AppLog.put("[queryTTF] 获取字体处理类出错", e) AppLog.put("获取字体处理类出错", e)
throw e throw e
} }
} }
fun queryTTF(data: Any?): QueryTTF? {
return queryTTF(data, true)
}
/** /**
* @param text 包含错误字体的内容 * @param text 包含错误字体的内容
* @param errorQueryTTF 错误的字体 * @param errorQueryTTF 错误的字体
* @param correctQueryTTF 正确的字体 * @param correctQueryTTF 正确的字体
* @param filter 删除 errorQueryTTF 中不存在的字符
*/ */
fun replaceFont( fun replaceFont(
text: String, text: String,
@ -826,9 +802,8 @@ interface JsExtensions : JsEncodeUtils {
if (errorQueryTTF.isBlankUnicode(oldCode)) { if (errorQueryTTF.isBlankUnicode(oldCode)) {
return@forEachIndexed return@forEachIndexed
} }
val glyf = errorQueryTTF.getGlyfByUnicode(oldCode)
// 删除轮廓数据不存在的字符 // 删除轮廓数据不存在的字符
var glyf = errorQueryTTF.getGlyfByUnicode(oldCode) // 轮廓数据不存在
if (errorQueryTTF.getGlyfIdByUnicode(oldCode) == 0) glyf = null // 轮廓数据指向保留索引0
if (filter && (glyf == null)) { if (filter && (glyf == null)) {
contentArray[index] = "" contentArray[index] = ""
return@forEachIndexed return@forEachIndexed
@ -842,11 +817,6 @@ interface JsExtensions : JsEncodeUtils {
return contentArray.joinToString("") return contentArray.joinToString("")
} }
/**
* @param text 包含错误字体的内容
* @param errorQueryTTF 错误的字体
* @param correctQueryTTF 正确的字体
*/
fun replaceFont( fun replaceFont(
text: String, text: String,
errorQueryTTF: QueryTTF?, errorQueryTTF: QueryTTF?,

View File

@ -648,8 +648,6 @@ public class QueryTTF {
var reader = new BufferReader(buffer, dataTable.offset); var reader = new BufferReader(buffer, dataTable.offset);
if (head.indexToLocFormat == 0) { if (head.indexToLocFormat == 0) {
loca = reader.ReadUInt16Array(dataTable.length / 2); loca = reader.ReadUInt16Array(dataTable.length / 2);
// 当loca表数据长度为Uint16时,需要翻倍
for (var i = 0; i < loca.length; i++) loca[i] *= 2;
} else { } else {
loca = reader.ReadInt32Array(dataTable.length / 4); loca = reader.ReadInt32Array(dataTable.length / 4);
} }
@ -685,7 +683,6 @@ public class QueryTTF {
int unicodeInclusive = 0; int unicodeInclusive = 0;
int unicodeExclusive = f.glyphIdArray.length; int unicodeExclusive = f.glyphIdArray.length;
for (; unicodeInclusive < unicodeExclusive; unicodeInclusive++) { for (; unicodeInclusive < unicodeExclusive; unicodeInclusive++) {
if (f.glyphIdArray[unicodeInclusive] == 0) continue; // 排除轮廓索引为0的Unicode
unicodeToGlyphId.put(unicodeInclusive, f.glyphIdArray[unicodeInclusive]); unicodeToGlyphId.put(unicodeInclusive, f.glyphIdArray[unicodeInclusive]);
} }
break; break;
@ -712,15 +709,12 @@ public class QueryTTF {
int idDelta = f.idDelta[segmentIndex]; int idDelta = f.idDelta[segmentIndex];
int idRangeOffset = f.idRangeOffsets[segmentIndex]; int idRangeOffset = f.idRangeOffsets[segmentIndex];
for (int unicode = unicodeInclusive; unicode <= unicodeExclusive; unicode++) { for (int unicode = unicodeInclusive; unicode <= unicodeExclusive; unicode++) {
int glyphId = 0;
if (idRangeOffset == 0) { if (idRangeOffset == 0) {
glyphId = (unicode + idDelta) & 0xFFFF; unicodeToGlyphId.put(unicode, (unicode + idDelta) & 0xFFFF);
} else { } else {
int gIndex = (idRangeOffset / 2) + unicode - unicodeInclusive + segmentIndex - segCount; int gIndex = (idRangeOffset / 2) + unicode - unicodeInclusive + segmentIndex;
if (gIndex < glyphIdArrayLength) glyphId = f.glyphIdArray[gIndex] + idDelta; unicodeToGlyphId.put(unicode, gIndex < glyphIdArrayLength ? f.glyphIdArray[gIndex] + idDelta : 0);
} }
if (glyphId == 0) continue; // 排除轮廓索引为0的Unicode
unicodeToGlyphId.put(unicode, glyphId);
} }
} }
break; break;
@ -777,24 +771,21 @@ public class QueryTTF {
var dataTable = directorys.get("glyf"); var dataTable = directorys.get("glyf");
assert dataTable != null; assert dataTable != null;
int glyfCount = maxp.numGlyphs; int glyfCount = maxp.numGlyphs;
glyfArray = new GlyfLayout[glyfCount]; // 创建字形容器 glyfArray = new GlyfLayout[glyfCount + 1]; // 创建容器多创建一个作为保留区
var reader = new BufferReader(buffer, 0); var reader = new BufferReader(buffer, 0);
for (int index = 0; index < glyfCount; index++) { for (int index = 1; index <= glyfCount; index++) {
if (loca[index] == loca[index + 1]) continue; // 当前loca与下一个loca相同表示这个字形不存在 if (loca[index - 1] == loca[index]) continue; // 当前loca与下一个loca相同表示这个字形不存在
int offset = dataTable.offset + loca[index]; int offset = dataTable.offset + loca[index - 1];
// 读GlyphHeaders // 读GlyphHeaders
var glyph = new GlyfLayout(); var glyph = new GlyfLayout();
reader.position(offset); reader.position(offset);
glyph.numberOfContours = reader.ReadInt16(); glyph.numberOfContours = reader.ReadInt16();
if (glyph.numberOfContours > maxp.maxContours) continue; // 如果字形轮廓数大于非复合字形中包含的最大轮廓数则说明该字形无效
glyph.xMin = reader.ReadInt16(); glyph.xMin = reader.ReadInt16();
glyph.yMin = reader.ReadInt16(); glyph.yMin = reader.ReadInt16();
glyph.xMax = reader.ReadInt16(); glyph.xMax = reader.ReadInt16();
glyph.yMax = reader.ReadInt16(); glyph.yMax = reader.ReadInt16();
// 轮廓数为0时不需要解析轮廓数据
if (glyph.numberOfContours == 0) continue;
// 读Glyph轮廓数据 // 读Glyph轮廓数据
if (glyph.numberOfContours > 0) { if (glyph.numberOfContours > 0) {
// 简单轮廓 // 简单轮廓
@ -897,7 +888,7 @@ public class QueryTTF {
if ((glyphTableComponent.flags & 0x20) == 0) break; if ((glyphTableComponent.flags & 0x20) == 0) break;
} }
} }
glyfArray[index] = glyph; glyfArray[index] = glyph; // 根据文档 glyfId=0 作为保留区使用这里赋值从索引1开始
} }
} }
@ -923,15 +914,7 @@ public class QueryTTF {
// 复合字形 // 复合字形
LinkedList<String> glyphIdList = new LinkedList<>(); LinkedList<String> glyphIdList = new LinkedList<>();
for (var g : glyph.glyphComponent) { for (var g : glyph.glyphComponent) {
glyphIdList.add("{" + glyphIdList.add(String.valueOf(g.glyphIndex));
"flags:" + g.flags + "," +
"glyphIndex:" + g.glyphIndex + "," +
"arg1:" + g.argument1 + "," +
"arg2:" + g.argument2 + "," +
"xScale:" + g.xScale + "," +
"scale01:" + g.scale01 + "," +
"scale10:" + g.scale10 + "," +
"yScale:" + g.yScale + "}");
} }
glyphString = "[" + String.join(",", glyphIdList) + "]"; glyphString = "[" + String.join(",", glyphIdList) + "]";
} }
@ -977,11 +960,10 @@ public class QueryTTF {
int glyfArrayLength = glyfArray.length; int glyfArrayLength = glyfArray.length;
for (var item : unicodeToGlyphId.entrySet()) { for (var item : unicodeToGlyphId.entrySet()) {
int key = item.getKey(); int key = item.getKey();
int val = item.getValue(); int val = item.getValue() + 1; // glyphArray已根据TTF文档将索引0作为保留位这里从1开始索引
if (val >= glyfArrayLength) continue; if (val >= glyfArrayLength) continue;
String glyfString = getGlyfById(val); String glyfString = getGlyfById(val);
unicodeToGlyph.put(key, glyfString); unicodeToGlyph.put(key, glyfString);
if (glyfString == null) continue; // null 不能用作hashmap的key
glyphToUnicode.put(glyfString, key); glyphToUnicode.put(glyfString, key);
} }
// Log.i("QueryTTF", "字体处理完成"); // Log.i("QueryTTF", "字体处理完成");
@ -999,8 +981,8 @@ public class QueryTTF {
*/ */
public int getGlyfIdByUnicode(int unicode) { public int getGlyfIdByUnicode(int unicode) {
var result = unicodeToGlyphId.get(unicode); var result = unicodeToGlyphId.get(unicode);
if (result == null) return 0; // 如果找不到Unicode对应的轮廓索引就返回默认值0 if (result == null) return 0;
return result; return result + 1; // 根据TTF文档轮廓索引的定义从1开始
} }
/** /**
@ -1021,7 +1003,7 @@ public class QueryTTF {
*/ */
public int getUnicodeByGlyf(String glyph) { public int getUnicodeByGlyf(String glyph) {
var result = glyphToUnicode.get(glyph); var result = glyphToUnicode.get(glyph);
if (result == null) return 0; // 如果轮廓数据找不到对应的Unicode就返回默认值0 if (result == null) return 0;
return result; return result;
} }

View File

@ -42,7 +42,7 @@ android.defaults.buildfeatures.shaders=false
# and none from the library's dependencies, thereby reducing the size of the R class for that library. # and none from the library's dependencies, thereby reducing the size of the R class for that library.
android.nonTransitiveRClass=true android.nonTransitiveRClass=true
# https://chromiumdash.appspot.com/releases?platform=Android # https://chromiumdash.appspot.com/releases?platform=Android
CronetVersion=126.0.6478.72 CronetVersion=126.0.6478.71
CronetMainVersion=126.0.0.0 CronetMainVersion=126.0.0.0
android.injected.testOnly=false android.injected.testOnly=false
android.nonFinalResIds=true android.nonFinalResIds=true