NetSurf
Functions | Variables
layout_pango.c File Reference

GTK implementation of layout handling using pango. More...

#include <assert.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include "utils/log.h"
#include "utils/nsoption.h"
#include "netsurf/inttypes.h"
#include "netsurf/layout.h"
#include "netsurf/plot_style.h"
#include "gtk/layout_pango.h"
#include "gtk/plotters.h"
Include dependency graph for layout_pango.c:

Go to the source code of this file.

Functions

static void nsfont_pango_check (void)
 
static nserror nsfont_width (const plot_font_style_t *fstyle, const char *string, size_t length, int *width)
 Measure the width of a string. More...
 
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...
 
nserror nsfont_paint (int x, int y, const char *string, size_t length, const plot_font_style_t *fstyle)
 Render a string. More...
 
PangoFontDescription * nsfont_style_to_description (const plot_font_style_t *fstyle)
 

Variables

static PangoContext * nsfont_pango_context = NULL
 
static PangoLayout * nsfont_pango_layout = NULL
 
static struct gui_layout_table layout_table
 
struct gui_layout_tablensgtk_layout_table = &layout_table
 

Detailed Description

GTK implementation of layout handling using pango.

Pango is used handle and render fonts.

Definition in file layout_pango.c.

Function Documentation

◆ nsfont_paint()

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

Render a string.

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

Definition at line 227 of file layout_pango.c.

References current_cr, plot_font_style::foreground, line(), NSERROR_OK, nsfont_pango_check(), nsfont_pango_layout, nsfont_style_to_description(), and nsgtk_set_colour().

Here is the call graph for this function:

◆ nsfont_pango_check()

static void nsfont_pango_check ( void  )
inlinestatic

Definition at line 43 of file layout_pango.c.

References nsfont_pango_context, nsfont_pango_layout, and NSLOG.

Referenced by nsfont_paint(), nsfont_position_in_string(), and nsfont_width().

Here is the caller graph for this function:

◆ 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
[in]fstylestyle for this text
[in]stringUTF-8 string to measure
[in]lengthlength of string, in bytes
[in]xcoordinate to search for
[out]char_offsetupdated to offset in string of actual_x, [0..length]
[out]actual_xupdated to x coordinate of character closest to x
Returns
NSERROR_OK and char_offset and actual_x updated or appropriate error code on faliure

Definition at line 110 of file layout_pango.c.

References NSERROR_OK, nsfont_pango_check(), nsfont_pango_layout, and nsfont_style_to_description().

Here is the call graph for this function:

◆ 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
[in]fstylestyle for this text
[in]stringUTF-8 string to measure
[in]lengthlength of string, in bytes
[in]xwidth available
[out]char_offsetupdated to offset in string of actual_x, [1..length]
[out]actual_xupdated to x coordinate of character closest to x
Returns
NSERROR_OK or appropriate error code on faliure

On exit, char_offset indicates first character after split point.

Note
char_offset of 0 must 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 167 of file layout_pango.c.

References line(), NSERROR_OK, nsfont_style_to_description(), and nsfont_width().

Here is the call graph for this function:

◆ nsfont_style_to_description()

PangoFontDescription * nsfont_style_to_description ( const plot_font_style_t fstyle)

◆ nsfont_width()

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

Measure the width of a string.

Parameters
[in]fstyleplot style for this text
[in]stringUTF-8 string to measure
[in]lengthlength of string, in bytes
[out]widthupdated to width of string[0..length)
Returns
NSERROR_OK and width updated or appropriate error code on faliure

Definition at line 66 of file layout_pango.c.

References NSERROR_OK, nsfont_pango_check(), nsfont_pango_layout, nsfont_style_to_description(), NSLOG, PRIsizet, and width.

Referenced by nsfont_split().

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 = 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_pango.c:110
static nserror nsfont_width(const plot_font_style_t *fstyle, const char *string, size_t length, int *width)
Measure the width of a string.
Definition: layout_pango.c:66
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_pango.c:167

Definition at line 303 of file layout_pango.c.

◆ nsfont_pango_context

PangoContext* nsfont_pango_context = NULL
static

Definition at line 40 of file layout_pango.c.

Referenced by nsfont_pango_check().

◆ nsfont_pango_layout

PangoLayout* nsfont_pango_layout = NULL
static

◆ nsgtk_layout_table

struct gui_layout_table* nsgtk_layout_table = &layout_table

Definition at line 309 of file layout_pango.c.

Referenced by gtk_print_signal_begin_print(), main(), and print_button_clicked_cb().