コード例 #1
0
zathura_error_t
pdf_document_attachment_save(zathura_document_t* document,
    PopplerDocument* poppler_document, const char* attachmentname, const char* file)
{
  if (document == NULL || poppler_document == NULL) {
    return ZATHURA_ERROR_INVALID_ARGUMENTS;
  }

  if (poppler_document_has_attachments(poppler_document) == FALSE) {
    girara_warning("PDF file has no attachments");
    return ZATHURA_ERROR_INVALID_ARGUMENTS;
  }


  GList* attachment_list = poppler_document_get_attachments(poppler_document);
  GList* attachments;

  for (attachments = attachment_list; attachments; attachments = g_list_next(attachments)) {
    PopplerAttachment* attachment = (PopplerAttachment*) attachments->data;
    if (g_strcmp0(attachment->name, attachmentname) != 0) {
      continue;
    }

    return poppler_attachment_save(attachment, file, NULL);
  }

  return ZATHURA_ERROR_OK;
}
コード例 #2
0
ファイル: test-document.c プロジェクト: kou/poppler-test
void
test_attachment_save (void)
{
  GList *attachments, *node;

  document = load_document ("attachment.pdf");
  cut_assert_true (poppler_document_has_attachments (document));

  attachments = poppler_document_get_attachments (document);
  gcut_take_list (attachments, attachment_unref);
  for (node = attachments; node; node = g_list_next (node))
    {
      PopplerAttachment *attachment = node->data;
      const gchar *filename;
      gchar *contents;
      const gchar *expected_contents;
      GError *error = NULL;

      filename = cut_take_string (g_build_filename (tmp_dir,
                                                    attachment->name,
                                                    NULL));
      poppler_attachment_save (attachment, filename, &error);
      gcut_assert_error (error);

      g_file_get_contents (filename, &contents, NULL, &error);
      gcut_assert_error (error);
      expected_contents = cut_get_fixture_data_string (attachment->name, NULL);
      cut_set_message ("%s", attachment->name);
      cut_assert_equal_string_with_free (expected_contents, contents);
    }
}
コード例 #3
0
girara_list_t*
pdf_document_attachments_get(zathura_document_t* document, void* data, zathura_error_t* error)
{
  if (document == NULL || data == NULL) {
    if (error != NULL) {
      *error = ZATHURA_ERROR_INVALID_ARGUMENTS;
    }
    return NULL;
  }

  PopplerDocument* poppler_document = data;
  if (poppler_document_has_attachments(poppler_document) == FALSE) {
    girara_warning("PDF file has no attachments");
    if (error != NULL) {
      *error = ZATHURA_ERROR_UNKNOWN;
    }
    return NULL;
  }

  girara_list_t* res = girara_sorted_list_new2((girara_compare_function_t) g_strcmp0, g_free);
  if (res == NULL) {
    if (error != NULL) {
      *error = ZATHURA_ERROR_OUT_OF_MEMORY;
    }
    return NULL;
  }

  GList* attachment_list = poppler_document_get_attachments(poppler_document);
  for (GList* attachments = attachment_list; attachments != NULL; attachments = g_list_next(attachments)) {
    PopplerAttachment* attachment = (PopplerAttachment*) attachments->data;
    girara_list_append(res, g_strdup(attachment->name));
  }

  return res;
}
コード例 #4
0
ファイル: test-document.c プロジェクト: kou/poppler-test
void
test_attachment (void)
{
  GList *expected = NULL, *actual;

  document = load_document ("attachment.pdf");
  cut_assert_true (poppler_document_has_attachments (document));

  expected = g_list_append (expected,
                            attachment_new ("hello.html", "hello.html", 300,
                                            0, 0, NULL));
  expected = g_list_append (expected,
                            attachment_new ("hello.txt", "hello.txt", 13,
                                            0, 0, NULL));

  actual = poppler_document_get_attachments (document);
  gcut_take_list (expected, attachment_unref);
  gcut_take_list (actual, attachment_unref);
  gcut_assert_equal_list (expected,
                          actual,
                          attachment_equal,
                          attachment_inspect,
                          NULL);
}
コード例 #5
0
ファイル: test-document.c プロジェクト: kou/poppler-test
void
test_no_attachment (void)
{
  document = load_document ("empty.pdf");
  cut_assert_false (poppler_document_has_attachments (document));
}
コード例 #6
0
static VALUE
rg_has_attachments_p(VALUE self)
{
    return CBOOL2RVAL(poppler_document_has_attachments(RVAL2DOC(self)));
}