summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
Diffstat (limited to 'desktop')
-rw-r--r--desktop/browser_history.c14
-rw-r--r--desktop/font.h97
-rw-r--r--desktop/save_pdf/font_haru.c2
-rw-r--r--desktop/save_pdf/font_haru.h2
-rw-r--r--desktop/selection.c18
-rw-r--r--desktop/textarea.c9
-rw-r--r--desktop/textinput.c20
-rw-r--r--desktop/tree.c11
-rw-r--r--desktop/treeview.c10
9 files changed, 142 insertions, 41 deletions
diff --git a/desktop/browser_history.c b/desktop/browser_history.c
index 8c21eed8e..1e8140626 100644
--- a/desktop/browser_history.c
+++ b/desktop/browser_history.c
@@ -18,7 +18,7 @@
*/
/** \file
- * Browser history tree (implementation).
+ * Browser history tree implementation.
*/
#include <assert.h>
@@ -27,20 +27,20 @@
#include <string.h>
#include <time.h>
+#include "utils/log.h"
+#include "utils/nsurl.h"
+#include "utils/utils.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "content/urldb.h"
#include "css/css.h"
+#include "image/bitmap.h"
+
#include "desktop/browser_history.h"
#include "desktop/browser_private.h"
#include "desktop/plotters.h"
#include "desktop/thumbnail.h"
-#include "image/bitmap.h"
-#include "render/font.h"
-#include "utils/log.h"
-#include "utils/nsurl.h"
-#include "utils/utils.h"
-
+#include "desktop/font.h"
#define WIDTH 100
#define HEIGHT 86
diff --git a/desktop/font.h b/desktop/font.h
new file mode 100644
index 000000000..4ebd75d73
--- /dev/null
+++ b/desktop/font.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
+ * Copyright 2005 James Bursa <bursa@users.sourceforge.net>
+ * Copyright 2004 John Tytgat <joty@netsurf-browser.org>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+/** \file
+ * Font handling interface.
+ *
+ * These functions provide font related services. They all work on
+ * UTF-8 strings with lengths given.
+ *
+ * Note that an interface to painting is not defined here. Painting is
+ * redirected through platform-dependent plotters anyway, so there is
+ * no gain in abstracting it here.
+ */
+
+#ifndef _NETSURF_DESKTOP_FONT_H_
+#define _NETSURF_DESKTOP_FONT_H_
+
+#include <stdbool.h>
+#include <stddef.h>
+
+#include "desktop/plot_style.h"
+
+struct font_functions
+{
+ /**
+ * Measure the width of a string.
+ *
+ * \param fstyle plot style for this text
+ * \param string UTF-8 string to measure
+ * \param length length of string, in bytes
+ * \param width updated to width of string[0..length)
+ * \return true on success, false on error and error reported
+ */
+ bool (*font_width)(const plot_font_style_t *fstyle,
+ const char *string, size_t length,
+ int *width);
+ /**
+ * 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, in bytes
+ * \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
+ */
+ bool (*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);
+ /**
+ * Find where to split a string to make it fit a width.
+ *
+ * \param fstyle style for this text
+ * \param string UTF-8 string to measure
+ * \param length length of string, in bytes
+ * \param x width available
+ * \param char_offset updated to offset in string of actual_x, [1..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 indicates first character after split point.
+ *
+ * Note: char_offset of 0 should 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
+ */
+ bool (*font_split)(const plot_font_style_t *fstyle,
+ const char *string, size_t length,
+ int x, size_t *char_offset, int *actual_x);
+};
+
+extern const struct font_functions nsfont;
+
+#endif
diff --git a/desktop/save_pdf/font_haru.c b/desktop/save_pdf/font_haru.c
index 57d36fe95..e8643f701 100644
--- a/desktop/save_pdf/font_haru.c
+++ b/desktop/save_pdf/font_haru.c
@@ -41,7 +41,7 @@
#include "utils/nsoption.h"
#include "desktop/save_pdf/font_haru.h"
-#include "render/font.h"
+#include "desktop/font.h"
#include "utils/log.h"
diff --git a/desktop/save_pdf/font_haru.h b/desktop/save_pdf/font_haru.h
index 0dd6dc0c4..c6578b09f 100644
--- a/desktop/save_pdf/font_haru.h
+++ b/desktop/save_pdf/font_haru.h
@@ -26,8 +26,8 @@
#include <hpdf.h>
-#include "render/font.h"
#include "desktop/plot_style.h"
+#include "desktop/font.h"
bool haru_nsfont_apply_style(const plot_font_style_t *fstyle,
HPDF_Doc doc, HPDF_Page page,
diff --git a/desktop/selection.c b/desktop/selection.c
index 34292fdce..ec01e5b81 100644
--- a/desktop/selection.c
+++ b/desktop/selection.c
@@ -28,21 +28,21 @@
#include <string.h>
#include <dom/dom.h>
+#include "utils/log.h"
+#include "utils/utf8.h"
+#include "utils/utils.h"
+#include "render/box.h"
+#include "render/form.h"
+#include "render/html_internal.h"
+#include "render/font.h"
+#include "render/textplain.h"
+
#include "desktop/browser_private.h"
#include "desktop/gui_factory.h"
#include "desktop/mouse.h"
#include "desktop/plotters.h"
#include "desktop/save_text.h"
#include "desktop/selection.h"
-#include "render/box.h"
-#include "render/font.h"
-#include "render/form.h"
-#include "render/html_internal.h"
-#include "render/textplain.h"
-#include "utils/log.h"
-#include "utils/utf8.h"
-#include "utils/utils.h"
-
/**
* Text selection works by labelling each node in the box tree with its
diff --git a/desktop/textarea.c b/desktop/textarea.c
index d29e5f247..8b84f3279 100644
--- a/desktop/textarea.c
+++ b/desktop/textarea.c
@@ -23,18 +23,19 @@
#include <stdint.h>
#include <string.h>
+
#include "css/utils.h"
+#include "utils/log.h"
+#include "utils/utf8.h"
+#include "utils/utils.h"
#include "desktop/mouse.h"
#include "desktop/textarea.h"
#include "desktop/textinput.h"
#include "desktop/plotters.h"
#include "desktop/scrollbar.h"
+#include "desktop/font.h"
#include "desktop/gui_factory.h"
-#include "render/font.h"
-#include "utils/log.h"
-#include "utils/utf8.h"
-#include "utils/utils.h"
#define CARET_COLOR 0x0000FF
#define TA_ALLOC_STEP 512
diff --git a/desktop/textinput.c b/desktop/textinput.c
index fd6ae9ff1..cf0697a2e 100644
--- a/desktop/textinput.c
+++ b/desktop/textinput.c
@@ -21,7 +21,7 @@
*/
/** \file
- * Textual input handling (implementation)
+ * Textual input handling implementation
*/
#include <assert.h>
@@ -29,21 +29,21 @@
#include <string.h>
#include <dom/dom.h>
+#include "utils/log.h"
+#include "utils/talloc.h"
+#include "utils/utf8.h"
+#include "utils/utils.h"
+#include "render/box.h"
+#include "render/form.h"
+#include "render/html_internal.h"
+#include "render/layout.h"
+
#include "desktop/browser_private.h"
#include "desktop/gui_factory.h"
#include "desktop/mouse.h"
#include "desktop/scrollbar.h"
#include "desktop/selection.h"
#include "desktop/textinput.h"
-#include "render/box.h"
-#include "render/font.h"
-#include "render/form.h"
-#include "render/html_internal.h"
-#include "render/layout.h"
-#include "utils/log.h"
-#include "utils/talloc.h"
-#include "utils/utf8.h"
-#include "utils/utils.h"
/* Define to enable textinput debug */
#undef TEXTINPUT_DEBUG
diff --git a/desktop/tree.c b/desktop/tree.c
index c29afa761..975f74409 100644
--- a/desktop/tree.c
+++ b/desktop/tree.c
@@ -26,16 +26,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+
+#include "utils/log.h"
+#include "utils/messages.h"
+#include "utils/utils.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "css/utils.h"
+#include "utils/nsoption.h"
+
#include "desktop/browser.h"
#include "desktop/tree.h"
-#include "utils/nsoption.h"
-#include "render/font.h"
-#include "utils/log.h"
-#include "utils/messages.h"
-#include "utils/utils.h"
struct tree {
unsigned int flags; /* Tree flags */
diff --git a/desktop/treeview.c b/desktop/treeview.c
index 484d279cf..4e597e0b5 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -16,14 +16,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/** \file
- * Treeview handling (implementation).
+/**
+ * \file
+ *
+ * Treeview handling implementation.
*/
#include "utils/log.h"
#include "css/utils.h"
#include "image/bitmap.h"
-#include "render/font.h"
#include "content/hlcache.h"
#include "desktop/system_colour.h"
@@ -31,8 +32,9 @@
#include "desktop/plotters.h"
#include "desktop/textarea.h"
#include "desktop/treeview.h"
+#include "desktop/font.h"
-/* TODO: get rid of REDRAW_MAX -- need to be able to know window size */
+/** @todo get rid of REDRAW_MAX -- need to be able to know window size */
#define REDRAW_MAX 8000
struct treeview_globals {