Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
c8daac6c66
Merge e1744cd36e into dc9ce168c1 2024-06-18 21:39:34 +08:00
2 changed files with 12 additions and 22 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

@ -714,7 +714,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,12 +773,12 @@ 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);
@ -893,7 +893,7 @@ public class QueryTTF {
if ((glyphTableComponent.flags & 0x20) == 0) break;
}
}
glyfArray[index] = glyph;
glyfArray[index] = glyph; // 根据文档 glyfId=0 作为保留区使用这里赋值从索引1开始
}
}
@ -919,15 +919,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 +965,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 +986,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 +1008,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;
}