From 2565a37a52a5c714e7c6bbd1808db0d6d37c6ea3 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Tue, 21 Jul 2009 10:59:53 +0000 Subject: Refactor text plotter and other font functions to remove dependency on CSS. svn path=/trunk/netsurf/; revision=8641 --- framebuffer/fbtk.c | 17 ++++---- framebuffer/font_freetype.c | 100 +++++++++++++------------------------------- framebuffer/font_freetype.h | 2 +- framebuffer/font_internal.c | 20 ++++----- framebuffer/font_internal.h | 2 +- framebuffer/framebuffer.c | 20 ++++----- 6 files changed, 61 insertions(+), 100 deletions(-) (limited to 'framebuffer') diff --git a/framebuffer/fbtk.c b/framebuffer/fbtk.c index 0284b19a1..c564a9117 100644 --- a/framebuffer/fbtk.c +++ b/framebuffer/fbtk.c @@ -39,7 +39,12 @@ #include "framebuffer/bitmap.h" #include "framebuffer/image_data.h" -static struct css_style root_style; +static plot_font_style_t root_style = { + .family = PLOT_FONT_FAMILY_SANS_SERIF, + .size = 11, + .weight = 400, + .flags = FONTF_NONE, +}; enum fbtk_widgettype_e { FB_WIDGET_TYPE_ROOT = 0, @@ -601,13 +606,14 @@ fb_redraw_text(fbtk_widget_t *root, fbtk_widget_t *widget, void *pw) } if (widget->u.text.text != NULL) { + root_style.background = widget->bg; + root_style.foreground = widget->fg; + plot.text(bbox.x0 + 3, bbox.y0 + 17, - &root_style, widget->u.text.text, strlen(widget->u.text.text), - widget->bg, - widget->fg); + &root_style); } nsfb_release(root->u.root.fb, &bbox); @@ -1301,9 +1307,6 @@ fbtk_init(nsfb_t *fb) root->y = 0; root->u.root.rootw = fbtk_create_window(root, 0, 0, 0, 0); - root_style.font_size.value.length.unit = CSS_UNIT_PX; - root_style.font_size.value.length.value = 14; - return root; } diff --git a/framebuffer/font_freetype.c b/framebuffer/font_freetype.c index a4bc7868b..a4ce9ff77 100644 --- a/framebuffer/font_freetype.c +++ b/framebuffer/font_freetype.c @@ -221,91 +221,54 @@ bool fb_font_finalise(void) return true; } -static void fb_fill_scalar(const struct css_style *style, FTC_Scaler srec) +static void fb_fill_scalar(const plot_font_style_t *fstyle, FTC_Scaler srec) { int selected_face = FB_FACE_DEFAULT; - switch (style->font_family) { + switch (fstyle->family) { /* - case CSS_FONT_FAMILY_CURSIVE: + case PLOT_FONT_FAMILY_CURSIVE: break; - case CSS_FONT_FAMILY_FANTASY: + case PLOT_FONT_FAMILY_FANTASY: break; */ - case CSS_FONT_FAMILY_SERIF: - switch (style->font_weight) { - case CSS_FONT_WEIGHT_700: - case CSS_FONT_WEIGHT_800: - case CSS_FONT_WEIGHT_900: - case CSS_FONT_WEIGHT_BOLD: + case PLOT_FONT_FAMILY_SERIF: + if (fstyle->weight >= 700) selected_face = FB_FACE_SERIF_BOLD; - break; - - case CSS_FONT_WEIGHT_NORMAL: - default: + else selected_face = FB_FACE_SERIF; - break; - } break; - case CSS_FONT_FAMILY_MONOSPACE: + case PLOT_FONT_FAMILY_MONOSPACE: selected_face = FB_FACE_MONOSPACE; break; - case CSS_FONT_FAMILY_SANS_SERIF: + case PLOT_FONT_FAMILY_SANS_SERIF: default: - switch (style->font_style) { - case CSS_FONT_STYLE_ITALIC: - switch (style->font_weight) { - case CSS_FONT_WEIGHT_700: - case CSS_FONT_WEIGHT_800: - case CSS_FONT_WEIGHT_900: - case CSS_FONT_WEIGHT_BOLD: + if ((fstyle->flags & FONTF_ITALIC) || + (fstyle->flags & FONTF_OBLIQUE)) { + if (fstyle->weight >= 700) selected_face = FB_FACE_SANS_SERIF_ITALIC_BOLD; - break; - - case CSS_FONT_WEIGHT_NORMAL: - default: + else selected_face = FB_FACE_SANS_SERIF_ITALIC; - break; - } - break; - - default: - switch (style->font_weight) { - case CSS_FONT_WEIGHT_700: - case CSS_FONT_WEIGHT_800: - case CSS_FONT_WEIGHT_900: - case CSS_FONT_WEIGHT_BOLD: + } else { + if (fstyle->weight >= 700) selected_face = FB_FACE_SANS_SERIF_BOLD; - break; - - case CSS_FONT_WEIGHT_NORMAL: - default: + else selected_face = FB_FACE_SANS_SERIF; - break; - } - break; } } srec->face_id = (FTC_FaceID)fb_faces[selected_face]; - if (style->font_size.value.length.unit == CSS_UNIT_PX) { - srec->width = srec->height = style->font_size.value.length.value; - srec->pixel = 1; - } else { - srec->width = srec->height = - css_len2pt(&style->font_size.value.length, style) * 64; - srec->pixel = 0; - - srec->x_res = srec->y_res = 72; - } + srec->width = srec->height = fstyle->size * 64; + srec->pixel = 0; + srec->x_res = srec->y_res = 72; } -FT_Glyph fb_getglyph(const struct css_style *style, uint32_t ucs4) +FT_Glyph fb_getglyph(const plot_font_style_t *fstyle, uint32_t ucs4) { FT_UInt glyph_index; FTC_ScalerRec srec; @@ -313,7 +276,7 @@ FT_Glyph fb_getglyph(const struct css_style *style, uint32_t ucs4) FT_Error error; fb_faceid_t *fb_face; - fb_fill_scalar(style, &srec); + fb_fill_scalar(fstyle, &srec); fb_face = (fb_faceid_t *)srec.face_id; @@ -335,14 +298,13 @@ FT_Glyph fb_getglyph(const struct css_style *style, uint32_t ucs4) /** * Measure the width of a string. * - * \param style css_style for this text, with style->font_size.size == - * CSS_FONT_SIZE_LENGTH + * \param fstyle style for this text * \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, +static bool nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { @@ -355,7 +317,7 @@ static bool nsfont_width(const struct css_style *style, ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr); nxtchr = utf8_next(string, length, nxtchr); - glyph = fb_getglyph(style, ucs4); + glyph = fb_getglyph(fstyle, ucs4); if (glyph == NULL) continue; @@ -368,8 +330,7 @@ static bool nsfont_width(const struct css_style *style, /** * 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 fstyle style for this text * \param string UTF-8 string to measure * \param length length of string * \param x x coordinate to search for @@ -378,7 +339,7 @@ static bool nsfont_width(const struct css_style *style, * \return true on success, false on error and error reported */ -static bool nsfont_position_in_string(const struct css_style *style, +static bool nsfont_position_in_string(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { @@ -390,7 +351,7 @@ static bool nsfont_position_in_string(const struct css_style *style, while (nxtchr < length) { ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr); - glyph = fb_getglyph(style, ucs4); + glyph = fb_getglyph(fstyle, ucs4); if (glyph == NULL) continue; @@ -409,8 +370,7 @@ static bool nsfont_position_in_string(const struct css_style *style, /** * 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 fstyle style for this text * \param string UTF-8 string to measure * \param length length of string * \param x width available @@ -423,7 +383,7 @@ static bool nsfont_position_in_string(const struct css_style *style, * char_offset == length] */ -static bool nsfont_split(const struct css_style *style, +static bool nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { @@ -437,7 +397,7 @@ static bool nsfont_split(const struct css_style *style, while (nxtchr < length) { ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr); - glyph = fb_getglyph(style, ucs4); + glyph = fb_getglyph(fstyle, ucs4); if (glyph == NULL) continue; diff --git a/framebuffer/font_freetype.h b/framebuffer/font_freetype.h index 68d986b8c..90d8b23e6 100644 --- a/framebuffer/font_freetype.h +++ b/framebuffer/font_freetype.h @@ -25,6 +25,6 @@ extern int ft_load_type; -FT_Glyph fb_getglyph(const struct css_style *style, uint32_t ucs4); +FT_Glyph fb_getglyph(const plot_font_style_t *fstyle, uint32_t ucs4); #endif /* NETSURF_FB_FONT_FREETYPE_H */ diff --git a/framebuffer/font_internal.c b/framebuffer/font_internal.c index ba03ecc08..82ad6b32e 100644 --- a/framebuffer/font_internal.c +++ b/framebuffer/font_internal.c @@ -34,7 +34,7 @@ bool fb_font_init(void) } const struct fb_font_desc* -fb_get_font(const struct css_style *style) +fb_get_font(const plot_font_style_t *fstyle) { return &font_vga_8x16; } @@ -56,11 +56,11 @@ utf8_convert_ret utf8_to_local_encoding(const char *string, } -static bool nsfont_width(const struct css_style *style, +static bool nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width) { - const struct fb_font_desc* fb_font = fb_get_font(style); + const struct fb_font_desc* fb_font = fb_get_font(fstyle); *width = fb_font->width * utf8_bounded_length(string, length); return true; } @@ -68,8 +68,7 @@ static bool nsfont_width(const struct css_style *style, /** * 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 fstyle style for this text * \param string UTF-8 string to measure * \param length length of string * \param x x coordinate to search for @@ -78,11 +77,11 @@ static bool nsfont_width(const struct css_style *style, * \return true on success, false on error and error reported */ -static bool nsfont_position_in_string(const struct css_style *style, +static bool nsfont_position_in_string(const plot_font_style_t *fstyle, 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); + const struct fb_font_desc* fb_font = fb_get_font(fstyle); *char_offset = x / fb_font->width; if (*char_offset > length) *char_offset = length; @@ -94,8 +93,7 @@ static bool nsfont_position_in_string(const struct css_style *style, /** * 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 fstyle style for this text * \param string UTF-8 string to measure * \param length length of string * \param x width available @@ -108,12 +106,12 @@ static bool nsfont_position_in_string(const struct css_style *style, * char_offset == length] */ -static bool nsfont_split(const struct css_style *style, +static bool nsfont_split(const plot_font_style_t *fstyle, 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); + const struct fb_font_desc* fb_font = fb_get_font(fstyle); *char_offset = x / fb_font->width; if (*char_offset > length) { *char_offset = length; diff --git a/framebuffer/font_internal.h b/framebuffer/font_internal.h index eaa9dfba8..66beb42d0 100644 --- a/framebuffer/font_internal.h +++ b/framebuffer/font_internal.h @@ -28,7 +28,7 @@ struct fb_font_desc { extern const struct fb_font_desc font_vga_8x16; -extern const struct fb_font_desc* fb_get_font(const struct css_style *style); +extern const struct fb_font_desc* fb_get_font(const plot_font_style_t *fstyle); extern utf8_convert_ret utf8_to_font_encoding(const struct fb_font_desc* font, const char *string, diff --git a/framebuffer/framebuffer.c b/framebuffer/framebuffer.c index 8885d1fe0..fe3fe12e2 100644 --- a/framebuffer/framebuffer.c +++ b/framebuffer/framebuffer.c @@ -42,7 +42,6 @@ /* netsurf framebuffer library handle */ static nsfb_t *nsfb; -#ifdef FB_USE_FREETYPE static bool framebuffer_plot_disc(int x, int y, int radius, const plot_style_t *style) @@ -75,8 +74,9 @@ static bool framebuffer_plot_polygon(const int *p, unsigned int n, const plot_st } -static bool framebuffer_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c) +#ifdef FB_USE_FREETYPE +static bool framebuffer_plot_text(int x, int y, const char *text, size_t length, + const plot_font_style_t *fstyle) { uint32_t ucs4; size_t nxtchr = 0; @@ -88,7 +88,7 @@ static bool framebuffer_plot_text(int x, int y, const struct css_style *style, ucs4 = utf8_to_ucs4(text + nxtchr, length - nxtchr); nxtchr = utf8_next(text, length, nxtchr); - glyph = fb_getglyph(style, ucs4); + glyph = fb_getglyph(fstyle, ucs4); if (glyph == NULL) continue; @@ -106,13 +106,13 @@ static bool framebuffer_plot_text(int x, int y, const struct css_style *style, &loc, bglyph->bitmap.buffer, bglyph->bitmap.pitch, - c); + fstyle->foreground); } else { nsfb_plot_glyph8(nsfb, &loc, bglyph->bitmap.buffer, bglyph->bitmap.pitch, - c); + fstyle->foreground); } } x += glyph->advance.x >> 16; @@ -122,10 +122,10 @@ static bool framebuffer_plot_text(int x, int y, const struct css_style *style, } #else -static bool framebuffer_plot_text(int x, int y, const struct css_style *style, - const char *text, size_t length, colour bg, colour c) +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(style); + const struct fb_font_desc* fb_font = fb_get_font(fstyle); const uint32_t *chrp; char *buffer = NULL; int chr; @@ -152,7 +152,7 @@ static bool framebuffer_plot_text(int x, int y, const struct css_style *style, 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, c); + nsfb_plot_glyph1(nsfb, &loc, (uint8_t *)chrp, 32, fstyle->foreground); x+=fb_font->width; -- cgit v1.2.3