NetSurf
Macros | Functions | Variables
font_internal.c File Reference
#include <inttypes.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include "utils/nsoption.h"
#include "utils/utils.h"
#include "utils/utf8.h"
#include "netsurf/utf8.h"
#include "netsurf/layout.h"
#include "netsurf/plot_style.h"
#include "framebuffer/gui.h"
#include "framebuffer/font.h"
#include <font-ns-sans.h>
Include dependency graph for font_internal.c:

Go to the source code of this file.

Macros

#define GLYPH_LEN   16
 
#define SEVEN_SET
 
#define THREE_SSS   ((1 << 0) | (1 << 1) | (1 << 2))
 
#define THREE_S_S   ((1 << 0) | (1 << 2))
 
#define THREE__SS   ((1 << 0) | (1 << 1) )
 
#define THREE_SS_   ( (1 << 1) | (1 << 2))
 
#define THREE_S__   (1 << 2)
 
#define THREE__S_   (1 << 1)
 
#define THREE___S   (1 << 0)
 

Functions

static uint8_t * get_codepoint (uint32_t id, bool italic)
 
bool fb_font_init (void)
 Initialise framebuffer font handling. More...
 
bool fb_font_finalise (void)
 Finalise framebuffer font handling. More...
 
enum fb_font_style fb_get_font_style (const plot_font_style_t *fstyle)
 
int fb_get_font_size (const plot_font_style_t *fstyle)
 
static const uint8_t * glyph_scale_2 (const uint8_t *glyph_data)
 
const uint8_t * fb_get_glyph (uint32_t ucs4, enum fb_font_style style, int scale)
 
static nserror utf8_to_local (const char *string, size_t len, char **result)
 
static nserror utf8_from_local (const char *string, size_t len, char **result)
 
nserror fb_font_width (const plot_font_style_t *fstyle, const char *string, size_t length, int *width)
 
nserror fb_font_position (const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x)
 
static nserror fb_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...
 

Variables

uint8_t code_point [GLYPH_LEN]
 
uint8_t glyph_x2 [GLYPH_LEN *4]
 
uint8_t frag [16][5]
 
const uint8_t glyph_lut [16]
 Lookup table to scale 4 bits to 8 bits, so e.g. More...
 
static struct gui_layout_table layout_table
 
struct gui_layout_tableframebuffer_layout_table = &layout_table
 
static struct gui_utf8_table utf8_table
 
struct gui_utf8_tableframebuffer_utf8_table = &utf8_table
 

Macro Definition Documentation

◆ GLYPH_LEN

#define GLYPH_LEN   16

Definition at line 37 of file font_internal.c.

◆ SEVEN_SET

