diff --git a/gtk/Makefile.target b/gtk/Makefile.target index bade14dc0..e450135b2 100644 --- a/gtk/Makefile.target +++ b/gtk/Makefile.target @@ -176,10 +176,10 @@ endif # ---------------------------------------------------------------------------- # 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 \ 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 \ compat.c cookies.c hotlist.c viewdata.c viewsource.c \ preferences.c about.c ssl_cert.c resources.c diff --git a/gtk/gui.c b/gtk/gui.c index 4263868a5..5578f63cb 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -1,6 +1,6 @@ /* * Copyright 2004-2010 James Bursa - * Copyright 2010 Vincent Sanders + * Copyright 2010-2016 Vincent Sanders * Copyright 2004-2009 John-Mark Bell * Copyright 2009 Paul Blokus * Copyright 2006-2009 Daniel Silverstone @@ -69,6 +69,7 @@ #include "gtk/bitmap.h" #include "gtk/resources.h" #include "gtk/login.h" +#include "gtk/layout_pango.h" bool nsgtk_complete = false; @@ -1058,6 +1059,7 @@ int main(int argc, char** argv) .search = nsgtk_search_table, .search_web = nsgtk_search_web_table, .bitmap = nsgtk_bitmap_table, + .layout = nsgtk_layout_table, }; ret = netsurf_register(&nsgtk_table); diff --git a/gtk/font_pango.c b/gtk/layout_pango.c similarity index 71% rename from gtk/font_pango.c rename to gtk/layout_pango.c index b28d8836f..f3f0e0755 100644 --- a/gtk/font_pango.c +++ b/gtk/layout_pango.c @@ -16,8 +16,9 @@ * along with this program. If not, see . */ -/** \file - * Font handling (GTK implementation). +/** + * \file + * GTK implementation of layout handling using pango. * * Pango is used handle and render fonts. */ @@ -30,29 +31,11 @@ #include "utils/utils.h" #include "utils/log.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" -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 PangoLayout *nsfont_pango_layout = NULL; @@ -72,22 +55,23 @@ static inline void nsfont_pango_check(void) /** * Measure the width of a string. * - * \param fstyle plot style for this text - * \param string UTF-8 string to measure - * \param length length of string - * \param width updated to width of string[0..length) - * \return true on success, false on error and error reported + * \param[in] fstyle plot style for this text + * \param[in] string UTF-8 string to measure + * \param[in] length length of string, in bytes + * \param[out] width updated to width of string[0..length) + * \return NSERROR_OK and width updated or appropriate error code on faliure */ - -bool nsfont_width(const plot_font_style_t *fstyle, - const char *string, size_t length, - int *width) +static nserror +nsfont_width(const plot_font_style_t *fstyle, + const char *string, + size_t length, + int *width) { PangoFontDescription *desc; if (length == 0) { *width = 0; - return true; + return NSERROR_OK; } nsfont_pango_check(); @@ -104,25 +88,29 @@ bool nsfont_width(const plot_font_style_t *fstyle, fstyle, length, string, length, *width); */ - return true; + return NSERROR_OK; } /** * Find the position in a string where an x coordinate falls. * - * \param fstyle plot style for this text - * \param string UTF-8 string to measure - * \param length length of string - * \param x x coordinate to search for - * \param char_offset updated to offset in string of actual_x, [0..length] - * \param actual_x updated to x coordinate of character closest to x - * \return true on success, false on error and error reported + * \param[in] fstyle style for this text + * \param[in] string UTF-8 string to measure + * \param[in] length length of string, in bytes + * \param[in] x coordinate to search for + * \param[out] char_offset updated to offset in string of actual_x, [0..length] + * \param[out] actual_x updated to x coordinate of character closest to x + * \return NSERROR_OK and char_offset and actual_x updated or appropriate + * error code on faliure */ - -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 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) { int index; 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); - if (pango_layout_xy_to_index(nsfont_pango_layout, x * PANGO_SCALE, - 0, &index, 0) == FALSE) + if (pango_layout_xy_to_index(nsfont_pango_layout, + x * PANGO_SCALE, + 0, &index, 0) == FALSE) { index = length; + } pango_layout_index_to_pos(nsfont_pango_layout, index, &pos); *char_offset = index; *actual_x = PANGO_PIXELS(pos.x); - return true; + return NSERROR_OK; } /** * Find where to split a string to make it fit a width. * - * \param fstyle style for this text - * \param string UTF-8 string to measure - * \param length length of string, in bytes - * \param x width available - * \param char_offset updated to offset in string of actual_x, [1..length] - * \param actual_x updated to x coordinate of character closest to x - * \return true on success, false on error and error reported + * \param[in] fstyle style for this text + * \param[in] string UTF-8 string to measure + * \param[in] length length of string, in bytes + * \param[in] x width available + * \param[out] char_offset updated to offset in string of actual_x, [1..length] + * \param[out] actual_x updated to x coordinate of character closest to x + * \return NSERROR_OK or appropriate error code on faliure * * 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: * 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 */ - -bool nsfont_split(const plot_font_style_t *fstyle, - const char *string, size_t length, - int x, size_t *char_offset, int *actual_x) +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) { int index = length; PangoFontDescription *desc; @@ -215,7 +208,7 @@ bool nsfont_split(const plot_font_style_t *fstyle, /* Obtain the pixel offset of the split character */ 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 * \return true on success, false on error and error reported */ - bool nsfont_paint(int x, int y, const char *string, size_t length, const plot_font_style_t *fstyle) { @@ -259,15 +251,9 @@ bool nsfont_paint(int x, int y, const char *string, size_t length, } -/** - * 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 plot_font_style_t *fstyle) +/* exported interface documented in gtk/layout_pango.h */ +PangoFontDescription * +nsfont_style_to_description(const plot_font_style_t *fstyle) { unsigned int size; PangoFontDescription *desc; @@ -315,3 +301,10 @@ PangoFontDescription *nsfont_style_to_description( 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; diff --git a/gtk/font_pango.h b/gtk/layout_pango.h similarity index 62% rename from gtk/font_pango.h rename to gtk/layout_pango.h index edcd19b47..137cebe68 100644 --- a/gtk/font_pango.h +++ b/gtk/layout_pango.h @@ -16,22 +16,28 @@ * along with this program. If not, see . */ -/** \file - * Font handling (GTK interface). +/** + * \file + * Interface to GTK layout handling using pango. */ -#ifndef _NETSURF_GTK_FONT_PANGO_H_ -#define _NETSURF_GTK_FONT_PANGO_H_ +#ifndef _NETSURF_GTK_LAYOUT_PANGO_H_ +#define _NETSURF_GTK_LAYOUT_PANGO_H_ #include -#include "desktop/plot_style.h" +struct plot_font_style; -bool nsfont_paint(int x, int y, const char *string, size_t length, - const plot_font_style_t *fstyle); +extern struct gui_layout_table *nsgtk_layout_table; + +bool nsfont_paint(int x, int y, const char *string, size_t length, const struct plot_font_style *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); -PangoFontDescription *nsfont_style_to_description( - const plot_font_style_t *fstyle); - - #endif diff --git a/gtk/plotters.c b/gtk/plotters.c index 33f4c65fe..1d8c19827 100644 --- a/gtk/plotters.c +++ b/gtk/plotters.c @@ -17,13 +17,12 @@ * along with this program. If not, see . */ -/** \file - * Target independent plotting (GDK / GTK+ and Cairo implementation). - * Can use either GDK drawing primitives (which are mostly passed straight - * to X to process, and thus accelerated) or Cairo drawing primitives (much - * higher quality, not accelerated). Cairo's fast enough, so it defaults - * to using it if it is available. It does this by checking for the - * CAIRO_VERSION define that the cairo headers set. +/** + * \file + * GTK and Cairo plotter implementations. + * + * Uses Cairo drawing primitives to render browser output. + * \todo remove the use of the gdk structure for clipping */ #include @@ -36,7 +35,7 @@ #include "desktop/plotters.h" #include "utils/nsoption.h" -#include "gtk/font_pango.h" +#include "gtk/layout_pango.h" #include "gtk/plotters.h" #include "gtk/scaffolding.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, - const plot_font_style_t *fstyle) + const struct plot_font_style *fstyle) { return nsfont_paint(x, y, text, length, fstyle); } diff --git a/gtk/print.c b/gtk/print.c index e5e9e847f..a6e639996 100644 --- a/gtk/print.c +++ b/gtk/print.c @@ -39,9 +39,8 @@ #include "desktop/plotters.h" #include "desktop/print.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/print.h" #include "gtk/scaffolding.h" @@ -562,8 +561,8 @@ void gtk_print_signal_begin_print (GtkPrintOperation *operation, settings->margins[MARGINRIGHT] = 0; settings->page_width = gtk_print_context_get_width(context); settings->page_height = gtk_print_context_get_height(context); - settings->scale = 0.7;/*at 0.7 the pages look the best*/ - settings->font_func = &nsfont; + settings->scale = 0.7; /* at 0.7 the pages look the best */ + settings->font_func = nsgtk_layout_table; if (print_set_up(content_to_print, >k_printer, settings, &height_to_print) == false) { diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c index 82b58fcb1..0ba768460 100644 --- a/gtk/scaffolding.c +++ b/gtk/scaffolding.c @@ -46,7 +46,6 @@ #include "desktop/save_text.h" #include "desktop/searchweb.h" #include "desktop/textinput.h" -#include "desktop/font.h" #include "content/hlcache.h" #include "gtk/compat.h" @@ -73,6 +72,7 @@ #include "gtk/schedule.h" #include "gtk/viewdata.h" #include "gtk/resources.h" +#include "gtk/layout_pango.h" /** Macro to define a handler for menu, button and activate events. */ #define MULTIHANDLER(q)\ @@ -874,7 +874,7 @@ MULTIHANDLER(print) } 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_CALLBACK(gtk_print_signal_begin_print), nssettings);