diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2015-05-06 15:07:20 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2015-05-06 15:07:20 +0200 |
commit | b59d73634725a939175fd0e98a6f86bd6ed0d570 (patch) | |
tree | d6e56c3d05411b4daae7ea2df4dbcf9ed78cbd9c | |
parent | 9fe8e91556693c90cdb83932f130ceefc518539b (diff) | |
download | mupdf-b59d73634725a939175fd0e98a6f86bd6ed0d570.tar.xz |
epub: Add 'auto' as a special number value.
-rw-r--r-- | include/mupdf/html.h | 3 | ||||
-rw-r--r-- | source/html/css-apply.c | 13 | ||||
-rw-r--r-- | source/html/html-layout.c | 10 |
3 files changed, 20 insertions, 6 deletions
diff --git a/include/mupdf/html.h b/include/mupdf/html.h index a768f9df..8d649ec9 100644 --- a/include/mupdf/html.h +++ b/include/mupdf/html.h @@ -105,7 +105,7 @@ enum { LST_ARMENIAN, LST_GEORGIAN, }; -enum { N_NUMBER='p', N_SCALE='m', N_PERCENT='%' }; +enum { N_NUMBER='p', N_SCALE='m', N_PERCENT='%', N_AUTO='a' }; struct fz_css_number_s { @@ -121,6 +121,7 @@ struct fz_css_color_s struct fz_css_style_s { fz_css_number font_size; + fz_css_number width, height; fz_css_number margin[4]; fz_css_number padding[4]; fz_css_number border_width[4]; diff --git a/source/html/css-apply.c b/source/html/css-apply.c index bf0336eb..a4468bd7 100644 --- a/source/html/css-apply.c +++ b/source/html/css-apply.c @@ -708,6 +708,12 @@ number_from_value(fz_css_value *value, float initial, int initial_unit) return make_number(x, N_NUMBER); } + if (value->type == CSS_KEYWORD) + { + if (!strcmp(value->data, "auto")) + return make_number(0, N_AUTO); + } + return make_number(initial, initial_unit); } @@ -755,6 +761,7 @@ fz_from_css_number(fz_css_number number, float em, float width) case N_NUMBER: return number.value; case N_SCALE: return number.value * em; case N_PERCENT: return number.value * 0.01 * width; + case N_AUTO: return width; } } @@ -766,6 +773,7 @@ fz_from_css_number_scale(fz_css_number number, float scale, float em, float widt case N_NUMBER: return number.value * scale; case N_SCALE: return number.value * em; case N_PERCENT: return number.value * 0.01 * width; + case N_AUTO: return width; } } @@ -922,6 +930,8 @@ fz_default_css_style(fz_context *ctx, fz_css_style *style) style->white_space = WS_NORMAL; style->list_style_type = LST_DISC; style->font_size = make_number(1, N_SCALE); + style->width = make_number(0, N_AUTO); + style->height = make_number(0, N_AUTO); } void @@ -999,6 +1009,9 @@ fz_apply_css_style(fz_context *ctx, fz_html_font_set *set, fz_css_style *style, style->text_indent = number_from_property(match, "text-indent", 0, N_NUMBER); + style->width = number_from_property(match, "width", 0, N_AUTO); + style->height = number_from_property(match, "height", 0, N_AUTO); + style->margin[0] = number_from_property(match, "margin-top", 0, N_NUMBER); style->margin[1] = number_from_property(match, "margin-right", 0, N_NUMBER); style->margin[2] = number_from_property(match, "margin-bottom", 0, N_NUMBER); diff --git a/source/html/html-layout.c b/source/html/html-layout.c index 39163c00..757289f9 100644 --- a/source/html/html-layout.c +++ b/source/html/html-layout.c @@ -369,15 +369,15 @@ static void generate_boxes(fz_context *ctx, fz_html_font_set *set, fz_archive *z } } -static void measure_image(fz_context *ctx, fz_html_flow *node, float w, float h) +static void measure_image(fz_context *ctx, fz_html_flow *node, float max_w, float max_h) { float xs = 1, ys = 1, s = 1; node->x = 0; node->y = 0; - if (node->image->w > w) - xs = w / node->image->w; - if (node->image->h > h) - ys = h / node->image->h; + if (node->image->w > max_w) + xs = max_w / node->image->w; + if (node->image->h > max_h) + ys = max_h / node->image->h; s = fz_min(xs, ys); node->w = node->image->w * s; node->h = node->image->h * s; |