1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43:
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55:
56: public class GdkFontPeer extends ClasspathFontPeer
57: {
58: static native void initStaticState();
59: private final int native_state = GtkGenericPeer.getUniqueInteger ();
60: private static ResourceBundle bundle;
61:
62: static
63: {
64: if (Configuration.INIT_LOAD_LIBRARY)
65: {
66: System.loadLibrary("gtkpeer");
67: }
68:
69: initStaticState ();
70:
71: try
72: {
73: bundle = ResourceBundle.getBundle ("gnu.java.awt.peer.gtk.font");
74: }
75: catch (Throwable ignored)
76: {
77: bundle = null;
78: }
79: }
80:
81: private native void initState ();
82: private native void dispose ();
83: private native void setFont (String family, int style, int size, boolean useGraphics2D);
84:
85: native void getFontMetrics(double [] metrics);
86: native void getTextMetrics(String str, double [] metrics);
87:
88: protected void finalize ()
89: {
90: if (GtkToolkit.useGraphics2D ())
91: GdkGraphics2D.releasePeerGraphicsResource(this);
92: dispose ();
93: }
94:
95:
101:
102: private String buildString(CharacterIterator iter)
103: {
104: StringBuffer sb = new StringBuffer();
105: for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
106: sb.append(c);
107: return sb.toString();
108: }
109:
110: private String buildString(CharacterIterator iter, int begin, int limit)
111: {
112: StringBuffer sb = new StringBuffer();
113: int i = 0;
114: for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next(), i++)
115: {
116: if (begin <= i)
117: sb.append(c);
118: if (limit <= i)
119: break;
120: }
121: return sb.toString();
122: }
123:
124: private String buildString(char[] chars, int begin, int limit)
125: {
126: return new String(chars, begin, limit - begin);
127: }
128:
129:
130:
131: public GdkFontPeer (String name, int style)
132: {
133:
134: this(name, style, 12);
135: }
136:
137: public GdkFontPeer (String name, int style, int size)
138: {
139: super(name, style, size);
140: initState ();
141: setFont (this.familyName, this.style, (int)this.size,
142: GtkToolkit.useGraphics2D());
143: }
144:
145: public GdkFontPeer (String name, Map attributes)
146: {
147: super(name, attributes);
148: initState ();
149: setFont (this.familyName, this.style, (int)this.size,
150: GtkToolkit.useGraphics2D());
151: }
152:
153: public String getSubFamilyName(Font font, Locale locale)
154: {
155: return null;
156: }
157:
158: public String getPostScriptName(Font font)
159: {
160: return null;
161: }
162:
163: public boolean canDisplay (Font font, char c)
164: {
165:
166: return true;
167: }
168:
169: public int canDisplayUpTo (Font font, CharacterIterator i, int start, int limit)
170: {
171:
172: return -1;
173: }
174:
175: private native GdkGlyphVector getGlyphVector(String txt,
176: Font f,
177: FontRenderContext ctx);
178:
179: public GlyphVector createGlyphVector (Font font,
180: FontRenderContext ctx,
181: CharacterIterator i)
182: {
183: return getGlyphVector(buildString (i), font, ctx);
184: }
185:
186: public GlyphVector createGlyphVector (Font font,
187: FontRenderContext ctx,
188: int[] glyphCodes)
189: {
190: return null;
191:
192: }
193:
194: public byte getBaselineFor (Font font, char c)
195: {
196: throw new UnsupportedOperationException ();
197: }
198:
199: protected class GdkFontLineMetrics extends LineMetrics
200: {
201: FontMetrics fm;
202: int nchars;
203:
204: public GdkFontLineMetrics (FontMetrics m, int n)
205: {
206: fm = m;
207: nchars = n;
208: }
209:
210: public float getAscent()
211: {
212: return (float) fm.getAscent ();
213: }
214:
215: public int getBaselineIndex()
216: {
217: return Font.ROMAN_BASELINE;
218: }
219:
220: public float[] getBaselineOffsets()
221: {
222: return new float[3];
223: }
224:
225: public float getDescent()
226: {
227: return (float) fm.getDescent ();
228: }
229:
230: public float getHeight()
231: {
232: return (float) fm.getHeight ();
233: }
234:
235: public float getLeading() { return 0.f; }
236: public int getNumChars() { return nchars; }
237: public float getStrikethroughOffset() { return 0.f; }
238: public float getStrikethroughThickness() { return 0.f; }
239: public float getUnderlineOffset() { return 0.f; }
240: public float getUnderlineThickness() { return 0.f; }
241:
242: }
243:
244: public LineMetrics getLineMetrics (Font font, CharacterIterator ci,
245: int begin, int limit, FontRenderContext rc)
246: {
247: return new GdkFontLineMetrics (getFontMetrics (font), limit - begin);
248: }
249:
250: public Rectangle2D getMaxCharBounds (Font font, FontRenderContext rc)
251: {
252: throw new UnsupportedOperationException ();
253: }
254:
255: public int getMissingGlyphCode (Font font)
256: {
257: throw new UnsupportedOperationException ();
258: }
259:
260: public String getGlyphName (Font font, int glyphIndex)
261: {
262: throw new UnsupportedOperationException ();
263: }
264:
265: public int getNumGlyphs (Font font)
266: {
267: throw new UnsupportedOperationException ();
268: }
269:
270: public Rectangle2D getStringBounds (Font font, CharacterIterator ci,
271: int begin, int limit, FontRenderContext frc)
272: {
273: GdkGlyphVector gv = getGlyphVector(buildString (ci, begin, limit), font, frc);
274: return gv.getVisualBounds();
275: }
276:
277: public boolean hasUniformLineMetrics (Font font)
278: {
279: return true;
280: }
281:
282: public GlyphVector layoutGlyphVector (Font font, FontRenderContext frc,
283: char[] chars, int start, int limit,
284: int flags)
285: {
286: int nchars = (limit - start) + 1;
287: char[] nc = new char[nchars];
288:
289: for (int i = 0; i < nchars; ++i)
290: nc[i] = chars[start + i];
291:
292: return createGlyphVector (font, frc,
293: new StringCharacterIterator (new String (nc)));
294: }
295:
296: public LineMetrics getLineMetrics (Font font, String str,
297: FontRenderContext frc)
298: {
299: return new GdkFontLineMetrics (getFontMetrics (font), str.length ());
300: }
301:
302: public FontMetrics getFontMetrics (Font font)
303: {
304: return new GdkFontMetrics (font);
305: }
306:
307: }