summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2016-04-24 18:41:00 +0100
committerVincent Sanders <vince@kyllikki.org>2016-04-24 18:41:00 +0100
commit6ddb66ccfbf2c5627e04b9fc6a70661b764d9a93 (patch)
tree8e21915ce7f0b8b6598af5e23698a5a0bcbd5ec9
parentc9d9537941a9b5b5a2b2557fd775201a2979f428 (diff)
downloadnetsurf-6ddb66ccfbf2c5627e04b9fc6a70661b764d9a93.tar.gz
netsurf-6ddb66ccfbf2c5627e04b9fc6a70661b764d9a93.tar.bz2
update atari to use font layout table
-rw-r--r--atari/font.c153
-rw-r--r--atari/font.h1
-rw-r--r--atari/gui.c6
3 files changed, 112 insertions, 48 deletions
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 <inttypes.h>
#include <assert.h>
#include <stdbool.h>
+#include <stdlib.h>
-#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);