Source for gnu.java.awt.peer.gtk.GtkFontPeer

   1: /* GtkFontPeer.java -- Implements FontPeer with GTK+
   2:    Copyright (C) 1999, 2004, 2005  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   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.
  10: 
  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.
  15: 
  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.
  20: 
  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.
  25: 
  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. */
  37: 
  38: 
  39: package gnu.java.awt.peer.gtk;
  40: 
  41: import gnu.java.awt.peer.ClasspathFontPeer;
  42: 
  43: import java.awt.Font;
  44: import java.awt.FontMetrics;
  45: import java.awt.font.FontRenderContext;
  46: import java.awt.font.GlyphVector;
  47: import java.awt.font.LineMetrics;
  48: import java.awt.geom.Rectangle2D;
  49: import java.text.CharacterIterator;
  50: import java.util.Locale;
  51: import java.util.MissingResourceException;
  52: import java.util.ResourceBundle;
  53: 
  54: public class GtkFontPeer extends ClasspathFontPeer
  55: {
  56:   private static ResourceBundle bundle;
  57: 
  58:   static
  59:   {
  60:     try
  61:       {
  62:     bundle = ResourceBundle.getBundle ("gnu.java.awt.peer.gtk.font");
  63:       }
  64:     catch (Throwable ignored)
  65:       {
  66:     bundle = null;
  67:       }
  68:   }
  69: 
  70:   private final String Xname;
  71: 
  72:   public GtkFontPeer (String name, int style)
  73:   {
  74:     // All fonts get a default size of 12 if size is not specified.
  75:     this(name, style, 12);
  76:   }
  77: 
  78:   public GtkFontPeer (String name, int style, int size)
  79:   {
  80:     super(name, style, size);
  81: 
  82:     String Xname = null;
  83:     if (bundle != null)
  84:       {
  85:     try
  86:       {
  87:         Xname = bundle.getString (name.toLowerCase () + "." + style);
  88:       }
  89:     catch (MissingResourceException mre)
  90:       {
  91:         // ignored
  92:       }
  93:       }
  94: 
  95:     if (Xname == null)
  96:       {
  97:     String weight;
  98:     String slant;
  99:     String spacing;
 100: 
 101:     if (style == Font.ITALIC || (style == (Font.BOLD+Font.ITALIC)))
 102:       slant = "i";
 103:     else
 104:       slant = "r";
 105:     if (style == Font.BOLD || (style == (Font.BOLD+Font.ITALIC)))
 106:       weight = "bold";
 107:     else
 108:       weight = "medium";
 109:     if (name.equals("Serif") || name.equals("SansSerif")
 110:         || name.equals("Helvetica") || name.equals("Times"))
 111:       spacing = "p";
 112:     else
 113:       spacing = "c";
 114: 
 115:         Xname = "-*-*-" + weight + "-" + slant + "-normal-*-*-" + size + "-*-*-" + spacing + "-*-*-*";
 116:       }
 117: 
 118:     this.Xname = Xname;
 119:   }
 120: 
 121:   public String getXLFD ()
 122:   {
 123:     return Xname;
 124:   }
 125: 
 126: 
 127:   /* remaining methods are for static compatibility with the newer
 128:      ClasspathFontPeer superclass; none of these methods ever existed or
 129:      worked on the older FontPeer interface, but we need to pretend to
 130:      support them anyways. */
 131: 
 132:   public boolean canDisplay (Font font, char c)
 133:   {
 134:     throw new UnsupportedOperationException();
 135:   }
 136: 
 137:   public int canDisplayUpTo (Font font, CharacterIterator i, int start, int limit)
 138:   {
 139:     throw new UnsupportedOperationException();
 140:   }
 141: 
 142:   public String getSubFamilyName (Font font, Locale locale)
 143:   {
 144:     throw new UnsupportedOperationException();
 145:   }
 146: 
 147:   public String getPostScriptName (Font font)
 148:   {
 149:     throw new UnsupportedOperationException();
 150:   }
 151: 
 152:   public int getNumGlyphs (Font font)
 153:   {
 154:     throw new UnsupportedOperationException();
 155:   }
 156: 
 157:   public int getMissingGlyphCode (Font font)
 158:   {
 159:     throw new UnsupportedOperationException();
 160:   }
 161: 
 162:   public byte getBaselineFor (Font font, char c)
 163:   {
 164:     throw new UnsupportedOperationException();
 165:   }
 166: 
 167:   public String getGlyphName (Font font, int glyphIndex)
 168:   {
 169:     throw new UnsupportedOperationException();
 170:   }
 171: 
 172:   public GlyphVector createGlyphVector (Font font,
 173:                                                  FontRenderContext frc,
 174:                                                  CharacterIterator ci)
 175:   {
 176:     throw new UnsupportedOperationException();
 177:   }
 178: 
 179:   public GlyphVector createGlyphVector (Font font, 
 180:                                                  FontRenderContext ctx, 
 181:                                                  int[] glyphCodes)
 182:   {
 183:     throw new UnsupportedOperationException();
 184:   }
 185: 
 186:   public GlyphVector layoutGlyphVector (Font font, 
 187:                                                  FontRenderContext frc, 
 188:                                                  char[] chars, int start, 
 189:                                                  int limit, int flags)
 190:   {
 191:     throw new UnsupportedOperationException();
 192:   }
 193: 
 194:   public FontMetrics getFontMetrics (Font font)
 195:   {
 196:     throw new UnsupportedOperationException();
 197:   }
 198: 
 199:   public boolean hasUniformLineMetrics (Font font)
 200:   {
 201:     throw new UnsupportedOperationException();
 202:   }
 203: 
 204:   public LineMetrics getLineMetrics (Font font, 
 205:                                               CharacterIterator ci, 
 206:                                               int begin, int limit, 
 207:                                               FontRenderContext rc)
 208:   {
 209:     throw new UnsupportedOperationException();
 210:   }
 211: 
 212:   public Rectangle2D getMaxCharBounds (Font font, 
 213:                                                 FontRenderContext rc)
 214:   {
 215:     throw new UnsupportedOperationException();
 216:   }
 217: 
 218:   public Rectangle2D getStringBounds (Font font, 
 219:                                                CharacterIterator ci, 
 220:                                                int begin, int limit, 
 221:                                                FontRenderContext frc)
 222:   {
 223:     throw new UnsupportedOperationException();
 224:   }
 225: }