예제 #1
0
/*
** If arg is a file wildcard specification, then figure out all matches and pass
** each match, one by one, to k2_proc_arg.
*/
void k2pdfopt_proc_wildarg(K2PDFOPT_SETTINGS *k2settings,char *arg,int process,
                           K2PDFOPT_OUTPUT *k2out)

    {
    int i;

#if (WILLUSDEBUGX & 1)
printf("@k2pdfopt_proc_wildarg(%s)\n",arg);
#endif
    /* Init width to -1 */
    if (k2settings->preview_page!=0 && k2out->bmp!=NULL)
        k2out->bmp->width = -1;
    if (wfile_status(arg)==0)
        {
        FILELIST *fl,_fl;

        fl=&_fl;
        filelist_init(fl);
        filelist_fill_from_disk_1(fl,arg,0,0);
        if (fl->n==0)
            {
#ifdef HAVE_K2GUI
            if ((!k2gui_active() && process) || (k2gui_active() && !process))
#endif
            k2printf(TTEXT_WARN "\n** File or folder %s could not be opened. **\n\n" TTEXT_NORMAL,arg);
#ifdef HAVE_K2GUI
            if (process && k2gui_active())
                {
                char buf[512];
                sprintf(buf,"File or folder %s cannot be opened.",arg);
                if (k2settings->preview_page>0)
                    k2gui_alertbox(0,"File not found",buf);
                else
                    {
                    k2gui_cbox_increment_error_count();
                    k2gui_cbox_set_pages_completed(0,buf);
                    }
                }
#endif
            return;
            }
        for (i=0;i<fl->n;i++)
            {
            char fullname[512];
            wfile_fullname(fullname,fl->dir,fl->entry[i].name);
            k2pdfopt_proc_arg(k2settings,fullname,process,k2out);
            }
        }
    else
        k2pdfopt_proc_arg(k2settings,arg,process,k2out);
    }
예제 #2
0
/*
** Conversion thread.  This is launched as a separate thread to do the
** conversions while the dialog box displays the progress.
*/
static void k2gui_cbox_start_conversion(void *data)

    {
    void **ptrs;
    int i;
    K2PDFOPT_CONVERSION *k2conv;
    K2PDFOPT_SETTINGS *k2settings;
    K2PDFOPT_FILELIST_PROCESS k2listproc;
    static char *funcname="k2gui_cbox_start_conversion";

    ptrs=(void **)data;
    k2conv=(K2PDFOPT_CONVERSION *)ptrs[0];
    k2settings=&k2conv->k2settings;
    /*
    ** Count files
    */
    k2gui_cbox_set_num_files(1);
    k2gui_cbox_set_files_completed(0,"Counting files...");
    overwrite_set(1);
    for (i=k2listproc.filecount=0;i<k2conv->k2files.n;i++)
        {
        k2listproc.bmp=NULL;
        k2listproc.outname=NULL;
        k2listproc.mode=K2PDFOPT_FILELIST_PROCESS_MODE_GET_FILECOUNT;
        k2pdfopt_proc_wildarg(k2settings,k2conv->k2files.file[i],&k2listproc);
        willus_mem_free((double **)&k2listproc.outname,funcname);
        }
    if (k2listproc.filecount==0)
        {
        k2gui_cbox_set_files_completed(0,"No files");
        k2gui_alertbox(0,"No files","No files can be opened for conversion.");
        k2gui_cbox_conversion_thread_cleanup();
        return;
        }
    k2gui_cbox_set_num_files(k2listproc.filecount);
    k2gui_cbox_set_files_completed(0,NULL);
    /*
    ** Process files
    */
    k2gui_cbox_set_error_count(0);
    k2gui_cbox_freelist();
    overwrite_set(0);
    for (i=k2listproc.filecount=0;i<k2conv->k2files.n;i++)
        {
        char *buf;
        K2PDFOPT_CONVERSION *k2c;
        STRBUF *cmdline,_cmdline;

        willus_mem_alloc_warn((void **)&buf,1024,funcname,10);
        k2gui_cbox_set_num_pages(1);
        sprintf(buf,"Starting conversion of %s...",k2gui_short_name(k2conv->k2files.file[i]));
        k2gui_cbox_set_pages_completed(0,buf);
        willus_mem_alloc_warn((void **)&k2c,sizeof(K2PDFOPT_CONVERSION),funcname,10);
        k2pdfopt_conversion_init(k2c);
        cmdline=&_cmdline;
        strbuf_init(cmdline);
        k2gui_settings_to_cmdline(cmdline,&k2conv->k2settings);
        parse_cmd_args(k2c,k2gui->env,cmdline,&k2gui->cmdxtra,1,1);
        k2listproc.outname=NULL;
        k2listproc.bmp=NULL;
        k2listproc.mode=K2PDFOPT_FILELIST_PROCESS_MODE_CONVERT_FILES;
        k2pdfopt_proc_wildarg(&k2c->k2settings,k2conv->k2files.file[i],&k2listproc);
#if (WILLUSDEBUGX & 0x2000)
printf("\n\nDone conversion...\n\n");
#endif
        str0_addstring(&k2gui_cbox->filelist,&k2gui_cbox->filelist_na,k2listproc.outname);
        willus_mem_free((double **)&k2listproc.outname,funcname);
        k2pdfopt_conversion_close(k2c);
        willus_mem_free((double **)&k2c,funcname);
        willus_mem_free((double **)&buf,funcname);
        }
    k2gui_cbox_set_files_completed(k2listproc.filecount,NULL);
    if (k2listproc.filecount==k2conv->k2files.n && k2gui_cbox->error_count==0)
        k2gui_cbox->successful=1;
    k2gui_cbox_conversion_thread_cleanup();
    }
