split out the layout glyph sizing and splitting API

This refactors the core "font" sizing API to be handled through gui
 function tables similar to every other core/frontend calling API.
This commit is contained in:
Vincent Sanders 2016-04-23 23:32:21 +01:00
parent cdd53bcffb
commit 974a4a21e1
17 changed files with 4236 additions and 4144 deletions

View File

@ -108,7 +108,7 @@ struct content_user
/** Corresponds to a single URL. */
struct content {
llcache_handle *llcache; /**< Low-level cache object */
llcache_handle *llcache; /**< Low-level cache object */
lwc_string *mime_type; /**< Original MIME type of data */

View File

@ -37,11 +37,11 @@
#include "css/css.h"
#include "image/bitmap.h"
#include "desktop/gui_layout.h"
#include "desktop/gui_internal.h"
#include "desktop/browser_history.h"
#include "desktop/browser_private.h"
#include "desktop/plotters.h"
#include "desktop/font.h"
#define WIDTH 100
#define HEIGHT 86
@ -273,6 +273,7 @@ browser_window_history__redraw_entry(struct history *history,
.stroke_width = entry == history->current ? 3 : 1,
};
plot_font_style_t fstyle = *plot_style_font;
nserror res;
if (clip) {
struct rect rect;
@ -292,17 +293,21 @@ browser_window_history__redraw_entry(struct history *history,
WIDTH, HEIGHT,
entry->bitmap, 0xffffff, 0);
}
if (!plot->rectangle(entry->x - 1 + xoffset,
entry->y - 1 + yoffset,
entry->x + xoffset + WIDTH,
entry->y + yoffset + HEIGHT,
&pstyle_history_rect))
&pstyle_history_rect)) {
return false;
}
if (!nsfont.font_position_in_string(plot_style_font, entry->page.title,
strlen(entry->page.title), WIDTH,
&char_offset, &actual_x))
res = guit->layout->position(plot_style_font, entry->page.title,
strlen(entry->page.title), WIDTH,
&char_offset, &actual_x);
if (res != NSERROR_OK) {
return false;
}
fstyle.background = HISTORY_COLOUR_BACKGROUND;
fstyle.foreground = c;

View File

