NetSurf
Macros | Functions | Variables
font.c File Reference

Windows font handling and character encoding implementation. More...

#include "utils/config.h"
#include <assert.h>
#include <windows.h>
#include "netsurf/inttypes.h"
#include "utils/log.h"
#include "utils/nsoption.h"
#include "utils/utf8.h"
#include "netsurf/layout.h"
#include "netsurf/utf8.h"
#include "netsurf/plot_style.h"
#include "windows/font.h"
Include dependency graph for font.c:

Go to the source code of this file.

Macros

#define WSTRLEN   4096
 

Functions

nserror utf8_to_font_encoding (const struct font_desc *font, const char *string, size_t len, char **result)
 convert from utf-8 to win32 font encoding. More...
 
static nserror utf8_to_local_encoding (const char *string, size_t len, char **result)
 Convert a string to UCS2 from UTF8. More...
 
static nserror utf8_from_local_encoding (const char *string, size_t len, char **result)
 Convert a string to UTF8 from local encoding. More...
 
HFONT get_font (const plot_font_style_t *style)
 
static nserror win32_font_width (const plot_font_style_t *style, const char *utf8str, size_t utf8len, int *width)
 Measure the width of a string. More...
 
static nserror win32_font_position (const plot_font_style_t *style, const char *utf8str, size_t utf8len, int x, size_t *char_offset, int *actual_x)
 Find the position in a string where an x coordinate falls. More...
 
static nserror win32_font_split (const plot_font_style_t *style, const char *string, size_t length, int x, size_t *offset, int *actual_x)
 Find where to split a string to make it fit a width. More...
 

Variables

HWND font_hwnd
 
static struct gui_layout_table layout_table
 win32 font operations table More...
 
struct gui_layout_tablewin32_layout_table = &layout_table
 
static struct gui_utf8_table utf8_table
 win32 utf8 encoding operations table More...
 
struct gui_utf8_tablewin32_utf8_table = &utf8_table
 

Detailed Description

Windows font handling and character encoding implementation.

Definition in file font.c.

Macro Definition Documentation

◆ WSTRLEN

#define WSTRLEN   4096

Definition at line 169 of file font.c.

Function Documentation

◆ get_font()

HFONT get_font ( const plot_font_style_t style)

Definition at line 92 of file font.c.

References plot_font_style::family, plot_font_style::flags, font_hwnd, FONTF_ITALIC, 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 text(), win32_font_position(), and win32_font_width().

Here is the caller graph for this function:

◆ utf8_from_local_encoding()

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

Convert a string to UTF8 from local encoding.

Parameters
[in]stringsource string
[in]lensource string length
[out]resultThe UTF8 string

Definition at line 74 of file font.c.

References NSERROR_NOMEM, NSERROR_OK, result, and strndup().

Here is the call graph for this function:

◆ utf8_to_font_encoding()

nserror utf8_to_font_encoding ( const struct font_desc font,
const char *  string,
size_t  len,
char **  result 
)

convert from utf-8 to win32 font encoding.

Parameters
[in]fontfont descriptor
[in]stringsource utf-8 string
[in]lenThe length of the utf-8 data
[out]resultThe reencoded string.

Definition at line 43 of file font.c.

References font_desc::encoding, result, and utf8_to_enc().

Here is the call graph for this function:

◆ utf8_to_local_encoding()

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

Convert a string to UCS2 from UTF8.

Parameters
[in]stringsource string
[in]lensource string length
[out]resultThe UCS2 string

Definition at line 60 of file font.c.

References result, and utf8_to_enc().

Here is the call graph for this function:

◆ win32_font_position()

static nserror win32_font_position ( const plot_font_style_t style,
const char *  utf8str,
size_t  utf8len,
int  x,
size_t *  char_offset,
int *  actual_x 
)
static

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

Parameters
stylecss_style for this text, with style->font_size.size == CSS_FONT_SIZE_LENGTH
utf8strstring to measure encoded in UTF-8
utf8lenlength of string
xcoordinate 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
NSERROR_OK on success otherwise appropriate error code

Definition at line 238 of file font.c.

References get_font(), NSERROR_OK, and NSERROR_UNKNOWN.

Referenced by win32_font_split().

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

◆ win32_font_split()

static nserror win32_font_split ( const plot_font_style_t style,
const char *  string,
size_t  length,
int  x,
size_t *  offset,
int *  actual_x 
)
static

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

Parameters
stylecss_style for this text, with style->font_size.size == CSS_FONT_SIZE_LENGTH
stringUTF-8 string to measure
lengthlength of string
xwidth available
[out]offsetupdated to offset in string of actual_x, [0..length]
actual_xupdated to x coordinate of character closest to x
Returns
NSERROR_OK on success otherwise appropriate error code

On exit, [char_offset == 0 || string[char_offset] == ' ' || char_offset == length]

Definition at line 296 of file font.c.

References NSERROR_OK, NSLOG, win32_font_position(), and win32_font_width().

Here is the call graph for this function:

◆ win32_font_width()

static nserror win32_font_width ( const plot_font_style_t style,
const char *  utf8str,
size_t  utf8len,
int *  width 
)
static

Measure the width of a string.

Parameters
[in]styleplot style for this text
[in]utf8strstring encoded in UTF-8 to measure
[in]utf8lenlength of string, in bytes
[out]widthupdated to width of string[0..length)
Returns
NSERROR_OK on success otherwise appropriate error code

Definition at line 182 of file font.c.

References get_font(), NSERROR_INVALID, NSERROR_NOSPACE, NSERROR_OK, width, and WSTRLEN.

Referenced by win32_font_split().

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

Variable Documentation

◆ font_hwnd

HWND font_hwnd

Definition at line 39 of file font.c.

Referenced by get_font(), and win32_window_create().

◆ layout_table

struct gui_layout_table layout_table
static
Initial value:
= {
.width = win32_font_width,
.position = win32_font_position,
.split = win32_font_split,
}
static nserror win32_font_width(const plot_font_style_t *style, const char *utf8str, size_t utf8len, int *width)
Measure the width of a string.
Definition: font.c:182
static nserror win32_font_position(const plot_font_style_t *style, const char *utf8str, size_t utf8len, int x, size_t *char_offset, int *actual_x)
Find the position in a string where an x coordinate falls.
Definition: font.c:238
static nserror win32_font_split(const plot_font_style_t *style, const char *string, size_t length, int x, size_t *offset, int *actual_x)
Find where to split a string to make it fit a width.
Definition: font.c:296

win32 font operations table

Definition at line 346 of file font.c.

◆ utf8_table

struct gui_utf8_table utf8_table
static
Initial value:
= {
.utf8_to_local = utf8_to_local_encoding,
.local_to_utf8 = utf8_from_local_encoding,
}
static nserror utf8_from_local_encoding(const char *string, size_t len, char **result)
Convert a string to UTF8 from local encoding.
Definition: font.c:74
static nserror utf8_to_local_encoding(const char *string, size_t len, char **result)
Convert a string to UCS2 from UTF8.
Definition: font.c:60

win32 utf8 encoding operations table

Definition at line 355 of file font.c.

◆ win32_layout_table

struct gui_layout_table* win32_layout_table = &layout_table

Definition at line 352 of file font.c.

Referenced by WinMain().

◆ win32_utf8_table

struct gui_utf8_table* win32_utf8_table = &utf8_table

Definition at line 360 of file font.c.

Referenced by WinMain().