#endif
#include "../lib/args.h"
#include "SWFOutputDev.h"
-extern "C" {
#include "log.h"
-}
#ifndef WIN32
#define FONTDIR SWFTOOLS_DATADIR "/fonts"
printf("-L --preloader=filename Link preloader \"name\" to the pdf (\"%s -L\" for list)\n",name);
}
-#ifdef HAVE_DIRENT_H
-void addfontdir(char* dirname, int*numfonts)
-{
- if(!numfonts)
- msg("<verbose> Adding %s to search path\n", dirname);
-
- DIR*dir = opendir(dirname);
- if(!dir) {
- msg("<warning> Couldn't open directory %s\n", dirname);
- return;
- }
- dirent*ent;
- while(1) {
- ent = readdir (dir);
- if (!ent)
- break;
- int l;
- char*name = ent->d_name;
- char type = 0;
- if(!name) continue;
- l=strlen(name);
- if(l<4)
- continue;
- if(!strncasecmp(&name[l-4], ".pfa", 4))
- type=1;
- if(!strncasecmp(&name[l-4], ".pfb", 4))
- type=3;
- if(!strncasecmp(&name[l-4], ".ttf", 4))
- type=2;
- if(type)
- {
- char*fontname = (char*)malloc(strlen(dirname)+strlen(name)+2);
- strcpy(fontname, dirname);
-#ifdef WIN32
- strcat(fontname, "\\");
-#else
- strcat(fontname, "/");
-#endif
- strcat(fontname, name);
- if(!numfonts)
- msg("<debug> Adding %s to fonts", fontname);
- pdfswf_addfont(fontname);
- if(numfonts)
- (*numfonts)++;
- }
- }
- closedir(dir);
-}
-#endif
-
-char* stripfilename(char*filename, char*newext)
+static char* stripfilename(char*filename, char*newext)
{
char*last1 = strrchr(filename, '/');
char*last2 = strrchr(filename, '\\');
exit(0);
}
-#ifdef HAVE_DIRENT_H
- // pass 1
- addfontdir(FONTDIR, &numfonts);
+ /* add fonts */
+ pdfswf_addfontdir(FONTDIR);
for(t=0;t<fontpathpos;t++) {
- addfontdir(fontpaths[t], &numfonts);
+ pdfswf_addfontdir(fontpaths[t]);
}
- // pass 2
- addfontdir(FONTDIR, 0);
- for(t=0;t<fontpathpos;t++) {
- addfontdir(fontpaths[t], 0);
- }
-#else
- msg("<error> Couldn't find any fonts!");
-#endif
-
- pdfswf_init(filename, password);
- pdfswf_setoutputfilename(outputname);
- int pages = pdfswf_numpages();
- for(t = 1; t <= pages; t++)
- {
- if(is_in_range(t, pagerange))
- pdfswf_convertpage(t);
+ pdf_doc_t* pdf = pdf_init(filename, password);
+ if(!pdf) {
+ msg("<error> Couldn't open %s", filename);
+ exit(1);
}
- pdfswf_performconversion();
+ swf_output_t* swf = swf_output_init();
- pdfswf_close();
+ for(t = 1; t <= pdf->num_pages; 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);
+ }
+ }
+ if(!swf_output_save(swf, outputname))
+ exit(1);
+ swf_output_destroy(swf);
+
+ pdf_destroy(pdf);
if(viewer || preloader) {
#ifndef SYSTEM_BACKTICKS
return 0;
}
-