Java:以像素为单位获取具有特定高度的字体 [英] Java: Getting a font with a specific height in pixels

查看:522
本文介绍了Java:以像素为单位获取具有特定高度的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 FontMetrics 可以很容易地确定字体的渲染高度,但是相反呢?我怎样才能获得一个字体,适合像素的特定高度?

lockquote
给我 Verdana




$ b

如何向Java请求这个?

解决方案Jen,



我不认为有直接的方式来找到一个字体的高度;只是一种间接的方式...通过循环遍历尺寸,并测试每个的高度是<=所需的高度。



如果你这样做了一次,只需循环浏览它们...如果你正在做即时,那么做二进制搜索,它会快点。



干杯。基思。

It’s easy to determine the rendered height of a font using FontMetrics, but what about the other way around? How can I obtain a font that will fit into a specific height in pixels?

"Give me Verdana in a size that is 30 pixels high from ascender to descender."

How do I ask Java for this?

解决方案

Jen,

I don't think there's a "direct" way to find a font by height; only an indirect way... by looping through the sizes, and testing the height of each is <= required height.

If you're doing this once, just loop through them... if you've doing it "on the fly" then do a binary search, it'll be quicker.

Cheers. Keith.

这篇关于Java:以像素为单位获取具有特定高度的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