问题
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