30#include <oslib/wimp.h>
31#include <oslib/wimpreadsysinfo.h>
60 error = xfont_find_font(
"Homerton.Medium\\ELatin1",
61 160, 160, 0, 0, &font, 0, 0);
63 if (error->errnum == error_FILE_NOT_FOUND) {
64 xwimp_start_task(
"TaskWindow -wimpslot 200K -quit "
65 "<NetSurf$Dir>.FixFonts", 0);
68 NSLOG(netsurf, INFO,
"xfont_find_font: 0x%x: %s",
69 error->errnum, error->errmess);
76 error = xfont_lose_font(font);
78 NSLOG(netsurf, INFO,
"xfont_lose_font: 0x%x: %s",
79 error->errnum, error->errmess);
104 *option = strdup(family);
106 *option = strdup(fallback);
118 const char *fallback;
123 NSLOG(netsurf, INFO,
"Initialise RUfl");
125 if (code != rufl_OK) {
126 if (code == rufl_FONT_MANAGER_ERROR)
128 "rufl_init: rufl_FONT_MANAGER_ERROR: 0x%x: %s",
129 rufl_fm_error->errnum,
130 rufl_fm_error->errmess);
132 NSLOG(netsurf, INFO,
"rufl_init: 0x%x", code);
133 die(
"The Unicode font library could not be initialized. "
134 "Please report this to the developers.");
136 NSLOG(netsurf, INFO,
"RUfl initialised");
138 if (rufl_family_list_entries == 0)
139 die(
"No fonts could be found. At least one font must be "
167 const char *fallback =
"Homerton";
171 "Homerton not found, dumping RUfl family list");
172 for (
unsigned int i = 0; i < rufl_family_list_entries; i++) {
173 NSLOG(netsurf, INFO,
"'%s'", rufl_family_list[i]);
175 fallback = rufl_family_list[0];
187 const char *key = keyval;
188 const char *
const *entry = datum;
189 return strcasecmp(key, *entry);
201 if (bsearch(font_family, rufl_family_list,
202 rufl_family_list_entries,
sizeof rufl_family_list[0],
220 const char *
string,
size_t length,
223 const char *font_family;
224 unsigned int font_size;
225 rufl_style font_style;
229 if (font_size == 0) {
234 code = rufl_width(font_family, font_style, font_size,
237 if (code != rufl_OK) {
238 if (code == rufl_FONT_MANAGER_ERROR)
240 "rufl_width: rufl_FONT_MANAGER_ERROR: 0x%x: %s",
241 rufl_fm_error->errnum,
242 rufl_fm_error->errmess);
244 NSLOG(netsurf, INFO,
"rufl_width: 0x%x", code);
268 const char *
string,
size_t length,
269 int x,
size_t *char_offset,
int *actual_x)
271 const char *font_family;
272 unsigned int font_size;
273 rufl_style font_style;
277 if (font_size == 0) {
283 code = rufl_x_to_offset(font_family, font_style, font_size,
285 x * 2, char_offset, actual_x);
286 if (code != rufl_OK) {
287 if (code == rufl_FONT_MANAGER_ERROR)
289 "rufl_x_to_offset: rufl_FONT_MANAGER_ERROR: ""0x%x: %s",
290 rufl_fm_error->errnum,
291 rufl_fm_error->errmess);
293 NSLOG(netsurf, INFO,
"rufl_x_to_offset: 0x%x", code);
330 const char *
string,
size_t length,
331 int x,
size_t *char_offset,
int *actual_x)
333 const char *font_family;
334 unsigned int font_size;
335 rufl_style font_style;
339 if (font_size == 0) {
345 code = rufl_split(font_family, font_style, font_size,
347 x * 2, char_offset, actual_x);
348 if (code != rufl_OK) {
349 if (code == rufl_FONT_MANAGER_ERROR) {
351 "rufl_split: rufl_FONT_MANAGER_ERROR: ""0x%x: %s",
352 rufl_fm_error->errnum,
353 rufl_fm_error->errmess);
355 NSLOG(netsurf, INFO,
"rufl_split: 0x%x", code);
363 if (*char_offset != length) {
365 size_t orig = *char_offset;
368 while (*char_offset &&
string[*char_offset] !=
' ') {
373 if (*char_offset == 0) {
375 while ((*char_offset != length) &&
376 (
string[*char_offset] !=
' ')) {
382 code = rufl_width(font_family, font_style, font_size,
383 string, *char_offset,
385 if (code != rufl_OK) {
386 if (code == rufl_FONT_MANAGER_ERROR) {
388 "rufl_width: rufl_FONT_MANAGER_ERROR: 0x%x: %s",
389 rufl_fm_error->errnum,
390 rufl_fm_error->errmess);
392 NSLOG(netsurf, INFO,
"rufl_width: 0x%x", code);
416 size_t length,
int x,
int y)
418 const char *font_family;
419 unsigned int font_size;
420 unsigned int flags = rufl_BLEND_FONT;
421 rufl_style font_style;
431 code = rufl_paint(font_family, font_style, font_size,
432 string, length, x, y, flags);
433 if (code != rufl_OK) {
434 if (code == rufl_FONT_MANAGER_ERROR) {
436 "rufl_paint: rufl_FONT_MANAGER_ERROR: 0x%x: %s",
437 rufl_fm_error->errnum,
438 rufl_fm_error->errmess);
440 NSLOG(netsurf, INFO,
"rufl_paint: 0x%x", code);
457 const char **font_family,
unsigned int *font_size,
458 rufl_style *font_style)
460 static const rufl_style weight_table[] = {
473 if (1600 < *font_size)
498 *font_style = rufl_SLANTED;
503 *font_style |= weight_table[(fstyle->
weight / 100) - 1];
522 rufl_style style = rufl_WEIGHT_400;
529 assert(20 < family_size);
533 error = xwimpreadsysinfo_font(&font_handle, NULL);
535 NSLOG(netsurf, INFO,
"xwimpreadsysinfo_font: 0x%x: %s",
536 error->errnum, error->errmess);
541 if (font_handle == font_SYSTEM) {
546 error = xfont_read_identifier(font_handle, NULL, &used);
548 NSLOG(netsurf, INFO,
"xfont_read_identifier: 0x%x: %s",
549 error->errnum, error->errmess);
554 if (family_size < (
size_t) used + 1) {
555 NSLOG(netsurf, INFO,
"desktop font name too long");
559 error = xfont_read_defn(font_handle, (
byte *) family,
560 &ptx, &pty, NULL, NULL, NULL, NULL);
562 NSLOG(netsurf, INFO,
"xfont_read_defn: 0x%x: %s",
563 error->errnum, error->errmess);
568 for (
size_t i = 0; i != (size_t) used; i++) {
569 if (family[i] <
' ') {
575 NSLOG(netsurf, INFO,
"desktop font \"%s\"", family);
578 style = rufl_WEIGHT_500;
580 style = rufl_WEIGHT_700;
582 style |= rufl_SLANTED;
584 char *dot = strchr(family,
'.');
588 *psize =
max(ptx, pty);
591 NSLOG(netsurf, INFO,
"family \"%s\", size %i, style %i", family,
597 strcpy(family,
"Homerton");
599 *pstyle = rufl_WEIGHT_400;
void die(const char *error)
Cause an abnormal program termination.
char * strcasestr(const char *haystack, const char *needle)
Case insensitive strstr implementation.
nserror
Enumeration of error codes.
@ NSERROR_INVALID
Invalid data.
void nsfont_init(void)
Initialize font handling.
static void ro_gui_wimp_desktop_font(char *family, size_t family_size, int *psize, rufl_style *pstyle)
Looks up the current desktop font and converts that to a family name, font size and style flags suita...
void ro_gui_wimp_get_desktop_font(void)
Retrieve the current desktop font family, size and style from the WindowManager in a form suitable fo...
rufl_style ro_gui_desktop_font_style
const char * nsfont_fallback_font(void)
Retrieve the fallback font name.
static nserror ro_font_position(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.
static void nsfont_check_fonts(void)
Check that at least Homerton.Medium is available.
static nserror ro_font_split(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.
int ro_gui_desktop_font_size
bool nsfont_exists(const char *font_family)
Check if a font family is available.
static void nsfont_check_option(char **option, const char *family, const char *fallback)
Check that a font option is valid, and fix it if not.
char ro_gui_desktop_font_family[80]
desktop font, size and style being used
static nserror ro_font_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width)
Measure the width of a string.
static struct gui_layout_table layout_table
static int nsfont_list_cmp(const void *keyval, const void *datum)
bsearch comparison routine
void nsfont_read_style(const plot_font_style_t *fstyle, const char **font_family, unsigned int *font_size, rufl_style *font_style)
Convert a font style to a font family, size and rufl_style.
struct gui_layout_table * riscos_layout_table
bool nsfont_paint(const plot_font_style_t *fstyle, const char *string, size_t length, int x, int y)
Paint a string.
Interface to platform-specific layout operation table.
#define NSLOG(catname, level, logmsg, args...)
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Localised message support (interface).
plotter style interfaces, generic styles and style colour helpers.
@ PLOT_FONT_FAMILY_CURSIVE
@ PLOT_FONT_FAMILY_SANS_SERIF
@ PLOT_FONT_FAMILY_FANTASY
@ PLOT_FONT_FAMILY_MONOSPACE
#define PLOT_STYLE_SCALE
Scaling factor for plot styles.
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
Interface to utility string handling.
nserror(* width)(const struct plot_font_style *fstyle, const char *string, size_t length, int *width)
Measure the width of a string.
plot_font_generic_family_t family
Generic family to plot with.
plot_font_flags_t flags
Font flags.
plot_style_fixed size
Font size, in pt.
int weight
Font weight: value in range [100,900] as per CSS.
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
#define nsoption_int(OPTION)
Get the value of an integer option.
#define nsoption_set_int(OPTION, VALUE)
set an integer option in the default table
Interface to a number of general purpose functionality.