找到字体真实边界的最佳方法
我正在寻找一种方法来查找渲染文本的边界,并遇到了 FontMetrics getStringBounds 方法。这似乎忽略了某些字体的下降并具有夸张的上升,因此它返回的边界不允许我正确垂直对齐。我更深入地挖掘了一下,发现 GlyphVector.getPixelBounds() 似乎可以做我想做的事情,但我不知道使用它是否会出现一些问题。
我写了一个小程序 http://breadmilkbeer香烟.com/bmbc /shelves/users/bbb/src/java/applet/glyphvector.html 显示两者之间的差异,似乎适合我的系统字体它返回正确的边界。有谁知道这是否是一种昂贵的方法,或者使用它是否存在其他可能的陷阱? FontMetrics 似乎从来没有对我正常工作过。或者也许我对它的期望是错误的。
谢谢, 血脑屏障
I was looking for a way to find the bounds on rendered text and encountered the FontMetrics getStringBounds method. This seems to ignore some font's descent and has an exaggerated ascent so that it returns a bounds that doesn't let me align vertically properly. I dug a bit deeper and found that GlyphVector.getPixelBounds() SEEMS to do what I want, but I don't know if there might be some problems with using it.
I wrote an applet http://breadmilkbeercigarettes.com/bmbc/shelves/users/bbb/src/java/applet/glyphvector.html that displays the difference between the two, and it seems for my system fonts it returns the correct bounds. Does anyone know if this is a costly method or if there are other possible pitfalls from using it? FontMetrics never seemed to work correctly for me. Or perhaps my expectations of it were misaligned.
Thanks,
BBB
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GlyphVector 有方法
GlyphVector has the method