【发布时间】:2015-05-26 21:43:47
【问题描述】:
我发现getGlyphOutline() 可以从 JAVA API 显示字体。
而且我还没有找到任何显示一个中文笔顺的API。
但这是真的:.ttf 包含笔画顺序。
我只是不知道如何通过 JAVA 获取它。
可能是我忘记了一些重要的 API?
shape = gv.getGlyphOutline(i, 200, 200);
((Graphics2D) g).draw(shape);
现在,我找到了 PathIterator
Shape shape = gv.getGlyphOutline(0, 200, 200);
PathIterator pi = shape.getPathIterator(new AffineTransform());
double[] coords = new double[6];
int count = 0;
while (!pi.isDone()) {
int kind = pi.currentSegment(coords);
int[] path = new int[4];
switch (kind) {
case PathIterator.SEG_MOVETO:
System.out.println("SEG_MOVETO");
break;
case PathIterator.SEG_LINETO:
System.out.println("SEG_LINETO");
break;
case PathIterator.SEG_CLOSE:
System.out.println("SEG_CLOSE");
g.drawLine((int) coords[0], (int) coords[1],
(int) coords[2], (int) coords[3]);
count++;
break;
case PathIterator.SEG_QUADTO:
System.out.println("SEG_QUADTO");
g.drawLine((int) coords[0], (int) coords[1],
(int) coords[2], (int) coords[3]);
count++;
break;
default:
throw new IllegalArgumentException("Bad path segment");
}
pi.next();
}
有一个问题,我无法获得完整的单词.. 它看起来像虚线......
【问题讨论】:
-
写中文的笔顺很明确archchinese.com/chinese_stroke_order_rules.html真的需要看.ttf文件才能得到吗?
-
我已经拿到订单了,但我只是拿到了笔画的分段..看起来像虚线..
-
case PathIterator.SEG_LINETO:应该有动作g.drawLine((int) coords[0], (int) coords[1], (int) coords[2], (int) coords[3]);&case PathIterator.SEG_QUADTO:应该是draw(Shape),其中Shape是QuadCurve2D。为了尽快获得更好的帮助,请发布MCVE(最小完整可验证示例)或SSCCE(基本相同)。 -
顺便说一句 - 你的意思是像 Kanji stroke order font v3.001 页面中所示的“笔顺”吗?我怀疑这是确实存储笔画顺序的少数TTF字体之一。即便如此,除了让
GeneralPath依次绘制每个笔画(与笔画顺序相同)之外,我不相信 TTF 甚至没有 容量 将“笔画顺序”存储在感觉你的意思。