1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44:
45: public class QtFontMetrics extends FontMetrics
46: {
47:
48: private long nativeObject;
49: private QtFontPeer peer;
50:
51: public QtFontMetrics( Font f )
52: {
53: super( f );
54: if(f.getPeer() == null || !(f.getPeer() instanceof QtFontPeer))
55: throw new IllegalArgumentException("Invalid Font object.");
56: peer = (QtFontPeer) f.getPeer();
57: init( peer );
58: }
59:
60: public QtFontMetrics( Font f, Graphics g )
61: {
62: super( f );
63: if(f.getPeer() == null || !(f.getPeer() instanceof QtFontPeer))
64: throw new IllegalArgumentException("Invalid Font object.");
65: if( !(g instanceof QtGraphics) )
66: throw new IllegalArgumentException("Invalid graphics object.");
67: peer = (QtFontPeer) f.getPeer();
68: initGraphics(peer, (QtGraphics)g );
69: }
70:
71: QtFontMetrics( QtFontPeer f, Graphics g )
72: {
73: super( null );
74: if( !(g instanceof QtGraphics) )
75: throw new IllegalArgumentException("Invalid graphics object.");
76: peer = f;
77: initGraphics(peer, (QtGraphics)g );
78: }
79:
80: public QtFontMetrics( QtFontPeer fp )
81: {
82: super( (Font)null );
83: peer = fp;
84: init( peer );
85: }
86:
87: private native void init(QtFontPeer fp);
88:
89: private native void initGraphics(QtFontPeer fp, QtGraphics g);
90:
91: private native void dispose();
92:
93: native Rectangle2D getStringBounds(String s);
94:
95:
96:
97: native boolean canDisplay( int c );
98:
99:
100:
101: public native int getAscent();
102:
103: public native int getDescent();
104:
105: public native int getHeight();
106:
107: public native int getLeading();
108:
109: public native int getMaxAdvance();
110:
111: public native int charWidth(char c);
112:
113: public int charsWidth(char[] chars, int off, int len)
114: {
115: return stringWidth( new String(chars, off, len) );
116: }
117:
118: public native int stringWidth(String str);
119:
120: public Rectangle2D getStringBounds(String str, Graphics context)
121: {
122: QtFontMetrics fm = new QtFontMetrics(peer, context);
123: return fm.getStringBounds( str );
124: }
125: }