1 /* GdkFontPeer.java -- Implements FontPeer with GTK+
2 Copyright (C) 1999, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.java.awt.peer.gtk;
40 import java.awt.peer.FontPeer;
42 import java.awt.geom.*;
43 import java.awt.font.*;
44 import java.util.Locale;
46 import java.util.ResourceBundle;
47 import java.util.MissingResourceException;
48 import java.text.CharacterIterator;
49 import java.text.AttributedCharacterIterator;
50 import java.text.StringCharacterIterator;
51 import gnu.classpath.Configuration;
52 import gnu.java.awt.peer.ClasspathFontPeer;
54 public class GdkFontPeer extends ClasspathFontPeer
57 native static void initStaticState ();
58 private final int native_state = GtkGenericPeer.getUniqueInteger ();
59 private static ResourceBundle bundle;
63 if (Configuration.INIT_LOAD_LIBRARY)
65 System.loadLibrary("gtkpeer");
72 bundle = ResourceBundle.getBundle ("gnu.java.awt.peer.gtk.font");
74 catch (Throwable ignored)
80 private native void initState ();
81 private native void dispose ();
82 private native void setFont (String family, int style, int size, boolean useGraphics2D);
84 protected void finalize ()
86 if (GtkToolkit.useGraphics2D ())
87 GdkGraphics2D.releasePeerGraphicsResource(this);
92 * Helpers for the 3-way overloading that this class seems to suffer
93 * from. Remove them if you feel like they're a performance bottleneck,
94 * for the time being I prefer my code not be written and debugged in
98 private String buildString(CharacterIterator iter)
100 StringBuffer sb = new StringBuffer();
101 for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
103 return sb.toString();
106 private String buildString(CharacterIterator iter, int begin, int limit)
108 StringBuffer sb = new StringBuffer();
110 for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next(), i++)
117 return sb.toString();
120 private String buildString(char[] chars, int begin, int limit)
122 return new String(chars, begin, limit - begin);
127 public GdkFontPeer (String name, int style)
129 // All fonts get a default size of 12 if size is not specified.
130 this(name, style, 12);
133 public GdkFontPeer (String name, int style, int size)
135 super(name, style, size);
137 setFont (this.familyName, this.style, (int)this.size,
138 GtkToolkit.useGraphics2D());
141 public GdkFontPeer (String name, Map attributes)
143 super(name, attributes);
145 setFont (this.familyName, this.style, (int)this.size,
146 GtkToolkit.useGraphics2D());
149 public String getSubFamilyName(Font font, Locale locale)
154 public String getPostScriptName(Font font)
159 public boolean canDisplay (Font font, char c)
161 throw new UnsupportedOperationException ();
164 public int canDisplayUpTo (Font font, CharacterIterator i, int start, int limit)
166 throw new UnsupportedOperationException ();
169 public GlyphVector createGlyphVector (Font font,
170 FontRenderContext ctx,
173 return new GdkGlyphVector(font, this, ctx, buildString (i));
176 public GlyphVector createGlyphVector (Font font,
177 FontRenderContext ctx,
180 return new GdkGlyphVector (font, this, ctx, glyphCodes);
183 public byte getBaselineFor (Font font, char c)
185 throw new UnsupportedOperationException ();
188 protected class GdkFontLineMetrics extends LineMetrics
193 public GdkFontLineMetrics (FontMetrics m, int n)
199 public float getAscent()
201 return (float) fm.getAscent ();
204 public int getBaselineIndex()
206 return Font.ROMAN_BASELINE;
209 public float[] getBaselineOffsets()
214 public float getDescent()
216 return (float) fm.getDescent ();
219 public float getHeight()
221 return (float) fm.getHeight ();
224 public float getLeading() { return 0.f; }
225 public int getNumChars() { return nchars; }
226 public float getStrikethroughOffset() { return 0.f; }
227 public float getStrikethroughThickness() { return 0.f; }
228 public float getUnderlineOffset() { return 0.f; }
229 public float getUnderlineThickness() { return 0.f; }
233 public LineMetrics getLineMetrics (Font font, CharacterIterator ci,
234 int begin, int limit, FontRenderContext rc)
236 return new GdkFontLineMetrics (getFontMetrics (font), limit - begin);
239 public Rectangle2D getMaxCharBounds (Font font, FontRenderContext rc)
241 throw new UnsupportedOperationException ();
244 public int getMissingGlyphCode (Font font)
246 throw new UnsupportedOperationException ();
249 public String getGlyphName (Font font, int glyphIndex)
251 throw new UnsupportedOperationException ();
254 public int getNumGlyphs (Font font)
256 throw new UnsupportedOperationException ();
259 public Rectangle2D getStringBounds (Font font, CharacterIterator ci,
260 int begin, int limit, FontRenderContext frc)
262 throw new UnsupportedOperationException ();
265 public boolean hasUniformLineMetrics (Font font)
270 public GlyphVector layoutGlyphVector (Font font, FontRenderContext frc,
271 char[] chars, int start, int limit,
274 int nchars = (limit - start) + 1;
275 char[] nc = new char[nchars];
277 for (int i = 0; i < nchars; ++i)
278 nc[i] = chars[start + i];
280 return createGlyphVector (font, frc,
281 new StringCharacterIterator (new String (nc)));
284 public LineMetrics getLineMetrics (Font font, String str,
285 FontRenderContext frc)
287 return new GdkFontLineMetrics (getFontMetrics (font), str.length ());
290 public FontMetrics getFontMetrics (Font font)
292 return new GdkFontMetrics (font);