Ejemplo n.º 1
0
fz_outline *
pdf_load_outline(pdf_document *xref)
{
	pdf_obj *root, *obj, *first;

	root = pdf_dict_gets(xref->trailer, "Root");
	obj = pdf_dict_gets(root, "Outlines");
	first = pdf_dict_gets(obj, "First");
	if (first)
		return pdf_load_outline_imp(xref, first);

	return NULL;
}
Ejemplo n.º 2
0
fz_outline *
pdf_load_outline(fz_context *ctx, pdf_document *doc)
{
    pdf_obj *root, *obj, *first;

    root = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root);
    obj = pdf_dict_get(ctx, root, PDF_NAME_Outlines);
    first = pdf_dict_get(ctx, obj, PDF_NAME_First);
    if (first)
        return pdf_load_outline_imp(ctx, doc, first);

    return NULL;
}
Ejemplo n.º 3
0
fz_outline *
pdf_load_outline(pdf_xref *xref)
{
    fz_obj *root, *obj, *first;
    fz_context *ctx = xref->ctx;

    root = fz_dict_gets(ctx, xref->trailer, "Root");
    obj = fz_dict_gets(ctx, root, "Outlines");
    first = fz_dict_gets(ctx, obj, "First");
    if (first)
        return pdf_load_outline_imp(xref, first);

    return NULL;
}
Ejemplo n.º 4
0
fz_outline *
pdf_load_outline(fz_context *ctx, pdf_document *doc)
{
	pdf_obj *root, *obj, *first;
	fz_outline *outline = NULL;

	pdf_load_page_tree(ctx, doc); /* cache page tree for fast link destination lookups */
	fz_try(ctx)
	{
		root = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root);
		obj = pdf_dict_get(ctx, root, PDF_NAME_Outlines);
		first = pdf_dict_get(ctx, obj, PDF_NAME_First);
		if (first)
			outline = pdf_load_outline_imp(ctx, doc, first);
	}
	fz_always(ctx)
		pdf_drop_page_tree(ctx, doc);
	fz_catch(ctx)
		fz_rethrow(ctx);

	return outline;
}
Ejemplo n.º 5
0
static fz_outline *
pdf_load_outline_imp(pdf_xref *xref, fz_obj *dict)
{
    pdf_link *link;
    fz_outline *node;
    fz_obj *obj;
    /* SumatraPDF: prevent potential stack overflow */
    fz_outline *prev, *root = NULL;
    fz_obj *origDict = dict;
    fz_context *ctx = xref->ctx;

    if (fz_is_null(ctx, dict))
        return NULL;

    /* SumatraPDF: prevent cyclic outlines */
    do
    {
        if (fz_dict_gets(ctx, dict, ".seen"))
            break;
        obj = fz_new_null(ctx);
        fz_dict_puts(ctx, dict, ".seen", obj);
        fz_drop_obj(ctx, obj);

        node = fz_malloc(ctx, sizeof(fz_outline));
        node->title = NULL;
        node->page = -1;
        node->down = NULL;
        node->next = NULL;

        obj = fz_dict_gets(ctx, dict, "Title");
        if (obj)
            node->title = pdf_to_utf8(ctx, obj);

        /* SumatraPDF: support expansion states */
        node->is_open = fz_to_int(ctx, fz_dict_gets(ctx, dict, "Count")) >= 0;
        /* SumatraPDF: extended outline actions */
        node->data = node->free_data = NULL;

        if (fz_dict_gets(ctx, dict, "Dest") || fz_dict_gets(ctx, dict, "A"))
        {
            link = pdf_load_link(xref, dict);
            if (link) /* SumatraPDF: don't crash if it's no link after all */
            {
                if (link->kind == PDF_LINK_GOTO)
                    node->page = pdf_find_page_number(xref, fz_array_get(ctx, link->dest, 0));
                /* SumatraPDF: extended outline actions */
                node->data = link;
                node->free_data = pdf_free_link;
            }
        }

        obj = fz_dict_gets(ctx, dict, "First");
        if (obj)
            node->down = pdf_load_outline_imp(xref, obj);

        /* SumatraPDF: prevent potential stack overflow */
        if (!root)
            prev = root = node;
        else
            prev = prev->next = node;

        dict = fz_dict_gets(ctx, dict, "Next");
    } while (dict && !fz_is_null(ctx, dict));
    node = root;
    /* SumatraPDF: prevent cyclic outlines */
    for (dict = origDict; dict && fz_dict_gets(ctx, dict, ".seen"); dict = fz_dict_gets(ctx, dict, "Next"))
        fz_dict_dels(ctx, dict, ".seen");

    return node;
}
Ejemplo n.º 6
0
static fz_outline *
pdf_load_outline_imp(fz_context *ctx, pdf_document *doc, pdf_obj *dict)
{
    fz_outline *node, **prev, *first;
    pdf_obj *obj;
    pdf_obj *odict = dict;

    fz_var(dict);
    fz_var(first);

    fz_try(ctx)
    {
        first = NULL;
        prev = &first;
        while (dict && pdf_is_dict(ctx, dict))
        {
            if (pdf_mark_obj(ctx, dict))
                break;
            node = fz_new_outline(ctx);
            *prev = node;
            prev = &node->next;

            obj = pdf_dict_get(ctx, dict, PDF_NAME_Title);
            if (obj)
                node->title = pdf_to_utf8(ctx, obj);

            if ((obj = pdf_dict_get(ctx, dict, PDF_NAME_Dest)) != NULL)
                node->uri = pdf_parse_link_dest(ctx, doc, obj);
            else if ((obj = pdf_dict_get(ctx, dict, PDF_NAME_A)) != NULL)
                node->uri = pdf_parse_link_action(ctx, doc, obj);
            else
                node->uri = NULL;

            if (node->uri)
                node->page = pdf_resolve_link(ctx, doc, node->uri, NULL, NULL);
            else
                node->page = -1;

            obj = pdf_dict_get(ctx, dict, PDF_NAME_First);
            if (obj)
            {
                node->down = pdf_load_outline_imp(ctx, doc, obj);

                obj = pdf_dict_get(ctx, dict, PDF_NAME_Count);
                if (pdf_to_int(ctx, obj) > 0)
                    node->is_open = 1;
            }

            dict = pdf_dict_get(ctx, dict, PDF_NAME_Next);
        }
    }
    fz_always(ctx)
    {
        for (dict = odict; dict && pdf_obj_marked(ctx, dict); dict = pdf_dict_get(ctx, dict, PDF_NAME_Next))
            pdf_unmark_obj(ctx, dict);
    }
    fz_catch(ctx)
    {
        fz_drop_outline(ctx, first);
        fz_rethrow(ctx);
    }

    return first;
}