2 * guilib - a minimal pixel framework
3 * Copyright (c) 2008, 2009 Daniel Mack <daniel@caiaq.de>
4 * Copyright (c) 2009 Holger Hans Peter Freyther <zecke@openmoko.org>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 /* wiki-lib includes */
24 /* gui-lib includes */
30 #include <wikireader.h>
32 void render_glyph(int start_x
, int start_y
, const struct glyph
*glyph
)
35 const char *d
= glyph
->data
;
37 for (y
= start_y
; y
< start_y
+ glyph
->height
; ++y
) {
38 for (x
= start_x
, w
= glyph
->width
; w
> 0;) {
40 unsigned byte
= (x
+ LCD_VRAM_WIDTH_PIXELS
* y
) / 8;
42 if (byte
>= LCD_VRAM_SIZE
)
45 use
= MIN(8 - (x
% 8) , w
);
46 use
= MIN(8 - bit
, use
);
47 #ifdef DISPLAY_INVERTED
48 framebuffer
[byte
] &= ~((*d
<< bit
& (unsigned char)(0xff << (8 - use
))) >> (x
% 8));
50 framebuffer
[byte
] |= (*d
<< bit
& (unsigned char)(0xff << (8 - use
))) >> (x
% 8);
64 /* we might need that later ... */
65 static int simple_kerning(struct Glyph
*a
, struct Glyph
*b
)
72 /* we do some very simple kerning here. The idea is to scan
73 * the left edge of the right glyph and the right edge of the
74 * left glyph and find out how far the two could move towards
75 * each other without colliding. */
76 delta
= MIN(a
->w
, b
->w
);
77 for (y
= 0; y
< MIN(a
->h
, b
->h
); y
++) {
80 /* right edge of left glyph */
81 for (x
= a
->w
- 1; x
> 0; x
--, d
++)
82 if (glyph_pixel(a
, x
, y
) != 0)
85 /* left edge of right pixel */
86 for (x
= 0; x
< b
->w
; x
++, d
++)
87 if (glyph_pixel(b
, x
, y
) != 0)
90 /* find smallest value for all rows */
100 * static copy a char map... true for some fonts e.g.
103 static int char_to_glyph(char c
)
112 * Simplistic string drawing
114 * @param font The font index to use
115 * @param string The string to draw. No text wrapping will be done
116 * @param start_x From where to start drawing (upper left)
117 * @param start_y From where to start drawing (upper left)
119 int render_string(const int font
, int start_x
,
120 int start_y
, const char *string
, const int text_length
)
122 if ((unsigned int) font
>= guilib_nr_fonts())
130 for (i
= 0; i
< text_length
; ++i
) {
131 const struct glyph
*glyph
= get_glyph(font
,
132 char_to_glyph(string
[i
] & 0x7f));
134 /* painting and advance */
135 /* TODO: use the above auto kerning for the advance */
136 render_glyph(x
, start_y
- glyph
->top_bearing
, glyph
);
137 x
+= glyph
->width
+ 1;
139 if (glyph
->height
> max_height
)
140 max_height
= glyph
->height
;