What's the difference between GC and FontData for getting font height?

懵懂的女人 提交于 2019-12-10 13:08:26

问题


This explains font metrics

I think we can get "Font height" in SWT like these;

GC gc = new GC(label);
System.out.println( gc.textExtent(label.getText()) );
System.out.println( label.getFont().getFontData()[0].getHeight() );

Why this two outs aren't same? And which one is correct height for a string ?


回答1:


GC#textExtent() returns extent in pixels, while FontData returns in font points. The units are different here.




回答2:


Use FontMetrics.getHeight() to get height in pixels.

FontMetrics fontMetrics = gc.getFontMetrics()


来源:https://stackoverflow.com/questions/13604492/whats-the-difference-between-gc-and-fontdata-for-getting-font-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!