summaryrefslogtreecommitdiff
path: root/source/html/layout.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2014-10-23 14:45:50 +0200
committerTor Andersson <tor.andersson@artifex.com>2014-12-03 12:25:51 +0100
commitb231d01f2ff24f294f9e30cf2ad82a62145ad437 (patch)
treeda7985c66ed63680884ae1b67bd27dcb356570f0 /source/html/layout.c
parentd79203b42621257aed8e4c02e4e6c95ec82d9243 (diff)
downloadmupdf-b231d01f2ff24f294f9e30cf2ad82a62145ad437.tar.xz
html: Start laying out boxes.
Diffstat (limited to 'source/html/layout.c')
-rw-r--r--source/html/layout.c59
1 files changed, 57 insertions, 2 deletions
diff --git a/source/html/layout.c b/source/html/layout.c
index 1d92b502..2960de73 100644
--- a/source/html/layout.c
+++ b/source/html/layout.c
@@ -186,8 +186,55 @@ static void generate_boxes(fz_context *ctx, fz_xml *node, struct box *top, struc
}
}
-static void layout_boxes(fz_context *ctx, struct box *top, float w, float h)
+static void layout_inline(fz_context *ctx, struct box *box, struct box *top)
{
+ struct computed_style style;
+ struct box *child;
+
+ compute_style(&style, &box->style, top->w);
+
+ box->y = top->y;
+ box->h = style.font_size;
+ for (child = box->down; child; child = child->next)
+ {
+ layout_inline(ctx, child, top);
+ }
+}
+
+static void layout_anonymous(fz_context *ctx, struct box *box, struct box *top)
+{
+ struct computed_style style;
+ struct box *child;
+
+ compute_style(&style, &box->style, top->w);
+
+ box->y = top->y + top->h;
+ box->h = 0;
+ for (child = box->down; child; child = child->next)
+ {
+ layout_inline(ctx, child, box);
+ if (child->h > box->h)
+ box->h = child->h;
+ }
+}
+
+static void layout_block(fz_context *ctx, struct box *box, struct box *top)
+{
+ struct computed_style style;
+ struct box *child;
+
+ compute_style(&style, &box->style, top->w);
+
+ box->y = top->y + top->h;
+ box->h = 0;
+ for (child = box->down; child; child = child->next)
+ {
+ if (child->type == BOX_BLOCK)
+ layout_block(ctx, child, box);
+ else if (child->type == BOX_ANONYMOUS)
+ layout_anonymous(ctx, child, box);
+ box->h += child->h;
+ }
}
static void indent(int level)
@@ -199,6 +246,7 @@ static void print_box(fz_context *ctx, struct box *box, int level)
{
while (box)
{
+ printf("%-5d", (int)box->y);
indent(level);
switch (box->type)
{
@@ -285,6 +333,7 @@ html_layout_document(html_document *doc, float w, float h)
{
struct rule *css = NULL;
struct box *root_box;
+ struct box *win_box;
#if 0
strcpy(dirname, argv[i]);
@@ -301,6 +350,12 @@ html_layout_document(html_document *doc, float w, float h)
root_box = new_box(doc->ctx, NULL, NULL);
generate_boxes(doc->ctx, doc->root, root_box, css);
- layout_boxes(doc->ctx, root_box, w, h);
+
+ win_box = new_box(doc->ctx, NULL, NULL);
+ win_box->w = w;
+ win_box->h = 0;
+
+ layout_block(doc->ctx, root_box, win_box);
+
print_box(doc->ctx, root_box, 0);
}