diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2014-11-26 13:36:38 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2014-12-03 12:25:52 +0100 |
commit | ce6e762510c9232d2594bd8d302c6d63f56dcff6 (patch) | |
tree | 6ee6ffd749c794286de43068aa0156a94f0b2b06 | |
parent | 3c88d1abef7ab287287a103fa617e50d54eece1d (diff) | |
download | mupdf-ce6e762510c9232d2594bd8d302c6d63f56dcff6.tar.xz |
html: Rename style, box and flow structs.
-rw-r--r-- | include/mupdf/html.h | 30 | ||||
-rw-r--r-- | source/html/css-apply.c | 6 | ||||
-rw-r--r-- | source/html/epub-doc.c | 2 | ||||
-rw-r--r-- | source/html/html-doc.c | 2 | ||||
-rw-r--r-- | source/html/html-layout.c | 90 |
5 files changed, 66 insertions, 64 deletions
diff --git a/include/mupdf/html.h b/include/mupdf/html.h index 860a8293..92b52e3a 100644 --- a/include/mupdf/html.h +++ b/include/mupdf/html.h @@ -4,8 +4,12 @@ #include "mupdf/fitz.h" typedef struct fz_html_font_set_s fz_html_font_set; +typedef struct fz_html_box_s fz_html_box; +typedef struct fz_html_flow_s fz_html_flow; + typedef struct fz_css_rule_s fz_css_rule; typedef struct fz_css_match_s fz_css_match; +typedef struct fz_css_style_s fz_css_style; struct fz_html_font_set_s { @@ -95,7 +99,7 @@ struct color unsigned char r, g, b, a; }; -struct computed_style +struct fz_css_style_s { struct number font_size; struct number margin[4]; @@ -121,16 +125,16 @@ enum BOX_INLINE, /* inline-level: contains only inline boxes */ }; -struct box +struct fz_html_box_s { int type; float x, y, w, h; /* content */ float padding[4]; float margin[4]; float border[4]; - struct box *up, *down, *last, *next; - struct flow *flow_head, **flow_tail; - struct computed_style style; + fz_html_box *up, *down, *last, *next; + fz_html_flow *flow_head, **flow_tail; + fz_css_style style; int is_first_flow; /* for text-indent */ }; @@ -141,14 +145,14 @@ enum FLOW_IMAGE, }; -struct flow +struct fz_html_flow_s { int type; float x, y, w, h, em; - struct computed_style *style; + fz_css_style *style; char *text, *broken_text; fz_image *image; - struct flow *next; + fz_html_flow *next; }; fz_css_rule *fz_parse_css(fz_context *ctx, fz_css_rule *old, const char *source); @@ -157,8 +161,8 @@ struct property *fz_parse_css_properties(fz_context *ctx, const char *source); void fz_match_css(fz_context *ctx, fz_css_match *match, fz_css_rule *rule, fz_xml *node); int fz_get_css_match_display(fz_css_match *node); -void fz_default_css_style(fz_context *ctx, struct computed_style *style); -void fz_apply_css_style(fz_context *ctx, fz_html_font_set *set, struct computed_style *style, fz_css_match *match); +void fz_default_css_style(fz_context *ctx, fz_css_style *style); +void fz_apply_css_style(fz_context *ctx, fz_html_font_set *set, fz_css_style *style, fz_css_match *match); float fz_from_css_number(struct number, float em, float width); float fz_from_css_number_scale(struct number number, float scale, float em, float width); @@ -168,8 +172,8 @@ fz_font *fz_load_html_font(fz_context *ctx, fz_html_font_set *set, const char *family, const char *variant, const char *style, const char *weight); void fz_free_html_font_set(fz_context *ctx, fz_html_font_set *htx); -struct box *fz_generate_html(fz_context *ctx, fz_html_font_set *htx, fz_archive *zip, const char *base_uri, fz_buffer *buf); -void fz_layout_html(fz_context *ctx, struct box *box, float w, float h, float em); -void fz_draw_html(fz_context *ctx, struct box *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm); +fz_html_box *fz_generate_html(fz_context *ctx, fz_html_font_set *htx, fz_archive *zip, const char *base_uri, fz_buffer *buf); +void fz_layout_html(fz_context *ctx, fz_html_box *box, float w, float h, float em); +void fz_draw_html(fz_context *ctx, fz_html_box *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm); #endif diff --git a/source/html/css-apply.c b/source/html/css-apply.c index aa02a1b0..95099eda 100644 --- a/source/html/css-apply.c +++ b/source/html/css-apply.c @@ -757,7 +757,7 @@ white_space_from_property(fz_css_match *match) } void -fz_default_css_style(fz_context *ctx, struct computed_style *style) +fz_default_css_style(fz_context *ctx, fz_css_style *style) { memset(style, 0, sizeof *style); style->text_align = TA_LEFT; @@ -767,7 +767,7 @@ fz_default_css_style(fz_context *ctx, struct computed_style *style) } void -fz_apply_css_style(fz_context *ctx, fz_html_font_set *set, struct computed_style *style, fz_css_match *match) +fz_apply_css_style(fz_context *ctx, fz_html_font_set *set, fz_css_style *style, fz_css_match *match) { struct value *value; @@ -967,7 +967,7 @@ print_rules(fz_css_rule *rule) } void -print_style(struct computed_style *style) +print_style(fz_css_style *style) { printf("style {\n"); printf("\tfont-size = %g%c;\n", style->font_size.value, style->font_size.unit); diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c index 11b43e0a..3ad81d66 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; - struct box *box; + fz_html_box *box; epub_chapter *next; }; diff --git a/source/html/html-doc.c b/source/html/html-doc.c index 11d21d56..531e61c4 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; - struct box *box; + fz_html_box *box; }; static void diff --git a/source/html/html-layout.c b/source/html/html-layout.c index ceea468d..412c4484 100644 --- a/source/html/html-layout.c +++ b/source/html/html-layout.c @@ -39,9 +39,9 @@ static int iswhite(int c) return c == ' ' || c == '\t' || c == '\r' || c == '\n'; } -static struct flow *add_flow(fz_context *ctx, struct box *top, struct computed_style *style, int type) +static fz_html_flow *add_flow(fz_context *ctx, fz_html_box *top, fz_css_style *style, int type) { - struct flow *flow = fz_malloc_struct(ctx, struct flow); + fz_html_flow *flow = fz_malloc_struct(ctx, fz_html_flow); flow->type = type; flow->style = style; *top->flow_tail = flow; @@ -49,9 +49,9 @@ static struct flow *add_flow(fz_context *ctx, struct box *top, struct computed_s return flow; } -static void add_flow_space(fz_context *ctx, struct box *top, struct computed_style *style) +static void add_flow_space(fz_context *ctx, fz_html_box *top, fz_css_style *style) { - struct flow *flow; + fz_html_flow *flow; /* delete space at the beginning of the line */ if (!top->flow_head) @@ -62,23 +62,23 @@ static void add_flow_space(fz_context *ctx, struct box *top, struct computed_sty flow->broken_text = ""; } -static void add_flow_word(fz_context *ctx, struct box *top, struct computed_style *style, const char *a, const char *b) +static void add_flow_word(fz_context *ctx, fz_html_box *top, fz_css_style *style, const char *a, const char *b) { - struct flow *flow = add_flow(ctx, top, style, FLOW_WORD); + fz_html_flow *flow = add_flow(ctx, top, style, FLOW_WORD); flow->text = fz_malloc(ctx, b - a + 1); memcpy(flow->text, a, b - a); flow->text[b - a] = 0; } -static void add_flow_image(fz_context *ctx, struct box *top, struct computed_style *style, fz_image *img) +static void add_flow_image(fz_context *ctx, fz_html_box *top, fz_css_style *style, fz_image *img) { - struct flow *flow = add_flow(ctx, top, style, FLOW_IMAGE); + 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, struct box *box, const char *text) +static void generate_text(fz_context *ctx, fz_html_box *box, const char *text) { - struct box *flow = box; + fz_html_box *flow = box; while (flow->type != BOX_FLOW) flow = flow->up; @@ -101,13 +101,13 @@ static void generate_text(fz_context *ctx, struct box *box, const char *text) } } -static void generate_image(fz_context *ctx, fz_archive *zip, const char *base_uri, struct box *box, const char *src) +static void generate_image(fz_context *ctx, fz_archive *zip, const char *base_uri, fz_html_box *box, const char *src) { fz_image *img; fz_buffer *buf; char path[2048]; - struct box *flow = box; + fz_html_box *flow = box; while (flow->type != BOX_FLOW) flow = flow->up; @@ -132,7 +132,7 @@ static void generate_image(fz_context *ctx, fz_archive *zip, const char *base_ur } } -static void init_box(fz_context *ctx, struct box *box) +static void init_box(fz_context *ctx, fz_html_box *box) { box->type = BOX_BLOCK; box->x = box->y = 0; @@ -149,14 +149,14 @@ static void init_box(fz_context *ctx, struct box *box) fz_default_css_style(ctx, &box->style); } -static struct box *new_box(fz_context *ctx) +static fz_html_box *new_box(fz_context *ctx) { - struct box *box = fz_malloc_struct(ctx, struct box); + fz_html_box *box = fz_malloc_struct(ctx, fz_html_box); init_box(ctx, box); return box; } -static void insert_box(fz_context *ctx, struct box *box, int type, struct box *top) +static void insert_box(fz_context *ctx, fz_html_box *box, int type, fz_html_box *top) { box->type = type; @@ -176,7 +176,7 @@ static void insert_box(fz_context *ctx, struct box *box, int type, struct box *t } } -static struct box *insert_block_box(fz_context *ctx, struct box *box, struct box *top) +static fz_html_box *insert_block_box(fz_context *ctx, fz_html_box *box, fz_html_box *top) { if (top->type == BOX_BLOCK) { @@ -197,7 +197,7 @@ static struct box *insert_block_box(fz_context *ctx, struct box *box, struct box return top; } -static struct box *insert_break_box(fz_context *ctx, struct box *box, struct box *top) +static fz_html_box *insert_break_box(fz_context *ctx, fz_html_box *box, fz_html_box *top) { if (top->type == BOX_BLOCK) { @@ -218,7 +218,7 @@ static struct box *insert_break_box(fz_context *ctx, struct box *box, struct box return top; } -static void insert_inline_box(fz_context *ctx, struct box *box, struct box *top) +static void insert_inline_box(fz_context *ctx, fz_html_box *box, fz_html_box *top) { if (top->type == BOX_BLOCK) { @@ -228,7 +228,7 @@ static void insert_inline_box(fz_context *ctx, struct box *box, struct box *top) } else { - struct box *flow = new_box(ctx); + fz_html_box *flow = new_box(ctx); flow->is_first_flow = !top->last; insert_box(ctx, flow, BOX_FLOW, top); insert_box(ctx, box, BOX_INLINE, flow); @@ -245,10 +245,10 @@ static void insert_inline_box(fz_context *ctx, struct box *box, struct box *top) } 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, fz_css_rule *rule, fz_css_match *up_match) + fz_xml *node, fz_html_box *top, fz_css_rule *rule, fz_css_match *up_match) { fz_css_match match; - struct box *box; + fz_html_box *box; const char *tag; int display; @@ -331,7 +331,7 @@ static void generate_boxes(fz_context *ctx, fz_html_font_set *set, fz_archive *z } } -static void measure_image(fz_context *ctx, struct flow *node, float w, float h) +static void measure_image(fz_context *ctx, fz_html_flow *node, float w, float h) { float xs = 1, ys = 1, s = 1; node->x = 0; @@ -345,7 +345,7 @@ static void measure_image(fz_context *ctx, struct flow *node, float w, float h) node->h = node->image->h * s; } -static void measure_word(fz_context *ctx, struct flow *node, float em) +static void measure_word(fz_context *ctx, fz_html_flow *node, float em) { const char *s; int c, g; @@ -368,7 +368,7 @@ static void measure_word(fz_context *ctx, struct flow *node, float em) node->em = em; } -static float measure_line(struct flow *node, struct flow *end, float *baseline) +static float measure_line(fz_html_flow *node, fz_html_flow *end, float *baseline) { float max_a = 0, max_d = 0, h = 0; while (node != end) @@ -393,7 +393,7 @@ static float measure_line(struct flow *node, struct flow *end, float *baseline) return h; } -static void layout_line(fz_context *ctx, float indent, float page_w, float line_w, int align, struct flow *node, struct flow *end, struct 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 *box, float baseline) { float x = box->x + indent; float y = box->y + box->h; @@ -404,7 +404,7 @@ static void layout_line(fz_context *ctx, float indent, float page_w, float line_ if (align == TA_JUSTIFY) { - struct flow *it; + fz_html_flow *it; for (it = node; it != end; it = it->next) if (it->type == FLOW_GLUE) ++n; @@ -442,7 +442,7 @@ static void layout_line(fz_context *ctx, float indent, float page_w, float line_ } } -static struct flow *find_next_glue(struct flow *node, float *w) +static fz_html_flow *find_next_glue(fz_html_flow *node, float *w) { while (node && node->type == FLOW_GLUE) { @@ -457,7 +457,7 @@ static struct flow *find_next_glue(struct flow *node, float *w) return node; } -static struct flow *find_next_word(struct flow *node, float *w) +static fz_html_flow *find_next_word(fz_html_flow *node, float *w) { while (node && node->type == FLOW_GLUE) { @@ -467,9 +467,9 @@ static struct flow *find_next_word(struct flow *node, float *w) return node; } -static void layout_flow(fz_context *ctx, struct box *box, struct box *top, float em, float page_h) +static void layout_flow(fz_context *ctx, fz_html_box *box, fz_html_box *top, float em, float page_h) { - struct flow *node, *line_start, *word_start, *word_end, *line_end; + fz_html_flow *node, *line_start, *word_start, *word_end, *line_end; float glue_w; float word_w; float line_w; @@ -545,9 +545,9 @@ static void layout_flow(fz_context *ctx, struct box *box, struct box *top, float } } -static void layout_block(fz_context *ctx, struct box *box, struct box *top, float em, float top_collapse_margin, float page_h) +static void layout_block(fz_context *ctx, fz_html_box *box, fz_html_box *top, float em, float top_collapse_margin, float page_h) { - struct box *child; + fz_html_box *child; float box_collapse_margin; int prev_br; @@ -635,10 +635,9 @@ static void layout_block(fz_context *ctx, struct box *box, struct box *top, floa } } -static void -draw_flow_box(fz_context *ctx, struct 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 *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm) { - struct flow *node; + fz_html_flow *node; fz_text *text; fz_matrix trm; const char *s; @@ -693,8 +692,7 @@ draw_flow_box(fz_context *ctx, struct box *box, float page_top, float page_bot, } } -static void -draw_rect(fz_context *ctx, fz_device *dev, const fz_matrix *ctm, float *rgba, float x0, float y0, float x1, float y1) +static void draw_rect(fz_context *ctx, fz_device *dev, const fz_matrix *ctm, float *rgba, float x0, float y0, float x1, float y1) { fz_path *path = fz_new_path(ctx); @@ -709,8 +707,7 @@ draw_rect(fz_context *ctx, fz_device *dev, const fz_matrix *ctm, float *rgba, fl fz_free_path(ctx, path); } -static void -draw_block_box(fz_context *ctx, struct 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 *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm) { float x0, y0, x1, y1; float color[4]; @@ -765,7 +762,7 @@ draw_block_box(fz_context *ctx, struct box *box, float page_top, float page_bot, } void -fz_draw_html(fz_context *ctx, struct box *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *inctm) +fz_draw_html(fz_context *ctx, fz_html_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); @@ -797,7 +794,8 @@ static char *concat_text(fz_context *ctx, fz_xml *root) return s; } -static fz_css_rule *html_load_css(fz_context *ctx, fz_archive *zip, const char *base_uri, fz_css_rule *css, fz_xml *root) +static fz_css_rule * +html_load_css(fz_context *ctx, fz_archive *zip, const char *base_uri, fz_css_rule *css, fz_xml *root) { fz_xml *node; fz_buffer *buf; @@ -843,9 +841,9 @@ static fz_css_rule *html_load_css(fz_context *ctx, fz_archive *zip, const char * } void -fz_layout_html(fz_context *ctx, struct box *box, float w, float h, float em) +fz_layout_html(fz_context *ctx, fz_html_box *box, float w, float h, float em) { - struct box page_box; + fz_html_box page_box; printf("html: laying out text.\n"); @@ -858,12 +856,12 @@ fz_layout_html(fz_context *ctx, struct box *box, float w, float h, float em) printf("html: finished.\n"); } -struct box * +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_xml *xml; fz_css_rule *css; - struct box *box; + fz_html_box *box; fz_css_match match; printf("html: parsing XHTML.\n"); |