Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
814d5ddf64
Merge d1af37e04b into 5acfe9be68 2024-06-11 17:03:13 +08:00
7 changed files with 25 additions and 35 deletions

View File

@ -802,9 +802,8 @@ interface JsExtensions : JsEncodeUtils {
if (errorQueryTTF.isBlankUnicode(oldCode)) {
return@forEachIndexed
}
val glyf = errorQueryTTF.getGlyfByUnicode(oldCode)
// 删除轮廓数据不存在的字符
var glyf = errorQueryTTF.getGlyfByUnicode(oldCode) // 轮廓数据不存在
if (errorQueryTTF.getGlyfIdByUnicode(oldCode) == 0) glyf = null; // 轮廓数据指向保留索引0
if (filter && (glyf == null)) {
contentArray[index] = ""
return@forEachIndexed

View File

@ -188,6 +188,7 @@ class ContentProcessor private constructor(
mContent = mContent.replace('\u00A0', ' ')
}
val contents = arrayListOf<String>()
val paragraphIndent = ReadBookConfig.paragraphIndent
mContent.split("\n").forEach { str ->
val paragraph = str.trim {
it.code <= 0x20 || it == ' '
@ -196,10 +197,14 @@ class ContentProcessor private constructor(
if (contents.isEmpty() && includeTitle) {
contents.add(paragraph)
} else {
contents.add("${ReadBookConfig.paragraphIndent}$paragraph")
contents.add("$paragraphIndent$paragraph")
}
}
}
if (contents.isEmpty()) {
contents.add("${paragraphIndent}加载正文失败")
contents.add("${paragraphIndent}内容处理后为空")
}
return BookContent(sameTitleRemoved, contents, effectiveReplaceRules)
}

View File

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

View File

@ -218,7 +218,7 @@ abstract class BaseReadAloudService : BaseService(),
}
nowSpeak = textChapter.getParagraphNum(readAloudNumber + 1, readAloudByPage) - 1
if (!readAloudByPage && startPos == 0 && !toLast) {
pos = page.chapterPosition -
pos = page.lines.first().chapterPosition -
textChapter.paragraphs[nowSpeak].chapterPosition
}
if (toLast) {
@ -226,7 +226,7 @@ abstract class BaseReadAloudService : BaseService(),
readAloudNumber = textChapter.getLastParagraphPosition()
nowSpeak = contentList.lastIndex
if (page.paragraphs.size == 1) {
pos = page.chapterPosition -
pos = page.lines.first().chapterPosition -
textChapter.paragraphs[nowSpeak].chapterPosition
}
}

View File

@ -112,7 +112,7 @@ data class TextChapter(
*/
fun getReadLength(pageIndex: Int): Int {
if (pageIndex < 0) return 0
return pages[min(pageIndex, lastIndex)].chapterPosition
return pages[min(pageIndex, lastIndex)].lines.first().chapterPosition
/*
var length = 0
val maxIndex = min(pageIndex, pages.size)
@ -224,13 +224,14 @@ data class TextChapter(
return -1
}
val bIndex = pages.fastBinarySearchBy(charIndex, 0, pageSize) {
it.chapterPosition
it.lines.first().chapterPosition
}
val index = abs(bIndex + 1) - 1
// 判断是否已经排版到 charIndex ,没有则返回 -1
if (!isCompleted && index == pageSize - 1) {
val page = pages[index]
val pageEndPos = page.chapterPosition + page.charSize
val line = page.lines.first()
val pageEndPos = line.chapterPosition + page.charSize
if (charIndex > pageEndPos) {
return -1
}

View File

@ -45,7 +45,6 @@ data class TextPage(
val lines: List<TextLine> get() = textLines
val lineSize: Int get() = textLines.size
val charSize: Int get() = text.length.coerceAtLeast(1)
val chapterPosition: Int get() = textLines.first().chapterPosition
val searchResult = hashSetOf<TextColumn>()
var isMsgPage: Boolean = false
var canvasRecorder = CanvasRecorderFactory.create(true)

View File

@ -177,7 +177,7 @@ class TextChapterLayout(
val contents = bookContent.textList
var absStartX = paddingLeft
var durY = 0f
if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume || contents.isEmpty()) {
if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume) {
//标题非隐藏
displayTitle.splitNotBlank("\n").forEach { text ->
setTypeText(