home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / awt / win32 / Win32FontMetrics.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  5.2 KB  |  193 lines

  1. /*
  2.  * @(#)Win32FontMetrics.java    1.6 95/11/24 Jim Graham
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package sun.awt.win32;
  21.  
  22. import java.awt.*;
  23. import java.util.Hashtable;
  24. import com.ms.awt.FontMetricsX;
  25.  
  26. /** 
  27.  * A font metrics object for a WServer font.
  28.  * 
  29.  * @version 1.6 11/24/95
  30.  * @author Jim Graham
  31.  */
  32.  // bugbug: Davidms/IanEl: made class public.
  33. public class Win32FontMetrics extends FontMetrics {
  34.     /**
  35.      * The widths of the first 256 characters.
  36.      */
  37.     int widths[];
  38.  
  39.     /** 
  40.      * The standard ascent of the font.  This is the logical height
  41.      * above the baseline for the Alphanumeric characters and should
  42.      * be used for determining line spacing.  Note, however, that some
  43.      * characters in the font may extend above this height.
  44.      */
  45.     int ascent;
  46.  
  47.     /** 
  48.      * The standard descent of the font.  This is the logical height
  49.      * below the baseline for the Alphanumeric characters and should
  50.      * be used for determining line spacing.  Note, however, that some
  51.      * characters in the font may extend below this height.
  52.      */
  53.     int descent;
  54.  
  55.     /** 
  56.      * The standard leading for the font.  This is the logical amount
  57.      * of space to be reserved between the descent of one line of text
  58.      * and the ascent of the next line.  The height metric is calculated
  59.      * to include this extra space.
  60.      */
  61.     int leading;
  62.  
  63.     /** 
  64.      * The standard height of a line of text in this font.  This is
  65.      * the distance between the baseline of adjacent lines of text.
  66.      * It is the sum of the ascent+descent+leading.  There is no
  67.      * guarantee that lines of text spaced at this distance will be
  68.      * disjoint; such lines may overlap if some characters overshoot
  69.      * the standard ascent and descent metrics.
  70.      */
  71.     int height;
  72.  
  73.     /** 
  74.      * The maximum ascent for all characters in this font.  No character
  75.      * will extend further above the baseline than this metric.
  76.      */
  77.     int maxAscent;
  78.  
  79.     /** 
  80.      * The maximum descent for all characters in this font.  No character
  81.      * will descend further below the baseline than this metric.
  82.      */
  83.     int maxDescent;
  84.  
  85.     /** 
  86.      * The maximum possible height of a line of text in this font.
  87.      * Adjacent lines of text spaced this distance apart will be
  88.      * guaranteed not to overlap.  Note, however, that many paragraphs
  89.      * that contain ordinary alphanumeric text may look too widely
  90.      * spaced if this metric is used to determine line spacing.  The
  91.      * height field should be preferred unless the text in a given
  92.      * line contains particularly tall characters.
  93.      */
  94.     int maxHeight;
  95.  
  96.     /** 
  97.      * The maximum advance width of any character in this font. 
  98.      */
  99.     int maxAdvance;
  100.  
  101.     /**
  102.      * Calculate the metrics from the given WServer and font.
  103.      */
  104.     public Win32FontMetrics(Font font) {
  105.     super(font);
  106.     init();
  107.     }
  108.  
  109.     /**
  110.      * Get leading
  111.      */
  112.     public int getLeading() {
  113.     return leading;
  114.     }
  115.  
  116.     /**
  117.      * Get ascent.
  118.      */
  119.     public int getAscent() {
  120.     return ascent;
  121.     }
  122.  
  123.     /**
  124.      * Get descent
  125.      */
  126.     public int getDescent() {
  127.     return descent;
  128.     }
  129.  
  130.     /**
  131.      * Get height
  132.      */
  133.     public int getHeight() {
  134.     return height;
  135.     }
  136.  
  137.     /**
  138.      * Get maxAscent
  139.      */
  140.     public int getMaxAscent() {
  141.     return maxAscent;
  142.     }
  143.  
  144.     /**
  145.      * Get maxDescent
  146.      */
  147.     public int getMaxDescent() {
  148.     return maxDescent;
  149.     }
  150.  
  151.     /**
  152.      * Get maxAdvance
  153.      */
  154.     public int getMaxAdvance() {
  155.     return maxAdvance;
  156.     }
  157.  
  158.     /** 
  159.      * Return the width of the specified string in this Font. 
  160.      */
  161.     public native int stringWidth(String str);
  162.  
  163.     /**
  164.      * Return the width of the specified char[] in this Font.
  165.      */
  166.     public native int charsWidth(char data[], int off, int len);
  167.  
  168.     /**
  169.      * Return the width of the specified byte[] in this Font. 
  170.      */
  171.     public native int bytesWidth(byte data[], int off, int len);
  172.  
  173.     /**
  174.      * Get the widths of the first 256 characters in the font.
  175.      */
  176.     public int[] getWidths() {
  177.     return widths;
  178.     }
  179.  
  180.     native void init();
  181.  
  182.     static Hashtable table = new Hashtable();
  183.     
  184.     static synchronized FontMetrics getFontMetrics(Font font) 
  185.     {
  186.         FontMetrics fm = (FontMetrics)table.get(font);
  187.         if (fm == null) 
  188.             table.put(font, fm = new FontMetricsX(font));
  189.             
  190.         return fm;
  191.     }
  192. }
  193.