Java: Getting a font with a specific height in pixels

后端 未结 4 1190
名媛妹妹
名媛妹妹 2020-12-20 16:17

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 specif

4条回答
  •  梦毁少年i
    2020-12-20 16:51

    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.

提交回复
热议问题