summaryrefslogtreecommitdiff
path: root/riscos
diff options
context:
space:
mode:
Diffstat (limited to 'riscos')
-rw-r--r--riscos/font.c108
-rw-r--r--riscos/gui.h6
-rw-r--r--riscos/wimp.c153
-rw-r--r--riscos/wimp.h7
4 files changed, 114 insertions, 160 deletions
diff --git a/riscos/font.c b/riscos/font.c
index 097c20578..9a53a4780 100644
--- a/riscos/font.c
+++ b/riscos/font.c
@@ -14,6 +14,7 @@
#include <assert.h>
#include <string.h>
#include "oslib/wimp.h"
+#include "oslib/wimpreadsysinfo.h"
#include "rufl.h"
#include "netsurf/css/css.h"
#include "netsurf/render/font.h"
@@ -26,12 +27,19 @@
wimp_menu *font_menu;
+/** desktop font, size and style being used */
+char ro_gui_desktop_font_family[80];
+int ro_gui_desktop_font_size = 12;
+rufl_style ro_gui_desktop_font_style = rufl_WEIGHT_400;
+
static void nsfont_check_option(char **option, const char *family,
const char *fallback);
static int nsfont_list_cmp(const void *keyval, const void *datum);
static void nsfont_check_fonts(void);
static void nsfont_init_menu(void);
+static void ro_gui_wimp_desktop_font(char *family, size_t bufsize, int *psize,
+ rufl_style *pstyle);
/**
@@ -506,3 +514,103 @@ void nsfont_read_style(const struct css_style *style,
break;
}
}
+
+
+/**
+ * Looks up the current desktop font and converts that to a family name,
+ * font size and style flags suitable for passing directly to rufl
+ *
+ * \param family buffer to receive font family
+ * \param family_size buffer size
+ * \param psize receives the font size in 1/16 points
+ * \param pstyle receives the style settings to be passed to rufl
+ */
+
+void ro_gui_wimp_desktop_font(char *family, size_t family_size, int *psize,
+ rufl_style *pstyle)
+{
+ rufl_style style = rufl_WEIGHT_400;
+ os_error *error;
+ int ptx, pty;
+ font_f font_handle;
+ int used;
+
+ assert(family);
+ assert(20 < family_size);
+ assert(psize);
+ assert(pstyle);
+
+ error = xwimpreadsysinfo_font(&font_handle, NULL);
+ if (error) {
+ LOG(("xwimpreadsysinfo_font: 0x%x: %s",
+ error->errnum, error->errmess));
+ warn_user("WimpError", error->errmess);
+ goto failsafe;
+ }
+
+ error = xfont_read_identifier(font_handle, NULL, &used);
+ if (error) {
+ LOG(("xfont_read_identifier: 0x%x: %s",
+ error->errnum, error->errmess));
+ warn_user("MiscError", error->errmess);
+ goto failsafe;
+ }
+
+ if (family_size < (size_t) used + 1) {
+ LOG(("desktop font name too long"));
+ goto failsafe;
+ }
+
+ error = xfont_read_defn(font_handle, family,
+ &ptx, &pty, NULL, NULL, NULL, NULL);
+ if (error) {
+ LOG(("xfont_read_defn: 0x%x: %s",
+ error->errnum, error->errmess));
+ warn_user("MiscError", error->errmess);
+ goto failsafe;
+ }
+
+ for (size_t i = 0; i != (size_t) used; i++) {
+ if (family[i] < ' ') {
+ family[i] = 0;
+ break;
+ }
+ }
+
+ LOG(("desktop font \"%s\"", family));
+
+ if (strstr(family, ".Bold"))
+ style = rufl_WEIGHT_700;
+ if (strstr(family, ".Italic") || strstr(family, ".Oblique"))
+ style |= rufl_SLANTED;
+
+ char *dot = strchr(family, '.');
+ if (dot)
+ *dot = 0;
+
+ *psize = max(ptx, pty);
+ *pstyle = style;
+
+ LOG(("family \"%s\", size %i, style %i", family, *psize, style));
+
+ return;
+
+failsafe:
+ strcpy(family, "Homerton");
+ *psize = 12*16;
+ *pstyle = rufl_WEIGHT_400;
+}
+
+
+/**
+ * Retrieve the current desktop font family, size and style from
+ * the WindowManager in a form suitable for passing to rufl
+ */
+
+void ro_gui_wimp_get_desktop_font(void)
+{
+ ro_gui_wimp_desktop_font(ro_gui_desktop_font_family,
+ sizeof(ro_gui_desktop_font_family),
+ &ro_gui_desktop_font_size,
+ &ro_gui_desktop_font_style);
+}
diff --git a/riscos/gui.h b/riscos/gui.h
index ca8f90b6b..7ffeb5194 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -62,6 +62,11 @@ typedef enum { GUI_DRAG_NONE, GUI_DRAG_SELECTION, GUI_DRAG_DOWNLOAD_SAVE,
extern gui_drag_type gui_current_drag_type;
+/** desktop font, size and style being used */
+extern char ro_gui_desktop_font_family[];
+extern int ro_gui_desktop_font_size;
+extern rufl_style ro_gui_desktop_font_style;
+
/** RISC OS data for a browser window. */
struct gui_window {
@@ -208,6 +213,7 @@ bool nsfont_paint(struct css_style *style, const char *string,
void nsfont_read_style(const struct css_style *style,
const char **font_family, unsigned int *font_size,
rufl_style *font_style);
+void ro_gui_wimp_get_desktop_font(void);
/* in plotters.c */
extern const struct plotter_table ro_plotters;
diff --git a/riscos/wimp.c b/riscos/wimp.c
index d1c0fd1fc..37c03d96b 100644
--- a/riscos/wimp.c
+++ b/riscos/wimp.c
@@ -20,7 +20,6 @@
#include "oslib/osfile.h"
#include "oslib/wimp.h"
#include "oslib/wimpextend.h"
-#include "oslib/wimpreadsysinfo.h"
#include "oslib/wimpspriteop.h"
#include "netsurf/desktop/gui.h"
#include "netsurf/riscos/gui.h"
@@ -31,14 +30,7 @@
#include "netsurf/utils/utils.h"
-/** desktop font, size and style being used */
-char ro_gui_desktop_font_family[48];
-int ro_gui_desktop_font_size = 12;
-rufl_style ro_gui_desktop_font_style = rufl_WEIGHT_400;
-
-
static void ro_gui_wimp_cache_furniture_sizes(wimp_w w);
-static void ro_gui_wimp_desktop_font(char *family, size_t bufsize, int *psize, rufl_style *pstyle);
static wimpextend_furniture_sizes furniture_sizes;
static wimp_w furniture_window = NULL;
@@ -936,148 +928,3 @@ bool ro_gui_wimp_check_window_furniture(wimp_w w, wimp_window_flags mask) {
}
return state.flags & mask;
}
-
-
-/**
- * Looks up the current desktop font and converts that to a family name,
- * font size and style flags suitable for passing directly to rufl
- *
- * \param family buffer to receive font family
- * \param bufsize buffer size
- * \param psize receives the font size in points
- * \param pstyle receives the style settings to be passed to rufl
- * \return pointer to family name
- */
-
-void ro_gui_wimp_desktop_font(char *family, size_t bufsize,
- int *psize, rufl_style *pstyle)
-{
- rufl_style style = rufl_WEIGHT_400;
- bool got_family = false;
- char *buf = NULL;
- os_error *error;
- int ptx, pty;
- char *p, *ep;
- font_f fh;
- int used;
-
- error = xwimpreadsysinfo_font(&fh, NULL);
- if (error) {
- LOG(("xwimpreadsysinfo_font: 0x%x: %s",
- error->errnum, error->errmess));
- warn_user("WimpError", error->errmess);
- goto failsafe;
- }
-
- error = xfont_read_identifier(fh, NULL, &used);
- if (error) {
- LOG(("xfont_read_identifier: 0x%x: %s",
- error->errnum, error->errmess));
- goto failsafe;
- }
-
- buf = malloc(used+1);
- if (!buf) {
- warn_user("NoMemory", NULL);
- goto failsafe;
- }
-
- if (psize) {
- error = xfont_read_defn(fh, buf,
- &ptx, &pty, NULL, NULL, NULL, NULL);
- if (error) {
- LOG(("xfont_read_defn: 0x%x: %s",
- error->errnum, error->errmess));
- goto failsafe;
- }
- *psize = max(ptx, pty);
- }
-
- error = xfont_read_identifier(fh, buf, NULL);
- if (error) {
- LOG(("xfont_read_identifier: 0x%x: %s",
- error->errnum, error->errmess));
- goto failsafe;
- }
-
- ep = buf + used;
- p = buf;
- *ep = '\0';
-
- while (p < ep) {
- if (*p++ != '\\') continue;
-
- if (toupper(*p) == 'F') {
- /* find the end of the family name */
- const char *match[] = { "Bold", "Italic", "Oblique" };
- const int match_len[] = { 4, 6, 7 };
- char *q = ++p;
- size_t len;
- while (*q > ' ' && *q != '\\' && *q != '.') q++;
- len = q - p;
- if (len >= bufsize) {
- LOG(("font family name too long"));
- goto failsafe;
- }
- memmove(family, p, len);
- family[len] = '\0';
- got_family = true;
- p = q;
- while (*p > ' ' && *p != '\\') {
- char *q;
- unsigned int m = 0;
- if (*p == '.') p++;
- q = p; while (*q > ' ' && *q != '.' && *q != '\\') q++;
-
- while (m < NOF_ELEMENTS(match) &&
- (q - p != match_len[m] ||
- strncasecmp(p, match[m], match_len[m])))
- m++;
-
- switch (m) {
- case 0: style = (style & ~rufl_WEIGHT_400) |
- rufl_WEIGHT_700;
- break;
- case 1: /* no break */
- case 2: style |= rufl_SLANTED; break;
- }
- p = q;
- }
- }
- else
- while (*p > ' ' && *p != '\\') p++;
- }
-
- if (got_family) {
- free(buf);
- if (pstyle) *pstyle = style;
- return;
- }
-
-failsafe:
- free(buf);
-
- if (bufsize >= 9) {
- memcpy(family, "Homerton", 9);
- } else {
- /** \todo what to do here? */
- assert(0);
- }
-
- if (psize) *psize = 12*16;
- if (pstyle) *pstyle = rufl_WEIGHT_400;
-}
-
-
-/**
- * Retrieve the current desktop font family, size and style from
- * the WindowManager in a form suitable for passing to rufl
- */
-
-void ro_gui_wimp_get_desktop_font(void)
-{
- ro_gui_wimp_desktop_font(ro_gui_desktop_font_family,
- sizeof(ro_gui_desktop_font_family),
- &ro_gui_desktop_font_size,
- &ro_gui_desktop_font_style);
-}
diff --git a/riscos/wimp.h b/riscos/wimp.h
index 6cc104d5c..456c96528 100644
--- a/riscos/wimp.h
+++ b/riscos/wimp.h
@@ -22,11 +22,6 @@
#include "oslib/wimp.h"
#include "rufl.h"
-/** desktop font, size and style being used */
-extern char ro_gui_desktop_font_family[];
-extern int ro_gui_desktop_font_size;
-extern rufl_style ro_gui_desktop_font_style;
-
int ro_get_hscroll_height(wimp_w w);
int ro_get_vscroll_width(wimp_w w);
@@ -68,6 +63,4 @@ void ro_gui_wimp_update_window_furniture(wimp_w w, wimp_window_flags bic_mask,
wimp_window_flags xor_mask);
bool ro_gui_wimp_check_window_furniture(wimp_w w, wimp_window_flags mask);
-void ro_gui_wimp_get_desktop_font(void);
-
#endif