Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / gnu / java / awt / peer / gtk / GdkFontPeer.java
blobc6d42b372761ba3cbac21d38f8690a79dacdeeef
1 /* GdkFontPeer.java -- Implements FontPeer with GTK+
2 Copyright (C) 1999, 2004, 2005 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)
9 any later version.
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., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
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
24 combination.
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;
41 import gnu.classpath.Configuration;
42 import gnu.java.awt.peer.ClasspathFontPeer;
44 import java.awt.Font;
45 import java.awt.FontMetrics;
46 import java.awt.font.FontRenderContext;
47 import java.awt.font.GlyphVector;
48 import java.awt.font.LineMetrics;
49 import java.awt.geom.Rectangle2D;
50 import java.text.CharacterIterator;
51 import java.text.StringCharacterIterator;
52 import java.util.Locale;
53 import java.util.Map;
54 import java.util.ResourceBundle;
56 public class GdkFontPeer extends ClasspathFontPeer
58 static native void initStaticState();
59 private final int native_state = GtkGenericPeer.getUniqueInteger ();
60 private static ResourceBundle bundle;
62 static
64 if (Configuration.INIT_LOAD_LIBRARY)
66 System.loadLibrary("gtkpeer");
69 initStaticState ();
71 try
73 bundle = ResourceBundle.getBundle ("gnu.java.awt.peer.gtk.font");
75 catch (Throwable ignored)
77 bundle = null;
81 private native void initState ();
82 private native void dispose ();
83 private native void setFont (String family, int style, int size, boolean useGraphics2D);
85 native void getFontMetrics(double [] metrics);
86 native void getTextMetrics(String str, double [] metrics);
88 protected void finalize ()
90 if (GtkToolkit.useGraphics2D ())
91 GdkGraphics2D.releasePeerGraphicsResource(this);
92 dispose ();
95 /*
96 * Helpers for the 3-way overloading that this class seems to suffer
97 * from. Remove them if you feel like they're a performance bottleneck,
98 * for the time being I prefer my code not be written and debugged in
99 * triplicate.
102 private String buildString(CharacterIterator iter)
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();
110 private String buildString(CharacterIterator iter, int begin, int limit)
112 StringBuffer sb = new StringBuffer();
113 int i = 0;
114 for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next(), i++)
116 if (begin <= i)
117 sb.append(c);
118 if (limit <= i)
119 break;
121 return sb.toString();
124 private String buildString(char[] chars, int begin, int limit)
126 return new String(chars, begin, limit - begin);
129 /* Public API */
131 public GdkFontPeer (String name, int style)
133 // All fonts get a default size of 12 if size is not specified.
134 this(name, style, 12);
137 public GdkFontPeer (String name, int style, int size)
139 super(name, style, size);
140 initState ();
141 setFont (this.familyName, this.style, (int)this.size,
142 GtkToolkit.useGraphics2D());
145 public GdkFontPeer (String name, Map attributes)
147 super(name, attributes);
148 initState ();
149 setFont (this.familyName, this.style, (int)this.size,
150 GtkToolkit.useGraphics2D());
153 public String getSubFamilyName(Font font, Locale locale)
155 return null;
158 public String getPostScriptName(Font font)
160 return null;
163 public boolean canDisplay (Font font, char c)
165 // FIXME: inquire with pango
166 return true;
169 public int canDisplayUpTo (Font font, CharacterIterator i, int start, int limit)
171 // FIXME: inquire with pango
172 return -1;
175 private native GdkGlyphVector getGlyphVector(String txt,
176 Font f,
177 FontRenderContext ctx);
179 public GlyphVector createGlyphVector (Font font,
180 FontRenderContext ctx,
181 CharacterIterator i)
183 return getGlyphVector(buildString (i), font, ctx);
186 public GlyphVector createGlyphVector (Font font,
187 FontRenderContext ctx,
188 int[] glyphCodes)
190 return null;
191 // return new GdkGlyphVector (font, this, ctx, glyphCodes);
194 public byte getBaselineFor (Font font, char c)
196 throw new UnsupportedOperationException ();
199 protected class GdkFontLineMetrics extends LineMetrics
201 FontMetrics fm;
202 int nchars;
204 public GdkFontLineMetrics (FontMetrics m, int n)
206 fm = m;
207 nchars = n;
210 public float getAscent()
212 return (float) fm.getAscent ();
215 public int getBaselineIndex()
217 return Font.ROMAN_BASELINE;
220 public float[] getBaselineOffsets()
222 return new float[3];
225 public float getDescent()
227 return (float) fm.getDescent ();
230 public float getHeight()
232 return (float) fm.getHeight ();
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; }
244 public LineMetrics getLineMetrics (Font font, CharacterIterator ci,
245 int begin, int limit, FontRenderContext rc)
247 return new GdkFontLineMetrics (getFontMetrics (font), limit - begin);
250 public Rectangle2D getMaxCharBounds (Font font, FontRenderContext rc)
252 throw new UnsupportedOperationException ();
255 public int getMissingGlyphCode (Font font)
257 throw new UnsupportedOperationException ();
260 public String getGlyphName (Font font, int glyphIndex)
262 throw new UnsupportedOperationException ();
265 public int getNumGlyphs (Font font)
267 throw new UnsupportedOperationException ();
270 public Rectangle2D getStringBounds (Font font, CharacterIterator ci,
271 int begin, int limit, FontRenderContext frc)
273 GdkGlyphVector gv = getGlyphVector(buildString (ci, begin, limit), font, frc);
274 return gv.getVisualBounds();
277 public boolean hasUniformLineMetrics (Font font)
279 return true;
282 public GlyphVector layoutGlyphVector (Font font, FontRenderContext frc,
283 char[] chars, int start, int limit,
284 int flags)
286 int nchars = (limit - start) + 1;
287 char[] nc = new char[nchars];
289 for (int i = 0; i < nchars; ++i)
290 nc[i] = chars[start + i];
292 return createGlyphVector (font, frc,
293 new StringCharacterIterator (new String (nc)));
296 public LineMetrics getLineMetrics (Font font, String str,
297 FontRenderContext frc)
299 return new GdkFontLineMetrics (getFontMetrics (font), str.length ());
302 public FontMetrics getFontMetrics (Font font)
304 return new GdkFontMetrics (font);