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

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