我愿意在 Windows 上使用标准 Java 使用 the parser described above。如果有人想这样做,则需要使用 Rectangle 而不是 Rect。这只是一个小的转换。我还删除了目录 jaredrummler,因为它有点太长了(不过,我将版权 cmets 保留在文件的开头)。但是这个解析器中有两个 TTFFile 类。这段代码:
TTFFile file;
File ttf = new File("C:\\Windows\\Fonts\\calibri.ttf" );
try { file = TTFFile.open(ttf); }
catch (IOException e) {e.printStackTrace(); }
Map<Integer, Map<Integer, Integer>> kerning = file.getKerning();
仅当您导入正确的类文件时才有效:
import com.fontreader.truetype.TTFFile;
最后,代码有效,但返回的字距调整对不起作用与您使用转换的路径:
void vectorize(Path2D.Float path, String s) {
PathIterator pIter;
FontRenderContext frc = new FontRenderContext(null,true,true);
GlyphVector gv;
Shape glyph;
gv = font.createGlyphVector(frc, s);
glyph = gv.getGlyphOutline(0);
pIter = glyph.getPathIterator(null);
while (!pIter.isDone()) {
switch(pIter.currentSegment(points)) {
case PathIterator.SEG_MOVETO:
path.moveTo(points[0], points[1]);
break;
case PathIterator.SEG_LINETO :
path.lineTo(points[0], points[1]);
break;
case PathIterator.SEG_QUADTO :
path.quadTo(points[0], points[1], points[2], points[3]);
break;
case PathIterator.SEG_CUBICTO :
path.curveTo(points[0], points[1], points[2], points[3], points[4], points[5]);
break;
case PathIterator.SEG_CLOSE :
path.closePath();
}
pIter.next();
}
}
lens在以下代码中恢复的长度:
double interchar = fontsize * 0.075;
int size = '}' - ' ' + 1;
Path2D.Float[] glyphs = new Path2D.Float[size];
double[] lens = new double[size];
String chars[] = new String[size];
int i; char c;
char[] s = { '0' };
for (i = 0, c = ' '; c <= '}'; c++, i++) { s[0] = c; chars[i] = new String(s); }
for (i = 0; i < size; i++) {
vectorize(glyphs[i] = new Path2D.Float(), chars[i], tx[i], 0f);
lens[i] = glyphs[i].getBounds2D().getWidth() + interchar;
}
为了清楚起见,我在 Graphics2D 中使用 fill 显示字形,并使用上面添加到库 Apache FOP 返回的字距偏移的长度进行翻译,但结果很糟糕. fontsize 是本讨论中建议的标准 1000,而 interchar 乘以字体大小后得到 75。这一切似乎都是正确的,但我的手动字距调整对看起来比使用 ttf 文件中的字距调整对要好得多。
有没有人受过这个库的培训,能够告诉我们应该如何使用这些字距调整对?
很抱歉稍微偏离了最初的问题,但这可能会完成信息,因为一旦阅读了字距调整对,如何在 Windows 或 Android 上正确使用它们?