NetSurf
Functions | Variables
font.c File Reference

RISC OS implementation of Font handling. More...

#include "utils/config.h"
#include <assert.h>
#include <string.h>
#include <oslib/wimp.h>
#include <oslib/wimpreadsysinfo.h>
#include "utils/nsoption.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "netsurf/layout.h"
#include "netsurf/plot_style.h"
#include "riscos/gui.h"
#include "riscos/font.h"
Include dependency graph for font.c:

Go to the source code of this file.

Functions

static void nsfont_check_fonts (void)
 Check that at least Homerton.Medium is available. More...
 
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. More...
 
void nsfont_init (void)
 Initialize font handling. More...
 
const char * nsfont_fallback_font (void)
 Retrieve the fallback font name. More...
 
static int nsfont_list_cmp (const void *keyval, const void *datum)
 bsearch comparison routine More...
 
bool nsfont_exists (const char *font_family)
 Check if a font family is available. More...
 
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. More...
 
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. More...
 
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. More...
 
bool nsfont_paint (const plot_font_style_t *fstyle, const char *string, size_t length, int x, int y)
 Paint a string. More...
 
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. More...
 
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 suitable for passing directly to rufl. More...
 
void ro_gui_wimp_get_desktop_font (void)
 Retrieve the current desktop font family, size and style from the WindowManager in a form suitable for passing to rufl. More...
 

Variables

char ro_gui_desktop_font_family [80]
 desktop font, size and style being used More...
 
int ro_gui_desktop_font_size = 12
 
rufl_style ro_gui_desktop_font_style = rufl_WEIGHT_400
 
bool no_font_blending = false
 
static struct gui_layout_table layout_table
 
struct gui_layout_tableriscos_layout_table = &layout_table
 

Detailed Description

RISC OS implementation of Font handling.

The RUfl is used to handle and render fonts.

Definition in file font.c.

Function Documentation

◆ nsfont_check_fonts()

static void nsfont_check_fonts ( void  )
static

Check that at least Homerton.Medium is available.

Definition at line 54 of file font.c.

References die(), messages_get(), and NSLOG.

Referenced by nsfont_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsfont_check_option()

static void nsfont_check_option ( char **  option,
const char *  family,
const char *  fallback 
)
static

Check that a font option is valid, and fix it if not.

Parameters
optionpointer to option, as used by options.[ch]
familyfont family to use if option is not set, or the set family is not available
fallbackfont family to use if family is not available either

Definition at line 95 of file font.c.

References nsfont_exists().

Referenced by nsfont_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsfont_exists()

bool nsfont_exists ( const char *  font_family)

Check if a font family is available.

Parameters
font_familyname of font family
Returns
true if the family is available

Definition at line 199 of file font.c.

References nsfont_list_cmp().

Referenced by nsfont_check_option(), nsfont_fallback_font(), and ro_gui_options_fonts_default().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsfont_fallback_font()

const char * nsfont_fallback_font ( void  )

Retrieve the fallback font name.

Returns
Fallback font name

Definition at line 165 of file font.c.

References nsfont_exists(), and NSLOG.

Referenced by nsfont_init(), and ro_gui_options_fonts_default().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsfont_init()

void nsfont_init ( void  )

Initialize font handling.

Exits through die() on error.

Definition at line 116 of file font.c.

References die(), nsfont_check_fonts(), nsfont_check_option(), nsfont_fallback_font(), NSLOG, nsoption_charp, nsoption_int, nsoption_set_int, PLOT_FONT_FAMILY_CURSIVE, PLOT_FONT_FAMILY_FANTASY, PLOT_FONT_FAMILY_MONOSPACE, PLOT_FONT_FAMILY_SANS_SERIF, and PLOT_FONT_FAMILY_SERIF.

Referenced by gui_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsfont_list_cmp()

static int nsfont_list_cmp ( const void *  keyval,
const void *  datum 
)
static

bsearch comparison routine

Definition at line 185 of file font.c.

Referenced by nsfont_exists().

Here is the caller graph for this function:

◆ nsfont_paint()

bool nsfont_paint ( const plot_font_style_t fstyle,
const char *  string,
size_t  length,
int  x,
int  y 
)

Paint a string.

Render a string.

Parameters
fstyleplot style for this text
stringUTF-8 string to measure
lengthlength of string
xx coordinate
yy coordinate
Returns
true on success, false on error and error reported

Definition at line 415 of file font.c.

References no_font_blending, nsfont_read_style(), NSLOG, and print_active.

Here is the call graph for this function:

◆ nsfont_read_style()

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.

