Artenus 2D Framework
Artenus Reference
Represents a font. A font is a special-purpose cut-out of an image that divides that image into characters of different widths. Each font can represent a limited set of characters out of the character space. Artenus fonts are normal SVG graphics with a comment block describing extra information. Below is an example of the comment block:

 <!--
 ARTENUS_FONT 80,-5,0
 A 0,  67
 B 67, 124
 C 124,198
 D 0,  80
 -->
 
The above block introduces a font height of 80 pixels, horizontal spacing of -5, and vertical spacing of 0. There are four letters defined in the font:

  • A starts from x=0 to x=67 in the first line of the graphics (y=0 to y=79).
  • B starts from x=0 to x=67 in the first line of the graphics (y=0 to y=79).
  • C starts from x=0 to x=67 in the first line of the graphics (y=0 to y=79).
  • D starts from x=0 to x=67 in the second line of the graphics (y=80 to y=159). Whenever the first x value is less than the previous letter's second x, the interpreter jumps to the next line. Thus you don't need to specify y values at all.

This comment block can be placed anywhere within the SVG file, but for best performance it is recommended to appear as high as possible.

public final class Font
extends Texture

Field Summary

Fields inherited from com.annahid.libs.artenus.graphics.Texture

Method Summary

Modifier and TypeMethod and Description
public voiddraw(RenderingContext context, TextureShaderProgram program, char[] ca, float sx, float sy, float h, float rot, boolean rtl)
Draws a text on the OpenGL context using the information provided.
public final floatgetTextWidth(String text, float h)
Calculates the width of a text if drawn with this Font, based of the font size specified.
public final floatgetTextWidth(char[] ca, float h)
Calculates the width of a text if drawn with this Font, based of the font size specified.
public static StringprocessText(String text)
Processes a text and conforms it to easily support accent-based characters in the framework without the need to include accented letters in the actual font.

Methods inherited from com.annahid.libs.artenus.graphics.Texture

Methods inherited from java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail

draw
public void draw(
    RenderingContext context,
    TextureShaderProgram program,
    char[] ca,
    float sx,
    float sy,
    float h,
    float rot,
    boolean rtl
)
Draws a text on the OpenGL context using the information provided. This method is internally called by TextSprite to draw the text.
Parameters:
contextRendering context
programShader program to use
caThe character array representation of the text
sxStarting x coordinate
syStarting y coordinate
hThe desired height of the text. This controls font size
rotRotation angle of the text
rtltrue if the text should be drawn in right-to-left direction, and false otherwise
getTextWidth
public final float getTextWidth(
    String text,
    float h
)
Calculates the width of a text if drawn with this Font, based of the font size specified.
Parameters:
textThe string representation of the text
hThe font height
Returns:
The width of the text
getTextWidth
public final float getTextWidth(
    char[] ca,
    float h
)
Calculates the width of a text if drawn with this Font, based of the font size specified. This method is faster that getTextWidth(String, float).
Parameters:
caThe character array representation of the text
hThe font height
Returns:
The width of the text
processText
public static String processText(
    String text
)
Processes a text and conforms it to easily support accent-based characters in the framework without the need to include accented letters in the actual font. You can use this method to get the framework representation of latin strings with accented letters.
Parameters:
textThe text to be processed
Returns:
The processed text