예제 #3
0
/*
** If arg is a folder, look for files inside of it for PDFs / DJVU files and process
** one by one, otherwise just process the passed argument.
**
** Processing file is two steps:
**     1. If auto-rotation is requested, determine the proper rotation of the file.
**     2. Process the file with the determined rotation.
**
*/
static void k2pdfopt_proc_arg(K2PDFOPT_SETTINGS *k2settings,char *arg,int process,
                              K2PDFOPT_OUTPUT *k2out)

    {
    char filename[MAXFILENAMELEN];
    int i;
    double rot;
    int autorot;

#if (WILLUSDEBUGX & 1)
printf("@k2pdfopt_proc_arg(%s)\n",arg);
printf("wfile_status(%s) = %d\n",arg,wfile_status(arg));
#endif
    strcpy(filename,arg);
    if (wfile_status(filename)==0)
        {
#ifdef HAVE_K2GUI
        if ((!k2gui_active() && process) || (k2gui_active() && !process))
#endif
        k2printf(TTEXT_WARN "\n** File or folder %s could not be opened. **\n\n" TTEXT_NORMAL,filename);
#ifdef HAVE_K2GUI
        if (process && k2gui_active())
            {
            char buf[512];
            k2gui_cbox_increment_error_count();
            sprintf(buf,"File %s cannot be opened.",filename);
            if (k2settings->preview_page>0)
                k2gui_alertbox(0,"File not found",buf);
            else
                k2gui_cbox_set_pages_completed(0,buf);
            }
#endif
        return;
        }
    if (k2settings->info) /* Info only? */
        autorot = 0;
    else if (k2settings->preview_page!=0)
        autorot = (fabs(k2settings->src_rot - SRCROT_AUTOPREV)<.5);
    else
        autorot = (fabs(k2settings->src_rot - SRCROT_AUTOPREV)<.5
                      || fabs(k2settings->src_rot - SRCROT_AUTO)<.5
                      || fabs(k2settings->src_rot - SRCROT_AUTOEP)<.5);
    /* If folder, first process all PDF/DJVU/PS files in the folder */
    if (wfile_status(filename)==2)
        {
        static char *eolist[]={""};
        static char *pdflist[]={"*.pdf","*.djvu","*.djv","*.ps","*.eps",""};
        static char *bmplist[]={"*.png","*.jpg",""};
        FILELIST *fl,_fl;
        FILELIST *fl2,_fl2;
        int nbmp;

        fl=&_fl;
        filelist_init(fl);
        filelist_fill_from_disk(fl,filename,pdflist,eolist,0,0);
        fl2=&_fl2;
        filelist_init(fl2);
        filelist_fill_from_disk(fl2,filename,bmplist,eolist,0,0);
        nbmp=fl2->n;
        filelist_free(fl2);
        if (fl->n>0)
            {
            for (i=0;i<fl->n;i++)
                {
                char fullname[512];

                wfile_fullname(fullname,filename,fl->entry[i].name);
                if (autorot)
                    {
                    if (process)
                        rot=k2pdfopt_proc_one(k2settings,fullname,SRCROT_AUTO,k2out);
                    else
                        rot=0.;
                    }
                else
                    rot=k2settings->src_rot < -990. ? 0. : k2settings->src_rot;
                if (process)
                    k2pdfopt_proc_one(k2settings,fullname,rot,k2out);
                if (!process || k2out->status==0)
                    k2out->filecount++;
#ifdef HAVE_K2GUI
                if (process && k2gui_active())
                    {
                    if (k2out->status!=0)
                        k2gui_cbox_error(filename,k2out->status);
                    else
                        k2gui_cbox_set_files_completed(k2out->filecount,NULL);
                    }
#endif
                }
            }
        filelist_free(fl);
        if (nbmp==0)
            return;
        }
    if (autorot)
        {
        if (process)
            rot=k2pdfopt_proc_one(k2settings,filename,SRCROT_AUTO,k2out);
        else
            rot=0.;
        }
    else
        rot=k2settings->src_rot < -990. ? 0. : k2settings->src_rot;
    if (process)
        k2pdfopt_proc_one(k2settings,filename,rot,k2out);
    if (!process || k2out->status==0)
        k2out->filecount++;
#ifdef HAVE_K2GUI
    if (process && k2gui_active())
        {
        if (k2out->status!=0)
            k2gui_cbox_error(filename,k2out->status);
        else
            k2gui_cbox_set_files_completed(k2out->filecount,NULL);
        }
#endif
    }
