lib/browser/GraphBrowser/DefaultFontMetrics.java
changeset 13968 689868b99bde
parent 11874 83c97febc828
child 13970 4aef7117817b
equal deleted inserted replaced
13967:9cdab3186c0b 13968:689868b99bde
     8   is available.
     8   is available.
     9 ***************************************************************************/
     9 ***************************************************************************/
    10 
    10 
    11 package GraphBrowser;
    11 package GraphBrowser;
    12 
    12 
    13 import java.awt.*;
    13 public class DefaultFontMetrics implements AbstractFontMetrics {
    14 
    14 
    15 public class DefaultFontMetrics extends FontMetrics
    15   private static int[] chars =
    16 {
       
    17     protected static int[] chars =
       
    18 	{13, 13, 17, 27, 27, 43, 32, 11, 16, 16, 19, 28, 13, 28, 13, 13, 27,
    16 	{13, 13, 17, 27, 27, 43, 32, 11, 16, 16, 19, 28, 13, 28, 13, 13, 27,
    19 	 27, 27, 27, 27, 27, 27, 27, 27, 27, 13, 13, 28, 28, 28, 27, 49, 32,
    17 	 27, 27, 27, 27, 27, 27, 27, 27, 27, 13, 13, 28, 28, 28, 27, 49, 32,
    20 	 32, 35, 35, 32, 29, 37, 35, 13, 24, 32, 27, 40, 35, 37, 32, 37, 35,
    18 	 32, 35, 35, 32, 29, 37, 35, 13, 24, 32, 27, 40, 35, 37, 32, 37, 35,
    21 	 32, 29, 35, 32, 45, 32, 32, 29, 13, 13, 13, 22, 27, 11, 27, 27, 24,
    19 	 32, 29, 35, 32, 45, 32, 32, 29, 13, 13, 13, 22, 27, 11, 27, 27, 24,
    22 	 27, 27, 13, 27, 27, 11, 11, 24, 11, 40, 27, 27, 27, 27, 16, 24, 13,
    20 	 27, 27, 13, 27, 27, 11, 11, 24, 11, 40, 27, 27, 27, 27, 16, 24, 13,
    23 	 27, 24, 35, 24, 24, 24, 16, 12, 16, 28};
    21 	 27, 24, 35, 24, 24, 24, 16, 12, 16, 28};
    24 
    22 
    25     int size;
    23   private int size;
    26 
    24 
    27     public DefaultFontMetrics(int size)
    25   public DefaultFontMetrics(int size)
    28     { super(null); this.size = size; }
    26   { this.size = size; }
    29 
    27 
    30     public int getLeading()
    28   public int getLeading()
    31     { return 1; }
    29   { return 1; }
    32 
    30 
    33     public int getAscent()
    31   public int getAscent()
    34     { return (int)(Math.round(size * 46.0 / 48.0)); }
    32   { return (int)(Math.round(size * 46.0 / 48.0)); }
    35 
    33   
    36     public int getDescent()
    34   public int getDescent() 
    37     { return (int)(Math.round(size * 10.0 / 48.0)); }
    35   { return (int)(Math.round(size * 10.0 / 48.0)); }
    38 
    36   
    39     public int charWidth(char c) {
    37   public int charWidth(char c) {
    40 	if (c < 32 || c > 126) { return 0; }
    38     if (c < 32 || c > 126) { return 0; }
    41 	else {
    39     else {
    42 	    return (int)(Math.round(chars[c - 32] * size / 48.0));
    40 	    return (int)(Math.round(chars[c - 32] * size / 48.0));
    43 	}
       
    44     }
    41     }
    45 
    42   }
    46     public int stringWidth(String s) {
    43   
    47 	int l=0, i;
    44   public int stringWidth(String s) {
    48 	for (i=0; i < s.length(); i++) { l += charWidth(s.charAt(i)); }
    45     int l=0, i;
    49 	return l;
    46     for (i=0; i < s.length(); i++) { l += charWidth(s.charAt(i)); }
    50     }
    47     return l;
       
    48   }
    51 }
    49 }