home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1QVILM6 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.8 KB  |  92 lines

  1. package java.awt;
  2.  
  3. import java.io.Serializable;
  4.  
  5. public abstract class FontMetrics implements Serializable {
  6.    protected Font font;
  7.    private static final long serialVersionUID = 1681126225205050147L;
  8.  
  9.    protected FontMetrics(Font font) {
  10.       this.font = font;
  11.    }
  12.  
  13.    public int bytesWidth(byte[] data, int off, int len) {
  14.       return this.stringWidth(new String(data, 0, off, len));
  15.    }
  16.  
  17.    public int charsWidth(char[] data, int off, int len) {
  18.       return this.stringWidth(new String(data, off, len));
  19.    }
  20.  
  21.    public int charWidth(char ch) {
  22.       if (ch < 256) {
  23.          return this.getWidths()[ch];
  24.       } else {
  25.          char[] data = new char[]{ch};
  26.          return this.charsWidth(data, 0, 1);
  27.       }
  28.    }
  29.  
  30.    public int charWidth(int ch) {
  31.       return this.charWidth((char)ch);
  32.    }
  33.  
  34.    public int getAscent() {
  35.       return this.font.getSize();
  36.    }
  37.  
  38.    public int getDescent() {
  39.       return 0;
  40.    }
  41.  
  42.    public Font getFont() {
  43.       return this.font;
  44.    }
  45.  
  46.    public int getHeight() {
  47.       return this.getLeading() + this.getAscent() + this.getDescent();
  48.    }
  49.  
  50.    public int getLeading() {
  51.       return 0;
  52.    }
  53.  
  54.    public int getMaxAdvance() {
  55.       return -1;
  56.    }
  57.  
  58.    public int getMaxAscent() {
  59.       return this.getAscent();
  60.    }
  61.  
  62.    /** @deprecated */
  63.    public int getMaxDecent() {
  64.       return this.getMaxDescent();
  65.    }
  66.  
  67.    public int getMaxDescent() {
  68.       return this.getDescent();
  69.    }
  70.  
  71.    public int[] getWidths() {
  72.       int[] widths = new int[256];
  73.  
  74.       for(char ch = 0; ch < 256; ++ch) {
  75.          widths[ch] = this.charWidth(ch);
  76.       }
  77.  
  78.       return widths;
  79.    }
  80.  
  81.    public int stringWidth(String str) {
  82.       int len = str.length();
  83.       char[] data = new char[len];
  84.       str.getChars(0, len, data, 0);
  85.       return this.charsWidth(data, 0, len);
  86.    }
  87.  
  88.    public String toString() {
  89.       return this.getClass().getName() + "[font=" + this.getFont() + "ascent=" + this.getAscent() + ", descent=" + this.getDescent() + ", height=" + this.getHeight() + "]";
  90.    }
  91. }
  92.