← Back

ofxTextAlign

github.com/nariakiiwatani/ofxTextAlign · @nariakiiwatani
OF 0.9 Typography

openframeworks addon for drawing text aligned

12 1 Last commit 9y ago Created 13y ago

Forks

Forks pushed to more recently than nariakiiwatani/ofxTextAlign itself, plus any admin-confirmed fork with commits of its own — worth checking if you're hitting issues with the original.

tettou771/ofxTextAlign by @tettou771 · ★ 1 · pushed 1y ago

README

ofxTextAlign



What can it do

With this addon, you can draw texts in various align. e.g. center-bottom aligned, fit in a rect,,,

center-middle align with min width and min height set. center-middle align with min width and min height set.

right-bottom align with min width and max width set. right-bottom align with min width and max width set.

How to use



TrueTypeFont

In case of using ttf, simply load a font and draw string.

	ofxTextAlignTTF text;

	text.load(OF_TTF_SANS, fontsize);
	text.draw("some cool text", x,y);


Other than TTF

You have to code a bit.

class YourClass : public ofxTextAlign
{
	const char drawChar(const char str, float x, float y);
	float getCharWidth(char ch) const;
	float getLineHeight() const;
};

const char YourClass::drawChar(const char str, float x, float y)
{
	// draw the first charactor of str as (x,y) position to be left-top point.
	string ch;
	ch.assign(str, 1);
	ofDrawBitmapString(ch, x, y);
	// and return pointer to next charactor.
	return str+1;
}

float YourClass::getCharWidth(char ch) const
{
	// return width of each charactor.
	// If it is constant, the text will be monospaced.
	return 32;
}
float YourClass::getLineHeight() const
{
	// return default line height. It may be ignored by setting min/max height.
	return ofTrueTypeFont::getLineHeight();
}


License

MIT License.

Get this addon

HTTPS
SSH