Esempio n. 1
0
static void insert_inline_box(fz_context *ctx, fz_pool *pool, fz_html *box, fz_html *top)
{
    if (top->type == BOX_BLOCK)
    {
        if (top->last && top->last->type == BOX_FLOW)
        {
            insert_box(ctx, box, BOX_INLINE, top->last);
        }
        else
        {
            fz_html *flow = new_box(ctx, pool);
            flow->is_first_flow = !top->last;
            insert_box(ctx, flow, BOX_FLOW, top);
            insert_box(ctx, box, BOX_INLINE, flow);
        }
    }
    else if (top->type == BOX_FLOW)
    {
        insert_box(ctx, box, BOX_INLINE, top);
    }
    else if (top->type == BOX_INLINE)
    {
        insert_box(ctx, box, BOX_INLINE, top);
    }
}
Esempio n. 2
0
static fz_html *insert_break_box(fz_context *ctx, fz_html *box, fz_html *top)
{
    if (top->type == BOX_BLOCK)
    {
        insert_box(ctx, box, BOX_BREAK, top);
    }
    else if (top->type == BOX_FLOW)
    {
        while (top->type != BOX_BLOCK)
            top = top->up;
        insert_box(ctx, box, BOX_BREAK, top);
    }
    else if (top->type == BOX_INLINE)
    {
        while (top->type != BOX_BLOCK)
            top = top->up;
        insert_box(ctx, box, BOX_BREAK, top);
    }
    return top;
}
Esempio n. 3
0
static void generate_boxes(fz_context *ctx, fz_pool *pool,
                           fz_html_font_set *set, fz_archive *zip, const char *base_uri,
                           fz_xml *node, fz_html *top, fz_css_rule *rule, fz_css_match *up_match, int list_counter)
{
    fz_css_match match;
    fz_html *box;
    const char *tag;
    int display;

    while (node)
    {
        match.up = up_match;
        match.count = 0;

        tag = fz_xml_tag(node);
        if (tag)
        {
            fz_match_css(ctx, &match, rule, node);

            display = fz_get_css_match_display(&match);

            if (!strcmp(tag, "br"))
            {
                if (top->type == BOX_INLINE)
                {
                    fz_html *flow = top;
                    while (flow->type != BOX_FLOW)
                        flow = flow->up;
                    add_flow_break(ctx, pool, flow, &top->style);
                }
                else
                {
                    box = new_box(ctx, pool);
                    fz_apply_css_style(ctx, set, &box->style, &match);
                    top = insert_break_box(ctx, box, top);
                }
            }

            else if (!strcmp(tag, "img"))
            {
                const char *src = fz_xml_att(node, "src");
                if (src)
                {
                    box = new_box(ctx, pool);
                    fz_apply_css_style(ctx, set, &box->style, &match);
                    insert_inline_box(ctx, pool, box, top);
                    generate_image(ctx, pool, zip, base_uri, box, src);
                }
            }

            else if (display != DIS_NONE)
            {
                box = new_box(ctx, pool);
                fz_apply_css_style(ctx, set, &box->style, &match);

                if (display == DIS_BLOCK || display == DIS_INLINE_BLOCK)
                {
                    top = insert_block_box(ctx, box, top);
                }
                else if (display == DIS_LIST_ITEM)
                {
                    top = insert_block_box(ctx, box, top);
                    box->list_item = ++list_counter;
                }
                else if (display == DIS_INLINE)
                {
                    insert_inline_box(ctx, pool, box, top);
                }
                else
                {
                    fz_warn(ctx, "unknown box display type");
                    insert_box(ctx, box, BOX_BLOCK, top);
                }

                if (fz_xml_down(node))
                {
                    int child_counter = list_counter;
                    if (!strcmp(tag, "ul") || !strcmp(tag, "ol"))
                        child_counter = 0;
                    generate_boxes(ctx, pool, set, zip, base_uri, fz_xml_down(node), box, rule, &match, child_counter);
                }

                // TODO: remove empty flow boxes
            }
        }
        else
        {
            if (top->type != BOX_INLINE)
            {
                /* Create anonymous inline box, with the same style as the top block box. */
                box = new_box(ctx, pool);
                insert_inline_box(ctx, pool, box, top);
                box->style = top->style;
                /* Make sure not to recursively multiply font sizes. */
                box->style.font_size.value = 1;
                box->style.font_size.unit = N_SCALE;
                generate_text(ctx, pool, box, fz_xml_text(node));
            }
            else
            {
                generate_text(ctx, pool, top, fz_xml_text(node));
            }
        }

        node = fz_xml_next(node);
    }
}
Esempio n. 4
0
static void generate_boxes(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri,
	fz_xml *node, fz_html *top, fz_css_rule *rule, fz_css_match *up_match)
{
	fz_css_match match;
	fz_html *box;
	const char *tag;
	int display;

	while (node)
	{
		match.up = up_match;
		match.count = 0;

		tag = fz_xml_tag(node);
		if (tag)
		{
			fz_match_css(ctx, &match, rule, node);

			display = fz_get_css_match_display(&match);

			if (!strcmp(tag, "br"))
			{
				box = new_box(ctx);
				fz_apply_css_style(ctx, set, &box->style, &match);
				top = insert_break_box(ctx, box, top);
			}

			else if (!strcmp(tag, "img"))
			{
				const char *src = fz_xml_att(node, "src");
				if (src)
				{
					box = new_box(ctx);
					fz_apply_css_style(ctx, set, &box->style, &match);
					insert_inline_box(ctx, box, top);
					generate_image(ctx, zip, base_uri, box, src);
				}
			}

			else if (display != DIS_NONE)
			{
				box = new_box(ctx);
				fz_apply_css_style(ctx, set, &box->style, &match);

				if (display == DIS_BLOCK)
				{
					top = insert_block_box(ctx, box, top);
				}
				else if (display == DIS_LIST_ITEM)
				{
					top = insert_block_box(ctx, box, top);
				}
				else if (display == DIS_INLINE)
				{
					insert_inline_box(ctx, box, top);
				}
				else
				{
					fz_warn(ctx, "unknown box display type");
					insert_box(ctx, box, BOX_BLOCK, top);
				}

				if (fz_xml_down(node))
					generate_boxes(ctx, set, zip, base_uri, fz_xml_down(node), box, rule, &match);

				// TODO: remove empty flow boxes
			}
		}
		else
		{
			if (top->type != BOX_INLINE)
			{
				box = new_box(ctx);
				insert_inline_box(ctx, box, top);
				box->style = top->style;
				generate_text(ctx, box, fz_xml_text(node));
			}
			else
			{
				generate_text(ctx, top, fz_xml_text(node));
			}
		}

		node = fz_xml_next(node);
	}
}
Esempio n. 5
0
void tex::fire_up(ptr c)
	{
	int	n;
	bool	wait;
	ptr	prev_p;
	scal	save_vfuzz;
	int	save_vbadness;
	ptr	save_split_top_skip;
	ptr	p, q, r;

	if (type(best_page_break) == PENALTY_NODE) {
		set_output_penalty(penalty(best_page_break));
		penalty(best_page_break) = INF_PENALTY;
	} else {
		set_output_penalty(INF_PENALTY);
	}
	if (bot_mark != null) {
		if (top_mark != null)
			delete_token_ref(top_mark);
		top_mark = bot_mark;
		add_token_ref(top_mark);
		delete_token_ref(first_mark);
		first_mark = null;
	}
	if (c == best_page_break) {
		best_page_break = null;
	}
	if (box(255) != null) {
		print_err(null_str);
		print_esc("box");
		print("255 is not void");
		help_box_255();
		box_error(255);
	}
	insert_penalties = 0;
	save_split_top_skip = split_top_skip;
	if (holding_inserts <= 0) {
		r = link(page_ins_head);
		while (r != page_ins_head) {
			if (best_ins_ptr(r) != null) {
				n = subtype(r);
				ensure_vbox(n);
				if (box(n) == null)
					box(n) = new_null_box();
				p = node_list(box(n));
				while (link(p) != null) {
					p = link(p);
				}
				last_ins_ptr(r) = p;
			}
			r = link(r);
		}
	}
	q = hold_head;
	link(q) = null;
	prev_p = page_head;
	p = link(prev_p);
	while (p != best_page_break) {
		if (type(p) == INS_NODE) {
			if (holding_inserts <= 0) {
				wait = insert_box(p);
				link(prev_p) = link(p);
				link(p) = null;
				if (wait) {
					q = link(q) = p;
					incr(insert_penalties);
				} else {
					delete_glue_ref(split_top_ptr(p));
					free_node(p, INS_NODE_SIZE);
				}
				p = prev_p;
			}
		} else if (type(p) == MARK_NODE) {
			if (first_mark == null) {
				first_mark = mark_ptr(p);
				add_token_ref(first_mark);
			}
			if (bot_mark != null)
				delete_token_ref(bot_mark);
			bot_mark = mark_ptr(p);
			add_token_ref(bot_mark);
		}
		prev_p = p;
		p = link(prev_p);
	}
	split_top_skip = save_split_top_skip;
	if (p != null) {
		if (link(contrib_head) == null) {
			if (nest_ptr == nest) {
				tail = page_tail;
			} else {
				contrib_tail = page_tail;
			}
		}
		link(page_tail) = link(contrib_head);
		link(contrib_head) = p;
		link(prev_p) = null;
	}
	save_vbadness = vbadness;
	save_vfuzz = vfuzz;
	vbadness = INF_BAD;
	vfuzz = MAX_DIMEN;
	box(255) = vpackage(link(page_head),
		best_size, EXACTLY, page_max_depth);
	vbadness = save_vbadness;
	vfuzz = save_vfuzz;
	if (last_glue != null)
		delete_glue_ref(last_glue);
	start_new_page();
	if (q != hold_head) {
		link(page_head) = link(hold_head);
		page_tail = q;
	}
	r = link(page_ins_head);
	while (r != page_ins_head) {
		q = link(r);
		free_node(r, PAGE_INS_NODE_SIZE);
		r = q;
	}
	link(page_ins_head) = page_ins_head;
	if (top_mark != null && first_mark == null) {
		first_mark = top_mark;
		add_token_ref(top_mark);
	}
	if (output_routine != null) {
		if (dead_cycles >= max_dead_cycles) {
			print_err("Output loop---");
			print_int(dead_cycles);
			print(" consecutive dead cycles");
			help_dead_cycles();
			error();
		} else {
			output_active = TRUE;
			incr(dead_cycles);
			push_nest();
			mode = -VMODE;
			prev_depth = IGNORE_DEPTH;
			mode_line = -line;
			begin_token_list(output_routine, OUTPUT_TEXT);
			new_save_level(OUTPUT_GROUP);
			normal_paragraph();
			scan_left_brace();
			return;
		}
	}
	if (link(page_head) != null) {
		if (link(contrib_head) == null) {
			if (nest_ptr == nest) {
				tail = page_tail;
			} else {
				contrib_tail = page_tail;
			}
		} else {
			link(page_tail) = link(contrib_head);
		}
		link(contrib_head) = link(page_head);
		link(page_head) = null;
		page_tail = page_head;
	}
	ship_out(box(255));
	box(255) = null;
}