c++/c fixes
[swftools.git] / pdf2swf / pdf2swf.cc
index a87c6e2..c943c69 100644 (file)
@@ -33,9 +33,7 @@
 #endif
 #include "../lib/args.h"
 #include "SWFOutputDev.h"
-extern "C" {
 #include "log.h"
-}
 
 #ifndef WIN32
 #define FONTDIR SWFTOOLS_DATADIR "/fonts"
@@ -344,7 +342,7 @@ void args_callback_usage(char*name)
 }
 
 #ifdef HAVE_DIRENT_H
-void addfontdir(char* dirname, int*numfonts)
+static void addfontdir(char* dirname, int*numfonts)
 {
     if(!numfonts)
        msg("<verbose> Adding %s to search path\n", dirname);
@@ -354,7 +352,7 @@ void addfontdir(char* dirname, int*numfonts)
        msg("<warning> Couldn't open directory %s\n", dirname);
        return;
     }
-    dirent*ent;
+    struct dirent*ent;
     while(1) {
        ent = readdir (dir);
        if (!ent) 
@@ -393,7 +391,7 @@ void addfontdir(char* dirname, int*numfonts)
 }
 #endif
 
-char* stripfilename(char*filename, char*newext)
+static char* stripfilename(char*filename, char*newext)
 {
     char*last1 = strrchr(filename, '/');
     char*last2 = strrchr(filename, '\\');
@@ -483,18 +481,29 @@ int main(int argn, char *argv[])
     msg("<error> Couldn't find any fonts!");
 #endif
 
-    pdfswf_init(filename, password);
-    pdfswf_setoutputfilename(outputname);
+    pdf_doc_t* pdf = pdf_init(filename, password);
+    if(!pdf) {
+        msg("<error> Couldn't open %s", filename);
+        exit(1);
+    }
+    swf_output_t* swf = swf_output_init();
 
-    int pages = pdfswf_numpages();
-    for(t = 1; t <= pages; t++) 
+    for(t = 1; t <= pdf->num_pages; t++) 
     {
-       if(is_in_range(t, pagerange))
-       pdfswf_convertpage(t);
+       if(is_in_range(t, pagerange)) {
+            /* for links: FIXME */
+            pdfswf_preparepage(t);
+        }
+       if(is_in_range(t, pagerange)) {
+            pdf_page_t*page = pdf_getpage(pdf, t);
+           pdf_page_render(page, swf);
+            pdf_page_destroy(page);
+        }
     }
-    pdfswf_performconversion();
+    swf_output_save(swf, outputname);
+    swf_output_destroy(swf);
 
-    pdfswf_close();
+    pdf_destroy(pdf);
 
     if(viewer || preloader) {
 #ifndef SYSTEM_BACKTICKS
@@ -529,4 +538,3 @@ int main(int argn, char *argv[])
     return 0;
 }
 
-