summaryrefslogtreecommitdiff
path: root/source/html
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2014-11-28 11:52:08 +0100
committerTor Andersson <tor.andersson@artifex.com>2014-12-03 12:25:52 +0100
commit46c3e7d3731c4e869e8b6b7b1e7f1a1b2d2491cd (patch)
tree0f6983df4ea5d5240ac1b525cc8ac9960512e779 /source/html
parent1cb7f8f9ae768b680477212c678a3111fca71ef7 (diff)
downloadmupdf-46c3e7d3731c4e869e8b6b7b1e7f1a1b2d2491cd.tar.xz
html: Clean up some naming.
Diffstat (limited to 'source/html')
-rw-r--r--source/html/css-parse.c10
-rw-r--r--source/html/epub-doc.c4
-rw-r--r--source/html/html-doc.c18
-rw-r--r--source/html/html-layout.c79
4 files changed, 48 insertions, 63 deletions
diff --git a/source/html/css-parse.c b/source/html/css-parse.c
index 18f33e16..abe20e74 100644
--- a/source/html/css-parse.c
+++ b/source/html/css-parse.c
@@ -140,13 +140,13 @@ static void css_lex_next(struct lexbuf *buf)
++buf->line;
}
-static void css_lex_init(fz_context *ctx, struct lexbuf *buf, const char *s, const char *file, int line)
+static void css_lex_init(fz_context *ctx, struct lexbuf *buf, const char *s, const char *file)
{
buf->ctx = ctx;
buf->s = s;
buf->c = 0;
buf->file = file;
- buf->line = line;
+ buf->line = 1;
css_lex_next(buf);
buf->color = 0;
@@ -851,15 +851,15 @@ static fz_css_rule *parse_stylesheet(struct lexbuf *buf, fz_css_rule *chain)
fz_css_property *fz_parse_css_properties(fz_context *ctx, const char *source)
{
struct lexbuf buf;
- css_lex_init(ctx, &buf, source, "<inline>", 1);
+ css_lex_init(ctx, &buf, source, "<inline>");
next(&buf);
return parse_declaration_list(&buf);
}
-fz_css_rule *fz_parse_css(fz_context *ctx, fz_css_rule *chain, const char *source, const char *file, int line)
+fz_css_rule *fz_parse_css(fz_context *ctx, fz_css_rule *chain, const char *source, const char *file)
{
struct lexbuf buf;
- css_lex_init(ctx, &buf, source, file, line);
+ css_lex_init(ctx, &buf, source, file);
next(&buf);
return parse_stylesheet(&buf, chain);
}
diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c
index 811e217e..3aaedd33 100644
--- a/source/html/epub-doc.c
+++ b/source/html/epub-doc.c
@@ -22,7 +22,7 @@ struct epub_document_s
struct epub_chapter_s
{
int start;
- fz_html_box *box;
+ fz_html *box;
epub_chapter *next;
};
@@ -157,7 +157,7 @@ epub_parse_chapter(epub_document *doc, const char *path)
fz_write_buffer_byte(ctx, buf, 0);
ch = fz_malloc_struct(ctx, epub_chapter);
- ch->box = fz_generate_html(ctx, doc->set, zip, base_uri, buf);
+ ch->box = fz_parse_html(ctx, doc->set, zip, base_uri, buf, NULL);
ch->next = NULL;
fz_drop_buffer(ctx, buf);
diff --git a/source/html/html-doc.c b/source/html/html-doc.c
index 688a9f88..ea5f7f3a 100644
--- a/source/html/html-doc.c
+++ b/source/html/html-doc.c
@@ -13,7 +13,7 @@ struct html_document_s
fz_archive *zip;
fz_html_font_set *set;
float page_w, page_h, em;
- fz_html_box *box;
+ fz_html *box;
};
static void
@@ -28,20 +28,13 @@ htdoc_close_document(html_document *doc)
static int
htdoc_count_pages(html_document *doc)
{
- int count;
-
- // TODO: reflow
-
- count = ceilf(doc->box->h / doc->page_h);
-printf("count pages! %g / %g = %d\n", doc->box->h, doc->page_h, count);
+ int count = ceilf(doc->box->h / doc->page_h);
return count;
}
static void *
htdoc_load_page(html_document *doc, int number)
{
-printf("load page %d\n", number);
- // TODO: reflow
return (void*)((intptr_t)number + 1);
}
@@ -62,8 +55,6 @@ htdoc_layout(html_document *doc, float w, float h, float em)
static fz_rect *
htdoc_bound_page(html_document *doc, void *page, fz_rect *bbox)
{
- // TODO: reflow
- printf("html: bound page\n");
bbox->x0 = bbox->y0 = 0;
bbox->x1 = doc->page_w;
bbox->y1 = doc->page_h;
@@ -74,7 +65,6 @@ static void
htdoc_run_page(html_document *doc, void *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie)
{
int n = ((intptr_t)page) - 1;
- printf("html: run page %d\n", n);
fz_draw_html(doc->ctx, doc->box, n * doc->page_h, (n+1) * doc->page_h, dev, ctm);
}
@@ -99,7 +89,7 @@ htdoc_open_document_with_stream(fz_context *ctx, fz_stream *file)
buf = fz_read_all(file, 0);
fz_write_buffer_byte(ctx, buf, 0);
- doc->box = fz_generate_html(ctx, doc->set, doc->zip, ".", buf);
+ doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, NULL);
fz_drop_buffer(ctx, buf);
htdoc_layout(doc, DEFW, DEFH, DEFEM);
@@ -131,7 +121,7 @@ htdoc_open_document(fz_context *ctx, const char *filename)
buf = fz_read_file(ctx, filename);
fz_write_buffer_byte(ctx, buf, 0);
- doc->box = fz_generate_html(ctx, doc->set, doc->zip, ".", buf);
+ doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, NULL);
fz_drop_buffer(ctx, buf);
htdoc_layout(doc, DEFW, DEFH, DEFEM);
diff --git a/source/html/html-layout.c b/source/html/html-layout.c
index ca67e030..42392d03 100644
--- a/source/html/html-layout.c
+++ b/source/html/html-layout.c
@@ -53,7 +53,7 @@ static void fz_free_html_flow(fz_context *ctx, fz_html_flow *flow)
}
}
-static fz_html_flow *add_flow(fz_context *ctx, fz_html_box *top, fz_css_style *style, int type)
+static fz_html_flow *add_flow(fz_context *ctx, fz_html *top, fz_css_style *style, int type)
{
fz_html_flow *flow = fz_malloc_struct(ctx, fz_html_flow);
flow->type = type;
@@ -63,7 +63,7 @@ static fz_html_flow *add_flow(fz_context *ctx, fz_html_box *top, fz_css_style *s
return flow;
}
-static void add_flow_space(fz_context *ctx, fz_html_box *top, fz_css_style *style)
+static void add_flow_space(fz_context *ctx, fz_html *top, fz_css_style *style)
{
fz_html_flow *flow;
@@ -76,7 +76,7 @@ static void add_flow_space(fz_context *ctx, fz_html_box *top, fz_css_style *styl
flow->broken_text = "";
}
-static void add_flow_word(fz_context *ctx, fz_html_box *top, fz_css_style *style, const char *a, const char *b)
+static void add_flow_word(fz_context *ctx, fz_html *top, fz_css_style *style, const char *a, const char *b)
{
fz_html_flow *flow = add_flow(ctx, top, style, FLOW_WORD);
flow->text = fz_malloc(ctx, b - a + 1);
@@ -84,15 +84,15 @@ static void add_flow_word(fz_context *ctx, fz_html_box *top, fz_css_style *style
flow->text[b - a] = 0;
}
-static void add_flow_image(fz_context *ctx, fz_html_box *top, fz_css_style *style, fz_image *img)
+static void add_flow_image(fz_context *ctx, fz_html *top, fz_css_style *style, fz_image *img)
{
fz_html_flow *flow = add_flow(ctx, top, style, FLOW_IMAGE);
flow->image = fz_keep_image(ctx, img);
}
-static void generate_text(fz_context *ctx, fz_html_box *box, const char *text)
+static void generate_text(fz_context *ctx, fz_html *box, const char *text)
{
- fz_html_box *flow = box;
+ fz_html *flow = box;
while (flow->type != BOX_FLOW)
flow = flow->up;
@@ -115,13 +115,13 @@ static void generate_text(fz_context *ctx, fz_html_box *box, const char *text)
}
}
-static void generate_image(fz_context *ctx, fz_archive *zip, const char *base_uri, fz_html_box *box, const char *src)
+static void generate_image(fz_context *ctx, fz_archive *zip, const char *base_uri, fz_html *box, const char *src)
{
fz_image *img;
fz_buffer *buf;
char path[2048];
- fz_html_box *flow = box;
+ fz_html *flow = box;
while (flow->type != BOX_FLOW)
flow = flow->up;
@@ -146,7 +146,7 @@ static void generate_image(fz_context *ctx, fz_archive *zip, const char *base_ur
}
}
-static void init_box(fz_context *ctx, fz_html_box *box)
+static void init_box(fz_context *ctx, fz_html *box)
{
box->type = BOX_BLOCK;
box->x = box->y = 0;
@@ -163,11 +163,11 @@ static void init_box(fz_context *ctx, fz_html_box *box)
fz_default_css_style(ctx, &box->style);
}
-void fz_free_html(fz_context *ctx, fz_html_box *box)
+void fz_free_html(fz_context *ctx, fz_html *box)
{
while (box)
{
- fz_html_box *next = box->next;
+ fz_html *next = box->next;
fz_free_html_flow(ctx, box->flow_head);
fz_free_html(ctx, box->down);
fz_free(ctx, box);
@@ -175,14 +175,14 @@ void fz_free_html(fz_context *ctx, fz_html_box *box)
}
}
-static fz_html_box *new_box(fz_context *ctx)
+static fz_html *new_box(fz_context *ctx)
{
- fz_html_box *box = fz_malloc_struct(ctx, fz_html_box);
+ fz_html *box = fz_malloc_struct(ctx, fz_html);
init_box(ctx, box);
return box;
}
-static void insert_box(fz_context *ctx, fz_html_box *box, int type, fz_html_box *top)
+static void insert_box(fz_context *ctx, fz_html *box, int type, fz_html *top)
{
box->type = type;
@@ -202,7 +202,7 @@ static void insert_box(fz_context *ctx, fz_html_box *box, int type, fz_html_box
}
}
-static fz_html_box *insert_block_box(fz_context *ctx, fz_html_box *box, fz_html_box *top)
+static fz_html *insert_block_box(fz_context *ctx, fz_html *box, fz_html *top)
{
if (top->type == BOX_BLOCK)
{
@@ -223,7 +223,7 @@ static fz_html_box *insert_block_box(fz_context *ctx, fz_html_box *box, fz_html_
return top;
}
-static fz_html_box *insert_break_box(fz_context *ctx, fz_html_box *box, fz_html_box *top)
+static fz_html *insert_break_box(fz_context *ctx, fz_html *box, fz_html *top)
{
if (top->type == BOX_BLOCK)
{
@@ -244,7 +244,7 @@ static fz_html_box *insert_break_box(fz_context *ctx, fz_html_box *box, fz_html_
return top;
}
-static void insert_inline_box(fz_context *ctx, fz_html_box *box, fz_html_box *top)
+static void insert_inline_box(fz_context *ctx, fz_html *box, fz_html *top)
{
if (top->type == BOX_BLOCK)
{
@@ -254,7 +254,7 @@ static void insert_inline_box(fz_context *ctx, fz_html_box *box, fz_html_box *to
}
else
{
- fz_html_box *flow = new_box(ctx);
+ fz_html *flow = new_box(ctx);
flow->is_first_flow = !top->last;
insert_box(ctx, flow, BOX_FLOW, top);
insert_box(ctx, box, BOX_INLINE, flow);
@@ -271,10 +271,10 @@ static void insert_inline_box(fz_context *ctx, fz_html_box *box, fz_html_box *to
}
static void generate_boxes(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri,
- fz_xml *node, fz_html_box *top, fz_css_rule *rule, fz_css_match *up_match)
+ fz_xml *node, fz_html *top, fz_css_rule *rule, fz_css_match *up_match)
{
fz_css_match match;
- fz_html_box *box;
+ fz_html *box;
const char *tag;
int display;
@@ -419,7 +419,7 @@ static float measure_line(fz_html_flow *node, fz_html_flow *end, float *baseline
return h;
}
-static void layout_line(fz_context *ctx, float indent, float page_w, float line_w, int align, fz_html_flow *node, fz_html_flow *end, fz_html_box *box, float baseline)
+static void layout_line(fz_context *ctx, float indent, float page_w, float line_w, int align, fz_html_flow *node, fz_html_flow *end, fz_html *box, float baseline)
{
float x = box->x + indent;
float y = box->y + box->h;
@@ -493,7 +493,7 @@ static fz_html_flow *find_next_word(fz_html_flow *node, float *w)
return node;
}
-static void layout_flow(fz_context *ctx, fz_html_box *box, fz_html_box *top, float em, float page_h)
+static void layout_flow(fz_context *ctx, fz_html *box, fz_html *top, float em, float page_h)
{
fz_html_flow *node, *line_start, *word_start, *word_end, *line_end;
float glue_w;
@@ -571,9 +571,9 @@ static void layout_flow(fz_context *ctx, fz_html_box *box, fz_html_box *top, flo
}
}
-static void layout_block(fz_context *ctx, fz_html_box *box, fz_html_box *top, float em, float top_collapse_margin, float page_h)
+static void layout_block(fz_context *ctx, fz_html *box, fz_html *top, float em, float top_collapse_margin, float page_h)
{
- fz_html_box *child;
+ fz_html *child;
float box_collapse_margin;
int prev_br;
@@ -661,7 +661,7 @@ static void layout_block(fz_context *ctx, fz_html_box *box, fz_html_box *top, fl
}
}
-static void draw_flow_box(fz_context *ctx, fz_html_box *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm)
+static void draw_flow_box(fz_context *ctx, fz_html *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm)
{
fz_html_flow *node;
fz_text *text;
@@ -733,7 +733,7 @@ static void draw_rect(fz_context *ctx, fz_device *dev, const fz_matrix *ctm, flo
fz_free_path(ctx, path);
}
-static void draw_block_box(fz_context *ctx, fz_html_box *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm)
+static void draw_block_box(fz_context *ctx, fz_html *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm)
{
float x0, y0, x1, y1;
float color[4];
@@ -788,7 +788,7 @@ static void draw_block_box(fz_context *ctx, fz_html_box *box, float page_top, fl
}
void
-fz_draw_html(fz_context *ctx, fz_html_box *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *inctm)
+fz_draw_html(fz_context *ctx, fz_html *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *inctm)
{
fz_matrix ctm = *inctm;
fz_pre_translate(&ctm, 0, -page_top);
@@ -848,7 +848,7 @@ html_load_css(fz_context *ctx, fz_archive *zip, const char *base_uri, fz_css_rul
buf = fz_read_archive_entry(ctx, zip, path);
fz_write_buffer_byte(ctx, buf, 0);
- css = fz_parse_css(ctx, css, (char*)buf->data, path, 1);
+ css = fz_parse_css(ctx, css, (char*)buf->data, path);
fz_drop_buffer(ctx, buf);
}
}
@@ -857,7 +857,7 @@ html_load_css(fz_context *ctx, fz_archive *zip, const char *base_uri, fz_css_rul
if (tag && !strcmp(tag, "style"))
{
char *s = concat_text(ctx, node);
- css = fz_parse_css(ctx, css, s, "<style>", 1);
+ css = fz_parse_css(ctx, css, s, "<style>");
fz_free(ctx, s);
}
if (fz_xml_down(node))
@@ -867,39 +867,34 @@ html_load_css(fz_context *ctx, fz_archive *zip, const char *base_uri, fz_css_rul
}
void
-fz_layout_html(fz_context *ctx, fz_html_box *box, float w, float h, float em)
+fz_layout_html(fz_context *ctx, fz_html *box, float w, float h, float em)
{
- fz_html_box page_box;
-
- printf("html: laying out text.\n");
+ fz_html page_box;
init_box(ctx, &page_box);
page_box.w = w;
page_box.h = 0;
layout_block(ctx, box, &page_box, em, 0, h);
-
- printf("html: finished.\n");
}
-fz_html_box *
-fz_generate_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri, fz_buffer *buf)
+fz_html *
+fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri, fz_buffer *buf, const char *user_css)
{
fz_xml *xml;
fz_css_rule *css;
- fz_html_box *box;
fz_css_match match;
+ fz_html *box;
- printf("html: parsing XHTML.\n");
xml = fz_parse_xml(ctx, buf->data, buf->len, 1);
- printf("html: parsing style sheets.\n");
- css = fz_parse_css(ctx, NULL, default_css, "<default>", 1);
+ css = fz_parse_css(ctx, NULL, default_css, "<default>");
+ if (user_css)
+ css = fz_parse_css(ctx, NULL, user_css, "<user>");
css = html_load_css(ctx, zip, base_uri, css, xml);
// print_rules(css);
- printf("html: applying styles and generating boxes.\n");
box = new_box(ctx);
match.up = NULL;