+ if (p->page_style->include_outline)
+ {
+ cairo_tag_end (p->cr, CAIRO_TAG_DEST);
+
+ if (chunk && p->slice_idx++ == 0)
+ {
+ char *attrs = xasprintf ("dest='%s'", dest_name);
+
+ int parent_group_id = (p->n_group_ids
+ ? p->group_ids[p->n_group_ids - 1]
+ : CAIRO_PDF_OUTLINE_ROOT);
+ for (size_t i = 0; i < p->n_opens; i++)
+ {
+ parent_group_id = add_outline (
+ p->cr, parent_group_id,
+ p->group_opens[i]->command_name, attrs,
+ CAIRO_PDF_OUTLINE_FLAG_OPEN);
+ group_open_item_unref (p->group_opens[i]);
+
+ if (p->n_group_ids >= p->allocated_group_ids)
+ p->group_ids = x2nrealloc (p->group_ids,
+ &p->allocated_group_ids,
+ sizeof *p->group_ids);
+ p->group_ids[p->n_group_ids++] = parent_group_id;
+ }
+ p->n_opens = 0;
+
+ const char *text;
+ if (is_table_item (p->item))
+ {
+ const struct table_item_text *title
+ = table_item_get_title (to_table_item (p->item));
+ text = title ? title->content : "Table";
+ }
+ else if (is_chart_item (p->item))
+ {
+ const char *title
+ = chart_item_get_title (to_chart_item (p->item));
+ text = title ? title : "Chart";
+ }
+ else
+ text = (is_page_eject_item (p->item) ? "Page Break"
+ : is_page_setup_item (p->item) ? "Page Setup"
+ : is_message_item (p->item) ? "Message"
+ : is_text_item (p->item) ? "Text"
+ : NULL);
+ if (text)
+ add_outline (p->cr, parent_group_id, text, attrs, 0);
+ free (attrs);
+ }
+ free (dest_name);
+ }
+