Beispiel #1
0
static fz_outline *
pdf_load_outline_imp(pdf_document *xref, pdf_obj *dict)
{
	fz_context *ctx = xref->ctx;
	fz_outline *node, **prev, *first;
	pdf_obj *obj;
	pdf_obj *odict = dict;

	fz_var(dict);

	fz_try(ctx)
	{
		first = NULL;
		prev = &first;
		while (dict && pdf_is_dict(dict))
		{
			if (pdf_obj_mark(dict))
				break;
			node = fz_malloc_struct(ctx, fz_outline);
			node->title = NULL;
			node->dest.kind = FZ_LINK_NONE;
			node->down = NULL;
			node->next = NULL;
			*prev = node;
			prev = &node->next;

			obj = pdf_dict_gets(dict, "Title");
			if (obj)
				node->title = pdf_to_utf8(xref, obj);

			/* SumatraPDF: support expansion states */
			node->is_open = pdf_to_int(pdf_dict_gets(dict, "Count")) >= 0;

			if ((obj = pdf_dict_gets(dict, "Dest")))
				node->dest = pdf_parse_link_dest(xref, obj);
			else if ((obj = pdf_dict_gets(dict, "A")))
				node->dest = pdf_parse_action(xref, obj);

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

			dict = pdf_dict_gets(dict, "Next");
		}
	}
	fz_always(ctx)
	{
		for (dict = odict; dict && pdf_obj_marked(dict); dict = pdf_dict_gets(dict, "Next"))
			pdf_obj_unmark(dict);
	}
	fz_catch(ctx)
	{
		/* SumatraPDF: fix memory leak */
		fz_free_outline(ctx, first);
		fz_rethrow(ctx);
	}

	return first;
}
Beispiel #2
0
static void drawoutline(xps_context *ctx)
{
	fz_outline *outline = xps_load_outline(ctx);
	if (showoutline > 1)
		fz_debug_outline_xml(outline, 0);
	else
		fz_debug_outline(outline, 0);
	fz_free_outline(outline);
}
Beispiel #3
0
void
fz_free_outline(fz_context *ctx, fz_outline *outline)
{
    while (outline)
    {
        fz_outline *next = outline->next;
        fz_free_outline(ctx, outline->down);
        fz_free(ctx, outline->title);
        fz_free_link_dest(ctx, &outline->dest);
        fz_free(ctx, outline);
        outline = next;
    }
}
Beispiel #4
0
void muctx::CleanUp(void)
{
	fz_free_outline(mu_ctx, mu_outline);
	fz_close_document(mu_doc);
	page_cache->Empty(mu_ctx);
	fz_free_context(mu_ctx);

	delete page_cache;
	page_cache = NULL;
	this->mu_ctx = NULL;
	this->mu_doc = NULL;
	this->mu_outline = NULL;
}
Beispiel #5
0
/* Destructor */
muctx::~muctx(void)
{
	fz_free_outline(mu_ctx, mu_outline);
	fz_close_document(mu_doc);
	page_cache->Empty(mu_ctx);
	fz_free_context(mu_ctx);

	mu_ctx = NULL;
	mu_doc = NULL;
	mu_outline = NULL;
	delete page_cache;
	page_cache = NULL;
}
Beispiel #6
0
PDFDocument::PDFOutlineItem *PDFDocument::PDFOutlineItem::Build(
    fz_context *ctx, fz_outline *src) {
  PDFOutlineItem *root = nullptr;
  std::vector<std::unique_ptr<OutlineItem>> items;
  BuildRecursive(src, &items);
  fz_free_outline(ctx, src);
  if (items.empty()) {
    return nullptr;
  } else if (items.size() == 1) {
    root =  dynamic_cast<PDFOutlineItem *>(items[0].release());
  } else {
    root = new PDFOutlineItem(nullptr);
    root->_title = "TABLE OF CONTENTS";
    root->_children.swap(items);
  }
  return root;
}
Beispiel #7
0
MuPDFDoc::~MuPDFDoc()
{
	CoTaskMemFree(m_cts);
	if (m_outline)
	{
		fz_free_outline(m_context, m_outline);
		m_outline = nullptr;
	}
	if (m_document)
	{
		ClearPages();
		fz_close_document(m_document);
		m_document = nullptr;
	}
	if (m_context)
	{
		fz_free_context(m_context);
		m_context = nullptr;
	}
}