Reputation: 707
Given any typical font, not necessarily a monospace one, how can I render text in a monospace style? I've tried messing around with drawing the bitmaps of the glyphs individually, but I can never get the x and y alignment between glyphs right. I'm using OpenGL and python, but the answer should be adaptable to any graphics context or language.
Upvotes: 0
Views: 1323
Reputation: 707
OK yep sorry I'm silly. I'm not even sure what I was doing wrong before. In case anyone equally as silly stumbles upon this, the simplest solution (in pseudocode) is just:
int charWidth = width of widest character in font;
void drawString(FT_Face face, string str, int xshift, int yshift) {
x = 0;
for (each character c in str) {
FT_Load_Char(face, c, ...);
draw the character at (xshift + x, yshift);
x += charWidth;
}
}
(It won't let me accept my own answer yet)
Upvotes: 1