home *** CD-ROM | disk | FTP | other *** search
- package java.awt;
-
- public abstract class FontMetrics {
- protected Font font;
-
- protected FontMetrics(Font font) {
- this.font = font;
- }
-
- public Font getFont() {
- return this.font;
- }
-
- public int getLeading() {
- return 0;
- }
-
- public int getAscent() {
- return this.font.getSize();
- }
-
- public int getDescent() {
- return 0;
- }
-
- public int getHeight() {
- return this.getLeading() + this.getAscent() + this.getDescent();
- }
-
- public int getMaxAscent() {
- return this.getAscent();
- }
-
- public int getMaxDescent() {
- return this.getDescent();
- }
-
- public int getMaxDecent() {
- return this.getMaxDescent();
- }
-
- public int getMaxAdvance() {
- return -1;
- }
-
- public int charWidth(int ch) {
- return this.charWidth((char)ch);
- }
-
- public int charWidth(char ch) {
- if (ch < 256) {
- return this.getWidths()[ch];
- } else {
- char[] data = new char[]{ch};
- return this.charsWidth(data, 0, 1);
- }
- }
-
- public int stringWidth(String str) {
- int len = str.length();
- char[] data = new char[len];
- str.getChars(0, len, data, 0);
- return this.charsWidth(data, 0, len);
- }
-
- public int charsWidth(char[] data, int off, int len) {
- return this.stringWidth(new String(data, off, len));
- }
-
- public int bytesWidth(byte[] data, int off, int len) {
- return this.stringWidth(new String(data, 0, off, len));
- }
-
- public int[] getWidths() {
- int[] widths = new int[256];
-
- for(char ch = 0; ch < 256; ++ch) {
- widths[ch] = this.charWidth(ch);
- }
-
- return widths;
- }
-
- public String toString() {
- return this.getClass().getName() + "[font=" + this.getFont() + "ascent=" + this.getAscent() + ", descent=" + this.getDescent() + ", height=" + this.getHeight() + "]";
- }
- }
-