@ -37,6 +37,7 @@
#include "desktop/gui_search.h"
#include "desktop/gui_clipboard.h"
#include "desktop/gui_utf8.h"
#include "desktop/gui_layout.h"
#include "desktop/netsurf.h"
/**
@ -644,6 +645,35 @@ static nserror verify_bitmap_register(struct gui_bitmap_table *gbt)
return NSERROR_OK;
}
/**
* verify layout table is valid
*
* \param glt The layout table to verify.
* \return NSERROR_OK if the table is valid else NSERROR_BAD_PARAMETER.
*/
static nserror verify_layout_register(struct gui_layout_table *glt)
{
/* check table is present */
if (glt == NULL) {
return NSERROR_BAD_PARAMETER;
}
/* check the mandantory fields are set */
if (glt->width == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (glt->position == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (glt->split == NULL) {
return NSERROR_BAD_PARAMETER;
}
return NSERROR_OK;
}
static void gui_default_quit(void)
{
}
@ -725,6 +755,8 @@ nserror netsurf_register(struct netsurf_table *gt)
return NSERROR_BAD_PARAMETER;
}
/* mandantory tables */
/* miscellaneous table */
err = verify_misc_register(gt->misc);
if (err != NSERROR_OK) {
@ -749,6 +781,14 @@ nserror netsurf_register(struct netsurf_table *gt)
return err;
}
/* layout table */
err = verify_layout_register(gt->layout);
if (err != NSERROR_OK) {
return err;
}
/* optional tables */
/* file table */
if (gt->file == NULL) {
gt->file = default_file_table;

View File

@ -1,7 +1,5 @@
/*
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
* Copyright 2005 James Bursa <bursa@users.sourceforge.net>
* Copyright 2004 John Tytgat <joty@netsurf-browser.org>
* Copyright 2016 Vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@ -18,26 +16,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* Font handling interface.
/**
* \file
*
* These functions provide font related services. They all work on
* UTF-8 strings with lengths given.
* Interface to platform-specific layout operation table.
*
* Note that an interface to painting is not defined here. Painting is
* redirected through platform-dependent plotters anyway, so there is
* no gain in abstracting it here.
* This table is part of the layout used to measure glyphs before
* rendering, previously referred to as font functions.
*
* \note This is an old interface within the browser, it has been
* broken out purely to make the API obvious not as an indication this
* is the correct approach.
*/
#ifndef _NETSURF_DESKTOP_FONT_H_
#define _NETSURF_DESKTOP_FONT_H_
#ifndef _NETSURF_DESKTOP_GUI_LAYOUT_H_
#define _NETSURF_DESKTOP_GUI_LAYOUT_H_
#include <stdbool.h>
#include <stddef.h>
struct plot_font_style;
#include "desktop/plot_style.h"
struct font_functions
struct gui_layout_table
{
/**
* Measure the width of a string.
@ -46,11 +43,12 @@ struct font_functions
* \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 true on success and width updated else false.
* \return NSERROR_OK and width updated or appropriate error
* code on faliure
*/
bool (*font_width)(const plot_font_style_t *fstyle,
const char *string, size_t length,
int *width);
nserror (*width)(const struct plot_font_style *fstyle, const char *string, size_t length, int *width);
/**
* Find the position in a string where an x coordinate falls.
*
@ -60,25 +58,25 @@ struct font_functions
* \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 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
*/
bool (*font_position_in_string)(const plot_font_style_t *fstyle,
const char *string, size_t length,
int x, size_t *char_offset, int *actual_x);
nserror (*position)(const struct plot_font_style *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.
*
* \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
@ -87,11 +85,7 @@ struct font_functions
*
* Returning char_offset == length means no split possible
*/
bool (*font_split)(const plot_font_style_t *fstyle,
const char *string, size_t length,
int x, size_t *char_offset, int *actual_x);
nserror (*split)(const struct plot_font_style *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x);
};
extern const struct font_functions nsfont;
#endif

View File

@ -38,6 +38,7 @@ struct gui_search_table;
struct gui_search_web_table;
struct gui_llcache_table;
struct gui_bitmap_table;
struct gui_layout_table;
/**
* NetSurf operation function table
@ -49,8 +50,9 @@ struct netsurf_table {
/**
* Browser table.
*
* Provides miscellaneous browser functionality. The table
* is mandantory and must be provided.
* Provides miscellaneous browser functionality.
*
* The table is mandantory and must be provided.
*/
struct gui_misc_table *misc;
@ -58,6 +60,8 @@ struct netsurf_table {
* Window table.
*
* Provides all operations which affect a frontends display window.
*
* The table is mandantory and must be provided.
*/
struct gui_window_table *window;
@ -75,15 +79,18 @@ struct netsurf_table {
/**
* Fetcher table
*
* The table is mandantory and must be provided.
*/
struct gui_fetch_table *fetch;
/**
* File table
*
* Provides file and filename operations to the core. The
* table is optional and may be NULL in which case the default
* posix compliant operations will be used.
* Provides file and filename operations to the core.
*
* The table is optional and may be NULL in which case the
* default posix compliant operations will be used.
*/
struct gui_file_table *file;
@ -91,8 +98,10 @@ struct netsurf_table {
* UTF8 table.
*
* Provides for conversion between the gui local character
* encoding and utf8. The table optional and may be NULL which
* implies the local encoding is utf8.
* encoding and utf8.
*
* The table optional and may be NULL which implies the local
* encoding is utf8.
*/
struct gui_utf8_table *utf8;
@ -106,9 +115,10 @@ struct netsurf_table {
/**
* Web search table.
*
* Used by the web search provider system. The table is
* optional and may be NULL which uses the default empty
* implementation.
* Used by the web search provider system.
*
* The table is optional and may be NULL which uses the
* default empty implementation.
*/
struct gui_search_web_table *search_web;
@ -116,8 +126,10 @@ struct netsurf_table {
* Low level cache table.
*
* Used by the low level cache to push objects to persistant
* storage. The table is optional and may be NULL which
* uses the default implementation.
* storage.
*
* The table is optional and may be NULL which uses the
* default implementation.
*/
struct gui_llcache_table *llcache;
@ -125,10 +137,21 @@ struct netsurf_table {
* Bitmap table.
*
* Used by the image convertors as a generic interface to
* native platform-specific image formats. The table
* is mandantory and must be provided.
* native platform-specific image formats.
*
* The table is mandantory and must be provided.
*/
struct gui_bitmap_table *bitmap;
/**
* Layout table
*
* Used by the layout process to measure glyphs in a frontend
* specific manner.
*
* The table is mandantory and must be provided.
*/
struct gui_layout_table *layout;
};
#endif

View File

@ -150,7 +150,7 @@ typedef unsigned long plot_font_flags_t;
/**
* Font style for plotting
*/
typedef struct {
typedef struct plot_font_style {
plot_font_generic_family_t family; /**< Generic family to plot with */
int size; /**< Font size, in points * FONT_SIZE_SCALE */
int weight; /**< Font weight: value in range [100,900] as per CSS */

View File

@ -246,7 +246,7 @@ bool print_cleanup(hlcache_handle *content, const struct printer *printer,
* configuration or lack of memory.
*/
struct print_settings *print_make_settings(print_configuration configuration,
const char *filename, const struct font_functions *font_func)
const char *filename, const struct gui_layout_table *font_func)
{
struct print_settings *settings;
css_fixed length = 0;

View File

@ -38,6 +38,7 @@
struct hlcache_handle;
struct printer;
struct gui_layout_table;
enum { MARGINLEFT = 0, MARGINRIGHT = 1, MARGINTOP = 2, MARGINBOTTOM = 3};
@ -60,7 +61,7 @@ struct print_settings{
const char *output;
/*the functions used to measure fonts*/
const struct font_functions *font_func;
const struct gui_layout_table *font_func;
};
@ -73,8 +74,10 @@ bool print_draw_next_page(const struct printer *printer,
bool print_cleanup(struct hlcache_handle *, const struct printer *,
struct print_settings *settings);
struct print_settings *print_make_settings(print_configuration configuration,
const char *url, const struct font_functions *font_func);
/**
* Setup print settings for print render operation.
*/
struct print_settings *print_make_settings(print_configuration configuration, const char *url, const struct gui_layout_table *font_func);
/*is the content currently redrawn for printing?*/
extern bool html_redraw_printing;

View File

@ -37,8 +37,8 @@
#include "desktop/textinput.h"
#include "desktop/plotters.h"
#include "desktop/scrollbar.h"
#include "desktop/font.h"
#include "desktop/gui_clipboard.h"
#include "desktop/gui_layout.h"
#include "desktop/gui_internal.h"
#define CARET_COLOR 0x0000FF
@ -404,7 +404,7 @@ static bool textarea_set_caret_internal(struct textarea *ta, int caret_b)
/* find byte offset of caret position */
b_off = index;
nsfont.font_width(&ta->fstyle,
guit->layout->width(&ta->fstyle,
ta->show->data +
ta->lines[ta->caret_pos.line].b_start,
b_off - ta->lines[ta->caret_pos.line].b_start,
@ -873,12 +873,12 @@ static bool textarea_reflow_singleline(struct textarea *ta, size_t b_off,
}
/* Measure new width */
nsfont.font_width(&ta->fstyle, ta->show->data,
guit->layout->width(&ta->fstyle, ta->show->data,
ta->show->len - 1, &x);
/* Get width of retained text */
if (b_off != ta->lines[0].b_length) {
nsfont.font_width(&ta->fstyle, ta->show->data,
guit->layout->width(&ta->fstyle, ta->show->data,
b_off, &retained_width);
} else {
retained_width = ta->lines[0].width;
@ -1019,7 +1019,7 @@ static bool textarea_reflow_multiline(struct textarea *ta,
}
/* Wrap current line in paragraph */
nsfont.font_split(&ta->fstyle, text, para_end - text,
guit->layout->split(&ta->fstyle, text, para_end - text,
avail_width, &b_off, &x);
/* b_off now marks space, or end of paragraph */
@ -1201,7 +1201,7 @@ static bool textarea_reflow_multiline(struct textarea *ta,
ta->lines[start].b_start;
text = ta->text.data + ta->lines[start].b_start;
nsfont.font_width(&ta->fstyle, text,
guit->layout->width(&ta->fstyle, text,
retain_end, &retained_width);
r->x0 = max(r->x0,
@ -1252,7 +1252,7 @@ static size_t textarea_get_b_off_xy(struct textarea *ta, int x, int y,
line = 0;
/* Get byte position */
nsfont.font_position_in_string(&ta->fstyle,
guit->layout->position(&ta->fstyle,
ta->show->data + ta->lines[line].b_start,
ta->lines[line].b_length, x, &bpos, &x);
@ -2303,7 +2303,7 @@ void textarea_redraw(struct textarea *ta, int x, int y, colour bg, float scale,
/* find clip left/right for this part of line */
left = right;
if (b_len_part != b_len) {
nsfont.font_width(&fstyle, line_text, b_end,
guit->layout->width(&fstyle, line_text, b_end,
&right);
} else {
right = ta->lines[line].width;

View File

@ -32,8 +32,8 @@
#include "desktop/plotters.h"
#include "desktop/textarea.h"
#include "desktop/treeview.h"
#include "desktop/font.h"
#include "desktop/gui_clipboard.h"
#include "desktop/gui_layout.h"
#include "desktop/gui_internal.h"
/** @todo get rid of REDRAW_MAX -- need to be able to know window size */
@ -540,10 +540,10 @@ static inline void treeview_insert_node(treeview_node *a,
/* Parent is expanded, so inserted node will be visible and
* affect layout */
if (a->text.width == 0) {
nsfont.font_width(&plot_style_odd.text,
a->text.data,
a->text.len,
&(a->text.width));
guit->layout->width(&plot_style_odd.text,
a->text.data,
a->text.len,
&(a->text.width));
}
do {
@ -644,7 +644,7 @@ nserror treeview_update_node_folder(treeview *tree,
if (folder->parent->flags & TV_NFLAGS_EXPANDED) {
/* Text will be seen, get its width */
nsfont.font_width(&plot_style_odd.text,
guit->layout->width(&plot_style_odd.text,
folder->text.data,
folder->text.len,
&(folder->text.width));
@ -694,7 +694,7 @@ nserror treeview_update_node_entry(treeview *tree,
if (entry->parent->flags & TV_NFLAGS_EXPANDED) {
/* Text will be seen, get its width */
nsfont.font_width(&plot_style_odd.text,
guit->layout->width(&plot_style_odd.text,
entry->text.data,
entry->text.len,
&(entry->text.width));
@ -714,7 +714,7 @@ nserror treeview_update_node_entry(treeview *tree,
if (entry->flags & TV_NFLAGS_EXPANDED) {
/* Text will be seen, get its width */
nsfont.font_width(&plot_style_odd.text,
guit->layout->width(&plot_style_odd.text,
e->fields[i - 1].value.data,
e->fields[i - 1].value.len,
&(e->fields[i - 1].value.width));
@ -1311,7 +1311,7 @@ nserror treeview_create(treeview **tree,
f->value.data = lwc_string_data(fields[i].field);
f->value.len = lwc_string_length(fields[i].field);
nsfont.font_width(&plot_style_odd.text, f->value.data,
guit->layout->width(&plot_style_odd.text, f->value.data,
f->value.len, &(f->value.width));
if (f->flags & TREE_FLAG_SHOW_NAME)
@ -1411,7 +1411,7 @@ static nserror treeview_node_expand_internal(treeview *tree,
do {
assert((child->flags & TV_NFLAGS_EXPANDED) == false);
if (child->text.width == 0) {
nsfont.font_width(&plot_style_odd.text,
guit->layout->width(&plot_style_odd.text,
child->text.data,
child->text.len,
&(child->text.width));
@ -1432,7 +1432,7 @@ static nserror treeview_node_expand_internal(treeview *tree,
for (i = 0; i < tree->n_fields - 1; i++) {
if (e->fields[i].value.width == 0) {
nsfont.font_width(&plot_style_odd.text,
guit->layout->width(&plot_style_odd.text,
e->fields[i].value.data,
e->fields[i].value.len,
&(e->fields[i].value.width));

View File

@ -49,8 +49,8 @@
#include "image/bitmap.h"
#include "javascript/js.h"
#include "desktop/browser.h"
#include "desktop/font.h"
#include "desktop/gui_utf8.h"
#include "desktop/gui_layout.h"
#include "desktop/gui_internal.h"
#include "render/box.h"
@ -844,7 +844,7 @@ html_create_html_data(html_content *c, const http_parameter *params)
c->frameset = NULL;
c->iframe = NULL;
c->page = NULL;
c->font_func = &nsfont;
c->font_func = guit->layout;
c->drag_type = HTML_DRAG_NONE;
c->drag_owner.no_owner = true;
c->selection_type = HTML_SELECTION_NONE;

View File

@ -19,7 +19,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
/**
* \file
* User interaction with a CONTENT_HTML (implementation).
*/
@ -42,9 +43,9 @@
#include "desktop/selection.h"
#include "desktop/textarea.h"
#include "desktop/textinput.h"
#include "desktop/font.h"
#include "javascript/js.h"
#include "desktop/gui_misc.h"
#include "desktop/gui_layout.h"
#include "desktop/gui_internal.h"
#include "render/box.h"
@ -209,8 +210,8 @@ static size_t html_selection_drag_end(struct html_content *html,
font_plot_style_from_css(box->style, &fstyle);
nsfont.font_position_in_string(&fstyle, box->text, box->length,
dx, &idx, &pixel_offset);
guit->layout->position(&fstyle, box->text, box->length,
dx, &idx, &pixel_offset);
idx += box->byte_offset;
}
@ -416,9 +417,9 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
font_plot_style_from_css(box->style, &fstyle);
nsfont.font_position_in_string(&fstyle,
box->text, box->length,
dx, &idx, &pixel_offset);
guit->layout->position(&fstyle,
box->text, box->length,
dx, &idx, &pixel_offset);
selection_track(&html->sel, mouse,
box->byte_offset + idx);
@ -910,12 +911,12 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
font_plot_style_from_css(text_box->style,
&fstyle);
nsfont.font_position_in_string(&fstyle,
text_box->text,
text_box->length,
x - text_box_x,
&idx,
&pixel_offset);
guit->layout->position(&fstyle,
text_box->text,
text_box->length,
x - text_box_x,
&idx,
&pixel_offset);
if (selection_click(&html->sel, mouse,
text_box->byte_offset + idx)) {

View File

@ -27,6 +27,8 @@
#include "desktop/selection.h"
#include "render/html.h"
struct gui_layout_table;
typedef enum {
HTML_DRAG_NONE, /** No drag */
HTML_DRAG_SELECTION, /** Own; Text selection */
@ -36,6 +38,7 @@ typedef enum {
HTML_DRAG_CONTENT_SELECTION, /** Not own; drag in child content */
HTML_DRAG_CONTENT_SCROLL /** Not own; drag in child content */
} html_drag_type;
union html_drag_owner {
bool no_owner;
struct box *content;
@ -109,8 +112,9 @@ typedef struct html_content {
struct box *layout;
/** Document background colour. */
colour background_colour;
/** Font callback table */
const struct font_functions *font_func;
const struct gui_layout_table *font_func;
/** Number of entries in scripts */
unsigned int scripts_count;

View File

@ -49,8 +49,9 @@
#include "desktop/print.h"
#include "desktop/scrollbar.h"
#include "desktop/textarea.h"
#include "desktop/font.h"
#include "image/bitmap.h"
#include "desktop/gui_layout.h"
#include "desktop/gui_internal.h"
#include "render/box.h"
#include "render/font.h"
@ -194,6 +195,7 @@ bool text_redraw(const char *utf8_text, size_t utf8_len,
int startx, endx;
plot_style_t pstyle_fill_hback = *plot_style_fill_white;
plot_font_style_t fstyle_hback = plot_fstyle;
nserror res;
if (end_idx > utf8_len) {
/* adjust for trailing space, not present in
@ -202,13 +204,19 @@ bool text_redraw(const char *utf8_text, size_t utf8_len,
endtxt_idx = utf8_len;
}
if (!nsfont.font_width(fstyle, utf8_text, start_idx,
&startx))
res = guit->layout->width(fstyle,
utf8_text, start_idx,
&startx);
if (res != NSERROR_OK) {
startx = 0;
}
if (!nsfont.font_width(fstyle, utf8_text, endtxt_idx,
&endx))
res = guit->layout->width(fstyle,
utf8_text, endtxt_idx,
&endx);
if (res != NSERROR_OK) {
endx = 0;
}
/* is there a trailing space that should be highlighted
* as well? */
@ -1262,6 +1270,7 @@ static bool html_redraw_file(int x, int y, int width, int height,
const char *text;
size_t length;
plot_font_style_t fstyle;
nserror res;
font_plot_style_from_css(box->style, &fstyle);
fstyle.background = background_colour;
@ -1272,13 +1281,16 @@ static bool html_redraw_file(int x, int y, int width, int height,
text = messages_get("Form_Drop");
length = strlen(text);
if (!nsfont.font_width(&fstyle, text, length, &text_width))
res = guit->layout->width(&fstyle, text, length, &text_width);
if (res != NSERROR_OK) {
return false;
}
text_width *= scale;
if (width < text_width + 8)
if (width < text_width + 8) {
x = x + width - text_width - 4;
else
} else {
x = x + 4;
}
return ctx->plot->text(x, y + height * 0.75, text, length, &fstyle);
}
@ -2425,17 +2437,25 @@ bool html_redraw_box(const html_content *html, struct box *box,
const char *obj = "\xef\xbf\xbc";
int obj_width;
int obj_x = x + padding_left;
nserror res;
if (!plot->rectangle(x + padding_left,
y + padding_top,
x + padding_left + width - 1,
y + padding_top + height - 1,
plot_style_broken_object))
plot_style_broken_object)) {
return false;
if (!nsfont.font_width(plot_fstyle_broken_object, obj,
sizeof(obj) - 1, &obj_width))
}
res = guit->layout->width(plot_fstyle_broken_object,
obj,
sizeof(obj) - 1,
&obj_width);
if (res != NSERROR_OK) {
obj_x += 1;
else
} else {
obj_x += width / 2 - obj_width / 2;
}
if (!plot->text(obj_x, y + padding_top + (int)
(height * 0.75),

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
/**
* \file
* HTML layout (interface).
*
* The main interface to the layout code is layout_document(), which takes a
@ -29,11 +30,47 @@
struct box;
struct html_content;
struct gui_layout_table;
/**
* Calculate positions of boxes in a document.
*
* \param content content of type CONTENT_HTML
* \param width available width
* \param height available height
* \return true on success, false on memory exhaustion
*/
bool layout_document(struct html_content *content, int width, int height);
bool layout_inline_container(struct box *box, int width,
struct box *cont, int cx, int cy, struct html_content *content);
/**
* Layout lines of text or inline boxes with floats.
*
* \param inline_container inline container box
* \param width horizontal space available
* \param cont ancestor box which defines horizontal space, for floats
* \param cx box position relative to cont
* \param cy box position relative to cont
* \param content memory pool for any new boxes
* \return true on success, false on memory exhaustion
*/
bool layout_inline_container(struct box *box, int width, struct box *cont, int cx, int cy, struct html_content *content);
/**
* Recursively calculate the descendant_[xy][01] values for a laid-out box tree
* and inform iframe browser windows of their size and position.
*
* \param box tree of boxes to update
*/
void layout_calculate_descendant_bboxes(struct box *box);
void layout_minmax_table(struct box *table,
const struct font_functions *font_func);
/**
* Calculate minimum and maximum width of a table.
*
* \param table box of type TABLE
* \param font_func Font functions
* \post table->min_width and table->max_width filled in,
* 0 <= table->min_width <= table->max_width
*/
void layout_minmax_table(struct box *table, const struct gui_layout_table *font_func);
#endif

View File

@ -47,7 +47,8 @@
#include "desktop/search.h"
#include "desktop/selection.h"
#include "desktop/textinput.h"
#include "desktop/font.h"
#include "desktop/gui_layout.h"
#include "desktop/gui_internal.h"
#include "render/search.h"
#include "render/textplain.h"
@ -466,13 +467,20 @@ void textplain_reformat(struct content *c, int width, int height)
size_t columns = 80;
int character_width;
size_t line_start;
nserror res;
LOG("content %p w:%d h:%d", c, width, height);
/* compute available columns (assuming monospaced font) - use 8
* characters for better accuracy */
if (!nsfont.font_width(&textplain_style, "ABCDEFGH", 8, &character_width))
* characters for better accuracy
*/
res = guit->layout->width(&textplain_style,
"ABCDEFGH", 8,
&character_width);
if (res != NSERROR_OK) {
return;
}
columns = (width - MARGIN - MARGIN) * 8 / character_width;
textplain_tab_width = (TAB_WIDTH * character_width) / 8;
@ -933,9 +941,12 @@ bool textplain_redraw(struct content *c, struct content_redraw_data *data,
break;
/* locate end of string and align to next tab position */
if (nsfont.font_width(&textplain_style, &text_d[offset],
next_offset - offset, &width))
if (guit->layout->width(&textplain_style,
&text_d[offset],
next_offset - offset,
&width)) {
tx += (int)(width * data->scale);
}
ntx = x + ((1 + (tx - x) / tab_width) * tab_width);
@ -1105,16 +1116,20 @@ size_t textplain_offset_from_coords(struct content *c, int x, int y, int dir)
while (next_offset < length && text[next_offset] != '\t')
next_offset = utf8_next(text, length, next_offset);
if (next_offset < length)
nsfont.font_width(&textplain_style, text, next_offset, &width);
if (next_offset < length) {
guit->layout->width(&textplain_style,
text,
next_offset,
&width);
}
if (x <= width) {
int pixel_offset;
size_t char_offset;
nsfont.font_position_in_string(&textplain_style,
text, next_offset, x,
&char_offset, &pixel_offset);
guit->layout->position(&textplain_style,
text, next_offset, x,
&char_offset, &pixel_offset);
idx += char_offset;
break;
@ -1192,10 +1207,12 @@ int textplain_coord_from_offset(const char *text, size_t offset, size_t length)
size_t next_offset = 0;
int tx;
while (next_offset < offset && text[next_offset] != '\t')
while (next_offset < offset && text[next_offset] != '\t') {
next_offset = utf8_next(text, length, next_offset);
}
guit->layout->width(&textplain_style, text, next_offset, &tx);
nsfont.font_width(&textplain_style, text, next_offset, &tx);
x += tx;
if (next_offset >= offset)