// vi:ft=cpp /* * (c) 2010 Adam Lackorzynski , * Alexander Warg * economic rights: Technische Universität Dresden (Germany) * * This file is part of TUD:OS and distributed under the terms of the * GNU General Public License 2. * Please see the COPYING-GPL-2 file for details. */ #pragma once #include #include namespace Mag_gfx { struct Font { unsigned char const *img; l4_int32_t const *wtab, *otab; int w, h; explicit Font(void const *_ttf) { char const *ttf = (char const *)_ttf; otab = (l4_int32_t const *)ttf; wtab = (l4_int32_t const *)(ttf + 1024); w = *(l4_int32_t const *)(ttf + 2048); h = *(l4_int32_t const *)(ttf + 2052); img = (unsigned char const *)(ttf + 2056); } /** * Calculate width of string when printed with the font */ int str_w(char const *_str) const { unsigned char const *str = (unsigned char const *)_str; int res = 0; for (; str && *str; ++str) res += wtab[*str]; return res; } int str_w(char const *_str, int len) const { unsigned char const *str = (unsigned char const *)_str; int res = 0; for (; str && *str && len; ++str, --len) res += wtab[*str]; return res; } /** * Calculate height of string when printed with the font */ int str_h(char const *) const { return h; } int str_h(char const *, int) const { return h; } Area str_sz(char const *s) const { return Area(str_w(s), str_h(s)); } Area str_sz(char const *s, int l) const { return Area(str_w(s, l), str_h(s, l)); } }; }