From 0cecbe3cbcef566fb679aed5f0055397cb4c040c Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 20 Feb 2009 09:51:21 +0000 Subject: allow framebuffer port to use freetype2 library svn path=/trunk/netsurf/; revision=6570 --- Makefile | 5 + Makefile.config | 4 + Makefile.sources | 8 +- framebuffer/fb_16bpp_plotters.c | 9 +- framebuffer/fb_32bpp_plotters.c | 116 ++++++++++++++++- framebuffer/fb_8bpp_plotters.c | 11 +- framebuffer/fb_font.c | 136 -------------------- framebuffer/fb_font.h | 15 +++ framebuffer/fb_font_freetype.c | 260 ++++++++++++++++++++++++++++++++++++++ framebuffer/fb_font_internal.c | 141 +++++++++++++++++++++ framebuffer/fb_font_internal.h | 39 ++++++ framebuffer/fb_frontend_linuxfb.c | 9 +- framebuffer/fb_gui.c | 8 +- framebuffer/fb_rootwindow.c | 8 +- 14 files changed, 617 insertions(+), 152 deletions(-) delete mode 100644 framebuffer/fb_font.c create mode 100644 framebuffer/fb_font_freetype.c create mode 100644 framebuffer/fb_font_internal.c create mode 100644 framebuffer/fb_font_internal.h diff --git a/Makefile b/Makefile index d0aa61e15..f0b926b87 100644 --- a/Makefile +++ b/Makefile @@ -508,6 +508,11 @@ endif ifeq ($(TARGET),framebuffer) $(eval $(call feature_enabled,MNG,-DWITH_MNG,-lmng,PNG support)) + ifeq ($(NETSURF_FB_FONTLIB),freetype) + CFLAGS += -DFB_USE_FREETYPE -I/usr/include/freetype2 + LDFLAGS += -lfreetype + endif + # define additional CFLAGS and LDFLAGS requirements for pkg-configed libs here NETSURF_FEATURE_RSVG_CFLAGS := -DWITH_RSVG NETSURF_FEATURE_ROSPRITE_CFLAGS := -DWITH_NSSPRITE diff --git a/Makefile.config b/Makefile.config index 0eb967d78..53f971022 100644 --- a/Makefile.config +++ b/Makefile.config @@ -223,6 +223,10 @@ ifeq ($(TARGET),framebuffer) # Valid options: YES, NO NETSURF_USE_HARU_PDF := NO + # Library to use for font plotting + # Valid options: internal, freetype + NETSURF_FB_FONTLIB := internal + # Framebuffer frontends may have differing root paths for resources # As such, these specify the resource path and config path. NETSURF_FB_RESPATH_linux := /usr/share/netsurf/ diff --git a/Makefile.sources b/Makefile.sources index b19139305..554e81d30 100644 --- a/Makefile.sources +++ b/Makefile.sources @@ -92,12 +92,18 @@ S_AMIGA := $(addprefix amiga/,$(S_AMIGA)) # S_FRAMEBUFFER are sources purely for the framebuffer build S_FRAMEBUFFER := fb_gui.c tree.c history.c hotlist.c fb_schedule.c \ - thumbnail.c misc.c fb_bitmap.c fb_font.c font_8x16.c \ + thumbnail.c misc.c fb_bitmap.c \ fb_filetype.c login.c fb_cursor.c fb_plotters.c \ fb_8bpp_plotters.c fb_16bpp_plotters.c fb_32bpp_plotters.c \ fb_findfile.c fb_rootwindow.c fb_image_data.c # fb_1bpp_plotters.c +S_FRAMEBUFFER += fb_font_$(NETSURF_FB_FONTLIB).c + +ifeq ($(NETSURF_FB_FONTLIB),internal) +S_FRAMEBUFFER += font_8x16.c +endif + ifeq ($(NETSURF_FB_FRONTEND),linux) S_FRAMEBUFFER += fb_frontend_linuxfb.c endif diff --git a/framebuffer/fb_16bpp_plotters.c b/framebuffer/fb_16bpp_plotters.c index 827cc8f6e..095dcda52 100644 --- a/framebuffer/fb_16bpp_plotters.c +++ b/framebuffer/fb_16bpp_plotters.c @@ -191,7 +191,13 @@ static bool fb_16bpp_clg(colour c) return true; } - +#ifdef FB_USE_FREETYPE +static bool fb_16bpp_text(int x, int y, const struct css_style *style, + const char *text, size_t length, colour bg, colour c) +{ + return false; +} +#else static bool fb_16bpp_text(int x, int y, const struct css_style *style, const char *text, size_t length, colour bg, colour c) { @@ -278,6 +284,7 @@ static bool fb_16bpp_text(int x, int y, const struct css_style *style, free(buffer); return true; } +#endif static bool fb_16bpp_disc(int x, int y, int radius, colour c, bool filled) { diff --git a/framebuffer/fb_32bpp_plotters.c b/framebuffer/fb_32bpp_plotters.c index 8e8f353f6..28a6030a9 100644 --- a/framebuffer/fb_32bpp_plotters.c +++ b/framebuffer/fb_32bpp_plotters.c @@ -178,7 +178,114 @@ static bool fb_32bpp_clg(colour c) return true; } +#ifdef FB_USE_FREETYPE + +static bool +fb_32bpp_draw_ft_bitmap(FT_Bitmap *bp, int x, int y, colour c) +{ + int height = bp->rows; + int width = bp->width; + uint32_t row; + int xloop, yloop; + + uint32_t *pvideo; + uint32_t fgcol; + + int x0,y0,x1,y1; + int xoff, yoff; /* x and y offset into image */ + + unsigned char *fntd; + + if (width == 0) { + LOG(("null width char!")); + return false; + } + + + y+=1; /* 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 + */ + + /* The part of the text displayed is cropped to the current context. */ + x0 = x; + y0 = y; + x1 = x + width; + y1 = y + height; + + if (!fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1)) { + return true; /* text lies outside current clipping region */ + } + + /* find width and height to plot */ + if (height > (y1 - y0)) + height = (y1 - y0); + + if (width > (x1 - x0)) + width = (x1 - x0); + + xoff = x0 - x; + yoff = y0 - y; + + fgcol = ((c & 0xff0000) >> 16) | (c & 0xff00) | ((c & 0xff) << 16); + + + pvideo = fb_32bpp_get_xy_loc(x, y0); + + for (yloop = yoff; yloop < height; yloop++) { + fntd = bp->buffer + (yloop * bp->pitch); + for (xloop = 0; xloop < width ; xloop++) { + if ((xloop % 8) == 0) { + row = *fntd++; + } + + if ((row & 0x80) != 0) { + *(pvideo + xloop) = fgcol; + } + row = row << 1; + } + + pvideo += (framebuffer->linelen >> 2); + } + + + return true; +} + +static bool fb_32bpp_text(int x, int y, const struct css_style *style, + const char *text, size_t length, colour bg, colour c) +{ + uint32_t ucs4; + size_t nxtchr = 0; + FT_UInt glyph_index; + FT_Face face = fb_get_face(style); + FT_Error error; + + while (nxtchr < length) { + ucs4 = utf8_to_ucs4(text + nxtchr, length - nxtchr); + nxtchr = utf8_next(text, length, nxtchr); + glyph_index = FT_Get_Char_Index(face, ucs4); + + error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT); + if (error) + continue; + + error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO ); + if (error) + continue; + + /* now, draw to our target surface */ + fb_32bpp_draw_ft_bitmap( &face->glyph->bitmap, + x + face->glyph->bitmap_left, + y - face->glyph->bitmap_top, + c); + + x += face->glyph->advance.x >> 6; + + } + return true; +} +#else static bool fb_32bpp_text(int x, int y, const struct css_style *style, const char *text, size_t length, colour bg, colour c) { @@ -259,17 +366,18 @@ static bool fb_32bpp_text(int x, int y, const struct css_style *style, free(buffer); return true; } +#endif static bool fb_32bpp_disc(int x, int y, int radius, colour c, bool filled) { - printf("disc\n"); + LOG(("disc unimplemented")); return true; } static bool fb_32bpp_arc(int x, int y, int radius, int angle1, int angle2, colour c) { - printf("arc\n"); + LOG(("arc unimplemented")); return true; } @@ -365,14 +473,14 @@ static bool fb_32bpp_bitmap_tile(int x, int y, int width, int height, static bool fb_32bpp_flush(void) { - printf("flush\n"); + LOG(("flush unimplemnted")); return true; } static bool fb_32bpp_path(const float *p, unsigned int n, colour fill, float width, colour c, const float transform[6]) { - printf("path\n"); + LOG(("path unimplemented")); return true; } diff --git a/framebuffer/fb_8bpp_plotters.c b/framebuffer/fb_8bpp_plotters.c index 087cf025b..1d0eccc83 100644 --- a/framebuffer/fb_8bpp_plotters.c +++ b/framebuffer/fb_8bpp_plotters.c @@ -127,6 +127,15 @@ static bool fb_8bpp_clg(colour c) return true; } +#ifdef FB_USE_FREETYPE + +static bool fb_8bpp_text(int x, int y, const struct css_style *style, + const char *text, size_t length, colour bg, colour c) +{ + return false; + +} +#else static bool fb_8bpp_text(int x, int y, const struct css_style *style, const char *text, size_t length, colour bg, colour c) { @@ -206,7 +215,7 @@ static bool fb_8bpp_text(int x, int y, const struct css_style *style, free(buffer); return true; } - +#endif static bool fb_8bpp_disc(int x, int y, int radius, colour c, bool filled) { diff --git a/framebuffer/fb_font.c b/framebuffer/fb_font.c deleted file mode 100644 index 15679ff15..000000000 --- a/framebuffer/fb_font.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2005 James Bursa - * 2008 Vincent Sanders - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf 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; version 2 of the License. - * - * NetSurf 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, see . - */ - -#include - -#include -#include "css/css.h" -#include "render/font.h" -#include "desktop/options.h" -#include "utils/utf8.h" - -#include "framebuffer/fb_gui.h" -#include "framebuffer/fb_font.h" - -const struct fb_font_desc* -fb_get_font(const struct css_style *style) -{ - return &font_vga_8x16; -} - -utf8_convert_ret utf8_to_font_encoding(const struct fb_font_desc* font, - const char *string, - size_t len, - char **result) -{ - return utf8_to_enc(string, font->encoding, len, result); - -} - -utf8_convert_ret utf8_to_local_encoding(const char *string, - size_t len, - char **result) -{ - return utf8_to_enc(string, "CP437", len, result); - -} - -static bool nsfont_width(const struct css_style *style, - const char *string, size_t length, - int *width) -{ - const struct fb_font_desc* fb_font = fb_get_font(style); - *width = fb_font->width * utf8_bounded_length(string, length); - return true; -} - -/** - * Find the position in a string where an x coordinate falls. - * - * \param style css_style for this text, with style->font_size.size == - * CSS_FONT_SIZE_LENGTH - * \param string UTF-8 string to measure - * \param length length of string - * \param x x coordinate to search for - * \param char_offset updated to offset in string of actual_x, [0..length] - * \param actual_x updated to x coordinate of character closest to x - * \return true on success, false on error and error reported - */ - -static bool nsfont_position_in_string(const struct css_style *style, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x) -{ - const struct fb_font_desc* fb_font = fb_get_font(style); - *char_offset = x / fb_font->width; - if (*char_offset > length) - *char_offset = length; - *actual_x = *char_offset * fb_font->width; - return true; -} - - -/** - * Find where to split a string to make it fit a width. - * - * \param style css_style for this text, with style->font_size.size == - * CSS_FONT_SIZE_LENGTH - * \param string UTF-8 string to measure - * \param length length of string - * \param x width available - * \param char_offset updated to offset in string of actual_x, [0..length] - * \param actual_x updated to x coordinate of character closest to x - * \return true on success, false on error and error reported - * - * On exit, [char_offset == 0 || - * string[char_offset] == ' ' || - * char_offset == length] - */ - -static bool nsfont_split(const struct css_style *style, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x) -{ - - const struct fb_font_desc* fb_font = fb_get_font(style); - *char_offset = x / fb_font->width; - if (*char_offset > length) { - *char_offset = length; - } else { - while (*char_offset > 0) { - if (string[*char_offset] == ' ') - break; - (*char_offset)--; - } - } - *actual_x = *char_offset * fb_font->width; - return true; -} - -const struct font_functions nsfont = { - nsfont_width, - nsfont_position_in_string, - nsfont_split -}; - -/* - * Local Variables: - * c-basic-offset:8 - * End: - */ diff --git a/framebuffer/fb_font.h b/framebuffer/fb_font.h index 502cf2e83..2e453d465 100644 --- a/framebuffer/fb_font.h +++ b/framebuffer/fb_font.h @@ -19,6 +19,20 @@ #ifndef NETSURF_FB_FONT_H #define NETSURF_FB_FONT_H +bool fb_font_init(void); +bool fb_font_finalise(void); + +#ifdef FB_USE_FREETYPE + +#include +#include FT_FREETYPE_H + +FT_Face fb_get_face(const struct css_style *style); + +#else + +#include "utils/utf8.h" + struct fb_font_desc { const char *name; int width, height; @@ -34,6 +48,7 @@ extern utf8_convert_ret utf8_to_font_encoding(const struct fb_font_desc* font, const char *string, size_t len, char **result); +#endif #endif /* NETSURF_FB_FONT_H */ diff --git a/framebuffer/fb_font_freetype.c b/framebuffer/fb_font_freetype.c new file mode 100644 index 000000000..36130fa55 --- /dev/null +++ b/framebuffer/fb_font_freetype.c @@ -0,0 +1,260 @@ +/* + * Copyright 2005 James Bursa + * 2008 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf 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; version 2 of the License. + * + * NetSurf 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, see . + */ + +#include +#include + +#include "css/css.h" +#include "render/font.h" +#include "desktop/options.h" +#include "utils/utf8.h" +#include "utils/log.h" + +#include "framebuffer/fb_gui.h" +#include "framebuffer/fb_font.h" + +static FT_Library library; +static FT_Face face_sans_serif; + + +utf8_convert_ret utf8_to_local_encoding(const char *string, + size_t len, + char **result) +{ + return utf8_to_enc(string, "UTF-8", len, result); +} + + +/* initialise font handling */ +bool fb_font_init(void) +{ + FT_Error error; + + error = FT_Init_FreeType( &library ); + if (error) { + LOG(("Freetype could not initialised (code %d)\n", error)); + return false; + } + + error = FT_New_Face(library, + "/usr/share/fonts/truetype/freefont/FreeSans.ttf", + 0, + &face_sans_serif ); + if (error) { + LOG(("Could not find default font (code %d)\n", error)); + FT_Done_FreeType(library); + return false; + } + + error = FT_Set_Pixel_Sizes(face_sans_serif, 0, 14 ); + if (error) { + LOG(("Could not set pixel size (code %d)\n", error)); + return false; + } + + + return true; +} + +bool fb_font_finalise(void) +{ + FT_Done_FreeType(library); + return true; +} + + + +FT_Face +fb_get_face(const struct css_style *style) +{ + FT_Face face; + face = face_sans_serif; + FT_Error error; + int size; + + if (style->font_size.value.length.unit == CSS_UNIT_PX) { + size = style->font_size.value.length.value; + + error = FT_Set_Pixel_Sizes(face_sans_serif, 0, size ); + if (error) { + LOG(("Could not set pixel size (code %d)\n", error)); + } + } else { + size = css_len2pt(&style->font_size.value.length, style); + error = FT_Set_Char_Size( face, 0, size*64, 72, 72 ); + if (error) { + LOG(("Could not set pixel size (code %d)\n", error)); + } + } + + + return face; +} + +/** + * Measure the width of a string. + * + * \param style css_style for this text, with style->font_size.size == + * CSS_FONT_SIZE_LENGTH + * \param string UTF-8 string to measure + * \param length length of string + * \param width updated to width of string[0..length) + * \return true on success, false on error and error reported + */ +static bool nsfont_width(const struct css_style *style, + const char *string, size_t length, + int *width) +{ + uint32_t ucs4; + size_t nxtchr = 0; + FT_UInt glyph_index; + FT_Face face = fb_get_face(style); + FT_Error error; + + *width = 0; + while (nxtchr < length) { + ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr); + nxtchr = utf8_next(string, length, nxtchr); + glyph_index = FT_Get_Char_Index(face, ucs4); + + error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT); + if (error) + continue; + + *width += face->glyph->advance.x >> 6; + } + + return true; +} + +/** + * Find the position in a string where an x coordinate falls. + * + * \param style css_style for this text, with style->font_size.size == + * CSS_FONT_SIZE_LENGTH + * \param string UTF-8 string to measure + * \param length length of string + * \param x x coordinate to search for + * \param char_offset updated to offset in string of actual_x, [0..length] + * \param actual_x updated to x coordinate of character closest to x + * \return true on success, false on error and error reported + */ + +static bool nsfont_position_in_string(const struct css_style *style, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x) +{ + uint32_t ucs4; + size_t nxtchr = 0; + FT_UInt glyph_index; + FT_Face face = fb_get_face(style); + FT_Error error; + + *actual_x = 0; + while (nxtchr < length) { + ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr); + glyph_index = FT_Get_Char_Index(face, ucs4); + + error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT); + if (error) + continue; + + *actual_x += face->glyph->advance.x >> 6; + if (*actual_x > x) + break; + + nxtchr = utf8_next(string, length, nxtchr); + } + + *char_offset = nxtchr; + return true; +} + + +/** + * Find where to split a string to make it fit a width. + * + * \param style css_style for this text, with style->font_size.size == + * CSS_FONT_SIZE_LENGTH + * \param string UTF-8 string to measure + * \param length length of string + * \param x width available + * \param char_offset updated to offset in string of actual_x, [0..length] + * \param actual_x updated to x coordinate of character closest to x + * \return true on success, false on error and error reported + * + * On exit, [char_offset == 0 || + * string[char_offset] == ' ' || + * char_offset == length] + */ + +static bool nsfont_split(const struct css_style *style, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x) +{ + uint32_t ucs4; + size_t nxtchr = 0; + FT_UInt glyph_index; + FT_Face face = fb_get_face(style); + FT_Error error; + int last_space_x = -1; + int last_space_idx = -1; + + *actual_x = 0; + while (nxtchr < length) { + ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr); + + if (ucs4 == 0x20) { + last_space_x = *actual_x; + last_space_idx = nxtchr; + } + + glyph_index = FT_Get_Char_Index(face, ucs4); + + error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT); + if (error) + continue; + + *actual_x += face->glyph->advance.x >> 6; + if (*actual_x > x) + break; + + nxtchr = utf8_next(string, length, nxtchr); + } + + if (last_space_x == -1) { + *char_offset = nxtchr; + } else { + *actual_x = last_space_x; + *char_offset = last_space_idx; + } + return true; +} + +const struct font_functions nsfont = { + nsfont_width, + nsfont_position_in_string, + nsfont_split +}; + +/* + * Local Variables: + * c-basic-offset:8 + * End: + */ diff --git a/framebuffer/fb_font_internal.c b/framebuffer/fb_font_internal.c new file mode 100644 index 000000000..9d7c9a76b --- /dev/null +++ b/framebuffer/fb_font_internal.c @@ -0,0 +1,141 @@ +/* + * Copyright 2005 James Bursa + * 2008 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf 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; version 2 of the License. + * + * NetSurf 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, see . + */ + +#include + +#include +#include "css/css.h" +#include "render/font.h" +#include "desktop/options.h" +#include "utils/utf8.h" + +#include "framebuffer/fb_gui.h" +#include "framebuffer/fb_font.h" + +bool fb_font_init(void) +{ + return true; +} + +const struct fb_font_desc* +fb_get_font(const struct css_style *style) +{ + return &font_vga_8x16; +} + +utf8_convert_ret utf8_to_font_encoding(const struct fb_font_desc* font, + const char *string, + size_t len, + char **result) +{ + return utf8_to_enc(string, font->encoding, len, result); + +} + +utf8_convert_ret utf8_to_local_encoding(const char *string, + size_t len, + char **result) +{ + return utf8_to_enc(string, "CP437", len, result); + +} + +static bool nsfont_width(const struct css_style *style, + const char *string, size_t length, + int *width) +{ + const struct fb_font_desc* fb_font = fb_get_font(style); + *width = fb_font->width * utf8_bounded_length(string, length); + return true; +} + +/** + * Find the position in a string where an x coordinate falls. + * + * \param style css_style for this text, with style->font_size.size == + * CSS_FONT_SIZE_LENGTH + * \param string UTF-8 string to measure + * \param length length of string + * \param x x coordinate to search for + * \param char_offset updated to offset in string of actual_x, [0..length] + * \param actual_x updated to x coordinate of character closest to x + * \return true on success, false on error and error reported + */ + +static bool nsfont_position_in_string(const struct css_style *style, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x) +{ + const struct fb_font_desc* fb_font = fb_get_font(style); + *char_offset = x / fb_font->width; + if (*char_offset > length) + *char_offset = length; + *actual_x = *char_offset * fb_font->width; + return true; +} + + +/** + * Find where to split a string to make it fit a width. + * + * \param style css_style for this text, with style->font_size.size == + * CSS_FONT_SIZE_LENGTH + * \param string UTF-8 string to measure + * \param length length of string + * \param x width available + * \param char_offset updated to offset in string of actual_x, [0..length] + * \param actual_x updated to x coordinate of character closest to x + * \return true on success, false on error and error reported + * + * On exit, [char_offset == 0 || + * string[char_offset] == ' ' || + * char_offset == length] + */ + +static bool nsfont_split(const struct css_style *style, + const char *string, size_t length, + int x, size_t *char_offset, int *actual_x) +{ + + const struct fb_font_desc* fb_font = fb_get_font(style); + *char_offset = x / fb_font->width; + if (*char_offset > length) { + *char_offset = length; + } else { + while (*char_offset > 0) { + if (string[*char_offset] == ' ') + break; + (*char_offset)--; + } + } + *actual_x = *char_offset * fb_font->width; + return true; +} + +const struct font_functions nsfont = { + nsfont_width, + nsfont_position_in_string, + nsfont_split +}; + +/* + * Local Variables: + * c-basic-offset:8 + * End: + */ diff --git a/framebuffer/fb_font_internal.h b/framebuffer/fb_font_internal.h new file mode 100644 index 000000000..502cf2e83 --- /dev/null +++ b/framebuffer/fb_font_internal.h @@ -0,0 +1,39 @@ +/* + * Copyright 2008 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf 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; version 2 of the License. + * + * NetSurf 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, see . + */ + +#ifndef NETSURF_FB_FONT_H +#define NETSURF_FB_FONT_H + +struct fb_font_desc { + const char *name; + int width, height; + const char *encoding; + const uint32_t *data; +}; + +extern const struct fb_font_desc font_vga_8x16; + +extern const struct fb_font_desc* fb_get_font(const struct css_style *style); + +extern utf8_convert_ret utf8_to_font_encoding(const struct fb_font_desc* font, + const char *string, + size_t len, + char **result); + +#endif /* NETSURF_FB_FONT_H */ + diff --git a/framebuffer/fb_frontend_linuxfb.c b/framebuffer/fb_frontend_linuxfb.c index b1e89c537..3422c9fb8 100644 --- a/framebuffer/fb_frontend_linuxfb.c +++ b/framebuffer/fb_frontend_linuxfb.c @@ -49,6 +49,7 @@ #include "framebuffer/fb_cursor.h" #include "framebuffer/fb_frontend.h" #include "framebuffer/fb_options.h" +#include "framebuffer/fb_rootwindow.h" #include "utils/log.h" #include "utils/messages.h" @@ -647,15 +648,11 @@ void fb_os_input(struct gui_window *g, bool active) } else if (event.type == EV_REL) { switch (event.code) { case 0: - fb_cursor_move(framebuffer, - event.value, - 0); + fb_rootwindow_move(framebuffer, g, event.value, 0, true); break; case 1: - fb_cursor_move(framebuffer, - 0, - event.value); + fb_rootwindow_move(framebuffer, g, 0, event.value, true); break; case 8: diff --git a/framebuffer/fb_gui.c b/framebuffer/fb_gui.c index dfa3865e3..705ccdc80 100644 --- a/framebuffer/fb_gui.c +++ b/framebuffer/fb_gui.c @@ -44,6 +44,7 @@ #include "framebuffer/fb_findfile.h" #include "framebuffer/fb_rootwindow.h" #include "framebuffer/fb_image_data.h" +#include "framebuffer/fb_font.h" #include "content/urldb.h" #include "desktop/history_core.h" @@ -225,6 +226,9 @@ void gui_init(int argc, char** argv) } framebuffer->cursor = fb_cursor_init(framebuffer, &pointer_image); + + fb_font_init(); + } void gui_init2(int argc, char** argv) @@ -542,7 +546,7 @@ bool gui_window_box_scroll_start(struct gui_window *g, bool gui_window_frame_resize_start(struct gui_window *g) { - printf("resize frame\n"); + LOG(("resize frame\n")); return true; } @@ -552,7 +556,7 @@ void gui_window_save_as_link(struct gui_window *g, struct content *c) void gui_window_set_scale(struct gui_window *g, float scale) { - printf("set scale\n"); + LOG(("set scale\n")); } struct gui_download_window *gui_download_window_create(const char *url, diff --git a/framebuffer/fb_rootwindow.c b/framebuffer/fb_rootwindow.c index dd04ff726..05b3eaeaf 100644 --- a/framebuffer/fb_rootwindow.c +++ b/framebuffer/fb_rootwindow.c @@ -79,6 +79,8 @@ struct fb_widget { char* text; }; +static struct css_style root_style; + static struct fb_widget *widget_list; /* widget for status */ @@ -141,7 +143,7 @@ fb_redraw_widget(struct fb_widget *widget) if (widget->text != NULL) { plot.text(fb_plot_ctx.x0 + 2, fb_plot_ctx.y0 + 15, - NULL, + &root_style, widget->text, strlen(widget->text), widget->bg, @@ -383,6 +385,10 @@ void fb_rootwindow_create(framebuffer_t *fb) /* no widget yet has input */ inputfocus_widget = NULL; + /* setup root css style (for text etc.) */ + root_style.font_size.value.length.unit = CSS_UNIT_PX; + root_style.font_size.value.length.value = 14; + /* underlying root window, cannot take input and lowest in stack */ rootwindow = calloc(1, sizeof(struct gui_window)); rootwindow->x = 0; -- cgit v1.2.3