예제 #4
0
/*
** Put up dialog box and begin conversion
**
**     0 okay
**    -1 dialog box already up
**    -2 could not create window
**    -3 could not create conversion thread
**
*/
static int k2gui_cbox_create_dialog_window(K2PDFOPT_CONVERSION *k2conv,STRBUF *env,STRBUF *cmdline,
                                           WILLUSGUIWINDOW *parent,void *hinst)

    {
    WILLUSGUIRECT rect;
    int w,h;
    static void *data[4];
    static char *blabel[]={"Abort","",""};

#if (WILLUSDEBUGX & 0x2000)
printf("@k2gui_cbox_create_dialog_window...\n");
#endif
    if (k2gui_cbox->converting)
        return(-1);
    k2gui_cbox->converting=1;
    k2gui_cbox->hinst=hinst; /* (HINSTANCE)GetModuleHandle(0); */
    willusgui_window_get_rect(parent,&rect);
    w=(rect.right-rect.left)*0.9;
    h=(rect.bottom-rect.top)*0.75;
    k2gui_cbox->mainwin.rect.left = rect.left + ((rect.right-rect.left)-w)/2;
    k2gui_cbox->mainwin.rect.top = rect.top + ((rect.bottom-rect.top)-h)/2;
    k2gui_cbox->mainwin.rect.right = k2gui_cbox->mainwin.rect.left + w - 1;
    k2gui_cbox->mainwin.rect.bottom = k2gui_cbox->mainwin.rect.top + h - 1;
    k2gui_cbox->maxwidth = rect.right-rect.left;
    k2gui_cbox->mf.size = k2gui_cbox->maxwidth/65;
    willusgui_font_get(&k2gui_cbox->mf);
    k2gui_cbox->bf.size = k2gui_cbox->maxwidth/40;
    willusgui_font_get(&k2gui_cbox->bf);
    strbuf_init(&k2gui_cbox->buf);
    k2gui_cbox->rgbcolor=0xb0b0ff;
    k2gui_cbox->hinst=hinst;
    k2gui_osdep_cbox_init(k2gui_cbox,&k2gui_cbox->mainwin,parent,hinst,k2gui_cbox->rgbcolor);
    if (k2gui_cbox->mainwin.handle==NULL)
        {
        k2gui_cbox->converting=0;
        return(-2);
        }
    /*
    ShowWindow(k2gui_cbox->hwnd,SW_SHOW);
    UpdateWindow(k2gui_cbox->hwnd);
    */
    k2gui_cbox_message_box_add_children(blabel,0);
    /* UpdateWindow(k2gui_cbox->hwnd); */
    willusgui_window_set_focus(&k2gui_cbox->control[1]);

    /*
    ** Start new thread to do the conversions
    */
    k2gui_cbox->semaphore = willusgui_semaphore_create_ex("k2pdfopt_conversion",1,1);
    if (k2gui_cbox->semaphore==NULL)
        {
        willusgui_control_enable(&k2gui->mainwin,1);
        k2gui_cbox_destroy();
        k2gui_alertbox(0,"Convert","Cannot create semaphore!");
        k2gui_cbox->converting=0;
        return(-3);
        }
    willusgui_semaphore_status_wait(k2gui_cbox->semaphore);
/*
printf("k2conv=%p\n",k2conv);
printf("k2conv->k2settings=%p\n",&k2conv->k2settings);
*/
    data[0] = (void *)k2conv;
    data[1] = (void *)env;
    data[2] = (void *)cmdline;

    /*
    ** Fork the new thread to k2gui_cbox_start_conversion().
    */
    k2gui_cbox->pid=willusgui_thread_create(k2gui_cbox_start_conversion,(void *)data);
    if (k2gui_cbox->pid==NULL)
        {
        willusgui_semaphore_close(k2gui_cbox->semaphore);
        k2gui_alertbox(0,"Convert","Cannot start conversion thread!");
        willusgui_control_enable(&k2gui->mainwin,1);
        k2gui_cbox_destroy();
        k2gui_cbox->converting=0;
        return(-4);
        }
/*
** Test for Franco Vivona (Ittiandro).  Put in delay to see if it helps the
** conversion not crash.
*/
#ifdef HAVE_WIN32_API
win_sleep(500);
#endif

    return(0);
    }