Parameters
fstyleplot style for this text
font_familyupdated to font family
font_sizeupdated to font size
font_styleupdated to font style

Definition at line 456 of file font.c.

References plot_font_style::family, plot_font_style::flags, FONTF_ITALIC, FONTF_OBLIQUE, nsoption_charp, PLOT_FONT_FAMILY_CURSIVE, PLOT_FONT_FAMILY_FANTASY, PLOT_FONT_FAMILY_MONOSPACE, PLOT_FONT_FAMILY_SANS_SERIF, PLOT_FONT_FAMILY_SERIF, PLOT_STYLE_SCALE, plot_font_style::size, and plot_font_style::weight.

Referenced by nsfont_paint(), print_fonts_plot_text(), ro_font_position(), ro_font_split(), and ro_font_width().

Here is the caller graph for this function:

◆ ro_font_position()

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 
)
static

Find the position in a string where an x coordinate falls.

Parameters
fstylestyle for this text
stringUTF-8 string to measure
lengthlength of string
xx coordinate to search for
char_offsetupdated to offset in string of actual_x, [0..length]
actual_xupdated to x coordinate of character closest to x
Returns
true on success, false on error and error reported

Definition at line 267 of file font.c.

References NSERROR_INVALID, NSERROR_OK, nsfont_read_style(), and NSLOG.

Here is the call graph for this function:

◆ ro_font_split()

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 
)
static

Find where to split a string to make it fit a width.

Parameters
fstylestyle for this text
stringUTF-8 string to measure
lengthlength of string, in bytes
xwidth available
char_offsetupdated to offset in string of actual_x, [1..length]
actual_xupdated to x coordinate of character closest to x
Returns
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

Definition at line 329 of file font.c.

References NSERROR_INVALID, NSERROR_OK, nsfont_read_style(), and NSLOG.

Here is the call graph for this function:

◆ ro_font_width()

static nserror ro_font_width ( const plot_font_style_t fstyle,
const char *  string,
size_t  length,
int *  width 
)
static

Measure the width of a string.

Parameters
fstyleplot style for this text
stringUTF-8 string to measure
lengthlength of string
widthupdated to width of string[0..length)
Returns
true on success, false on error and error reported

Definition at line 219 of file font.c.

References NSERROR_INVALID, NSERROR_OK, nsfont_read_style(), NSLOG, and width.

Here is the call graph for this function:

◆ ro_gui_wimp_desktop_font()

static void ro_gui_wimp_desktop_font ( char *  family,
size_t  family_size,
int *  psize,
rufl_style *  pstyle 
)
static

Looks up the current desktop font and converts that to a family name, font size and style flags suitable for passing directly to rufl.

Parameters
familybuffer to receive font family
family_sizebuffer size
psizereceives the font size in 1/16 points
pstylereceives the style settings to be passed to rufl

Definition at line 517 of file font.c.

References max, NSLOG, ro_warn_user(), and strcasestr().

Referenced by ro_gui_wimp_get_desktop_font().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_gui_wimp_get_desktop_font()

void ro_gui_wimp_get_desktop_font ( void  )

Retrieve the current desktop font family, size and style from the WindowManager in a form suitable for passing to rufl.

Definition at line 607 of file font.c.

References ro_gui_desktop_font_family, ro_gui_desktop_font_size, ro_gui_desktop_font_style, and ro_gui_wimp_desktop_font().

Referenced by gui_init(), and ro_gui_user_message().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ layout_table

struct gui_layout_table layout_table
static
Initial value:
= {
.width = ro_font_width,
.position = ro_font_position,
.split = ro_font_split,
}
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.
Definition: font.c:267
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.
Definition: font.c:329
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.
Definition: font.c:219

Definition at line 616 of file font.c.

◆ no_font_blending

bool no_font_blending = false

◆ riscos_layout_table

struct gui_layout_table* riscos_layout_table = &layout_table

Definition at line 622 of file font.c.

Referenced by main().

◆ ro_gui_desktop_font_family

char ro_gui_desktop_font_family[80]

desktop font, size and style being used

Definition at line 45 of file font.c.

Referenced by ro_gui_status_bar_redraw(), and ro_gui_wimp_get_desktop_font().

◆ ro_gui_desktop_font_size

int ro_gui_desktop_font_size = 12

Definition at line 46 of file font.c.

Referenced by ro_gui_status_bar_redraw(), and ro_gui_wimp_get_desktop_font().

◆ ro_gui_desktop_font_style

rufl_style ro_gui_desktop_font_style = rufl_WEIGHT_400

Definition at line 47 of file font.c.

Referenced by ro_gui_status_bar_redraw(), and ro_gui_wimp_get_desktop_font().