From 2a4b9b2217bd2931b6cd615f7d4727ae24a8c35c Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 10 Feb 2013 11:50:04 +0000 Subject: Comment current html wrap/text-splitting behaviour. --- render/layout.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'render/layout.c') diff --git a/render/layout.c b/render/layout.c index 331e1efdb..25d6c2448 100644 --- a/render/layout.c +++ b/render/layout.c @@ -2712,8 +2712,7 @@ bool layout_line(struct box *first, int *width, int *y, !(split_box->flags & REPLACE_DIM) && !(split_box->flags & IFRAME) && !split_box->gadget && split_box->text) { - /* skip leading spaces, otherwise code gets fooled into - * thinking it's all one long word */ + /* skip leading spaces */ for (i = 0; i != split_box->length && split_box->text[i] == ' '; i++) ; @@ -2721,15 +2720,18 @@ bool layout_line(struct box *first, int *width, int *y, for (; i != split_box->length && split_box->text[i] != ' '; i++) ; + /* if not at end of text, we've found a split point */ if (i != split_box->length) space = i; } - /* space != 0 implies split_box->text != 0 */ + /* space != 0 implies split_box->text != 0 + * and that there is a place we could split the text at */ if (space == 0 || no_wrap) w = split_box->width; else { + /* find width of the text to where we could split */ font_plot_style_from_css(split_box->style, &fstyle); /** \todo handle errors */ font_func->font_width(&fstyle, split_box->text, -- cgit v1.2.3 From f98c0d848cb86aa26087dac6756aceaffb943237 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 10 Feb 2013 12:19:13 +0000 Subject: Make nowrap code path a bit plainer. --- render/layout.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'render/layout.c') diff --git a/render/layout.c b/render/layout.c index 25d6c2448..44f92aeb1 100644 --- a/render/layout.c +++ b/render/layout.c @@ -2706,7 +2706,7 @@ bool layout_line(struct box *first, int *width, int *y, x = x_previous; - if ((split_box->type == BOX_INLINE || + if (!no_wrap && (split_box->type == BOX_INLINE || split_box->type == BOX_TEXT) && !split_box->object && !(split_box->flags & REPLACE_DIM) && @@ -2725,10 +2725,10 @@ bool layout_line(struct box *first, int *width, int *y, space = i; } - /* space != 0 implies split_box->text != 0 + /* space != 0 implies split_box->text != NULL * and that there is a place we could split the text at */ - if (space == 0 || no_wrap) + if (space == 0) w = split_box->width; else { /* find width of the text to where we could split */ @@ -2750,7 +2750,7 @@ bool layout_line(struct box *first, int *width, int *y, !left && !right && inline_count == 1) { /* first word of box doesn't fit, but no floats and * first box on line so force in */ - if (space == 0 || no_wrap) { + if (space == 0) { /* only one word in this box, or not text * or white-space:nowrap */ b = split_box->next; -- cgit v1.2.3 From 7bc725fe1f2cb28f824b439a1c2be62fadfecb47 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 10 Feb 2013 16:50:15 +0000 Subject: Update HTML layout not to demand that nsfont_split only splits on a space. This allows the HTML layout code to wrap unicode text correctly. For example on our Japanese Welcome page, the characters will be wrapped if the platform's nsfont_split implementation implements the Unicode line breaking algorithm. --- render/layout.c | 99 +++++++++++++++++++++++++-------------------------------- 1 file changed, 43 insertions(+), 56 deletions(-) (limited to 'render/layout.c') diff --git a/render/layout.c b/render/layout.c index 44f92aeb1..3fd50d18d 100644 --- a/render/layout.c +++ b/render/layout.c @@ -2147,20 +2147,21 @@ static bool layout_text_box_split(html_content *content, int space_width = split_box->space; struct box *c2; const struct font_functions *font_func = content->font_func; + bool space = (split_box->text[new_length] == ' '); + int used_length = new_length + (space ? 1 : 0); - if (space_width == 0) { - /* Currently split_box has no space. */ - /* Get the space width because the split_box will need it */ - /* Don't set it in split_box yet, or it will get cloned. */ + if ((space && space_width == 0) || space_width == UNKNOWN_WIDTH) { + /* We're need to add a space, and we don't know how big + * it's to be, OR we have a space of unknown width anyway; + * Calculate space width */ font_func->font_width(fstyle, " ", 1, &space_width); - } else if (space_width == UNKNOWN_WIDTH) { - /* Split_box has a space but its width is unknown. */ - /* Get the space width because the split_box will need it */ - /* Set it in split_box, so it gets cloned. */ - font_func->font_width(fstyle, " ", 1, &space_width); - split_box->space = space_width; } + if (split_box->space == UNKNOWN_WIDTH) + split_box->space = space_width; + if (!space) + space_width = 0; + /* Create clone of split_box, c2 */ c2 = talloc_memdup(content->bctx, split_box, sizeof *c2); if (!c2) @@ -2173,18 +2174,18 @@ static bool layout_text_box_split(html_content *content, /* TODO: Move text inputs to core textarea widget and remove * this */ c2->text = talloc_strndup(content->bctx, - split_box->text + new_length + 1, - split_box->length - (new_length + 1)); + split_box->text + used_length, + split_box->length - used_length); if (!c2->text) return false; } else { - c2->text += new_length + 1; + c2->text += used_length; } /* 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); + c2->length = split_box->length - used_length; /* Update split_box for its reduced text */ split_box->width = new_width; @@ -2200,7 +2201,14 @@ static bool layout_text_box_split(html_content *content, c2->next->prev = c2; else c2->parent->last = c2; - +#ifdef LAYOUT_DEBUG + LOG(("split_box %p len: %u \"%.*s\"", + split_box, split_box->length, + split_box->length, split_box->text)); + LOG((" new_box %p len: %u \"%.*s\"", + c2, c2->length, + c2->length, c2->text)); +#endif return true; } @@ -2696,8 +2704,7 @@ bool layout_line(struct box *first, int *width, int *y, if (x1 - x0 < x && split_box) { /* the last box went over the end */ - unsigned int i; - size_t space = 0; + size_t split = 0; int w; bool no_wrap = css_computed_white_space( split_box->style) == CSS_WHITE_SPACE_NOWRAP || @@ -2712,52 +2719,39 @@ bool layout_line(struct box *first, int *width, int *y, !(split_box->flags & REPLACE_DIM) && !(split_box->flags & IFRAME) && !split_box->gadget && split_box->text) { - /* skip leading spaces */ - for (i = 0; i != split_box->length && - split_box->text[i] == ' '; i++) - ; - /* find end of word */ - for (; i != split_box->length && - split_box->text[i] != ' '; i++) - ; - /* if not at end of text, we've found a split point */ - if (i != split_box->length) - space = i; - } - /* space != 0 implies split_box->text != NULL - * and that there is a place we could split the text at */ - - if (space == 0) - w = split_box->width; - else { - /* find width of the text to where we could split */ font_plot_style_from_css(split_box->style, &fstyle); /** \todo handle errors */ - font_func->font_width(&fstyle, split_box->text, - space, &w); + font_func->font_split(&fstyle, + split_box->text, split_box->length, + x1 - x0 - x - space_before, &split, &w); } + /* split == 0 implies that text can't be split */ + + if (split == 0) + w = split_box->width; + #ifdef LAYOUT_DEBUG - LOG(("splitting: split_box %p \"%.*s\", space %zu, w %i, " + LOG(("splitting: split_box %p \"%.*s\", spilt %zu, w %i, " "left %p, right %p, inline_count %u", split_box, (int) split_box->length, - split_box->text, space, w, + split_box->text, split, w, left, right, inline_count)); #endif - if ((space == 0 || x1 - x0 <= x + space_before + w) && + if ((split == 0 || x1 - x0 <= x + space_before + w) && !left && !right && inline_count == 1) { /* first word of box doesn't fit, but no floats and * first box on line so force in */ - if (space == 0) { + if (split == 0 || split == split_box->length) { /* only one word in this box, or not text * or white-space:nowrap */ b = split_box->next; } else { /* cut off first word for this line */ if (!layout_text_box_split(content, &fstyle, - split_box, space, w)) + split_box, split, w)) return false; b = split_box->next; } @@ -2765,7 +2759,7 @@ bool layout_line(struct box *first, int *width, int *y, #ifdef LAYOUT_DEBUG LOG(("forcing")); #endif - } else if ((space == 0 || x1 - x0 <= x + space_before + w) && + } else if ((split == 0 || x1 - x0 <= x + space_before + w) && inline_count == 1) { /* first word of first box doesn't fit, but a float is * taking some of the width so move below it */ @@ -2792,7 +2786,7 @@ bool layout_line(struct box *first, int *width, int *y, #ifdef LAYOUT_DEBUG LOG(("moving below float")); #endif - } else if (space == 0 || x1 - x0 <= x + space_before + w) { + } else if (split == 0 || x1 - x0 <= x + space_before + w) { /* first word of box doesn't fit so leave box for next * line */ b = split_box; @@ -2801,21 +2795,14 @@ bool layout_line(struct box *first, int *width, int *y, #endif } else { /* fit as many words as possible */ - assert(space != 0); - font_plot_style_from_css(split_box->style, &fstyle); - /** \todo handle errors */ - font_func->font_split(&fstyle, - split_box->text, split_box->length, - x1 - x0 - x - space_before, &space, &w); + assert(split != 0); #ifdef LAYOUT_DEBUG LOG(("'%.*s' %i %zu %i", (int) split_box->length, - split_box->text, x1 - x0, space, w)); + split_box->text, x1 - x0, split, w)); #endif - if (space == 0) - space = 1; - if (space != split_box->length) { + if (split != split_box->length) { if (!layout_text_box_split(content, &fstyle, - split_box, space, w)) + split_box, split, w)) return false; b = split_box->next; } -- cgit v1.2.3