home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / netscape / application / FontMetrics.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-12  |  3.6 KB  |  123 lines

  1. package netscape.application;
  2.  
  3. public class FontMetrics {
  4.    Font _font;
  5.    java.awt.FontMetrics _awtMetrics;
  6.    static final String LEADING = "Leading";
  7.    static final String ASCENT = "Ascent";
  8.    static final String DESCENT = "Descent";
  9.    static final String TOTAL_HEIGHT = "Total Height";
  10.    static final String MAX_ASCENT = "Maximum Ascent";
  11.    static final String MAX_DESCENT = "Maximum Descent";
  12.    static final String MAX_ADVANCE = "Maximum Advance";
  13.  
  14.    public FontMetrics() {
  15.    }
  16.  
  17.    public FontMetrics(Font var1) {
  18.       this();
  19.       this._font = var1;
  20.       if (!this._font.wasDownloaded()) {
  21.          this._awtMetrics = AWTCompatibility.awtToolkit().getFontMetrics(this._font._awtFont);
  22.       }
  23.  
  24.    }
  25.  
  26.    FontMetrics(java.awt.FontMetrics var1) {
  27.       this();
  28.       this._font = AWTCompatibility.fontForAWTFont(var1.getFont());
  29.       this._awtMetrics = var1;
  30.    }
  31.  
  32.    public Font font() {
  33.       return this._font;
  34.    }
  35.  
  36.    public int leading() {
  37.       return this._awtMetrics != null ? this._awtMetrics.getLeading() : this._font._intValueFromDescription("Leading");
  38.    }
  39.  
  40.    public int ascent() {
  41.       return this._awtMetrics != null ? this._awtMetrics.getAscent() : this._font._intValueFromDescription("Ascent");
  42.    }
  43.  
  44.    public int descent() {
  45.       return this._awtMetrics != null ? this._awtMetrics.getDescent() : this._font._intValueFromDescription("Descent");
  46.    }
  47.  
  48.    public int height() {
  49.       return this._awtMetrics != null ? this._awtMetrics.getHeight() : this._font._intValueFromDescription("Total Height");
  50.    }
  51.  
  52.    public int charHeight() {
  53.       return this._awtMetrics != null ? this._awtMetrics.getAscent() + this._awtMetrics.getDescent() : this._font._intValueFromDescription("Ascent") + this._font._intValueFromDescription("Descent");
  54.    }
  55.  
  56.    public int maxAscent() {
  57.       return this._awtMetrics != null ? this._awtMetrics.getMaxAscent() : this._font._intValueFromDescription("Maximum Ascent");
  58.    }
  59.  
  60.    public int maxDescent() {
  61.       return this._awtMetrics != null ? this._awtMetrics.getMaxDecent() : this._font._intValueFromDescription("Maximum Descent");
  62.    }
  63.  
  64.    public int maxAdvance() {
  65.       return this._awtMetrics != null ? this._awtMetrics.getMaxAdvance() : this._font._intValueFromDescription("Maximum Advance");
  66.    }
  67.  
  68.    public int charWidth(int var1) {
  69.       return this._awtMetrics != null ? this._awtMetrics.charWidth(var1) : 0;
  70.    }
  71.  
  72.    public int charWidth(char var1) {
  73.       return this._awtMetrics != null ? this._awtMetrics.charWidth(var1) : 0;
  74.    }
  75.  
  76.    public int stringWidth(String var1) {
  77.       if (var1 == null) {
  78.          return 0;
  79.       } else if (this._awtMetrics != null) {
  80.          return this._awtMetrics.stringWidth(var1);
  81.       } else {
  82.          int var2 = 0;
  83.  
  84.          for(int var3 = 0; var3 < var1.length(); ++var3) {
  85.             char var4 = var1.charAt(var3);
  86.             if (var4 >= 0 && var4 < this._font._widthsArray.length) {
  87.                var2 += this._font._widthsArray[var4];
  88.             }
  89.          }
  90.  
  91.          return var2;
  92.       }
  93.    }
  94.  
  95.    public int stringHeight() {
  96.       return this.ascent() + this.descent();
  97.    }
  98.  
  99.    public Size stringSize(String var1) {
  100.       return new Size(this.stringWidth(var1), this.stringHeight());
  101.    }
  102.  
  103.    public int charsWidth(char[] var1, int var2, int var3) {
  104.       return this._awtMetrics != null ? this._awtMetrics.charsWidth(var1, var2, var3) : 0;
  105.    }
  106.  
  107.    public int bytesWidth(byte[] var1, int var2, int var3) {
  108.       return this._awtMetrics != null ? this._awtMetrics.bytesWidth(var1, var2, var3) : 0;
  109.    }
  110.  
  111.    public int[] widthsArray() {
  112.       return this._awtMetrics != null ? this._awtMetrics.getWidths() : this._font._widthsArray;
  113.    }
  114.  
  115.    public int widthsArrayBase() {
  116.       return this._font._widthsArrayBase;
  117.    }
  118.  
  119.    public String toString() {
  120.       return this._awtMetrics != null ? this._awtMetrics.toString() : "";
  121.    }
  122. }
  123.