com.yospace.yae.yogi
Class CustomFont

java.lang.Object
  |
  +--com.yospace.yae.yogi.Font
        |
        +--com.yospace.yae.yogi.CustomFont

public class CustomFont
extends Font

This font class is a YoGI replacement for the MIDP font class. It offers the same functionality as MIDP fonts but extends it to allow antialiased fonts and kerned fonts. It uses fonts that have the ".yaef" extension. The way that the implementation works means that the speed of rendering and the amount of memory taken is directly proportional to the size of the source file for the font.


Fields inherited from class com.yospace.yae.yogi.Font
FACE_MONOSPACE, FACE_PROPORTIONAL, FACE_SYSTEM, SIZE_LARGE, SIZE_MEDIUM, SIZE_SMALL, STYLE_BOLD, STYLE_ITALIC, STYLE_PLAIN, STYLE_UNDERLINED
 
Constructor Summary
protected CustomFont(java.lang.String name)
          Creates a CustomFont given a resource name for the font file.
 
Method Summary
 int charsWidth(char[] ch, int offset, int length)
          Returns the width in pixels of a subset of a character array (kerning WILL affect the width returned).
 int charWidth(char ch)
          Returns the width in pixels of a character (kerning will NOT affect the width of the character).
 void drawGlyph(Graphics g, char c, int x, int y)
          Renders a character onto a Graphics at a specified position, which is the top left of the character (no kerning will occur when drawing characters individually like this).
 void drawGlyph(Graphics g, char c, int x, int y, int backgroundColor)
          Renders a character onto a Graphics at a specified position, which is the top left of the character, with a specified background color (no kerning will occur when drawing characters individually like this).
 void drawString(Graphics g, java.lang.String s, int x, int y)
          Renders a String onto a Graphics at a specified position, which is the top left of the String (kerning will occur if the font contains kerning information).
 void drawString(Graphics g, java.lang.String s, int x, int y, int backgroundColor)
          Renders a String onto a Graphics at a specified position, which is the top left of the String, with a specified background color (kerning will occur if the font contains kerning information).
 int getBaselinePosition()
          Returns the distance in pixels from the top of the text to the text's baseline (as per MIDP Font class).
 int getFace()
          Returns the face of the Font (as per MIDP Font class).
 int getHeight()
          Returns the height of the font (as per MIDP Font class).
 java.lang.String getName()
          Returns the name of this font.
 int getSize()
          Returns the size of the Font (as per MIDP Font class).
 int getStyle()
          Returns the style of the Font (as per MIDP Font class).
 boolean isBold()
          Returns whether the font is bold (as per MIDP Font class).
 boolean isItalic()
          Returns whether the font is italic (as per MIDP Font class).
 boolean isPlain()
          Returns whether the font is plain (as per MIDP Font class).
 boolean isUnderlined()
          Returns whether the font is underlined (as per MIDP Font class).
 int stringWidth(java.lang.String str)
          Returns the width in pixels of a String (kerning WILL affect the width returned).
 int substringWidth(java.lang.String str, int offset, int length)
          Returns the width in pixels of a subset of a String (kerning WILL affect the width returned).
 
Methods inherited from class com.yospace.yae.yogi.Font
getDefaultFont, getFont, getFont, getFontSmallerThan
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomFont

protected CustomFont(java.lang.String name)
              throws java.io.IOException
Creates a CustomFont given a resource name for the font file. This resource can be over an HTTP connection.
Parameters:
name - the resource to load the font from.
Throws:
java.io.IOException - if an I/O error occurs.
Method Detail

getName

public java.lang.String getName()
Returns the name of this font.
Returns:
the font name

getStyle

public int getStyle()
Returns the style of the Font (as per MIDP Font class).
Overrides:
getStyle in class Font
Returns:
the MIDP style.

getSize

public int getSize()
Returns the size of the Font (as per MIDP Font class).
Overrides:
getSize in class Font
Returns:
SIZE_MEDIUM.

getFace

public int getFace()
Returns the face of the Font (as per MIDP Font class).
Overrides:
getFace in class Font
Returns:
FACE_SYSTEM.

isPlain

public boolean isPlain()
Returns whether the font is plain (as per MIDP Font class).
Overrides:
isPlain in class Font
Returns:
true if the font is plain, false otherwise.

isBold

public boolean isBold()
Returns whether the font is bold (as per MIDP Font class).
Overrides:
isBold in class Font
Returns:
true if the font is bold, false otherwise.

