]> granicus.if.org Git - graphviz/commitdiff
work in progress
authorJohn Ellson <ellson@research.att.com>
Mon, 1 Jul 2013 04:04:41 +0000 (00:04 -0400)
committerJohn Ellson <ellson@research.att.com>
Mon, 1 Jul 2013 04:04:41 +0000 (00:04 -0400)
plugin/poppler/Makefile.test
plugin/poppler/gvloadimage_poppler.c
plugin/poppler/pdftoimage.c
plugin/poppler/pdftops.c

index c652719c7927b442bcfd452d71d56fad8e3ded29..63734afa100dbcc32fccda1d34aa054636318c78 100644 (file)
@@ -1,11 +1,17 @@
 CFLAGS=`pkg-config --cflags cairo poppler-glib`
 LDFLAGS=`pkg-config --libs cairo poppler-glib`
 
-all: pdftops pdftoimage
+all: pdftops pdftoimage hello.png
 
 pdftops: pdftops.c
 
 pdftoimage: pdftoimage.c
 
+hello.png: pdftoimage hello.pdf
+       ./pdftoimage hello.pdf hello.png 1
+
+hello.pdf:
+       echo 'digraph {hello->world}' | dot -Tpdf -o hello.pdf
+
 clean:
-       rm -f pdftops pdftoimage
+       rm -f pdftops pdftoimage hello.*
index 601480fd81eee28f023bc95a1ef5aecbb61b2a41..39f56b61b6797edffb63c40e47adb6b0279fdfae 100644 (file)
 
 #include "gvplugin_loadimage.h"
 
-// NOT YET
+// not ready yet
 #undef HAVE_POPPLER
 
-
 #ifdef HAVE_POPPLER
 #ifdef HAVE_PANGOCAIRO
-#include <ghostscript/iapi.h>
-#include <ghostscript/ierrors.h>
+#include <poppler.h>
 #include <cairo/cairo.h>
 
 #ifdef WIN32
@@ -61,6 +59,7 @@ static void gvloadimage_poppler_free(usershape_t *us)
     free(poppler);
 }
 
+#if 0
 static int poppler_writer(void *caller_handle, const char *str, int len)
 {
     GVJ_t *job = (GVJ_t*)caller_handle;
@@ -88,19 +87,53 @@ static void poppler_error(GVJ_t * job, const char *name, const char *funstr, int
     job->common->errorfn("%s: %s() returned: %d \"%s\" (%s)\n",
                name, funstr, err, poppler_error_names[-err - 1], errsrc);
 }
+#endif
 
 static int gvloadimage_process_file(GVJ_t *job, usershape_t *us, void *instance)
 {
     int rc = 0, exit_code;
+    gchar *absolute, *ura, *dir;
+    PopplerDocument *document;
+    PopplerPage *page;
+    GError *error;
+    int num_pages;
 
     if (! gvusershape_file_access(us)) {
        job->common->errorfn("Failure to read shape file\n");
        return -1;
     }
-    rc = popplerapi_run_file(instance, us->name, -1, &exit_code);
-    if (rc) {
-       poppler_error(job, us->name, "popplerapi_run_file", rc);
+    if (g_path_is_absolute(pdf_file)) {
+        absolute = g_strdup (pdf_file);
+    } else {
+       dir = g_get_current_dir ();
+       absolute = g_build_filename (dir, pdf_file, (gchar *) 0);
+       free (dir);
+    }
+
+    uri = g_filename_to_uri (absolute, NULL, &error);
+    free (absolute);
+    if (uri == NULL) {
+        printf("%s\n", error->message);
+        return 1;
     }
+                   }
+    document = poppler_document_new_from_file (uri, NULL, &error);
+    if (document == NULL) {
+       printf("%s\n", error->message);
+       return 1;
+    }
+    num_pages = poppler_document_get_n_pages (document);
+    if (page_num < 1) {
+       printf("must be at least one page in the pdf\n");
+       return 1;
+    }
+
+    page = poppler_document_get_page (document, 1);
+    if (page == NULL) {
+       printf("poppler fail: page 1 not found\n");
+       return 1;
+    }
+
     gvusershape_file_release(us);
     return rc;
 }
index a39e24cb458ce128487c7a2a8aaed103c13061fa..c0cbdc38e898a5e32689dbe0539f5e3670e4ae96 100644 (file)
@@ -39,6 +39,9 @@ int main(int argc, char *argv[])
     }
 
     uri = g_filename_to_uri (absolute, NULL, &error);
+
+    fprintf(stderr, "%s\n%s\n", absolute, uri);
+
     free (absolute);
     if (uri == NULL) {
         printf("%s\n", error->message);
index 035e0b8d8a4f40a89eda96891ceb4f03d2e3170a..610913bc7d0ce0ee623e8535722e0fe9553663b3 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdlib.h>
 #include <poppler.h>
 #include <cairo.h>
 #include <cairo-ps.h>