This commit was manufactured by cvs2svn to create branch 'gomp-branch'.
[official-gcc.git] / libjava / gnu / java / awt / peer / gtk / GdkClasspathFontPeer.java
blob1cf24a98d610fe9c15cc52bd610a94c8ceec3d2f
1 /* GdkClasspathFontPeer.java -- backend implementation for Font object
2 Copyright (C) 2003 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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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 java.awt.*;
42 import java.awt.font.*;
43 import java.awt.geom.*;
44 import java.io.InputStream;
45 import java.io.IOException;
46 import java.io.Serializable;
47 import java.util.Locale;
48 import java.util.Map;
49 import java.util.StringTokenizer;
50 import java.text.CharacterIterator;
51 import java.text.AttributedCharacterIterator;
52 import java.text.StringCharacterIterator;
53 import java.awt.font.TextAttribute;
54 import gnu.classpath.Configuration;
55 import gnu.java.awt.peer.ClasspathFontPeer;
57 /**
58 * This class represents a windowing system font using the Pango
59 * unicode/glyph/font library and the Cairo rendering library.
61 * @author Graydon Hoare (graydon@redhat.com)
64 public class GdkClasspathFontPeer extends ClasspathFontPeer
67 static
69 if (Configuration.INIT_LOAD_LIBRARY)
71 System.loadLibrary("gtkpeer");
74 if (GtkToolkit.useGraphics2D ())
75 initStaticState ();
77 native static void initStaticState ();
78 private final int native_state = GtkGenericPeer.getUniqueInteger ();
81 /* Instance Variables */
83 private native void initState ();
84 private native void dispose ();
85 private native void setFont (String family, int style, int size);
87 protected void sync ()
89 this.setFont (this.familyName, this.style, (int)this.size);
92 protected void finalize ()
94 dispose ();
97 /*
98 * Helpers for the 3-way overloading that this class seems to suffer
99 * from. Remove them if you feel like they're a performance bottleneck,
100 * for the time being I prefer my code not be written and debugged in
101 * triplicate.
104 private String buildString(CharacterIterator i) {
105 String s = new String ();
106 for(char c = i.first(); c != CharacterIterator.DONE; c = i.next())
107 s += c;
108 return s;
111 private String buildString(CharacterIterator iter, int begin, int limit) {
112 String s = new String ();
113 int i = 0;
114 for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next(), i++)
116 if (begin <= i)
117 s += c;
118 if (limit <= i)
119 break;
121 return s;
124 private String buildString(char[] chars, int begin, int limit) {
125 String s = new String ();
126 for(int i = begin; i <= limit; i++)
127 s += chars[i];
128 return s;
131 /* Public API */
133 public GdkClasspathFontPeer (String name, int style, int size)
135 super(name, style, size);
136 initState ();
137 setFont (this.familyName, this.style, (int)this.size);
140 public GdkClasspathFontPeer (String name, Map attributes)
142 super(name, attributes);
143 initState ();
144 setFont (this.familyName, this.style, (int)this.size);
147 public String getSubFamilyName(Font font, Locale locale)
149 return null;
152 public String getPostScriptName(Font font)
154 return null;
157 public boolean canDisplay (Font font, char c)
159 throw new UnsupportedOperationException ();
162 public int canDisplayUpTo (Font font, CharacterIterator i, int start, int limit)
164 throw new UnsupportedOperationException ();
167 public GlyphVector createGlyphVector (Font font,
168 FontRenderContext ctx,
169 CharacterIterator i)
171 return new GdkGlyphVector(font, this, ctx, buildString (i));
174 public GlyphVector createGlyphVector (Font font,
175 FontRenderContext ctx,
176 int[] glyphCodes)
178 return new GdkGlyphVector (font, this, ctx, glyphCodes);
181 public byte getBaselineFor (Font font, char c)
183 throw new UnsupportedOperationException ();
186 protected class GdkFontLineMetrics extends LineMetrics
188 FontMetrics fm;
189 int nchars;
191 public GdkFontLineMetrics (FontMetrics m, int n)
193 fm = m;
194 nchars = n;
197 public float getAscent()
199 return (float) fm.getAscent ();
202 public int getBaselineIndex()
204 return Font.ROMAN_BASELINE;
207 public float[] getBaselineOffsets()
209 return new float[3];
212 public float getDescent()
214 return (float) fm.getDescent ();
217 public float getHeight()
219 return (float) fm.getHeight ();
222 public float getLeading() { return 0.f; }
223 public int getNumChars() { return nchars; }
224 public float getStrikethroughOffset() { return 0.f; }
225 public float getStrikethroughThickness() { return 0.f; }
226 public float getUnderlineOffset() { return 0.f; }
227 public float getUnderlineThickness() { return 0.f; }
232 public LineMetrics getLineMetrics (Font font, CharacterIterator ci,
233 int begin, int limit, FontRenderContext rc)
235 return new GdkFontLineMetrics (getFontMetrics (font), limit - begin);
238 public Rectangle2D getMaxCharBounds (Font font, FontRenderContext rc)
240 throw new UnsupportedOperationException ();
243 public int getMissingGlyphCode (Font font)
245 throw new UnsupportedOperationException ();
248 public String getGlyphName (Font font, int glyphIndex)
250 throw new UnsupportedOperationException ();
253 public int getNumGlyphs (Font font)
255 throw new UnsupportedOperationException ();
258 public Rectangle2D getStringBounds (Font font, CharacterIterator ci,
259 int begin, int limit, FontRenderContext frc)
261 throw new UnsupportedOperationException ();
264 public boolean hasUniformLineMetrics (Font font)
266 return true;
269 public GlyphVector layoutGlyphVector (Font font, FontRenderContext frc,
270 char[] chars, int start, int limit,
271 int flags)
273 int nchars = (limit - start) + 1;
274 char[] nc = new char[nchars];
276 for (int i = 0; i < nchars; ++i)
277 nc[i] = chars[start + i];
279 return createGlyphVector (font, frc,
280 new StringCharacterIterator (new String (nc)));
283 public LineMetrics getLineMetrics (Font font, String str,
284 FontRenderContext frc)
286 return new GdkFontLineMetrics (getFontMetrics (font), str.length ());
289 public FontMetrics getFontMetrics (Font font)
291 return new GdkClasspathFontPeerMetrics (font);