summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2002-12-27 17:28:19 +0000
committerJames Bursa <james@netsurf-browser.org>2002-12-27 17:28:19 +0000
commitc3a910193ff564f49bc5bb7353e0a27a39f2f728 (patch)
tree3e6c750848b13783599aaf3013876fe64f0e2738 /render
parent8f5c1d0e6e5c0d57d27bd0b2aa953386df9df1f2 (diff)
downloadnetsurf-c3a910193ff564f49bc5bb7353e0a27a39f2f728.tar.gz
netsurf-c3a910193ff564f49bc5bb7353e0a27a39f2f728.tar.bz2
[project @ 2002-12-27 17:28:19 by bursa]
Improved word space handling svn path=/import/netsurf/; revision=60
Diffstat (limited to 'render')
-rw-r--r--render/box.c8
-rw-r--r--render/box.h3
-rw-r--r--render/layout.c51
3 files changed, 40 insertions, 22 deletions
diff --git a/render/box.c b/render/box.c
index 67b21250c..147818d55 100644
--- a/render/box.c
+++ b/render/box.c
@@ -1,5 +1,5 @@
/**
- * $Id: box.c,v 1.20 2002/10/15 10:41:12 monkeyson Exp $
+ * $Id: box.c,v 1.21 2002/12/27 17:28:19 bursa Exp $
*/
#include <assert.h>
@@ -186,6 +186,12 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style,
box = box_create(n, BOX_INLINE, parent_style, href);
box->text = squash_whitespace(tolat1(n->content));
box->length = strlen(box->text);
+ if (box->text[box->length - 1] == ' ') {
+ box->space = 1;
+ box->length--;
+ } else {
+ box->space = 0;
+ }
box->font = font_open(fonts, box->style);
box_add_child(inline_container, box);
} else {
diff --git a/render/box.h b/render/box.h
index 3df758a60..ad5290d34 100644
--- a/render/box.h
+++ b/render/box.h
@@ -1,5 +1,5 @@
/**
- * $Id: box.h,v 1.11 2002/09/26 21:38:33 bursa Exp $
+ * $Id: box.h,v 1.12 2002/12/27 17:28:19 bursa Exp $
*/
#ifndef _NETSURF_RENDER_BOX_H_
@@ -34,6 +34,7 @@ struct box {
unsigned long x, y, width, height;
unsigned long min_width, max_width;
const char * text;
+ int space; /* 1 <=> followed by a space */
const char * href;
unsigned int length;
unsigned int columns;
diff --git a/render/layout.c b/render/layout.c
index d12c1f555..ced6f16ef 100644
--- a/render/layout.c
+++ b/render/layout.c
@@ -1,5 +1,5 @@
/**
- * $Id: layout.c,v 1.23 2002/12/26 23:02:38 bursa Exp $
+ * $Id: layout.c,v 1.24 2002/12/27 17:28:19 bursa Exp $
*/
#include <assert.h>
@@ -285,13 +285,14 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
unsigned long height;
unsigned long x0 = 0;
unsigned long x1 = width;
- unsigned long x, h, xp;
+ unsigned long x, h, x_previous;
struct box * left;
struct box * right;
struct box * b;
struct box * c;
struct box * d;
int move_y = 0;
+ unsigned int space_before = 0, space_after = 0;
/* fprintf(stderr, "layout_line: '%.*s' %li %li %li\n", first->length, first->text, width, *y, cy); */
@@ -310,7 +311,7 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
if (h > height) height = h;
if (b->width == UNKNOWN_WIDTH)
b->width = font_width(b->font, b->text, b->length);
- x += b->width;
+ x += b->width + b->space ? b->font->space_width : 0;
}
}
@@ -320,11 +321,14 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
find_sides(cont->float_children, cy, cy + height, &x0, &x1, &left, &right);
/* pass 2: place boxes in line */
- for (x = xp = 0, b = first; x <= x1 - x0 && b != 0; b = b->next) {
+ for (x = x_previous = 0, b = first; x <= x1 - x0 && b != 0; b = b->next) {
if (b->type == BOX_INLINE) {
+ x_previous = x;
+ x += space_after;
b->x = x;
- xp = x;
x += b->width;
+ space_before = space_after;
+ space_after = b->space ? b->font->space_width : 0;
c = b;
move_y = 1;
/* fprintf(stderr, "layout_line: '%.*s' %li %li\n", b->length, b->text, xp, x); */
@@ -363,52 +367,62 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long
if (x1 - x0 < x) {
/* the last box went over the end */
char * space = strchr(c->text, ' ');
- char * space2 = space;
- unsigned long w, wp;
+ unsigned long w;
struct box * c2;
+ x = x_previous;
+
+ if (space != 0 && c->length <= space - c->text)
+ /* space after end of string */
+ space = 0;
+
if (space == 0)
- wp = w = c->width;
+ w = c->width;
else
- wp = w = font_width(c->font, c->text, space - c->text);
+ w = font_width(c->font, c->text, space - c->text);
- if (x1 - x0 < xp + w && left == 0 && right == 0 && c == first) {
+ if (x1 - x0 < x + space_before + w && left == 0 && right == 0 && c == first) {
/* first word doesn't fit, but no floats and first on line so force in */
if (space == 0) {
+ /* only one word in this box */
b = c->next;
} else {
+ /* cut off first word for this line */
c2 = memcpy(xcalloc(1, sizeof(struct box)), c, sizeof(struct box));
c2->text = xstrdup(space + 1);
c2->length = c->length - ((space + 1) - c->text);
c2->width = UNKNOWN_WIDTH;
c->length = space + 1 - c->text;
- c->width = wp + 4; /* should be the width of a space */
+ c->width = w;
+ c->space = 1;
c2->next = c->next;
c->next = c2;
b = c2;
}
- x = xp + wp;
+ x += space_before + w;
/* fprintf(stderr, "layout_line: overflow, forcing\n"); */
- } else if (x1 - x0 < xp + w) {
+ } else if (x1 - x0 < x + space_before + w) {
/* first word doesn't fit, but full width not available so leave for later */
b = c;
/* fprintf(stderr, "layout_line: overflow, leaving\n"); */
} else {
/* fit as many words as possible */
assert(space != 0);
- space = font_split(c->font, c->text, c->length, x1 - x0 - xp, &wp);
+ space = font_split(c->font, c->text, c->length,
+ x1 - x0 - x - space_before, &w);
LOG(("'%.*s' %lu %lu (%c) %lu", c->length, c->text,
- x1 - x0, space - c->text, *space, wp));
+ x1 - x0, space - c->text, *space, w));
c2 = memcpy(xcalloc(1, sizeof(struct box)), c, sizeof(struct box));
c2->text = xstrdup(space + 1);
c2->length = c->length - ((space + 1) - c->text);
c2->width = UNKNOWN_WIDTH;
c->length = space + 1 - c->text;
+ c->width = w;
+ c->space = 1;
c2->next = c->next;
c->next = c2;
b = c2;
- c->width = wp + 4; /* should be the width of a space */
- x = xp + wp;
+ x += space_before + w;
/* fprintf(stderr, "layout_line: overflow, fit\n"); */
}
move_y = 1;
@@ -465,9 +479,6 @@ void place_float_below(struct box * c, unsigned long width, unsigned long y, str
/**
* layout a table
- *
- * this is the fixed table layout algorithm,
- * <http://www.w3.org/TR/REC-CSS2/tables.html#fixed-table-layout>
*/
void layout_table(struct box * table, unsigned long width, struct box * cont,