update framebuffer frontend to use layout table

This commit is contained in:
Vincent Sanders 2016-04-24 11:05:05 +01:00
parent ae01f36619
commit 0b7edfd252
7 changed files with 107 additions and 71 deletions

View File

@ -29,7 +29,6 @@
#include "utils/log.h"
#include "desktop/browser.h"
#include "desktop/font.h"
#include "framebuffer/gui.h"
#include "framebuffer/fbtk.h"
@ -342,7 +341,7 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
widget->u.text.len--;
widget->u.text.text[widget->u.text.len] = 0;
nsfont.font_width(&font_style, widget->u.text.text,
fb_font_width(&font_style, widget->u.text.text,
widget->u.text.len, &widget->u.text.width);
caret_moved = true;
@ -428,14 +427,14 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
widget->u.text.len++;
widget->u.text.text[widget->u.text.len] = '\0';
nsfont.font_width(&font_style, widget->u.text.text,
fb_font_width(&font_style, widget->u.text.text,
widget->u.text.len, &widget->u.text.width);
caret_moved = true;
break;
}
if (caret_moved) {
nsfont.font_width(&font_style, widget->u.text.text,
fb_font_width(&font_style, widget->u.text.text,
widget->u.text.idx, &widget->u.text.idx_offset);
fbtk_set_caret(widget, true,
widget->u.text.idx_offset + border,
@ -467,7 +466,7 @@ text_input_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
widget->u.text.idx = widget->u.text.len;
nsfont.font_position_in_string(&font_style, widget->u.text.text,
fb_font_position(&font_style, widget->u.text.text,
widget->u.text.len, cbi->x - border,
&idx,
&widget->u.text.idx_offset);
@ -529,9 +528,9 @@ fbtk_set_text(fbtk_widget_t *widget, const char *text)
fb_text_font_style(widget, &fh, &border, &font_style);
nsfont.font_width(&font_style, widget->u.text.text,
fb_font_width(&font_style, widget->u.text.text,
widget->u.text.len, &widget->u.text.width);
nsfont.font_width(&font_style, widget->u.text.text,
fb_font_width(&font_style, widget->u.text.text,
widget->u.text.idx, &widget->u.text.idx_offset);
if (fbtk_get_caret(widget, &c_x, &c_y, &c_h)) {

View File

@ -19,13 +19,45 @@
#ifndef NETSURF_FB_FONT_H
#define NETSURF_FB_FONT_H
#include "utils/utf8.h"
extern struct gui_layout_table *framebuffer_layout_table;
extern struct gui_utf8_table *framebuffer_utf8_table;
/**
* Initialise framebuffer font handling.
*/
bool fb_font_init(void);
/**
* Finalise framebuffer font handling.
*/
bool fb_font_finalise(void);
/**
* Find the position in a string where an x coordinate falls.
*
* \param[in] fstyle style for this text
* \param[in] string UTF-8 string to measure
* \param[in] length length of string, in bytes
* \param[in] x coordinate to search for
* \param[out] char_offset updated to offset in string of actual_x, [0..length]
* \param[out] actual_x updated to x coordinate of character closest to x
* \return NSERROR_OK and char_offset and actual_x updated or
* appropriate error code on faliure
*/
nserror fb_font_position(const struct plot_font_style *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x);
/**
* Measure the width of a string.
*
* \param[in] fstyle plot style for this text
* \param[in] string UTF-8 string to measure
* \param[in] length length of string, in bytes
* \param[out] width updated to width of string[0..length)
* \return NSERROR_OK and width updated or appropriate error code on faliure
*/
nserror fb_font_width(const struct plot_font_style *fstyle, const char *string, size_t length, int *width);
#ifdef FB_USE_FREETYPE
#include "framebuffer/font_freetype.h"
#else

View File

@ -28,7 +28,7 @@
#include "utils/log.h"
#include "utils/nsoption.h"
#include "desktop/gui_utf8.h"
#include "desktop/font.h"
#include "desktop/gui_layout.h"
#include "desktop/browser.h"
#include "framebuffer/gui.h"
@ -74,8 +74,14 @@ enum fb_face_e {
static fb_faceid_t *fb_faces[FB_FACE_COUNT];
/* map cache manager handle to face id */
static FT_Error ft_face_requester(FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *face )
/**
* map cache manager handle to face id
*/
static FT_Error
ft_face_requester(FTC_FaceID face_id,
FT_Library library,
FT_Pointer request_data,
FT_Face *face )
{
FT_Error error;
fb_faceid_t *fb_face = (fb_faceid_t *)face_id;
@ -103,7 +109,9 @@ static FT_Error ft_face_requester(FTC_FaceID face_id, FT_Library library, FT_Po
return error;
}
/* create new framebuffer face and cause it to be loaded to check its ok */
/**
* create new framebuffer face and cause it to be loaded to check its ok
*/
static fb_faceid_t *
fb_new_face(const char *option, const char *resname, const char *fontname)
{
@ -132,7 +140,7 @@ fb_new_face(const char *option, const char *resname, const char *fontname)
return newf;
}
/* initialise font handling */
/* exported interface documented in framebuffer/font.h */
bool fb_font_init(void)
{
FT_Error error;
@ -298,6 +306,7 @@ bool fb_font_init(void)
return true;
}
/* exported interface documented in framebuffer/font.h */
bool fb_font_finalise(void)
{
int i, j;
@ -324,6 +333,9 @@ bool fb_font_finalise(void)
return true;
}
/**
* fill freetype scalar
*/
static void fb_fill_scalar(const plot_font_style_t *fstyle, FTC_Scaler srec)
{
int selected_face = FB_FACE_DEFAULT;
@ -380,6 +392,7 @@ static void fb_fill_scalar(const plot_font_style_t *fstyle, FTC_Scaler srec)
srec->x_res = srec->y_res = browser_get_dpi();
}
/* exported interface documented in framebuffer/freetype_font.h */
FT_Glyph fb_getglyph(const plot_font_style_t *fstyle, uint32_t ucs4)
{
FT_UInt glyph_index;
@ -410,16 +423,9 @@ FT_Glyph fb_getglyph(const plot_font_style_t *fstyle, uint32_t ucs4)
}
/**
* Measure the width of a string.
*
* \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 plot_font_style_t *fstyle,
/* exported interface documented in framebuffer/freetype_font.h */
nserror
fb_font_width(const plot_font_style_t *fstyle,
const char *string, size_t length,
int *width)
{
@ -442,19 +448,10 @@ static bool nsfont_width(const plot_font_style_t *fstyle,
return true;
}
/**
* Find the position in a string where an x coordinate falls.
*
* \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
* \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 plot_font_style_t *fstyle,
/* exported interface documented in framebuffer/freetype_font.h */
nserror
fb_font_position(const plot_font_style_t *fstyle,
const char *string, size_t length,
int x, size_t *char_offset, int *actual_x)
{
@ -510,8 +507,8 @@ static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
*
* Returning char_offset == length means no split possible
*/
static bool nsfont_split(const plot_font_style_t *fstyle,
static nserror
fb_font_split(const plot_font_style_t *fstyle,
const char *string, size_t length,
int x, size_t *char_offset, int *actual_x)
{
@ -551,12 +548,15 @@ static bool nsfont_split(const plot_font_style_t *fstyle,
return true;
}
const struct font_functions nsfont = {
nsfont_width,
nsfont_position_in_string,
nsfont_split
static struct gui_layout_table layout_table = {
.width = fb_font_width,
.position = fb_font_position,
.split = fb_font_split,
};
struct gui_layout_table *framebuffer_layout_table = &layout_table;
struct gui_utf8_table *framebuffer_utf8_table = NULL;
/*

View File

@ -25,7 +25,7 @@
#include "utils/nsoption.h"
#include "utils/utf8.h"
#include "desktop/gui_utf8.h"
#include "desktop/font.h"
#include "desktop/gui_layout.h"
#include "framebuffer/gui.h"
#include "framebuffer/font.h"
@ -343,8 +343,11 @@ static nserror utf8_from_local(const char *string,
}
static bool nsfont_width(const plot_font_style_t *fstyle,
const char *string, size_t length,
/* exported interface documented in framebuffer/freetype_font.h */
nserror
fb_font_width(const plot_font_style_t *fstyle,
const char *string,
size_t length,
int *width)
{
size_t nxtchr = 0;
@ -364,21 +367,15 @@ static bool nsfont_width(const plot_font_style_t *fstyle,
return true;
}
/**
* Find the position in a string where an x coordinate falls.
*
* \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
* \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 plot_font_style_t *fstyle,
const char *string, size_t length,
int x, size_t *char_offset, int *actual_x)
/* exported interface documented in framebuffer/freetype_font.h */
nserror
fb_font_position(const plot_font_style_t *fstyle,
const char *string,
size_t length,
int x,
size_t *char_offset,
int *actual_x)
{
const int width = fb_get_font_size(fstyle) * FB_FONT_WIDTH;
size_t nxtchr = 0;
@ -404,7 +401,6 @@ static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
}
/**
* Find where to split a string to make it fit a width.
*
@ -427,10 +423,13 @@ static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
*
* Returning char_offset == length means no split possible
*/
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)
static nserror
fb_font_split(const plot_font_style_t *fstyle,
const char *string,
size_t length,
int x,
size_t *char_offset,
int *actual_x)
{
const int width = fb_get_font_size(fstyle) * FB_FONT_WIDTH;
size_t nxtchr = 0;
@ -467,12 +466,16 @@ static bool nsfont_split(const plot_font_style_t *fstyle,
return true;
}
const struct font_functions nsfont = {
nsfont_width,
nsfont_position_in_string,
nsfont_split
static struct gui_layout_table layout_table = {
.width = fb_font_width,
.position = fb_font_position,
.split = fb_font_split,
};
struct gui_layout_table *framebuffer_layout_table = &layout_table;
static struct gui_utf8_table utf8_table = {
.utf8_to_local = utf8_to_local,
.local_to_utf8 = utf8_from_local,

View File

@ -40,10 +40,10 @@ enum fb_font_style {
enum fb_font_style fb_get_font_style(const plot_font_style_t *fstyle);
int fb_get_font_size(const plot_font_style_t *fstyle);
const uint8_t *fb_get_glyph(uint32_t ucs4, enum fb_font_style style, int scale);
#define codepoint_displayable(u) \
(!(u >= 0x200b && u <= 0x200f))
const uint8_t *fb_get_glyph(uint32_t ucs4, enum fb_font_style style, int scale);
#endif /* NETSURF_FB_FONT_INTERNAL_H */

View File

@ -30,6 +30,7 @@
#include "utils/utils.h"
#include "utils/log.h"
#include "utils/utf8.h"
#include "desktop/browser.h"
#include "image/bitmap.h"

View File

@ -2082,6 +2082,7 @@ main(int argc, char** argv)
.fetch = framebuffer_fetch_table,
.utf8 = framebuffer_utf8_table,
.bitmap = framebuffer_bitmap_table,
.layout = framebuffer_layout_table,
};
ret = netsurf_register(&framebuffer_table);