1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
22 * Copyright (C) 2009-2010 Cyril Hrubis <metan@ucw.cz> *
24 *****************************************************************************/
27 * A bitmap text drawing algorithm.
30 #define DEF_TEXT_FN(FN_NAME, CONTEXT_T, PIXVAL_T, HLINE) \
31 void FN_NAME(CONTEXT_T context, const GP_TextStyle *style, int x, int y, \
32 const char *str, PIXVAL_T pixval) \
34 /* Remember the original starting height. */ \
38 for (p = str; *p != '\0'; p++) { \
40 /* Calculate the address of the character data. */ \
41 const GP_CharData *data = GP_GetCharData(style->font, *p); \
44 /* unencoded character */ \
45 data = GP_GetCharData(style->font, ' '); \
48 /* Starting and final X for each character line. */ \
49 int x0 = x + data->pre_offset * (style->pixel_xmul + style->pixel_xspace); \
50 int x1 = x0 + data->char_width * (style->pixel_xmul + style->pixel_xspace); \
52 /* Draw the character line by line. */ \
53 const uint8_t *src = data->bitmap; \
55 for (line = 0, y = y0; line < style->font->height; line++, y += style->pixel_yspace) { \
57 /* repeat the line as specified by pixel_ymul */ \
58 for (linerep = 0; linerep < style->pixel_ymul; linerep++, y++) { \
59 uint8_t const * linesrc = src + line * style->font->bytes_per_line; \
60 uint8_t mask = 0x80; \
62 /* draw the line of the character bitmap */ \
63 for (x = x0; x < x1; x += style->pixel_xmul + style->pixel_xspace) { \
64 if (*linesrc & mask) { \
66 x, x + style->pixel_xmul - 1, \
78 /* Update the X position. */ \
79 x = x0 + data->post_offset * (style->pixel_xmul + style->pixel_xspace); \
80 x += style->char_xspace * style->pixel_xmul; /* optional extra spacing */ \