From 9be22ab5908a50fef1f53c366fd68204a15f939c Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 5 Mar 2011 22:18:06 +0000 Subject: [PATCH] Make sure the last clone box for a wrapped text is properly measuered. svn path=/trunk/netsurf/; revision=11920 --- render/box.h | 3 ++- render/layout.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/render/box.h b/render/box.h index 522aeafd1..7d7cd84a6 100644 --- a/render/box.h +++ b/render/box.h @@ -122,7 +122,8 @@ typedef enum { STYLE_OWNED = 1 << 1, /* style is owned by this box */ PRINTED = 1 << 2, /* box has already been printed */ PRE_STRIP = 1 << 3, /* PRE tag needing leading newline stripped */ - CLONE = 1 << 4 /* continuation of previous box from wrapping */ + CLONE = 1 << 4, /* continuation of previous box from wrapping */ + MEASURED = 1 << 5 /* text box width has been measured */ } box_flags; /* Sides of a box */ diff --git a/render/layout.c b/render/layout.c index 067321708..1c0d68111 100644 --- a/render/layout.c +++ b/render/layout.c @@ -1950,11 +1950,13 @@ static bool layout_text_box_split(struct content *content, /* Set c2 according to the remaining text */ c2->width -= new_width + space_width; + c2->flags &= ~MEASURED; /* width has been estimated */ c2->length = split_box->length - (new_length + 1); /* Update split_box for its reduced text */ split_box->length = new_length; split_box->width = new_width; + split_box->flags |= MEASURED; /* Insert c2 into box list */ c2->next = split_box->next; @@ -2166,9 +2168,20 @@ bool layout_line(struct box *first, int *width, int *y, } else { font_func->font_width(&fstyle, b->text, b->length, &b->width); + b->flags |= MEASURED; } } + /* If the current text has not been measured (i.e. its + * width was estimated after splitting), and it fits on + * the line, measure it properly. */ + if (b->text && (x + b->width < x1 - x0) && + !(b->flags & MEASURED)) { + font_func->font_width(&fstyle, b->text, + b->length, &b->width); + b->flags |= MEASURED; + } + x += b->width; if (b->space == UNKNOWN_WIDTH) { font_func->font_width(&fstyle, " ", 1, @@ -2782,6 +2795,7 @@ struct box *layout_minmax_line(struct box *first, } else { font_func->font_width(&fstyle, b->text, b->length, &b->width); + b->flags |= MEASURED; } } max += b->width; @@ -3826,6 +3840,7 @@ void layout_lists(struct box *box, marker->text, marker->length, &marker->width); + marker->flags |= MEASURED; } marker->x = -marker->width; marker->y = 0;