X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fdraw%2Fao_text_width.c;fp=src%2Fdraw%2Fao_text_width.c;h=9f08bd03501997410701c978aa7cd98654e46a3e;hb=c2b775a6cd8888f98f086b4b730edb31bb846f91;hp=0000000000000000000000000000000000000000;hpb=f856f20b31c542caeb5decbf3546c6a0242ab33d;p=fw%2Faltos diff --git a/src/draw/ao_text_width.c b/src/draw/ao_text_width.c new file mode 100644 index 00000000..9f08bd03 --- /dev/null +++ b/src/draw/ao_text_width.c @@ -0,0 +1,40 @@ +/* + * Copyright © 2024 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include +#include +#include "ao_font.h" +#include +#include + +int16_t +ao_text_width(const struct ao_font *font, + const char *string) +{ + char c; + int16_t x = 0; + + while ((c = *string++)) { + if (font->metrics) { + x += font->metrics[(uint8_t) c].advance; + } else { + x += font->max_width; + } + } + return x; +}