mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-19 02:32:44 +03:00
Update gtk frontend to use layout table
This commit is contained in:
parent
974a4a21e1
commit
922faa743b
@ -176,7 +176,7 @@ endif
|
|||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
# S_GTK are sources purely for the GTK build
|
# S_GTK are sources purely for the GTK build
|
||||||
S_GTK := font_pango.c bitmap.c gui.c schedule.c plotters.c \
|
S_GTK := gui.c schedule.c layout_pango.c bitmap.c plotters.c \
|
||||||
treeview.c scaffolding.c gdk.c completion.c login.c throbber.c \
|
treeview.c scaffolding.c gdk.c completion.c login.c throbber.c \
|
||||||
selection.c history.c window.c fetch.c download.c menu.c \
|
selection.c history.c window.c fetch.c download.c menu.c \
|
||||||
print.c search.c tabs.c toolbar.c gettext.c \
|
print.c search.c tabs.c toolbar.c gettext.c \
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2010 James Bursa <bursa@users.sourceforge.net>
|
* Copyright 2004-2010 James Bursa <bursa@users.sourceforge.net>
|
||||||
* Copyright 2010 Vincent Sanders <vince@debian.org>
|
* Copyright 2010-2016 Vincent Sanders <vince@netsurf-browser.org>
|
||||||
* Copyright 2004-2009 John-Mark Bell <jmb@netsurf-browser.org>
|
* Copyright 2004-2009 John-Mark Bell <jmb@netsurf-browser.org>
|
||||||
* Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
|
* Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
|
||||||
* Copyright 2006-2009 Daniel Silverstone <dsilvers@netsurf-browser.org>
|
* Copyright 2006-2009 Daniel Silverstone <dsilvers@netsurf-browser.org>
|
||||||
@ -69,6 +69,7 @@
|
|||||||
#include "gtk/bitmap.h"
|
#include "gtk/bitmap.h"
|
||||||
#include "gtk/resources.h"
|
#include "gtk/resources.h"
|
||||||
#include "gtk/login.h"
|
#include "gtk/login.h"
|
||||||
|
#include "gtk/layout_pango.h"
|
||||||
|
|
||||||
bool nsgtk_complete = false;
|
bool nsgtk_complete = false;
|
||||||
|
|
||||||
@ -1058,6 +1059,7 @@ int main(int argc, char** argv)
|
|||||||
.search = nsgtk_search_table,
|
.search = nsgtk_search_table,
|
||||||
.search_web = nsgtk_search_web_table,
|
.search_web = nsgtk_search_web_table,
|
||||||
.bitmap = nsgtk_bitmap_table,
|
.bitmap = nsgtk_bitmap_table,
|
||||||
|
.layout = nsgtk_layout_table,
|
||||||
};
|
};
|
||||||
|
|
||||||
ret = netsurf_register(&nsgtk_table);
|
ret = netsurf_register(&nsgtk_table);
|
||||||
|
@ -16,8 +16,9 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file
|
/**
|
||||||
* Font handling (GTK implementation).
|
* \file
|
||||||
|
* GTK implementation of layout handling using pango.
|
||||||
*
|
*
|
||||||
* Pango is used handle and render fonts.
|
* Pango is used handle and render fonts.
|
||||||
*/
|
*/
|
||||||
@ -30,29 +31,11 @@
|
|||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
#include "utils/log.h"
|
#include "utils/log.h"
|
||||||
#include "utils/nsoption.h"
|
#include "utils/nsoption.h"
|
||||||
#include "desktop/font.h"
|
#include "desktop/gui_layout.h"
|
||||||
|
|
||||||
#include "gtk/font_pango.h"
|
#include "gtk/layout_pango.h"
|
||||||
#include "gtk/plotters.h"
|
#include "gtk/plotters.h"
|
||||||
|
|
||||||
static bool nsfont_width(const plot_font_style_t *fstyle,
|
|
||||||
const char *string, size_t length,
|
|
||||||
int *width);
|
|
||||||
|
|
||||||
static bool 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 bool nsfont_split(const plot_font_style_t *style,
|
|
||||||
const char *string, size_t length,
|
|
||||||
int x, size_t *char_offset, int *actual_x);
|
|
||||||
|
|
||||||
const struct font_functions nsfont = {
|
|
||||||
nsfont_width,
|
|
||||||
nsfont_position_in_string,
|
|
||||||
nsfont_split
|
|
||||||
};
|
|
||||||
|
|
||||||
static PangoContext *nsfont_pango_context = NULL;
|
static PangoContext *nsfont_pango_context = NULL;
|
||||||
static PangoLayout *nsfont_pango_layout = NULL;
|
static PangoLayout *nsfont_pango_layout = NULL;
|
||||||
|
|
||||||
@ -72,22 +55,23 @@ static inline void nsfont_pango_check(void)
|
|||||||
/**
|
/**
|
||||||
* Measure the width of a string.
|
* Measure the width of a string.
|
||||||
*
|
*
|
||||||
* \param fstyle plot style for this text
|
* \param[in] fstyle plot style for this text
|
||||||
* \param string UTF-8 string to measure
|
* \param[in] string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param[in] length length of string, in bytes
|
||||||
* \param width updated to width of string[0..length)
|
* \param[out] width updated to width of string[0..length)
|
||||||
* \return true on success, false on error and error reported
|
* \return NSERROR_OK and width updated or appropriate error code on faliure
|
||||||
*/
|
*/
|
||||||
|
static nserror
|
||||||
bool nsfont_width(const plot_font_style_t *fstyle,
|
nsfont_width(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string,
|
||||||
|
size_t length,
|
||||||
int *width)
|
int *width)
|
||||||
{
|
{
|
||||||
PangoFontDescription *desc;
|
PangoFontDescription *desc;
|
||||||
|
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
*width = 0;
|
*width = 0;
|
||||||
return true;
|
return NSERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsfont_pango_check();
|
nsfont_pango_check();
|
||||||
@ -104,25 +88,29 @@ bool nsfont_width(const plot_font_style_t *fstyle,
|
|||||||
fstyle, length, string, length, *width);
|
fstyle, length, string, length, *width);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return true;
|
return NSERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the position in a string where an x coordinate falls.
|
* Find the position in a string where an x coordinate falls.
|
||||||
*
|
*
|
||||||
* \param fstyle plot style for this text
|
* \param[in] fstyle style for this text
|
||||||
* \param string UTF-8 string to measure
|
* \param[in] string UTF-8 string to measure
|
||||||
* \param length length of string
|
* \param[in] length length of string, in bytes
|
||||||
* \param x x coordinate to search for
|
* \param[in] x coordinate to search for
|
||||||
* \param char_offset updated to offset in string of actual_x, [0..length]
|
* \param[out] char_offset updated to offset in string of actual_x, [0..length]
|
||||||
* \param actual_x updated to x coordinate of character closest to x
|
* \param[out] actual_x updated to x coordinate of character closest to x
|
||||||
* \return true on success, false on error and error reported
|
* \return NSERROR_OK and char_offset and actual_x updated or appropriate
|
||||||
|
* error code on faliure
|
||||||
*/
|
*/
|
||||||
|
static nserror
|
||||||
bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
nsfont_position_in_string(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
size_t length,
|
||||||
|
int x,
|
||||||
|
size_t *char_offset,
|
||||||
|
int *actual_x)
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
PangoFontDescription *desc;
|
PangoFontDescription *desc;
|
||||||
@ -136,33 +124,35 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
|||||||
|
|
||||||
pango_layout_set_text(nsfont_pango_layout, string, length);
|
pango_layout_set_text(nsfont_pango_layout, string, length);
|
||||||
|
|
||||||
if (pango_layout_xy_to_index(nsfont_pango_layout, x * PANGO_SCALE,
|
if (pango_layout_xy_to_index(nsfont_pango_layout,
|
||||||
0, &index, 0) == FALSE)
|
x * PANGO_SCALE,
|
||||||
|
0, &index, 0) == FALSE) {
|
||||||
index = length;
|
index = length;
|
||||||
|
}
|
||||||
|
|
||||||
pango_layout_index_to_pos(nsfont_pango_layout, index, &pos);
|
pango_layout_index_to_pos(nsfont_pango_layout, index, &pos);
|
||||||
|
|
||||||
*char_offset = index;
|
*char_offset = index;
|
||||||
*actual_x = PANGO_PIXELS(pos.x);
|
*actual_x = PANGO_PIXELS(pos.x);
|
||||||
|
|
||||||
return true;
|
return NSERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find where to split a string to make it fit a width.
|
* Find where to split a string to make it fit a width.
|
||||||
*
|
*
|
||||||
* \param fstyle style for this text
|
* \param[in] fstyle style for this text
|
||||||
* \param string UTF-8 string to measure
|
* \param[in] string UTF-8 string to measure
|
||||||
* \param length length of string, in bytes
|
* \param[in] length length of string, in bytes
|
||||||
* \param x width available
|
* \param[in] x width available
|
||||||
* \param char_offset updated to offset in string of actual_x, [1..length]
|
* \param[out] char_offset updated to offset in string of actual_x, [1..length]
|
||||||
* \param actual_x updated to x coordinate of character closest to x
|
* \param[out] actual_x updated to x coordinate of character closest to x
|
||||||
* \return true on success, false on error and error reported
|
* \return NSERROR_OK or appropriate error code on faliure
|
||||||
*
|
*
|
||||||
* On exit, char_offset indicates first character after split point.
|
* On exit, char_offset indicates first character after split point.
|
||||||
*
|
*
|
||||||
* Note: char_offset of 0 should never be returned.
|
* \note char_offset of 0 must never be returned.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* char_offset giving split point closest to x, where actual_x <= x
|
* char_offset giving split point closest to x, where actual_x <= x
|
||||||
@ -171,10 +161,13 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle,
|
|||||||
*
|
*
|
||||||
* Returning char_offset == length means no split possible
|
* Returning char_offset == length means no split possible
|
||||||
*/
|
*/
|
||||||
|
static nserror
|
||||||
bool nsfont_split(const plot_font_style_t *fstyle,
|
nsfont_split(const plot_font_style_t *fstyle,
|
||||||
const char *string, size_t length,
|
const char *string,
|
||||||
int x, size_t *char_offset, int *actual_x)
|
size_t length,
|
||||||
|
int x,
|
||||||
|
size_t *char_offset,
|
||||||
|
int *actual_x)
|
||||||
{
|
{
|
||||||
int index = length;
|
int index = length;
|
||||||
PangoFontDescription *desc;
|
PangoFontDescription *desc;
|
||||||
@ -215,7 +208,7 @@ bool nsfont_split(const plot_font_style_t *fstyle,
|
|||||||
/* Obtain the pixel offset of the split character */
|
/* Obtain the pixel offset of the split character */
|
||||||
nsfont_width(fstyle, string, index, actual_x);
|
nsfont_width(fstyle, string, index, actual_x);
|
||||||
|
|
||||||
return true;
|
return NSERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -229,7 +222,6 @@ bool nsfont_split(const plot_font_style_t *fstyle,
|
|||||||
* \param fstyle plot style for this text
|
* \param fstyle plot style for this text
|
||||||
* \return true on success, false on error and error reported
|
* \return true on success, false on error and error reported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool nsfont_paint(int x, int y, const char *string, size_t length,
|
bool nsfont_paint(int x, int y, const char *string, size_t length,
|
||||||
const plot_font_style_t *fstyle)
|
const plot_font_style_t *fstyle)
|
||||||
{
|
{
|
||||||
@ -259,15 +251,9 @@ bool nsfont_paint(int x, int y, const char *string, size_t length,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/* exported interface documented in gtk/layout_pango.h */
|
||||||
* Convert a plot style to a PangoFontDescription.
|
PangoFontDescription *
|
||||||
*
|
nsfont_style_to_description(const plot_font_style_t *fstyle)
|
||||||
* \param fstyle plot style for this text
|
|
||||||
* \return A new Pango font description
|
|
||||||
*/
|
|
||||||
|
|
||||||
PangoFontDescription *nsfont_style_to_description(
|
|
||||||
const plot_font_style_t *fstyle)
|
|
||||||
{
|
{
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
PangoFontDescription *desc;
|
PangoFontDescription *desc;
|
||||||
@ -315,3 +301,10 @@ PangoFontDescription *nsfont_style_to_description(
|
|||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct gui_layout_table layout_table = {
|
||||||
|
.width = nsfont_width,
|
||||||
|
.position = nsfont_position_in_string,
|
||||||
|
.split = nsfont_split,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gui_layout_table *nsgtk_layout_table = &layout_table;
|
@ -16,22 +16,28 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file
|
/**
|
||||||
* Font handling (GTK interface).
|
* \file
|
||||||
|
* Interface to GTK layout handling using pango.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _NETSURF_GTK_FONT_PANGO_H_
|
#ifndef _NETSURF_GTK_LAYOUT_PANGO_H_
|
||||||
#define _NETSURF_GTK_FONT_PANGO_H_
|
#define _NETSURF_GTK_LAYOUT_PANGO_H_
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "desktop/plot_style.h"
|
struct plot_font_style;
|
||||||
|
|
||||||
bool nsfont_paint(int x, int y, const char *string, size_t length,
|
extern struct gui_layout_table *nsgtk_layout_table;
|
||||||
const plot_font_style_t *fstyle);
|
|
||||||
|
|
||||||
PangoFontDescription *nsfont_style_to_description(
|
bool nsfont_paint(int x, int y, const char *string, size_t length, const struct plot_font_style *fstyle);
|
||||||
const plot_font_style_t *fstyle);
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a plot style to a PangoFontDescription.
|
||||||
|
*
|
||||||
|
* \param fstyle plot style for this text
|
||||||
|
* \return A new Pango font description
|
||||||
|
*/
|
||||||
|
PangoFontDescription *nsfont_style_to_description(const struct plot_font_style *fstyle);
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -17,13 +17,12 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file
|
/**
|
||||||
* Target independent plotting (GDK / GTK+ and Cairo implementation).
|
* \file
|
||||||
* Can use either GDK drawing primitives (which are mostly passed straight
|
* GTK and Cairo plotter implementations.
|
||||||
* to X to process, and thus accelerated) or Cairo drawing primitives (much
|
*
|
||||||
* higher quality, not accelerated). Cairo's fast enough, so it defaults
|
* Uses Cairo drawing primitives to render browser output.
|
||||||
* to using it if it is available. It does this by checking for the
|
* \todo remove the use of the gdk structure for clipping
|
||||||
* CAIRO_VERSION define that the cairo headers set.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@ -36,7 +35,7 @@
|
|||||||
#include "desktop/plotters.h"
|
#include "desktop/plotters.h"
|
||||||
#include "utils/nsoption.h"
|
#include "utils/nsoption.h"
|
||||||
|
|
||||||
#include "gtk/font_pango.h"
|
#include "gtk/layout_pango.h"
|
||||||
#include "gtk/plotters.h"
|
#include "gtk/plotters.h"
|
||||||
#include "gtk/scaffolding.h"
|
#include "gtk/scaffolding.h"
|
||||||
#include "gtk/bitmap.h"
|
#include "gtk/bitmap.h"
|
||||||
@ -272,7 +271,7 @@ static bool nsgtk_plot_polygon(const int *p, unsigned int n, const plot_style_t
|
|||||||
|
|
||||||
|
|
||||||
static bool nsgtk_plot_text(int x, int y, const char *text, size_t length,
|
static bool nsgtk_plot_text(int x, int y, const char *text, size_t length,
|
||||||
const plot_font_style_t *fstyle)
|
const struct plot_font_style *fstyle)
|
||||||
{
|
{
|
||||||
return nsfont_paint(x, y, text, length, fstyle);
|
return nsfont_paint(x, y, text, length, fstyle);
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,8 @@
|
|||||||
#include "desktop/plotters.h"
|
#include "desktop/plotters.h"
|
||||||
#include "desktop/print.h"
|
#include "desktop/print.h"
|
||||||
#include "desktop/printer.h"
|
#include "desktop/printer.h"
|
||||||
#include "desktop/font.h"
|
|
||||||
|
|
||||||
#include "gtk/font_pango.h"
|
#include "gtk/layout_pango.h"
|
||||||
#include "gtk/bitmap.h"
|
#include "gtk/bitmap.h"
|
||||||
#include "gtk/print.h"
|
#include "gtk/print.h"
|
||||||
#include "gtk/scaffolding.h"
|
#include "gtk/scaffolding.h"
|
||||||
@ -562,8 +561,8 @@ void gtk_print_signal_begin_print (GtkPrintOperation *operation,
|
|||||||
settings->margins[MARGINRIGHT] = 0;
|
settings->margins[MARGINRIGHT] = 0;
|
||||||
settings->page_width = gtk_print_context_get_width(context);
|
settings->page_width = gtk_print_context_get_width(context);
|
||||||
settings->page_height = gtk_print_context_get_height(context);
|
settings->page_height = gtk_print_context_get_height(context);
|
||||||
settings->scale = 0.7;/*at 0.7 the pages look the best*/
|
settings->scale = 0.7; /* at 0.7 the pages look the best */
|
||||||
settings->font_func = &nsfont;
|
settings->font_func = nsgtk_layout_table;
|
||||||
|
|
||||||
if (print_set_up(content_to_print, >k_printer,
|
if (print_set_up(content_to_print, >k_printer,
|
||||||
settings, &height_to_print) == false) {
|
settings, &height_to_print) == false) {
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
#include "desktop/save_text.h"
|
#include "desktop/save_text.h"
|
||||||
#include "desktop/searchweb.h"
|
#include "desktop/searchweb.h"
|
||||||
#include "desktop/textinput.h"
|
#include "desktop/textinput.h"
|
||||||
#include "desktop/font.h"
|
|
||||||
#include "content/hlcache.h"
|
#include "content/hlcache.h"
|
||||||
|
|
||||||
#include "gtk/compat.h"
|
#include "gtk/compat.h"
|
||||||
@ -73,6 +72,7 @@
|
|||||||
#include "gtk/schedule.h"
|
#include "gtk/schedule.h"
|
||||||
#include "gtk/viewdata.h"
|
#include "gtk/viewdata.h"
|
||||||
#include "gtk/resources.h"
|
#include "gtk/resources.h"
|
||||||
|
#include "gtk/layout_pango.h"
|
||||||
|
|
||||||
/** Macro to define a handler for menu, button and activate events. */
|
/** Macro to define a handler for menu, button and activate events. */
|
||||||
#define MULTIHANDLER(q)\
|
#define MULTIHANDLER(q)\
|
||||||
@ -874,7 +874,7 @@ MULTIHANDLER(print)
|
|||||||
}
|
}
|
||||||
gtk_print_operation_set_default_page_setup(print_op, page_setup);
|
gtk_print_operation_set_default_page_setup(print_op, page_setup);
|
||||||
|
|
||||||
nssettings = print_make_settings(PRINT_DEFAULT, NULL, &nsfont);
|
nssettings = print_make_settings(PRINT_DEFAULT, NULL, nsgtk_layout_table);
|
||||||
|
|
||||||
g_signal_connect(print_op, "begin_print",
|
g_signal_connect(print_op, "begin_print",
|
||||||
G_CALLBACK(gtk_print_signal_begin_print), nssettings);
|
G_CALLBACK(gtk_print_signal_begin_print), nssettings);
|
||||||
|
Loading…
Reference in New Issue
Block a user