summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2014-11-26 02:14:34 +0100
committerTor Andersson <tor.andersson@artifex.com>2014-12-03 12:25:52 +0100
commit673f6e7149c3c5b0e2a1fe334c3b04124fc807c6 (patch)
tree0009993139bd79dcaf3a3ed867b759069ef6433e /source
parentcf42f2f4d5e95b7254479e80614d1814e74e2387 (diff)
downloadmupdf-673f6e7149c3c5b0e2a1fe334c3b04124fc807c6.tar.xz
html: Clean up some names.
Diffstat (limited to 'source')
-rw-r--r--source/html/css-apply.c4
-rw-r--r--source/html/font.c18
-rw-r--r--source/html/handler.c43
-rw-r--r--source/html/layout.c51
4 files changed, 55 insertions, 61 deletions
diff --git a/source/html/css-apply.c b/source/html/css-apply.c
index bbfc7ffa..289811c6 100644
--- a/source/html/css-apply.c
+++ b/source/html/css-apply.c
@@ -990,7 +990,7 @@ default_computed_style(struct computed_style *style)
}
void
-compute_style(fz_context *ctx, html_context *htx, struct computed_style *style, struct style *node)
+compute_style(fz_context *ctx, fz_html_font_set *set, struct computed_style *style, struct style *node)
{
struct value *value;
@@ -1087,7 +1087,7 @@ compute_style(fz_context *ctx, html_context *htx, struct computed_style *style,
const char *font_variant = get_style_property_string(node, "font-variant", "normal");
const char *font_style = get_style_property_string(node, "font-style", "normal");
const char *font_weight = get_style_property_string(node, "font-weight", "normal");
- style->font = html_load_font(ctx, htx, font_family, font_variant, font_style, font_weight);
+ style->font = fz_html_load_font(ctx, set, font_family, font_variant, font_style, font_weight);
}
}
diff --git a/source/html/font.c b/source/html/font.c
index 51654ae9..ce8c2ed1 100644
--- a/source/html/font.c
+++ b/source/html/font.c
@@ -9,7 +9,7 @@ static const char *font_names[16] = {
};
fz_font *
-html_load_font(fz_context *ctx, html_context *htx,
+fz_html_load_font(fz_context *ctx, fz_html_font_set *set,
const char *family, const char *variant, const char *style, const char *weight)
{
unsigned char *data;
@@ -21,15 +21,25 @@ html_load_font(fz_context *ctx, html_context *htx,
int is_italic = !strcmp(style, "italic") || !strcmp(style, "oblique");
int idx = is_mono * 8 + is_sans * 4 + is_bold * 2 + is_italic;
- if (!htx->fonts[idx])
+ if (!set->fonts[idx])
{
data = pdf_lookup_builtin_font(font_names[idx], &size);
if (!data) {
printf("data=%p idx=%d s=%s\n", data, idx, font_names[idx]);
abort();
}
- htx->fonts[idx] = fz_new_font_from_memory(ctx, font_names[idx], data, size, 0, 1);
+ set->fonts[idx] = fz_new_font_from_memory(ctx, font_names[idx], data, size, 0, 1);
}
- return htx->fonts[idx];
+ return set->fonts[idx];
+}
+
+fz_html_font_set *fz_new_html_font_set(fz_context *ctx)
+{
+ return fz_malloc_struct(ctx, fz_html_font_set);
+}
+
+void fz_free_html_font_set(fz_context *ctx, fz_html_font_set *set)
+{
+ fz_free(ctx, set);
}
diff --git a/source/html/handler.c b/source/html/handler.c
index 626ed443..11d21d56 100644
--- a/source/html/handler.c
+++ b/source/html/handler.c
@@ -10,16 +10,18 @@ struct html_document_s
{
fz_document super;
fz_context *ctx;
- html_context htx;
+ fz_archive *zip;
+ fz_html_font_set *set;
+ float page_w, page_h, em;
struct box *box;
};
static void
htdoc_close_document(html_document *doc)
{
- fz_context *ctx = doc->ctx;
- html_fini(ctx, &doc->htx);
- fz_free(ctx, doc);
+ fz_close_archive(doc->ctx, doc->zip);
+ fz_free_html_font_set(doc->ctx, doc->set);
+ fz_free(doc->ctx, doc);
}
static int
@@ -29,8 +31,8 @@ htdoc_count_pages(html_document *doc)
// TODO: reflow
- count = ceilf(doc->box->h / doc->htx.page_h);
-printf("count pages! %g / %g = %d\n", doc->box->h, doc->htx.page_h, count);
+ count = ceilf(doc->box->h / doc->page_h);
+printf("count pages! %g / %g = %d\n", doc->box->h, doc->page_h, count);
return count;
}
@@ -50,7 +52,10 @@ htdoc_free_page(html_document *doc, void *page)
static void
htdoc_layout(html_document *doc, float w, float h, float em)
{
- html_layout(doc->ctx, &doc->htx, doc->box, w, h, em);
+ doc->page_w = w;
+ doc->page_h = h;
+ doc->em = em;
+ fz_layout_html(doc->ctx, doc->box, w, h, em);
}
static fz_rect *
@@ -59,8 +64,8 @@ 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->htx.page_w;
- bbox->y1 = doc->htx.page_h;
+ bbox->x1 = doc->page_w;
+ bbox->y1 = doc->page_h;
return bbox;
}
@@ -69,22 +74,19 @@ htdoc_run_page(html_document *doc, void *page, fz_device *dev, const fz_matrix *
{
int n = ((intptr_t)page) - 1;
printf("html: run page %d\n", n);
- html_draw(doc->ctx, &doc->htx, doc->box, n * doc->htx.page_h, (n+1) * doc->htx.page_h, dev, ctm);
+ fz_draw_html(doc->ctx, doc->box, n * doc->page_h, (n+1) * doc->page_h, dev, ctm);
}
-
static html_document *
htdoc_open_document_with_stream(fz_context *ctx, fz_stream *file)
{
html_document *doc;
- fz_archive *zip;
fz_buffer *buf;
- zip = fz_open_directory(ctx, ".");
-
doc = fz_malloc_struct(ctx, html_document);
doc->ctx = ctx;
- html_init(ctx, &doc->htx, zip);
+ doc->zip = fz_open_directory(ctx, ".");
+ doc->set = fz_new_html_font_set(ctx);
doc->super.close = (void*)htdoc_close_document;
doc->super.layout = (void*)htdoc_layout;
@@ -96,9 +98,11 @@ 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 = html_generate(ctx, &doc->htx, ".", buf);
+ doc->box = fz_generate_html(ctx, doc->set, doc->zip, ".", buf);
fz_drop_buffer(ctx, buf);
+ htdoc_layout(doc, DEFW, DEFH, DEFEM);
+
return doc;
}
@@ -106,16 +110,15 @@ static html_document *
htdoc_open_document(fz_context *ctx, const char *filename)
{
char dirname[2048];
- fz_archive *zip;
fz_buffer *buf;
html_document *doc;
fz_dirname(dirname, filename, sizeof dirname);
- zip = fz_open_directory(ctx, dirname);
doc = fz_malloc_struct(ctx, html_document);
doc->ctx = ctx;
- html_init(ctx, &doc->htx, zip);
+ doc->zip = fz_open_directory(ctx, dirname);
+ doc->set = fz_new_html_font_set(ctx);
doc->super.close = (void*)htdoc_close_document;
doc->super.layout = (void*)htdoc_layout;
@@ -127,7 +130,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 = html_generate(ctx, &doc->htx, ".", buf);
+ doc->box = fz_generate_html(ctx, doc->set, doc->zip, ".", buf);
fz_drop_buffer(ctx, buf);
htdoc_layout(doc, DEFW, DEFH, DEFEM);
diff --git a/source/html/layout.c b/source/html/layout.c
index f07108b5..3243a6ae 100644
--- a/source/html/layout.c
+++ b/source/html/layout.c
@@ -100,7 +100,7 @@ static void generate_text(fz_context *ctx, struct box *box, const char *text)
}
}
-static void generate_image(fz_context *ctx, html_context *htx, const char *base_uri, struct box *box, const char *src)
+static void generate_image(fz_context *ctx, fz_archive *zip, const char *base_uri, struct box *box, const char *src)
{
fz_image *img;
fz_buffer *buf;
@@ -115,7 +115,7 @@ static void generate_image(fz_context *ctx, html_context *htx, const char *base_
fz_strlcat(path, src, sizeof path);
fz_cleanname(path);
- buf = fz_read_archive_entry(ctx, htx->zip, path);
+ buf = fz_read_archive_entry(ctx, zip, path);
img = fz_new_image_from_buffer(ctx, buf);
fz_drop_buffer(ctx, buf);
@@ -236,7 +236,7 @@ static void insert_inline_box(fz_context *ctx, struct box *box, struct box *top)
}
}
-static void generate_boxes(fz_context *ctx, html_context *htx, const char *base_uri,
+static void generate_boxes(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri,
fz_xml *node, struct box *top, struct rule *rule, struct style *up_style)
{
struct style style;
@@ -259,7 +259,7 @@ static void generate_boxes(fz_context *ctx, html_context *htx, const char *base_
if (!strcmp(tag, "br"))
{
box = new_box(ctx, node);
- compute_style(ctx, htx, &box->style, &style);
+ compute_style(ctx, set, &box->style, &style);
top = insert_break_box(ctx, box, top);
}
@@ -269,16 +269,16 @@ static void generate_boxes(fz_context *ctx, html_context *htx, const char *base_
if (src)
{
box = new_box(ctx, node);
- compute_style(ctx, htx, &box->style, &style);
+ compute_style(ctx, set, &box->style, &style);
insert_inline_box(ctx, box, top);
- generate_image(ctx, htx, base_uri, box, src);
+ generate_image(ctx, zip, base_uri, box, src);
}
}
else if (display != DIS_NONE)
{
box = new_box(ctx, node);
- compute_style(ctx, htx, &box->style, &style);
+ compute_style(ctx, set, &box->style, &style);
if (display == DIS_BLOCK)
{
@@ -299,7 +299,7 @@ static void generate_boxes(fz_context *ctx, html_context *htx, const char *base_
}
if (fz_xml_down(node))
- generate_boxes(ctx, htx, base_uri, fz_xml_down(node), box, rule, &style);
+ generate_boxes(ctx, set, zip, base_uri, fz_xml_down(node), box, rule, &style);
// TODO: remove empty flow boxes
}
@@ -806,7 +806,7 @@ draw_block_box(fz_context *ctx, struct box *box, float page_top, float page_bot,
}
void
-html_draw(fz_context *ctx, html_context *htx, struct box *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *inctm)
+fz_draw_html(fz_context *ctx, struct box *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);
@@ -838,7 +838,7 @@ static char *concat_text(fz_context *ctx, fz_xml *root)
return s;
}
-static struct rule *html_load_css(fz_context *ctx, html_context *htx, const char *base_uri, struct rule *css, fz_xml *root)
+static struct rule *html_load_css(fz_context *ctx, fz_archive *zip, const char *base_uri, struct rule *css, fz_xml *root)
{
fz_xml *node;
fz_buffer *buf;
@@ -863,7 +863,7 @@ static struct rule *html_load_css(fz_context *ctx, html_context *htx, const char
fz_strlcat(path, href, sizeof path);
fz_cleanname(path);
- buf = fz_read_archive_entry(ctx, htx->zip, path);
+ buf = fz_read_archive_entry(ctx, zip, path);
fz_write_buffer_byte(ctx, buf, 0);
css = fz_parse_css(ctx, css, (char*)buf->data);
fz_drop_buffer(ctx, buf);
@@ -878,19 +878,16 @@ static struct rule *html_load_css(fz_context *ctx, html_context *htx, const char
fz_free(ctx, s);
}
if (fz_xml_down(node))
- css = html_load_css(ctx, htx, base_uri, css, fz_xml_down(node));
+ css = html_load_css(ctx, zip, base_uri, css, fz_xml_down(node));
}
return css;
}
void
-html_layout(fz_context *ctx, html_context *htx, struct box *box, float w, float h, float em)
+fz_layout_html(fz_context *ctx, struct box *box, float w, float h, float em)
{
struct box page_box;
- htx->page_w = w;
- htx->page_h = h;
-
printf("html: laying out text.\n");
init_box(ctx, &page_box, NULL);
@@ -903,7 +900,7 @@ html_layout(fz_context *ctx, html_context *htx, struct box *box, float w, float
}
struct box *
-html_generate(fz_context *ctx, html_context *htx, const char *base_uri, fz_buffer *buf)
+fz_generate_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri, fz_buffer *buf)
{
fz_xml *xml;
struct rule *css;
@@ -915,7 +912,7 @@ html_generate(fz_context *ctx, html_context *htx, const char *base_uri, fz_buffe
printf("html: parsing style sheets.\n");
css = fz_parse_css(ctx, NULL, default_css);
- css = html_load_css(ctx, htx, base_uri, css, xml);
+ css = html_load_css(ctx, zip, base_uri, css, xml);
// print_rules(css);
@@ -925,23 +922,7 @@ html_generate(fz_context *ctx, html_context *htx, const char *base_uri, fz_buffe
style.up = NULL;
style.count = 0;
- generate_boxes(ctx, htx, base_uri, xml, box, css, &style);
+ generate_boxes(ctx, set, zip, base_uri, xml, box, css, &style);
return box;
}
-
-void html_init(fz_context *ctx, html_context *html, fz_archive *zip)
-{
- memset(html, 0, sizeof *html);
- html->zip = zip;
-}
-
-void html_rebind(html_context *html, fz_context *ctx)
-{
- fz_rebind_archive(html->zip, ctx);
-}
-
-void html_fini(fz_context *ctx, html_context *html)
-{
- fz_close_archive(ctx, html->zip);
-}