示例#1
0
文件: doc.c 项目: arsane/vipdf
static void
xv_doc_build_index(GtkTreeModel* model, GtkTreeIter* parent, PopplerIndexIter* index_iter)
{
    do {
        GtkTreeIter       tree_iter;
        PopplerIndexIter *child;
        PopplerAction    *action;
        gboolean          expand;
        gchar            *markup;

        action = poppler_index_iter_get_action(index_iter);
        expand = poppler_index_iter_is_open(index_iter);

        if(!action) {
            continue;
        }

        markup = g_markup_escape_text(action->any.title, -1);

        gtk_tree_store_append(GTK_TREE_STORE(model), &tree_iter, parent);
        gtk_tree_store_set(GTK_TREE_STORE(model), &tree_iter, 0, markup, 1, action, -1);
        g_object_weak_ref(G_OBJECT(model), (GWeakNotify) poppler_action_free, action);
        g_free(markup);

        child = poppler_index_iter_get_child(index_iter);
        if(child) {
            xv_doc_build_index(model, &tree_iter, child);
        }

        poppler_index_iter_free(child);
    } while(poppler_index_iter_next(index_iter));
}
示例#2
0
static VALUE
rg_initialize(VALUE self, VALUE document)
{
    PopplerIndexIter *iter;
    iter = poppler_index_iter_new(RVAL2POPPLERDOCUMENT(document));
    G_INITIALIZE(self, iter);
    poppler_index_iter_free(iter);
    rb_ivar_set(self, id_valid, CBOOL2RVAL(iter));
    return Qnil;
}
示例#3
0
static VALUE
rg_child(VALUE self)
{
    PopplerIndexIter *child;
    VALUE rb_child;

    CHECK_IITER_IS_VALID(self);
    child = poppler_index_iter_get_child(RVAL2IITER(self));
    rb_child = IITER2RVAL(child);
    poppler_index_iter_free(child);
    return rb_child;
}
示例#4
0
static VALUE
rg_child(VALUE self)
{
    PopplerIndexIter *child;
    VALUE rb_child;

    CHECK_IITER_IS_VALID(self);
    child = poppler_index_iter_get_child(RVAL2POPPLERINDEXITER(self));
    rb_child = POPPLERINDEXITER2RVAL(child);
    rb_ivar_set(rb_child, id_valid, CBOOL2RVAL(child));
    poppler_index_iter_free(child);
    return rb_child;
}
示例#5
0
static void
collect_action (PopplerIndexIter *iter)
{
  do
    {
      PopplerAction *action;
      PopplerIndexIter *child;

      action = poppler_index_iter_get_action (iter);
      actual_action_types = g_list_append (actual_action_types,
                                           GUINT_TO_POINTER (action->type));
      poppler_action_free (action);
      child = poppler_index_iter_get_child (iter);
      if (child)
	collect_action (child);
      poppler_index_iter_free (child);
    }
  while (poppler_index_iter_next (iter));
}
示例#6
0
文件: doc.c 项目: arsane/vipdf
GtkTreeModel *
xv_doc_get_index_tree_model (struct xv_doc_t *doc)
{
    PopplerIndexIter *index_iter;

    if (doc->model) {
        return doc->model;
    }

    index_iter = poppler_index_iter_new(doc->doc);
    if(index_iter) {
        doc->model = GTK_TREE_MODEL(gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER));
        xv_doc_build_index(doc->model, NULL, index_iter);
        poppler_index_iter_free(index_iter);
    } else {
        printf ("This document does not contain any index");
    }

    return doc->model;
}
示例#7
0
void
test_action (void)
{
  PopplerIndexIter *iter;

  document = load_document ("slide.pdf");
  iter = poppler_index_iter_new (document);
  cut_assert_not_null (iter);

  collect_action (iter);
  poppler_index_iter_free (iter);

#define APPEND(type)                                                    \
  expected_action_types =                                               \
    g_list_append (expected_action_types, GINT_TO_POINTER (type))

  APPEND(POPPLER_ACTION_GOTO_DEST);
  APPEND(POPPLER_ACTION_GOTO_DEST);
#undef APPEND

  gcut_assert_equal_list_enum (POPPLER_TYPE_ACTION_TYPE,
                               expected_action_types, actual_action_types);
}
示例#8
0
static void
read_toc (PopplerIndexIter  *index,
          GString          **toc)
{
	if (!index) {
		return;
	}

	if (!*toc) {
		*toc = g_string_new ("");
	}

	do {
		PopplerAction *action;
		PopplerIndexIter *iter;

		action = poppler_index_iter_get_action (index);

		if (!action) {
			continue;
		}

		switch (action->type) {
			case POPPLER_ACTION_GOTO_DEST: {
				PopplerActionGotoDest *ag = (PopplerActionGotoDest *)action;
				PopplerDest *agd = ag->dest;

				if (!tracker_is_empty_string (ag->title)) {
					g_string_append_printf (*toc, "%s ", ag->title);
				}

				if (!tracker_is_empty_string (agd->named_dest)) {
					g_string_append_printf (*toc, "%s ", agd->named_dest);
				}

				break;
			}

			case POPPLER_ACTION_LAUNCH: {
				PopplerActionLaunch *al = (PopplerActionLaunch *)action;

				if (!tracker_is_empty_string (al->title)) {
					g_string_append_printf (*toc, "%s ", al->title);
				}

				if (!tracker_is_empty_string (al->file_name)) {
					g_string_append_printf (*toc, "%s ", al->file_name);
				}

				if (!tracker_is_empty_string (al->params)) {
					g_string_append_printf (*toc, "%s ", al->params);
				}

				break;
			}

			case POPPLER_ACTION_URI: {
				PopplerActionUri *au = (PopplerActionUri *)action;

				if (!tracker_is_empty_string (au->uri)) {
					g_string_append_printf (*toc, "%s ", au->uri);
				}

				break;
			}

			case POPPLER_ACTION_NAMED: {
				PopplerActionNamed *an = (PopplerActionNamed *)action;

				if (!tracker_is_empty_string (an->title)) {
					g_string_append_printf (*toc, "%s, ", an->title);
				}

				if (!tracker_is_empty_string (an->named_dest)) {
					g_string_append_printf (*toc, "%s ", an->named_dest);
				}

				break;
			}

			case POPPLER_ACTION_MOVIE: {
				PopplerActionMovie *am = (PopplerActionMovie *)action;

				if (!tracker_is_empty_string (am->title)) {
					g_string_append_printf (*toc, "%s ", am->title);
				}

				break;
			}

			case POPPLER_ACTION_NONE:
			case POPPLER_ACTION_UNKNOWN:
			case POPPLER_ACTION_GOTO_REMOTE:
			case POPPLER_ACTION_RENDITION:
			case POPPLER_ACTION_OCG_STATE:
			case POPPLER_ACTION_JAVASCRIPT:
				/* Do nothing */
				break;
		}

		poppler_action_free (action);
		iter = poppler_index_iter_get_child (index);
		read_toc (iter, toc);
	} while (poppler_index_iter_next (index));

	poppler_index_iter_free (index);
}