From 6ddb66ccfbf2c5627e04b9fc6a70661b764d9a93 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 24 Apr 2016 18:41:00 +0100 Subject: update atari to use font layout table --- atari/font.c | 153 +++++++++++++++++++++++++++++++++++++++++------------------ atari/font.h | 1 + atari/gui.c | 6 ++- 3 files changed, 112 insertions(+), 48 deletions(-) (limited to 'atari') diff --git a/atari/font.c b/atari/font.c index 729986ca6..cb0c574ea 100644 --- a/atari/font.c +++ b/atari/font.c @@ -19,11 +19,12 @@ #include #include #include +#include -#include "desktop/font.h" #include "utils/utf8.h" #include "utils/log.h" #include "utils/nsoption.h" +#include "desktop/gui_layout.h" #include "desktop/mouse.h" #include "desktop/plotters.h" @@ -35,61 +36,121 @@ extern FONT_PLOTTER fplotter; -static bool atari_font_position_in_string(const plot_font_style_t * fstyle,const char *string, - size_t length,int x, size_t *char_offset, int *actual_x ) -{ - float scale = plot_get_scale(); - - if (scale != 1.0) { - plot_font_style_t newstyle = *fstyle; - newstyle.size = (int)((float)fstyle->size*scale); - fplotter->pixel_pos(fplotter, &newstyle, string, length, x, char_offset, actual_x); - } else { - fplotter->pixel_pos(fplotter, fstyle, string, length, x, char_offset, actual_x); - } - return( true ); -} - -static bool atari_font_split( const plot_font_style_t * fstyle, const char *string, - size_t length,int x, size_t *char_offset, int *actual_x ) +/** + * 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 + */ +static nserror +atari_font_position(const plot_font_style_t *fstyle, + const char *string, + size_t length, + int x, + size_t *char_offset, + int *actual_x) { - float scale = plot_get_scale(); - - if (scale != 1.0) { - plot_font_style_t newstyle = *fstyle; - newstyle.size = (int)((float)fstyle->size*scale); - fplotter->str_split(fplotter, &newstyle, string, length, x, char_offset, - actual_x); - } else { - fplotter->str_split(fplotter, fstyle, string, length, x, char_offset, - actual_x); - } + float scale = plot_get_scale(); + + if (scale != 1.0) { + plot_font_style_t newstyle = *fstyle; + newstyle.size = (int)((float)fstyle->size*scale); + fplotter->pixel_pos(fplotter, &newstyle, string, length, x, + char_offset, actual_x); + } else { + fplotter->pixel_pos(fplotter, fstyle, string, length, x, + char_offset, actual_x); + } + + return NSERROR_OK; +} - return( true ); +/** + * Find where to split a string to make it fit a width. + * + * \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 width available + * \param[out] char_offset updated to offset in string of actual_x, [1..length] + * \param[out] actual_x updated to x coordinate of character closest to x + * \return NSERROR_OK or appropriate error code on faliure + * + * On exit, char_offset indicates first character after split point. + * + * \note char_offset of 0 must never be returned. + * + * Returns: + * char_offset giving split point closest to x, where actual_x <= x + * else + * char_offset giving split point closest to x, where actual_x > x + * + * Returning char_offset == length means no split possible + */ +static nserror +atari_font_split(const plot_font_style_t *fstyle, + const char *string, + size_t length, + int x, + size_t *char_offset, + int *actual_x) +{ + float scale = plot_get_scale(); + + if (scale != 1.0) { + plot_font_style_t newstyle = *fstyle; + newstyle.size = (int)((float)fstyle->size*scale); + fplotter->str_split(fplotter, &newstyle, string, length, x, + char_offset, actual_x); + } else { + fplotter->str_split(fplotter, fstyle, string, length, x, + char_offset, actual_x); + } + + return NSERROR_OK; } -static bool atari_font_width( const plot_font_style_t *fstyle, const char * str, - size_t length, int * width ) -{ - float scale = plot_get_scale(); - if (scale != 1.0) { - plot_font_style_t newstyle = *fstyle; - newstyle.size = (int)((float)fstyle->size*scale); - fplotter->str_width(fplotter, &newstyle, str, length, width); - } else { - fplotter->str_width(fplotter, fstyle, str, length, width); - } +/** + * 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 + */ +static nserror +atari_font_width(const plot_font_style_t *fstyle, + const char *str, + size_t length, + int * width) +{ + float scale = plot_get_scale(); + if (scale != 1.0) { + plot_font_style_t newstyle = *fstyle; + newstyle.size = (int)((float)fstyle->size*scale); + fplotter->str_width(fplotter, &newstyle, str, length, width); + } else { + fplotter->str_width(fplotter, fstyle, str, length, width); + } - return( true ); + return NSERROR_OK; } -const struct font_functions nsfont = { - atari_font_width, - atari_font_position_in_string, - atari_font_split + +static struct gui_layout_table layout_table = { + .width = atari_font_width, + .position = atari_font_position, + .split = atari_font_split, }; +struct gui_layout_table *atari_layout_table = &layout_table; diff --git a/atari/font.h b/atari/font.h index 065a35acc..a01d000c0 100644 --- a/atari/font.h +++ b/atari/font.h @@ -19,6 +19,7 @@ #ifndef NS_ATARI_FONT_H #define NS_ATARI_FONT_H +struct gui_layout_table *atari_layout_table; #endif /* NETSURF_FB_FONT_H */ diff --git a/atari/gui.c b/atari/gui.c index 5e5ef19b0..47b669353 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -35,7 +35,7 @@ #include "content/hlcache.h" #include "desktop/treeview.h" #include "desktop/browser.h" -#include "desktop/font.h" +#include "desktop/gui_layout.h" #include "desktop/gui_window.h" #include "desktop/gui_clipboard.h" #include "desktop/gui_fetch.h" @@ -66,6 +66,7 @@ #include "atari/file.h" #include "atari/filetype.h" #include "atari/bitmap.h" +#include "atari/font.h" #include "cflib.h" static bool atari_quit = false; @@ -1118,7 +1119,8 @@ int main(int argc, char** argv) .utf8 = atari_utf8_table, .search = atari_search_table, .llcache = filesystem_llcache_table, - .bitmap = atari_bitmap_table + .bitmap = atari_bitmap_table, + .layout = atari_layout_table }; ret = netsurf_register(&atari_table); -- cgit v1.2.3