#define SEVEN_SET
Value:
((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | \
(1 << 4) | (1 << 5) | (1 << 6))

Definition at line 42 of file font_internal.c.

◆ THREE___S

#define THREE___S   (1 << 0)

Definition at line 51 of file font_internal.c.

◆ THREE__S_

#define THREE__S_   (1 << 1)

Definition at line 50 of file font_internal.c.

◆ THREE__SS

#define THREE__SS   ((1 << 0) | (1 << 1) )

Definition at line 47 of file font_internal.c.

◆ THREE_S__

#define THREE_S__   (1 << 2)

Definition at line 49 of file font_internal.c.

◆ THREE_S_S

#define THREE_S_S   ((1 << 0) | (1 << 2))

Definition at line 46 of file font_internal.c.

◆ THREE_SS_

#define THREE_SS_   ( (1 << 1) | (1 << 2))

Definition at line 48 of file font_internal.c.

◆ THREE_SSS

#define THREE_SSS   ((1 << 0) | (1 << 1) | (1 << 2))

Definition at line 45 of file font_internal.c.

Function Documentation

◆ fb_font_finalise()

bool fb_font_finalise ( void  )

Finalise framebuffer font handling.

Definition at line 193 of file font_internal.c.

References FB_FACE_COUNT, fb_faces, ft_cmanager, and library.

Referenced by main().

Here is the caller graph for this function:

◆ fb_font_init()

bool fb_font_init ( void  )

Initialise framebuffer font handling.

Definition at line 188 of file font_internal.c.

References CACHE_MIN_SIZE, FB_FACE_CURSIVE, FB_FACE_FANTASY, FB_FACE_MONOSPACE, FB_FACE_MONOSPACE_BOLD, FB_FACE_SANS_SERIF, FB_FACE_SANS_SERIF_BOLD, FB_FACE_SANS_SERIF_ITALIC, FB_FACE_SANS_SERIF_ITALIC_BOLD, FB_FACE_SERIF, FB_FACE_SERIF_BOLD, fb_faces, fb_new_face(), ft_cmanager, ft_cmap_cache, ft_face_requester(), ft_image_cache, ft_load_type, library, NSLOG, nsoption_bool, nsoption_charp, and nsoption_int.

Referenced by main().

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

◆ fb_font_position()

nserror fb_font_position ( const plot_font_style_t fstyle,
const char *  string,
size_t  length,
int  x,
size_t *  char_offset,
int *  actual_x 
)

Definition at line 383 of file font_internal.c.

References codepoint_displayable, FB_FONT_WIDTH, fb_get_font_size(), NSERROR_OK, utf8_next(), utf8_to_ucs4(), and width.

Here is the call graph for this function:

◆ fb_font_split()

static nserror fb_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 437 of file font_internal.c.

References codepoint_displayable, FB_FONT_WIDTH, fb_get_font_size(), NSERROR_OK, utf8_next(), utf8_to_ucs4(), and width.

Here is the call graph for this function:

◆ fb_font_width()

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

Definition at line 358 of file font_internal.c.

References codepoint_displayable, FB_FONT_WIDTH, fb_get_font_size(), NSERROR_OK, utf8_next(), utf8_to_ucs4(), and width.

Here is the call graph for this function:

◆ fb_get_font_size()

int fb_get_font_size ( const plot_font_style_t fstyle)

Definition at line 212 of file font_internal.c.

References nsoption_int, PLOT_STYLE_SCALE, and plot_font_style::size.

Referenced by fb_font_position(), fb_font_split(), fb_font_width(), and framebuffer_plot_text().

Here is the caller graph for this function:

◆ fb_get_font_style()

enum fb_font_style fb_get_font_style ( const plot_font_style_t fstyle)

Definition at line 199 of file font_internal.c.

References FB_BOLD, FB_ITALIC, FB_REGULAR, plot_font_style::flags, FONTF_ITALIC, FONTF_OBLIQUE, and plot_font_style::weight.

Referenced by framebuffer_plot_text().

Here is the caller graph for this function:

◆ fb_get_glyph()

const uint8_t * fb_get_glyph ( uint32_t  ucs4,
enum fb_font_style  style,
int  scale 
)

Definition at line 250 of file font_internal.c.

References fallthrough, FB_BOLD, FB_BOLD_ITALIC, FB_ITALIC, FB_REGULAR, get_codepoint(), and glyph_scale_2().

Referenced by framebuffer_plot_text().

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

◆ get_codepoint()

static uint8_t * get_codepoint ( uint32_t  id,
bool  italic 
)
static

Definition at line 151 of file font_internal.c.

References code_point, frag, and SEVEN_SET.

Referenced by fb_get_glyph().

Here is the caller graph for this function:

◆ glyph_scale_2()

static const uint8_t * glyph_scale_2 ( const uint8_t *  glyph_data)
static

Definition at line 234 of file font_internal.c.

References GLYPH_LEN, glyph_lut, and glyph_x2.

Referenced by fb_get_glyph().

Here is the caller graph for this function:

◆ utf8_from_local()

static nserror utf8_from_local ( const char *  string,
size_t  len,
char **  result 
)
static

Definition at line 339 of file font_internal.c.

References NSERROR_NOMEM, NSERROR_OK, and result.

◆ utf8_to_local()

static nserror utf8_to_local ( const char *  string,
size_t  len,
char **  result 
)
static

Definition at line 331 of file font_internal.c.

References result, and utf8_to_enc().

Here is the call graph for this function:

Variable Documentation

◆ code_point

uint8_t code_point[GLYPH_LEN]

Definition at line 39 of file font_internal.c.

Referenced by get_codepoint().

◆ frag

uint8_t frag[16][5]

Definition at line 53 of file font_internal.c.

Referenced by get_codepoint().

◆ framebuffer_layout_table

struct gui_layout_table* framebuffer_layout_table = &layout_table

Definition at line 486 of file font_internal.c.

Referenced by main().

◆ framebuffer_utf8_table

struct gui_utf8_table* framebuffer_utf8_table = &utf8_table

Definition at line 494 of file font_internal.c.

Referenced by main().

◆ glyph_lut

const uint8_t glyph_lut[16]
Initial value:
= {
0x00, 0x03, 0x0c, 0x0f,
0x30, 0x33, 0x3c, 0x3f,
0xc0, 0xc3, 0xcc, 0xcf,
0xf0, 0xf3, 0xfc, 0xff
}

Lookup table to scale 4 bits to 8 bits, so e.g.

0101 --> 00110011

Definition at line 226 of file font_internal.c.

Referenced by glyph_scale_2().

◆ glyph_x2

uint8_t glyph_x2[GLYPH_LEN *4]

Definition at line 40 of file font_internal.c.

Referenced by glyph_scale_2().

◆ layout_table

struct gui_layout_table layout_table
static
Initial value:
= {
.width = fb_font_width,
.position = fb_font_position,
.split = fb_font_split,
}
nserror fb_font_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width)
static nserror fb_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.
nserror fb_font_position(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x)

Definition at line 480 of file font_internal.c.

◆ utf8_table

struct gui_utf8_table utf8_table
static
Initial value:
= {
.utf8_to_local = utf8_to_local,
.local_to_utf8 = utf8_from_local,
}
static nserror utf8_from_local(const char *string, size_t len, char **result)
static nserror utf8_to_local(const char *string, size_t len, char **result)

Definition at line 489 of file font_internal.c.