summaryrefslogtreecommitdiff
path: root/framebuffer/framebuffer.c
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2014-05-06 21:31:05 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2014-05-06 21:31:05 +0100
commit4cbc56ebc103e1b8302a4b710309e3af6a553ffc (patch)
tree7baf6129d4580ffd915b44974b751e026eb9e9c9 /framebuffer/framebuffer.c
parentd67504677b9316dd0401b58e9cec8d7908a329cd (diff)
downloadnetsurf-4cbc56ebc103e1b8302a4b710309e3af6a553ffc.tar.gz
netsurf-4cbc56ebc103e1b8302a4b710309e3af6a553ffc.tar.bz2
Add Unicode support to internal font.
+ Now contains more glpyhs (was previously limited to cp-1252). + When a glyph is unavailable, the codepoint is now rendered. + Added glyph data file. + Added converter to generate the font's .c file from the data. TODO: The generated file is currently checked into the repo, but it should be generated as part of the build process, in the build-* directory. To update the generated source file, first build the converter: $ gcc -O2 -Wall framebuffer/convert_font.c -lm \ -o build-Linux-framebuffer/tools/convert_font And then use it to generate the souce file: $ build-Linux-framebuffer/tools/convert_font \ framebuffer/res/fonts/glyph_data \ framebuffer/GEN_font_internal.c -v The converter's usage is: convert_font [options] <in_file> <out_file> See convert_font --help for more details.
Diffstat (limited to 'framebuffer/framebuffer.c')
-rw-r--r--framebuffer/framebuffer.c41
1 files changed, 16 insertions, 25 deletions
diff --git a/framebuffer/framebuffer.c b/framebuffer/framebuffer.c
index c2d73acb0..0115d838c 100644
--- a/framebuffer/framebuffer.c
+++ b/framebuffer/framebuffer.c
@@ -125,42 +125,33 @@ framebuffer_plot_text(int x, int y, const char *text, size_t length,
static bool framebuffer_plot_text(int x, int y, const char *text, size_t length,
const plot_font_style_t *fstyle)
{
- const struct fb_font_desc* fb_font = fb_get_font(fstyle);
- const uint32_t *chrp;
- char *buffer = NULL;
- int chr;
- int blen;
+ enum fb_font_style style = fb_get_font_style(fstyle);
+ const uint8_t *chrp;
+ size_t nxtchr = 0;
nsfb_bbox_t loc;
+ uint32_t ucs4;
- utf8_to_font_encoding(fb_font, text, length, &buffer);
- if (buffer == NULL)
- return true;
-
- /* y is given as the baseline, at 3/4 from top.
- * we need it to the top */
- y -= ((fb_font->height * 3) / 4);
-
- /* the coord is the bottom-left of the pixels offset by 1 to make
- * it work since fb coords are the top-left of pixels
- */
- y += 1;
+ y -= ((FB_FONT_HEIGHT * 3) / 4);
+ /* the coord is the bottom-left of the pixels offset by 1 to make
+ * it work since fb coords are the top-left of pixels */
+ y += 1;
- blen = strlen(buffer);
+ while (nxtchr < length) {
+ ucs4 = utf8_to_ucs4(text + nxtchr, length - nxtchr);
+ nxtchr = utf8_next(text, length, nxtchr);
- for (chr = 0; chr < blen; chr++) {
loc.x0 = x;
loc.y0 = y;
- loc.x1 = loc.x0 + fb_font->width;
- loc.y1 = loc.y0 + fb_font->height;
+ loc.x1 = loc.x0 + FB_FONT_WIDTH;
+ loc.y1 = loc.y0 + FB_FONT_HEIGHT;
- chrp = fb_font->data + ((unsigned char)buffer[chr] * fb_font->height);
- nsfb_plot_glyph1(nsfb, &loc, (uint8_t *)chrp, 32, fstyle->foreground);
+ chrp = fb_get_glyph(ucs4, style);
+ nsfb_plot_glyph1(nsfb, &loc, chrp, FB_FONT_PITCH, fstyle->foreground);
- x += fb_font->width;
+ x += FB_FONT_WIDTH;
}
- free(buffer);
return true;
}
#endif