|
Post by NeX on Oct 12, 2015 9:46:13 GMT -8
Hi there,
I asked previously if there was a way to get the pixel width of a string of text and got this great code:
int text_width(byte font, const char *s){ //calculates the width of text unsigned char widths[128];
uint32_t font_addr = GD.rd32(0xffffc);
font_addr += 148 * (font - 16);
for (int i = 0; i < 128; i++)
widths[i] = GD.rd(font_addr + i);
int w = 0;
while (*s)
w += widths[*s++];
return w;
} and it works perfectly,
but there is a problem, it doesn't work with custom fonts, only built in fonts.
is there a way it could work for built in fonts?
thanks
|
|
|
Post by NeX on Oct 14, 2015 0:21:24 GMT -8
oops, i meant to say, can the code be modified to work with custom fonts? is there an automatic way of working out the width of text written with a custom font?
|
|
|
Post by jamesbowman on Jul 20, 2017 14:23:26 GMT -8
|
|