From d97c9eda43563ca95b11e1da7ad43fd2a320d8e0 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 6 Oct 2015 12:33:59 +0200 Subject: epub: Implement style 'visibility' attribute. --- source/html/css-apply.c | 15 +++++++++++++ source/html/html-layout.c | 56 ++++++++++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 23 deletions(-) (limited to 'source/html') diff --git a/source/html/css-apply.c b/source/html/css-apply.c index 551dc2d8..acb19244 100644 --- a/source/html/css-apply.c +++ b/source/html/css-apply.c @@ -944,10 +944,24 @@ white_space_from_property(fz_css_match *match) return WS_NORMAL; } +static int +visibility_from_property(fz_css_match *match) +{ + fz_css_value *value = value_from_property(match, "visibility"); + if (value) + { + if (!strcmp(value->data, "visible")) return V_VISIBLE; + else if (!strcmp(value->data, "hidden")) return V_HIDDEN; + else if (!strcmp(value->data, "collapse")) return V_COLLAPSE; + } + return V_VISIBLE; +} + void fz_default_css_style(fz_context *ctx, fz_css_style *style) { memset(style, 0, sizeof *style); + style->visibility = V_VISIBLE; style->text_align = TA_LEFT; style->vertical_align = VA_BASELINE; style->white_space = WS_NORMAL; @@ -967,6 +981,7 @@ fz_apply_css_style(fz_context *ctx, fz_html_font_set *set, fz_css_style *style, fz_default_css_style(ctx, style); + style->visibility = visibility_from_property(match); style->white_space = white_space_from_property(match); value = value_from_property(match, "text-align"); diff --git a/source/html/html-layout.c b/source/html/html-layout.c index 3ee6808b..f742969c 100644 --- a/source/html/html-layout.c +++ b/source/html/html-layout.c @@ -865,9 +865,12 @@ static void draw_flow_box(fz_context *ctx, fz_html *box, float page_top, float p g = fz_encode_character(ctx, node->style->font, c); if (g) { - if (!text) - text = fz_new_text(ctx, node->style->font, &trm, 0); - fz_add_text(ctx, text, g, c, x, y); + if (node->style->visibility == V_VISIBLE) + { + if (!text) + text = fz_new_text(ctx, node->style->font, &trm, 0); + fz_add_text(ctx, text, g, c, x, y); + } x += fz_advance_glyph(ctx, node->style->font, g) * node->em; } else @@ -875,9 +878,12 @@ static void draw_flow_box(fz_context *ctx, fz_html *box, float page_top, float p g = fz_encode_character(ctx, node->style->fallback, c); if (g) { - if (!falltext) - falltext = fz_new_text(ctx, node->style->fallback, &trm, 0); - fz_add_text(ctx, falltext, g, c, x, y); + if (node->style->visibility == V_VISIBLE) + { + if (!falltext) + falltext = fz_new_text(ctx, node->style->fallback, &trm, 0); + fz_add_text(ctx, falltext, g, c, x, y); + } } x += fz_advance_glyph(ctx, node->style->fallback, g) * node->em; } @@ -896,10 +902,13 @@ static void draw_flow_box(fz_context *ctx, fz_html *box, float page_top, float p } else if (node->type == FLOW_IMAGE) { - fz_matrix local_ctm = *ctm; - fz_pre_translate(&local_ctm, node->x, node->y); - fz_pre_scale(&local_ctm, node->w, node->h); - fz_fill_image(ctx, dev, node->image, &local_ctm, 1); + if (node->style->visibility == V_VISIBLE) + { + fz_matrix local_ctm = *ctm; + fz_pre_translate(&local_ctm, node->x, node->y); + fz_pre_scale(&local_ctm, node->w, node->h); + fz_fill_image(ctx, dev, node->image, &local_ctm, 1); + } } } } @@ -1102,20 +1111,21 @@ static void draw_block_box(fz_context *ctx, fz_html *box, float page_top, float if (y0 > page_bot || y1 < page_top) return; - draw_rect(ctx, dev, ctm, box->style.background_color, x0, y0, x1, y1); - - if (border[T] > 0) - draw_rect(ctx, dev, ctm, box->style.border_color[T], x0 - border[L], y0 - border[T], x1 + border[R], y0); - if (border[B] > 0) - draw_rect(ctx, dev, ctm, box->style.border_color[B], x0 - border[L], y1, x1 + border[R], y1 + border[B]); - if (border[L] > 0) - draw_rect(ctx, dev, ctm, box->style.border_color[L], x0 - border[L], y0 - border[T], x0, y1 + border[B]); - if (border[R] > 0) - draw_rect(ctx, dev, ctm, box->style.border_color[R], x1, y0 - border[T], x1 + border[R], y1 + border[B]); - - if (box->list_item) + if (box->style.visibility == V_VISIBLE) { - draw_list_mark(ctx, box, page_top, page_bot, dev, ctm, box->list_item); + draw_rect(ctx, dev, ctm, box->style.background_color, x0, y0, x1, y1); + + if (border[T] > 0) + draw_rect(ctx, dev, ctm, box->style.border_color[T], x0 - border[L], y0 - border[T], x1 + border[R], y0); + if (border[B] > 0) + draw_rect(ctx, dev, ctm, box->style.border_color[B], x0 - border[L], y1, x1 + border[R], y1 + border[B]); + if (border[L] > 0) + draw_rect(ctx, dev, ctm, box->style.border_color[L], x0 - border[L], y0 - border[T], x0, y1 + border[B]); + if (border[R] > 0) + draw_rect(ctx, dev, ctm, box->style.border_color[R], x1, y0 - border[T], x1 + border[R], y1 + border[B]); + + if (box->list_item) + draw_list_mark(ctx, box, page_top, page_bot, dev, ctm, box->list_item); } for (box = box->down; box; box = box->next) -- cgit v1.2.3