NetSurf
Functions | Variables
layout.c File Reference

monkey implementation of font layout. More...

#include <stddef.h>
#include "utils/utf8.h"
#include "netsurf/plot_style.h"
#include "netsurf/layout.h"
#include "monkey/layout.h"
Include dependency graph for layout.c:

Go to the source code of this file.

Functions

static nserror nsfont_width (const plot_font_style_t *fstyle, const char *string, size_t length, int *width)
 
static nserror nsfont_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 the position in a string where an x coordinate falls. More...
 
static nserror nsfont_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...
 

Variables

static struct gui_layout_table layout_table
 
struct gui_layout_tablemonkey_layout_table = &layout_table
 

Detailed Description

monkey implementation of font layout.

Definition in file layout.c.

Function Documentation

◆ nsfont_position_in_string()

static nserror nsfont_position_in_string ( 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 52 of file layout.c.

References NSERROR_OK, PLOT_STYLE_SCALE, and plot_font_style::size.

◆ nsfont_split()

static nserror nsfont_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 87 of file layout.c.

References NSERROR_OK, PLOT_STYLE_SCALE, and plot_font_style::size.

◆ nsfont_width()

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

Definition at line 32 of file layout.c.

References NSERROR_OK, PLOT_STYLE_SCALE, plot_font_style::size, utf8_bounded_length(), and width.

Here is the call graph for this function:

Variable Documentation

◆ layout_table

struct gui_layout_table layout_table
static
Initial value:
= {
.width = nsfont_width,
.split = nsfont_split,
}
static nserror nsfont_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 the position in a string where an x coordinate falls.
Definition: layout.c:52
static nserror nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width)
Definition: layout.c:32
static nserror nsfont_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: layout.c:87

Definition at line 111 of file layout.c.

◆ monkey_layout_table

struct gui_layout_table* monkey_layout_table = &layout_table

Definition at line 117 of file layout.c.

Referenced by main().