Source for gnu.java.awt.peer.qt.QtFontPeer

   1: /* QtFontPeer.java --
   2:    Copyright (C)  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: package gnu.java.awt.peer.qt;
  39: 
  40: import java.awt.Font;
  41: import java.awt.FontMetrics;
  42: import java.awt.geom.Rectangle2D;
  43: import java.awt.font.FontRenderContext;
  44: import java.awt.font.GlyphVector;
  45: import java.awt.font.LineMetrics;
  46: import java.text.CharacterIterator;
  47: import java.util.Locale;
  48: import java.util.Map;
  49: import java.awt.peer.FontPeer;
  50: 
  51: import gnu.java.awt.peer.ClasspathFontPeer;
  52: 
  53: public class QtFontPeer extends ClasspathFontPeer
  54: {
  55:   // Pointer to native QFont structure.
  56:   private long nativeObject;
  57:   private QtFontMetrics metrics;
  58: 
  59: 
  60:   public QtFontPeer (String name, int style)
  61:   {
  62:     this(name, style, 12);
  63:   }
  64: 
  65:   public QtFontPeer (String name, int style, int size)
  66:   {
  67:     super(name, style, size);
  68:     init();
  69:   }
  70: 
  71:   public QtFontPeer (String name, Map attributes)
  72:   {
  73:     super(name, attributes);
  74:     init();
  75:   }
  76: 
  77:   public void init()
  78:   {
  79:     if(this.familyName == null)
  80:       throw new IllegalArgumentException("null family name");
  81:     if(this.familyName.equals("Helvetica"))
  82:       this.familyName = "sans serif";
  83:     if(this.familyName.equals("Dialog"))
  84:       this.familyName = "sans serif";
  85:     create(this.familyName, this.style, (int)this.size);
  86:     metrics = new QtFontMetrics(this);
  87:   }
  88: 
  89:   /**
  90:    * Creates the QFont object.
  91:    */
  92:   private native void create(String name, int style, int size);
  93: 
  94:   /**
  95:    * Destroys the QFont.
  96:    */
  97:   public native void dispose();
  98: 
  99: 
 100:   // ****************** ClasspathFontPeer Methods.
 101: 
 102:   public boolean canDisplay (Font font, char c)
 103:   {
 104:     return metrics.canDisplay( c );
 105:   }
 106: 
 107:   public int canDisplayUpTo (Font font, CharacterIterator i, 
 108:                  int start, int limit)
 109:   {
 110:     int index = start;
 111:     char c = i.setIndex( index );
 112:     while( index <= limit )
 113:       {
 114:     if(!canDisplay(font, c))
 115:       return index;
 116:     index++;
 117:     c = i.next();
 118:       }
 119:     return -1;
 120:   }
 121: 
 122:   public String getSubFamilyName (Font font, Locale locale)
 123:   {
 124:     throw new UnsupportedOperationException();
 125:   }
 126: 
 127:   public String getPostScriptName (Font font)
 128:   {
 129:     throw new UnsupportedOperationException();
 130:   }
 131: 
 132:   public int getNumGlyphs (Font font)
 133:   {
 134:     throw new UnsupportedOperationException();
 135:   }
 136: 
 137:   public int getMissingGlyphCode (Font font)
 138:   {
 139:     throw new UnsupportedOperationException();
 140:   }
 141: 
 142:   public byte getBaselineFor (Font font, char c)
 143:   {
 144:     throw new UnsupportedOperationException();
 145:   }
 146: 
 147:   public String getGlyphName (Font font, int glyphIndex)
 148:   {
 149:     throw new UnsupportedOperationException();
 150:   }
 151: 
 152:   public GlyphVector createGlyphVector (Font font,
 153:                     FontRenderContext frc,
 154:                     CharacterIterator ci)
 155:   {
 156:     throw new UnsupportedOperationException();
 157:   }
 158: 
 159:   public GlyphVector createGlyphVector (Font font, 
 160:                     FontRenderContext ctx, 
 161:                     int[] glyphCodes)
 162:   {
 163:     throw new UnsupportedOperationException();
 164:   }
 165: 
 166:   public GlyphVector layoutGlyphVector (Font font, 
 167:                     FontRenderContext frc, 
 168:                     char[] chars, int start, 
 169:                     int limit, int flags)
 170:   {
 171:     throw new UnsupportedOperationException();
 172:   }
 173: 
 174:   public FontMetrics getFontMetrics (Font font)
 175:   {
 176:     return new QtFontMetrics( this );
 177:   }
 178: 
 179:   public boolean hasUniformLineMetrics (Font font)
 180:   {
 181:     throw new UnsupportedOperationException();
 182:   }
 183: 
 184:   public LineMetrics getLineMetrics (Font font, 
 185:                      CharacterIterator ci, 
 186:                      int begin, int limit, 
 187:                      FontRenderContext rc)
 188:   {
 189:     throw new UnsupportedOperationException();
 190:   }
 191: 
 192:   public Rectangle2D getMaxCharBounds (Font font, 
 193:                        FontRenderContext rc)
 194:   {
 195:     throw new UnsupportedOperationException();
 196:   }
 197: 
 198:   public Rectangle2D getStringBounds (Font font, 
 199:                       CharacterIterator ci, 
 200:                       int begin, int limit, 
 201:                       FontRenderContext frc)
 202:   {
 203:     int index = begin;
 204:     String s = "" + ci.setIndex( index );
 205:     while( index++ <= limit )
 206:       s = s + ci.next();
 207:     return metrics.getStringBounds(s);
 208:   }
 209: }