Exemple #1
0
static void generate_image(fz_context *ctx, fz_pool *pool, fz_archive *zip, const char *base_uri, fz_html *box, const char *src)
{
	fz_image *img = NULL;
	fz_buffer *buf = NULL;
	char path[2048];

	fz_html *flow = box;
	while (flow->type != BOX_FLOW)
		flow = flow->up;

	fz_strlcpy(path, base_uri, sizeof path);
	fz_strlcat(path, "/", sizeof path);
	fz_strlcat(path, src, sizeof path);
	fz_urldecode(path);
	fz_cleanname(path);

	fz_var(buf);
	fz_var(img);

	fz_try(ctx)
	{
		buf = fz_read_archive_entry(ctx, zip, path);
		img = fz_new_image_from_buffer(ctx, buf);
		add_flow_image(ctx, pool, flow, &box->style, img);
	}
	fz_always(ctx)
	{
		fz_drop_buffer(ctx, buf);
		fz_drop_image(ctx, img);
	}
	fz_catch(ctx)
	{
		const char *alt = "[image]";
		fz_warn(ctx, "html: cannot add image src='%s'", src);
		add_flow_word(ctx, pool, flow, &box->style, alt, alt + 7);
	}
}
Exemple #2
0
static void generate_text(fz_context *ctx, fz_html *box, const char *text)
{
	fz_html *flow = box;
	while (flow->type != BOX_FLOW)
		flow = flow->up;

	while (*text)
	{
		if (iswhite(*text))
		{
			++text;
			while (iswhite(*text))
				++text;
			add_flow_space(ctx, flow, &box->style);
		}
		if (*text)
		{
			const char *mark = text++;
			while (*text && !iswhite(*text))
				++text;
			add_flow_word(ctx, flow, &box->style, mark, text);
		}
	}
}
Exemple #3
0
static void generate_text(fz_context *ctx, fz_pool *pool, fz_html *box, const char *text)
{
    fz_html *flow;

    int collapse = box->style.white_space & WS_COLLAPSE;
    int bsp = box->style.white_space & WS_ALLOW_BREAK_SPACE;
    int bnl = box->style.white_space & WS_FORCE_BREAK_NEWLINE;

    flow = box;
    while (flow->type != BOX_FLOW)
        flow = flow->up;

    while (*text)
    {
        if (bnl && (*text == '\n' || *text == '\r'))
        {
            if (text[0] == '\r' && text[1] == '\n')
                text += 2;
            else
                text += 1;
            add_flow_break(ctx, pool, flow, &box->style);
        }
        else if (iswhite(*text))
        {
            const char *mark = text++;
            if (collapse)
                while (iswhite(*text))
                    ++text;
            /* TODO: tabs */
            if (bsp)
                add_flow_glue(ctx, pool, flow, &box->style, " ", 1);
            else
                add_flow_word(ctx, pool, flow, &box->style, mark, text);
        }
        else
        {
            const char *mark = text;
            int c, addglue = 0;
            while (*text && !iswhite(*text))
            {
                /* TODO: Unicode Line Breaking Algorithm (UAX #14) */
                text += fz_chartorune(&c, text);
                if (iscjk(c))
                {
                    int cat = ucdn_get_general_category(c);
                    if (addglue && !not_at_bol(cat, c))
                        add_flow_glue(ctx, pool, flow, &box->style, "", 0);
                    add_flow_word(ctx, pool, flow, &box->style, mark, text);
                    if (!not_at_eol(cat, c))
                        addglue = 1;
                    mark = text;
                }
                else
                {
                    addglue = 0;
                }
            }
            if (mark != text)
                add_flow_word(ctx, pool, flow, &box->style, mark, text);
        }
    }
}