isItalic

public boolean isItalic()
Returns whether the font is italic (as per MIDP Font class).
Overrides:
isItalic in class Font
Returns:
true if the font is italic, false otherwise.

isUnderlined

public boolean isUnderlined()
Returns whether the font is underlined (as per MIDP Font class).
Overrides:
isUnderlined in class Font
Returns:
true if the font is underlined, false otherwise.

getHeight

public int getHeight()
Returns the height of the font (as per MIDP Font class).
Overrides:
getHeight in class Font
Returns:
the height of a line of text in this font.

getBaselinePosition

public int getBaselinePosition()
Returns the distance in pixels from the top of the text to the text's baseline (as per MIDP Font class).
Overrides:
getBaselinePosition in class Font
Returns:
the distance in pixels from the top of the text to the text's baseline.

charWidth

public int charWidth(char ch)
Returns the width in pixels of a character (kerning will NOT affect the width of the character).
Overrides:
charWidth in class Font
Parameters:
ch - the character to find the width of.
Returns:
the width of the character.

charsWidth

public int charsWidth(char[] ch,
                      int offset,
                      int length)
Returns the width in pixels of a subset of a character array (kerning WILL affect the width returned).
Overrides:
charsWidth in class Font
Parameters:
ch - the source character array.
offset - the index of the first character in the subset.
length - the total number of characters in the subset.
Returns:
the width of the character subset.

stringWidth

public int stringWidth(java.lang.String str)
Returns the width in pixels of a String (kerning WILL affect the width returned).
Overrides:
stringWidth in class Font
Parameters:
str - the String.
Returns:
the width of the String.

substringWidth

public int substringWidth(java.lang.String str,
                          int offset,
                          int length)
Returns the width in pixels of a subset of a String (kerning WILL affect the width returned).
Overrides:
substringWidth in class Font
Parameters:
str - the source String.
offset - the index of the first character in the subset.
length - the total number of characters in the subset.
Returns:
the width of the String subset.

drawGlyph

public void drawGlyph(Graphics g,
                      char c,
                      int x,
                      int y)
Renders a character onto a Graphics at a specified position, which is the top left of the character (no kerning will occur when drawing characters individually like this).
Overrides:
drawGlyph in class Font
Parameters:
g - the Graphics area to draw onto.
c - the character to be drawn.
x - the x coordinate of the top-left location which the character will be drawn from.
y - the y coordinate of the top-left location which the character will be drawn from.

drawString

public void drawString(Graphics g,
                       java.lang.String s,
                       int x,
                       int y)
Renders a String onto a Graphics at a specified position, which is the top left of the String (kerning will occur if the font contains kerning information).
Overrides:
drawString in class Font
Parameters:
g - the Graphics area to draw onto.
s - the String to be drawn.
x - the x coordinate of the top-left location which the String will be drawn from.
y - the y coordinate of the top-left location which the String will be drawn from.

drawGlyph

public void drawGlyph(Graphics g,
                      char c,
                      int x,
                      int y,
                      int backgroundColor)
Renders a character onto a Graphics at a specified position, which is the top left of the character, with a specified background color (no kerning will occur when drawing characters individually like this). The extra backgroundColor argument is to allow this to be set to a different color than the background color that the character is being drawn onto. This is only useful for antialiased fonts.
Overrides:
drawGlyph in class Font
Parameters:
g - the Graphics area to draw onto.
c - the character to be drawn.
x - the x coordinate of the top-left location which the character will be drawn from.
y - the y coordinate of the top-left location which the character will be drawn from.
backgroundColor - the background color that will be used.

drawString

public void drawString(Graphics g,
                       java.lang.String s,
                       int x,
                       int y,
                       int backgroundColor)
Renders a String onto a Graphics at a specified position, which is the top left of the String, with a specified background color (kerning will occur if the font contains kerning information). The extra backgroundColor argument is to allow this to be set to a different color than the background color that the character is being drawn onto. This is only useful for antialiased fonts.
Overrides:
drawString in class Font
Parameters:
g - the Graphics area to draw onto.
s - the String to be drawn.
x - the x coordinate of the top-left location which the String will be drawn from.
y - the y coordinate of the top-left location which the String will be drawn from.
backgroundColor - the background color that will be used.

Copyright 2002 Yospace Holdings Ltd. All Rights Reserved.