- english
- /
- japanese
methods
- bind()
- drawString()
- drawStringAsShapes()
- getLetterSpacing()
- getLineHeight()
- getNumCharacters()
- getSize()
- getSpaceSize()
- getStringAsPoints()
- getStringBoundingBox()
- hasFullCharacterSet()
- isAntiAliased()
- isLoaded()
- loadFont()
- setGlobalDpi()
- setLetterSpacing()
- setLineHeight()
- setSpaceSize()
- stringHeight()
- stringWidth()
- unbind()
variables
The ofTrueTypeFont class provides an interface to load fonts into openframeworks. The fonts are converted to textures, and can be drawn on screen. There are some options when you load the font - what size the font is rendered at, wether or not it is anti-aliased, and wether the font object will be the full character set or a subset (ie, extended ascii, which can include accents, umlauts, or normal ascii). The default is anti-aliased, non-full character set. The library uses freetype, which has certain patent problems in regards to true type hinting, especially at small sizes, so non-anti-aliased type doesn't always render beautifully. But we find it quite adequate, and at larger sizes it seems to works well.
drawString(...)
void ofTrueTypeFont::drawString(string s, float x, float y)
Draws a string with that typeface, on screen, at point(x,y). For example, you can write some text on screen like this:
// in the h file:
ofTrueTypeFont myfont;
.....
// in setup:
myfont.loadFont("arial.ttf", 32);
// in draw:
myfont.drawString("hi!!", 100,100);
Your strings can even be multiline:
myfont.drawString("a test of multiline text", 300,300);
you can also using dynamically generated strings. For example, to print the frame rate:
char fpsStr[255]; // an array of chars
sprintf(fpsStr, "frame rate: %f", ofGetFrameRate());
myfont.drawString(fpsStr, 100,100);
drawStringAsShapes(...)
void ofTrueTypeFont::drawStringAsShapes(string s, float x, float y)
drawStringAsShapes function draws the s string as if it was a geometrical shapes using the information contained in ofTTFContour and ofTTFCharacter. Parameters x and y sets the position of the shape.
getLineHeight()
float ofTrueTypeFont::getLineHeight()
The line height is computed, based on the font size, and can be adjusted. Useful if you are print multi-line text.
getStringBoundingBox(...)
ofRectangle ofTrueTypeFont::getStringBoundingBox(string s, float x, float y)
e.g:
//in setup()
franklinBook.loadFont("frabk.ttf", 32);
//in update()
char tempString[255];
ofRectangle rect = franklinBook.getStringBoundingBox(tempString, 0,0);
//in draw
ofSetColor(0xcccccc);
ofRect(rect.x, rect.y, rect.width, rect.height);
loadFont(...)
void ofTrueTypeFont::loadFont(string filename, int fontsize)
Loads a fonts of a given filename in, and renders it to a texture at a given size (fontsize). It will look for the font file in the data/ folder. For example, to load the font arial at type size 32:
// int the h file:
ofTrueTypeFont myFont;
...
myFont.loadFont("arial.ttf", 32);
loadFont(...)
void ofTrueTypeFont::loadFont(string filename, int fontsize, bool _bAntiAliased, bool _bFullCharacterSet, bool makeContours)
This loads a font, but in addition to setting the font name and size, you can also pass in two flags: is this font antiAliased, and does it include the full character set?
loadFont(...)
bool ofTrueTypeFont::loadFont(string filename, int fontsize, bool _bAntiAliased=true, bool _bFullCharacterSet=false, bool makeContours=false, float simplifyAmt=0.3, int dpi=0)
setLineHeight(...)
void ofTrueTypeFont::setLineHeight(float height)
Sets the line height for text that is drawn on screen.
bool bAntiAlised
bool ofTrueTypeFont::bAntiAlised
A variable which tells you if the font is antiAliased.
bool bFullCharacterSet
bool ofTrueTypeFont::bFullCharacterSet
A variable which tells you if the font contains the full character set, or a subset.
bool bLoadedOk
bool ofTrueTypeFont::bLoadedOk
bLoadedOk is a boolean variable containing true if the font was successfully loaded.
int nCharacters
int ofTrueTypeFont::nCharacters
nCharacters contains the number of characters that our font has.
Last updated
Thursday, 16 May 2013 14:01:02 UTC
-
cbf0910627a25e6153f2452833c5313fe6067059

