NetSurf
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
font_freetype.c File Reference
#include <assert.h>
#include <ft2build.h>
#include "netsurf/inttypes.h"
#include "utils/filepath.h"
#include "utils/utf8.h"
#include "utils/log.h"
#include "utils/nsoption.h"
#include "netsurf/utf8.h"
#include "netsurf/layout.h"
#include "netsurf/browser.h"
#include "netsurf/plot_style.h"
#include "framebuffer/gui.h"
#include "framebuffer/font.h"
#include "framebuffer/findfile.h"
Include dependency graph for font_freetype.c:

Go to the source code of this file.

Data Structures

struct  fb_faceid_s
 

Macros

#define CACHE_MIN_SIZE   (100 * 1024)
 
#define BOLD_WEIGHT   700
 
#define FB_FACE_DEFAULT   0
 

Typedefs

typedef struct fb_faceid_s fb_faceid_t
 

Enumerations

enum  fb_face_e {
  FB_FACE_SANS_SERIF = 0 , FB_FACE_SANS_SERIF_BOLD , FB_FACE_SANS_SERIF_ITALIC , FB_FACE_SANS_SERIF_ITALIC_BOLD ,
  FB_FACE_SERIF , FB_FACE_SERIF_BOLD , FB_FACE_MONOSPACE , FB_FACE_MONOSPACE_BOLD ,
  FB_FACE_CURSIVE , FB_FACE_FANTASY , FB_FACE_COUNT
}
 

Functions

static FT_Error ft_face_requester (FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *face)
 map cache manager handle to face id More...
 
static fb_faceid_tfb_new_face (const char *option, const char *resname, const char *fontname)
 create new framebuffer face and cause it to be loaded to check its ok More...
 
bool fb_font_init (void)
 Initialise framebuffer font handling. More...
 
bool fb_font_finalise (void)
 Finalise framebuffer font handling. More...
 
static void fb_fill_scalar (const plot_font_style_t *fstyle, FTC_Scaler srec)
 fill freetype scalar More...
 
FT_Glyph fb_getglyph (const plot_font_style_t *fstyle, uint32_t ucs4)
 
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

static FT_Library library
 
static FTC_Manager ft_cmanager
 
static FTC_CMapCache ft_cmap_cache
 
static FTC_ImageCache ft_image_cache
 
int ft_load_type
 
static fb_faceid_tfb_faces [FB_FACE_COUNT]
 
static struct gui_layout_table layout_table
 
struct gui_layout_tableframebuffer_layout_table = &layout_table
 
struct gui_utf8_tableframebuffer_utf8_table = NULL
 

Macro Definition Documentation

◆ BOLD_WEIGHT

#define BOLD_WEIGHT   700

Definition at line 42 of file font_freetype.c.

◆ CACHE_MIN_SIZE

#define CACHE_MIN_SIZE   (100 * 1024)

Definition at line 40 of file font_freetype.c.

◆ FB_FACE_DEFAULT

#define FB_FACE_DEFAULT   0

Definition at line 74 of file font_freetype.c.

Typedef Documentation

◆ fb_faceid_t

typedef struct fb_faceid_s fb_faceid_t

Enumeration Type Documentation

◆ fb_face_e

enum fb_face_e
Enumerator
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_FACE_MONOSPACE 
FB_FACE_MONOSPACE_BOLD 
FB_FACE_CURSIVE 
FB_FACE_FANTASY 
FB_FACE_COUNT 

Definition at line 59 of file font_freetype.c.

Function Documentation

◆ fb_fill_scalar()

static void fb_fill_scalar ( const plot_font_style_t fstyle,
FTC_Scaler  srec 
)
static

fill freetype scalar

Definition at line 345 of file font_freetype.c.

References BOLD_WEIGHT, browser_get_dpi(), plot_font_style::family, FB_FACE_CURSIVE, FB_FACE_DEFAULT, 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, plot_font_style::flags, FONTF_ITALIC, FONTF_OBLIQUE, 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 fb_getglyph().

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

◆ fb_font_finalise()

bool fb_font_finalise ( void  )

Finalise framebuffer font handling.

Definition at line 316 of file font_freetype.c.

◆ fb_font_init()

bool fb_font_init ( void  )

Initialise framebuffer font handling.

Definition at line 147 of file font_freetype.c.

◆ 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 459 of file font_freetype.c.

References fb_getglyph(), NSERROR_OK, utf8_next(), and utf8_to_ucs4().

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 516 of file font_freetype.c.

References fb_getglyph(), NSERROR_OK, utf8_next(), and utf8_to_ucs4().

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 434 of file font_freetype.c.

References fb_getglyph(), NSERROR_OK, utf8_next(), utf8_to_ucs4(), and width.

Here is the call graph for this function:

◆ fb_getglyph()

FT_Glyph fb_getglyph ( const plot_font_style_t fstyle,
uint32_t  ucs4 
)

Definition at line 402 of file font_freetype.c.

References fb_faceid_s::cidx, fb_fill_scalar(), ft_cmap_cache, ft_image_cache, and ft_load_type.

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

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

◆ fb_new_face()

static fb_faceid_t * fb_new_face ( const char *  option,
const char *  resname,
const char *  fontname 
)
static

create new framebuffer face and cause it to be loaded to check its ok

Definition at line 118 of file font_freetype.c.

References filepath_sfind(), fb_faceid_s::fontfile, ft_cmanager, NSLOG, PATH_MAX, and respaths.

Referenced by fb_font_init().

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

◆ ft_face_requester()

static FT_Error ft_face_requester ( FTC_FaceID  face_id,
FT_Library  library,
FT_Pointer  request_data,
FT_Face *  face 
)
static

map cache manager handle to face id

Definition at line 82 of file font_freetype.c.

References fb_faceid_s::cidx, fb_faceid_s::fontfile, fb_faceid_s::index, library, and NSLOG.

Referenced by fb_font_init().

Here is the caller graph for this function:

Variable Documentation

◆ fb_faces

fb_faceid_t* fb_faces[FB_FACE_COUNT]
static

Definition at line 76 of file font_freetype.c.

Referenced by fb_fill_scalar(), fb_font_finalise(), and fb_font_init().

◆ framebuffer_layout_table

struct gui_layout_table* framebuffer_layout_table = &layout_table

Definition at line 562 of file font_freetype.c.

◆ framebuffer_utf8_table

struct gui_utf8_table* framebuffer_utf8_table = NULL

Definition at line 565 of file font_freetype.c.

◆ ft_cmanager

FTC_Manager ft_cmanager
static

Definition at line 45 of file font_freetype.c.

Referenced by fb_font_finalise(), fb_font_init(), and fb_new_face().

◆ ft_cmap_cache

FTC_CMapCache ft_cmap_cache
static

Definition at line 46 of file font_freetype.c.

Referenced by fb_font_init(), and fb_getglyph().

◆ ft_image_cache

FTC_ImageCache ft_image_cache
static

Definition at line 47 of file font_freetype.c.

Referenced by fb_font_init(), and fb_getglyph().

◆ ft_load_type

int ft_load_type

Definition at line 49 of file font_freetype.c.

Referenced by fb_font_init(), and fb_getglyph().

◆ 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 556 of file font_freetype.c.

◆ library

FT_Library library
static

Definition at line 44 of file font_freetype.c.

Referenced by fb_font_finalise(), fb_font_init(), and ft_face_requester().